示例#1
0
  private SSLContext getSslContext(final Client client, final Configuration config) {
    final SslConfigurator sslConfigurator =
        PropertiesHelper.getValue(
            config.getProperties(), JettyClientProperties.SSL_CONFIG, SslConfigurator.class, null);

    return sslConfigurator != null ? sslConfigurator.createSSLContext() : client.getSslContext();
  }
 /**
  * @return
  * @throws KeyStoreException
  * @throws IOException
  * @throws NoSuchAlgorithmException
  * @throws CertificateException
  * @throws KeyManagementException
  * @throws UnrecoverableKeyException
  */
 public SSLContext getSSLContext()
     throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException,
         KeyManagementException, UnrecoverableKeyException {
   SslConfigurator sslConfig =
       SslConfigurator.newInstance()
           .trustStoreFile(config.getTrustStore().getFile())
           .trustStorePassword(config.getTrustStore().getPassword())
           .trustStoreType(config.getTrustStore().getType())
           .keyStoreFile(config.getKeyStore().getFile())
           .keyPassword(config.getKeyStore().getPassword())
           .keyStoreType(config.getKeyStore().getType())
           .securityProtocol("TLS");
   return sslConfig.createSSLContext();
 }
示例#3
0
 /**
  * Get a new instance of a {@link SSLContext} configured using default configuration settings.
  *
  * <p>If {@code readSystemProperties} parameter is set to {@code true}, the default SSL
  * configuration is initialized from system properties.
  *
  * @param readSystemProperties if {@code true}, the default SSL context will be initialized using
  *     system properties.
  * @return new instance of a default SSL context initialized from system properties.
  */
 public static SSLContext getDefaultContext(boolean readSystemProperties) {
   if (readSystemProperties) {
     return new SslConfigurator(true).createSSLContext();
   } else {
     return DEFAULT_CONFIG_NO_PROPS.createSSLContext();
   }
 }
示例#4
0
  private static SslConfigurator getSslConfigurator() {
    final String trustStore;
    if (System.getProperty("javax.net.ssl.trustStore") != null) {
      trustStore = System.getProperty("javax.net.ssl.trustStore");
    } else {
      trustStore = "C:" + File.separator + "FiddlerKeystore.jks";
    }

    final String trustStorePassword;
    if (System.getProperty("javax.net.ssl.trustStorePassword") != null) {
      trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");
    } else {
      trustStorePassword = "******";
    }

    final SslConfigurator sslConfigurator =
        SslConfigurator.newInstance()
            .trustStoreFile(trustStore)
            .trustStorePassword(trustStorePassword)
            .trustStoreType("JKS")
            .trustManagerFactoryAlgorithm("PKIX")
            .securityProtocol("SSL");

    return sslConfigurator;
  }
示例#5
0
  /**
   * The response entity from message service is
   * {"statusCode":"000000","templateSMS":{"dateCreated":"20140827105250",
   * "smsMessageSid":"20140827105250065847"}}
   *
   * @param phoneNumber
   * @return
   * @throws NoSuchAlgorithmException
   * @throws UnsupportedEncodingException
   */
  @GET
  @Path("registration/sms")
  @Produces(MediaType.APPLICATION_JSON)
  public Response sendVerifyMessageToMobile(@QueryParam("phoneNumber") String phoneNumber)
      throws NoSuchAlgorithmException, UnsupportedEncodingException {
    if (phoneNumber == null) {
      return Response.ok(
              new PhoneVerifyResponse(
                  AuthenticationConstants.MESSAGESENDFAILURE,
                  "Parameter phoneNumber provided is null",
                  null))
          .build();
    }
    Properties tzProperties = PropertiesUtils.getProperties(servletConfig.getServletContext());
    SslConfigurator sslConfig =
        SslConfigurator.newInstance()
            .trustStoreFile(tzProperties.getProperty("ssl.trust.store.file"))
            .trustStorePassword(tzProperties.getProperty("ssl.trust.store.pass"))
            .trustStoreType("JKS")
            .trustManagerFactoryAlgorithm("PKIX")
            .keyStoreFile(tzProperties.getProperty("ssl.key.store.file"))
            .keyPassword(tzProperties.getProperty("ssl.key.store.pass"))
            .keyStoreType("JKS")
            .keyManagerFactoryAlgorithm("SunX509")
            .keyStoreProvider("SUN")
            .securityProtocol("SSL");

    SSLContext sslContext = sslConfig.createSSLContext();
    Client client = ClientBuilder.newBuilder().sslContext(sslContext).build();

    WebTarget target = client.target(tzProperties.getProperty("mobile.verify.service"));
    String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
    String accountSid = tzProperties.getProperty("mobile.account.sid");
    String encodeString = accountSid + tzProperties.getProperty("mobile.auth.token") + timeStamp;
    String authenticationString = accountSid + ":" + timeStamp;
    String sig = new EncryptUtil().md5Digest(encodeString);

    JsonObjectBuilder messageBuilder = Json.createObjectBuilder();
    JsonArrayBuilder datasBuilder = Json.createArrayBuilder();
    String verificationCode = String.valueOf(VerificationCodeGenerator.randInt(100000, 999999));
    datasBuilder.add(verificationCode).add(tzProperties.getProperty("mobile.code.active.time"));
    messageBuilder
        .add("to", phoneNumber)
        .add("appId", tzProperties.getProperty("mobile.appid"))
        .add("templateId", tzProperties.getProperty("mobile.templateid"))
        .add("datas", datasBuilder);

    Response providerResponse =
        target
            .queryParam("sig", sig)
            .request(MediaType.APPLICATION_JSON)
            .header(HttpHeaders.AUTHORIZATION, Base64.encodeAsString(authenticationString))
            .post(Entity.entity(messageBuilder.build(), MediaType.APPLICATION_JSON));
    JsonObject jsonObject = providerResponse.readEntity(JsonObject.class);
    if (jsonObject.getString("statusCode").equals("000000")) {
      TokenHolder.verificationCodeMap.put(phoneNumber, verificationCode);
      return Response.ok(
              new PhoneVerifyResponse(
                  AuthenticationConstants.MESSAGESENDSUCCESS,
                  jsonObject.toString(),
                  verificationCode))
          .build();
    } else {
      return Response.ok(
              new PhoneVerifyResponse(
                  AuthenticationConstants.MESSAGESENDFAILURE, jsonObject.toString(), null))
          .build();
    }
  }