Exemplo n.º 1
0
  @Override
  public String getDocumentAccess(Long nID_Access, String sSecret) throws Exception {
    Session oSession = getSession();

    DocumentAccess docAcc = new DocumentAccess();
    List<DocumentAccess> list = findAll();
    if (list == null || list.isEmpty()) {
      throw new Exception("Access not accepted!");
    } else {
      for (DocumentAccess da : list) {
        if (da.getId() == nID_Access && da.getSecret().equals(sSecret)) {
          docAcc = da;
          break;
        }
      }
    }
    String sTelephone = "";
    if (docAcc.getTelephone() != null) {
      sTelephone = docAcc.getTelephone();
    }
    String sAnswer = SecurityUtils.generateAnswer();
    docAcc.setAnswer(sAnswer);
    String otpPassword = getOtpPassword(docAcc);
    return otpPassword;
  }
Exemplo n.º 2
0
 @Override
 public String setDocumentAccess(Long nID_Access, String sSecret, String sAnswer)
     throws Exception {
   Session oSession = getSession();
   DocumentAccess docAcc =
       (DocumentAccess)
           createCriteria()
               .add(Restrictions.eq("nID", nID_Access))
               .add(Restrictions.eq("sSecret", sSecret))
               .add(Restrictions.eq("sAnswer", sAnswer))
               .uniqueResult();
   if (docAcc == null) {
     throw new Exception("Access not accepted!");
   } else {
     oSession.saveOrUpdate(docAcc);
   }
   return docAcc.toString();
 }
Exemplo n.º 3
0
 @Override
 public DocumentAccess getDocumentLink(Long nID_Access, String sSecret) {
   Session oSession = getSession();
   List<DocumentAccess> list = null;
   DocumentAccess docAcc = null;
   try {
     list = (List<DocumentAccess>) oSession.createCriteria(DocumentAccess.class).list();
     for (DocumentAccess da : list) {
       if (da.getId() == nID_Access && da.getSecret().equals(sSecret)) {
         docAcc = da;
         break;
       }
     }
   } catch (Exception e) {
     throw e;
   }
   return docAcc;
 }
Exemplo n.º 4
0
  @Override
  public String sSentDocumentAccessOTP_Phone(String sCode) throws Exception {
    String sPhoneSent = null;
    // Session oSession = getSession();
    boolean bSent = false;
    DocumentAccess oDocumentAccess = findBy("sCode", sCode).orNull();
    if (oDocumentAccess.getTelephone() != null
        && oDocumentAccess.getTelephone().trim().length() > 6) {
      String sPhone = oDocumentAccess.getTelephone();
      sPhoneSent = sPhone;
      log.info("[bSentDocumentAccessOTP]sPhone=" + sPhone);

      String sAnswer = SecurityUtils.generateAnswer();
      log.info("[bSentDocumentAccessOTP]sAnswer=" + sAnswer);

      // o.setDateAnswerExpire(null);
      // SEND SMS with this code
      String sReturn;
      if (generalConfig.bTest()) {
        sAnswer = "4444";
      }
      oDocumentAccess.setAnswer(sAnswer);
      //                        writeRow(oDocumentAccess);
      saveOrUpdate(oDocumentAccess);
      log.info("oDocumentAccess.getId()=" + oDocumentAccess.getId() + ":Ok!");

      if (generalConfig.bTest()) {
        sReturn = "test";
      } else {
        sReturn = sendPasswordOTP(sPhone, sAnswer);
      }

      log.info("[bSentDocumentAccessOTP]sReturn=" + sReturn);

      bSent = true;
    } else {
      // TODO loging warn
    }
    // return  bSent;
    return sPhoneSent;
  }
