示例#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;
  }
示例#2
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;
  }
示例#3
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();
 }