Exemplo n.º 5
0
  @Override
  public String setDocumentLink(
      Long nID_Document, String sFIO, String sTarget, String sTelephone, Long nMS, String sMail)
      throws Exception {
    DocumentAccess oDocumentAccess = new DocumentAccess();
    oDocumentAccess.setID_Document(nID_Document);
    oDocumentAccess.setDateCreate(new DateTime());
    oDocumentAccess.setMS(nMS);
    oDocumentAccess.setFIO(sFIO);
    oDocumentAccess.setMail(sMail);
    oDocumentAccess.setTarget(sTarget);
    oDocumentAccess.setTelephone(sTelephone);
    oDocumentAccess.setSecret(SecurityUtils.generateSecret());

    //		String id = writeRow(oDocumentAccess).toString();

    if (oDocumentAccess.getsCode() == null) oDocumentAccess.setsCode("null");
    if (oDocumentAccess.getsCodeType() == null) oDocumentAccess.setsCodeType("null");

    saveOrUpdate(oDocumentAccess);

    String id = oDocumentAccess.getId().toString();
    log.info("id=" + id);

    // sCode;sCodeType
    oDocumentAccess.setsCode(id);
    oDocumentAccess.setsCodeType((sTelephone != null && sTelephone.length() > 6) ? "sms" : "");
    //		writeRow(oDocumentAccess);
    saveOrUpdate(oDocumentAccess);
    log.info("id=" + id + ":Ok!");

    /*StringBuilder osURL = new StringBuilder(sURL);
          osURL.append("nID_Access=");
    osURL.append(getIdAccess()+"&");
    osURL.append("sSecret=");
    osURL.append(oDocumentAccess.getSecret());*/
    // return osURL.toString();

    if (sMail != null && !"".equals(sMail.trim())) {
      String saToMail = sMail;
      String sHead = "Доступ до документу";
      String sBody =
          "Вам надано доступ до документу на Порталі державних послуг iGov.org.ua.<br>"
              + "<br>"
              + "<b>Код документу:</b> %"
              + id
              + "%<br>"
              + "<br>"
              + "Щоб переглянути цей документ, зайдіть на <a href=\""
              + generalConfig.sHostCentral()
              + "\">iGov.org.ua</a>, пункт меню <b>Документи</b>, вкладка <b>Пошук документу за кодом</b>. Там оберіть тип документу, того, хто його надає та введіть код.<br>"
              + "<br>"
              + "З повагою,<br>"
              + "команда порталу державних послу iGov";
      oMail.reset();
      oMail._To(saToMail)._Head(sHead)._Body(sBody);
      oMail.send();
    }

    return id;
  }
Exemplo n.º 6
0
 private <T> String getOtpPassword(DocumentAccess docAcc) throws Exception {
   Properties prop = new Properties();
   File file = new File(System.getProperty("catalina.base") + "/conf/merch.properties");
   FileInputStream fis = new FileInputStream(file);
   prop.load(fis);
   OtpPassword otp = new OtpPassword();
   otp.setMerchant_id(prop.getProperty("merchant_id"));
   otp.setMerchant_password(prop.getProperty("merchant_password"));
   fis.close();
   OtpCreate otpCreate = new OtpCreate();
   otpCreate.setCategory("qwerty");
   otpCreate.setFrom("10060");
   if (!docAcc.getTelephone().isEmpty() || docAcc.getTelephone() != null) {
     otpCreate.setPhone(docAcc.getTelephone());
   } else {
     otpCreate.setPhone("null");
   }
   SmsTemplate smsTemplate1 = new SmsTemplate();
   smsTemplate1.setText("text:" + "Parol: ");
   smsTemplate1.setPassword("password:"******"2");
   SmsTemplate smsTemplate2 = new SmsTemplate();
   smsTemplate2.setText("text:" + "-");
   smsTemplate2.setPassword("password:"******"2");
   SmsTemplate smsTemplate3 = new SmsTemplate();
   smsTemplate3.setText("text:" + "-");
   smsTemplate3.setPassword("password:"******"2");
   SmsTemplate smsTemplate4 = new SmsTemplate();
   smsTemplate4.setText("text:" + "-");
   smsTemplate4.setPassword("password:"******"2");
   List<T> list = new ArrayList<T>();
   list.add((T) new OtpText("Parol:"));
   list.add((T) new OtpPass("2"));
   list.add((T) new OtpText("-"));
   list.add((T) new OtpPass("2"));
   list.add((T) new OtpText("-"));
   list.add((T) new OtpPass("2"));
   list.add((T) new OtpText("-"));
   list.add((T) new OtpPass("2"));
   otpCreate.setSms_template(list);
   List<OtpCreate> listOtpCreate = new ArrayList<>();
   listOtpCreate.add(otpCreate);
   otp.setOtp_create(listOtpCreate);
   Gson g = new Gson();
   String jsonObj = g.toJson(otp);
   URL url = new URL(urlConn);
   HttpURLConnection con = (HttpURLConnection) url.openConnection();
   con.setRequestMethod("POST");
   con.setRequestProperty("content-type", "application/json;charset=UTF-8");
   con.setDoOutput(true);
   DataOutputStream dos = new DataOutputStream(con.getOutputStream());
   dos.writeBytes(jsonObj);
   dos.flush();
   dos.close();
   BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
   StringBuilder sb = new StringBuilder();
   String inputLine;
   while ((inputLine = br.readLine()) != null) {
     sb.append(inputLine);
   }
   br.close();
   return sb.toString();
 }