org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor Java Examples

The following examples show how to use org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PublicOpKeyService.java    From oxd with Apache License 2.0 6 votes vote down vote up
public PublicKey getPublicKey(String jwkSetUrl, String keyId) {
    try {
        PublicKey publicKey = null;

        final Pair<String, String> mapKey = new Pair<>(jwkSetUrl, keyId);

        PublicKey cachedKey = cache.getIfPresent(mapKey);
        if (cachedKey != null) {
            LOG.debug("Taken public key from cache, mapKey: " + mapKey);
            return cachedKey;
        }

        JwkClient jwkClient = opClientFactory.createJwkClient(jwkSetUrl);
        jwkClient.setExecutor(new ApacheHttpClient4Executor(httpService.getHttpClient()));

        JwkResponse jwkResponse = jwkClient.exec();
        if (jwkResponse != null && jwkResponse.getStatus() == 200) {
            publicKey = jwkResponse.getPublicKey(keyId);
        }

        return publicKey;
    } catch (Exception e) {
        LOG.error("Failed to fetch public key.", e);
        throw new RuntimeException("Failed to fetch public key.", e);
    }
}
 
Example #2
Source File: Utils.java    From oxAuth with MIT License 5 votes vote down vote up
public static ClientExecutor createTrustAllExecutor() {
    try {
        return new ApacheHttpClient4Executor(createHttpClientTrustAll());
    } catch (Exception e) {
        throw new RuntimeException("Failed to create trust_all executor.", e);
    }
}
 
Example #3
Source File: TokenBindingHttpTest.java    From oxAuth with MIT License 5 votes vote down vote up
private AuthorizationResponse requestAuthorization(
        final String userId, final String userSecret, final String redirectUri, List<ResponseType> responseTypes,
        String clientId, List<String> scopes) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    String nonce = UUID.randomUUID().toString();
    String state = UUID.randomUUID().toString();

    AuthorizationRequest authorizationRequest = new AuthorizationRequest(
            responseTypes, clientId, scopes, redirectUri, nonce);
    authorizationRequest.setState(state);
    authorizationRequest.setAuthUsername(userId);
    authorizationRequest.setAuthPassword(userSecret);
    authorizationRequest.getPrompts().add(Prompt.NONE);

    AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
    authorizeClient.setExecutor(new ApacheHttpClient4Executor(createHttpClientTrustAll()));
    authorizeClient.setRequest(authorizationRequest);
    authorizeClient.getHeaders().put("Sec-Token-Binding", ENCODED_TOKEN_BINDING_MESSAGE);

    AuthorizationResponse authorizationResponse = authorizeClient.exec();
    showClient(authorizeClient);

    assertNotNull(authorizationResponse.getLocation(), "The location is null");
    assertNotNull(authorizationResponse.getAccessToken(), "The access token is null");
    assertNotNull(authorizationResponse.getState(), "The state is null");
    assertNotNull(authorizationResponse.getTokenType(), "The token type is null");
    assertNotNull(authorizationResponse.getExpiresIn(), "The expires in value is null");
    assertNotNull(authorizationResponse.getScope(), "The scope must be null");
    assertNotNull(authorizationResponse.getIdToken(), "The id token must be null");
    return authorizationResponse;
}
 
Example #4
Source File: PingCallbackClient.java    From oxAuth with MIT License 4 votes vote down vote up
/**
 * Creates an executor responsible to process rest calls using special SSL context defined in FAPI-CIBA specs.
 */
private ApacheHttpClient4Executor getApacheHttpClient4ExecutorForMTLS() {
    // Ciphers accepted by FAPI-CIBA specs and OpenJDK.
    String[] ciphers = new String[] { "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" };
    return new ApacheHttpClient4Executor(ClientUtil.createHttpClient("TLSv1.2", ciphers));
}
 
Example #5
Source File: MTSLClientAuthenticationTest.java    From oxAuth with MIT License 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        File jdkJks = new File("u:\\tmp\\ce-ob\\clientkeystore");
        if (!jdkJks.exists()) {
            throw new RuntimeException("Failed to find jks trust store");
        }

        File certificate = new File("u:\\tmp\\ce-ob\\fullchain.p12");
        if (!certificate.exists()) {
            throw new RuntimeException("Failed to find certificate");
        }

        HttpClient httpclient = new DefaultHttpClient();
// truststore
        KeyStore ts = KeyStore.getInstance("JKS", "SUN");
        ts.load(new FileInputStream(jdkJks), "secret".toCharArray());
// if you remove me, you've got 'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated' on missing truststore
        if(0 == ts.size()) throw new IOException("Error loading truststore");
// tmf
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(ts);
// keystore
        KeyStore ks = KeyStore.getInstance("PKCS12", "SunJSSE");
        ks.load(new FileInputStream(certificate), "".toCharArray());
// if you remove me, you've got 'javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated' on missing keystore
        if(0 == ks.size()) throw new IOException("Error loading keystore");
// kmf
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(ks, "".toCharArray());
// SSL
        SSLContext ctx = SSLContext.getInstance("TLS");
        ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
// socket
        SSLSocketFactory socketFactory = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        Scheme sch = new Scheme("https", 443, socketFactory);
        httpclient.getConnectionManager().getSchemeRegistry().register(sch);

        String clientId = "@!D445.22BF.5EF1.0D87!0001!03F2.297D!0008!F599.E2C7";
        String clientSecret = "testClientSecret";

        TokenRequest tokenRequest = new TokenRequest(GrantType.AUTHORIZATION_CODE);
        tokenRequest.setCode("testCode");
        tokenRequest.setRedirectUri("https://ce-ob.gluu.org/cas/login");
        tokenRequest.setAuthUsername(clientId);
        tokenRequest.setAuthPassword(clientSecret);
        tokenRequest.setAuthenticationMethod(AuthenticationMethod.TLS_CLIENT_AUTH);

        TokenClient tokenClient = new TokenClient("https://ce-ob.gluu.org/oxauth/restv1/token");
        tokenClient.setExecutor(new ApacheHttpClient4Executor(httpclient));
        tokenClient.setRequest(tokenRequest);
        TokenResponse tokenResponse = tokenClient.exec();

        System.out.println(tokenResponse);
        showClient(tokenClient);
    }
 
Example #6
Source File: ConfigurationTest.java    From oxAuth with MIT License 4 votes vote down vote up
@Test
@Parameters({"swdResource"})
public void requestOpenIdConfiguration(final String resource) throws Exception {
    showTitle("OpenID Connect Discovery");

    OpenIdConnectDiscoveryClient openIdConnectDiscoveryClient = new OpenIdConnectDiscoveryClient(resource);
    OpenIdConnectDiscoveryResponse openIdConnectDiscoveryResponse = openIdConnectDiscoveryClient.exec(
            new ApacheHttpClient4Executor(createHttpClient(HostnameVerifierType.ALLOW_ALL)));

    showClient(openIdConnectDiscoveryClient);
    assertEquals(openIdConnectDiscoveryResponse.getStatus(), 200, "Unexpected response code");
    assertNotNull(openIdConnectDiscoveryResponse.getSubject());
    assertTrue(openIdConnectDiscoveryResponse.getLinks().size() > 0);

    String configurationEndpoint = openIdConnectDiscoveryResponse.getLinks().get(0).getHref() +
            "/.well-known/openid-configuration";

    showTitle("OpenID Connect Configuration");

    OpenIdConfigurationClient client = new OpenIdConfigurationClient(configurationEndpoint);
    OpenIdConfigurationResponse response = client.execOpenIdConfiguration();

    showClient(client);
    assertEquals(response.getStatus(), 200, "Unexpected response code");
    assertNotNull(response.getIssuer(), "The issuer is null");
    assertNotNull(response.getAuthorizationEndpoint(), "The authorizationEndpoint is null");
    assertNotNull(response.getTokenEndpoint(), "The tokenEndpoint is null");
    assertNotNull(response.getRevocationEndpoint(), "The tokenRevocationEndpoint is null");
    assertNotNull(response.getUserInfoEndpoint(), "The userInfoEndPoint is null");
    assertNotNull(response.getEndSessionEndpoint(), "The endSessionEndpoint is null");
    assertNotNull(response.getJwksUri(), "The jwksUri is null");
    assertNotNull(response.getRegistrationEndpoint(), "The registrationEndpoint is null");

    assertTrue(response.getGrantTypesSupported().size() > 0, "The grantTypesSupported is empty");
    assertTrue(response.getGrantTypesSupported().contains(GrantType.CIBA.getParamName()), "The grantTypes urn:openid:params:grant-type:ciba is null");

    assertNotNull(response.getBackchannelAuthenticationEndpoint(), "The backchannelAuthenticationEndpoint is null");
    assertTrue(response.getBackchannelTokenDeliveryModesSupported().size() > 0, "The backchannelTokenDeliveryModesSupported is empty");
    assertTrue(response.getBackchannelAuthenticationRequestSigningAlgValuesSupported().size() > 0, "The backchannelAuthenticationRequestSigningAlgValuesSupported is empty");
    assertNotNull(response.getBackchannelUserCodeParameterSupported(), "The backchannelUserCodeParameterSupported is null");
}
 
Example #7
Source File: ConfigurationRestWebServiceHttpTest.java    From oxAuth with MIT License 4 votes vote down vote up
@Test
  @Parameters({"swdResource"})
  public void requestOpenIdConfiguration(final String resource) throws Exception {
      showTitle("OpenID Connect Discovery");

      OpenIdConnectDiscoveryClient openIdConnectDiscoveryClient = new OpenIdConnectDiscoveryClient(resource);
      
      CloseableHttpClient httpClient = createHttpClient(HostnameVerifierType.ALLOW_ALL);
      OpenIdConnectDiscoveryResponse openIdConnectDiscoveryResponse;
try {
	openIdConnectDiscoveryResponse = openIdConnectDiscoveryClient.exec(new ApacheHttpClient4Executor(httpClient));
} finally {
	httpClient.close();
}

      showClient(openIdConnectDiscoveryClient);
      assertEquals(openIdConnectDiscoveryResponse.getStatus(), 200, "Unexpected response code");
      assertNotNull(openIdConnectDiscoveryResponse.getSubject());
      assertTrue(openIdConnectDiscoveryResponse.getLinks().size() > 0);

      String configurationEndpoint = openIdConnectDiscoveryResponse.getLinks().get(0).getHref() +
              "/.well-known/openid-configuration";

      showTitle("OpenID Connect Configuration");

      OpenIdConfigurationClient client = new OpenIdConfigurationClient(configurationEndpoint);
      OpenIdConfigurationResponse response = client.execOpenIdConfiguration();

      showClient(client);
      assertEquals(response.getStatus(), 200, "Unexpected response code");
      assertNotNull(response.getIssuer(), "The issuer is null");
      assertNotNull(response.getAuthorizationEndpoint(), "The authorizationEndpoint is null");
      assertNotNull(response.getTokenEndpoint(), "The tokenEndpoint is null");
      assertNotNull(response.getRevocationEndpoint(), "The tokenRevocationEndpoint is null");
      assertNotNull(response.getUserInfoEndpoint(), "The userInfoEndPoint is null");
      assertNotNull(response.getClientInfoEndpoint(), "The clientInfoEndPoint is null");
      assertNotNull(response.getCheckSessionIFrame(), "The checkSessionIFrame is null");
      assertNotNull(response.getEndSessionEndpoint(), "The endSessionEndpoint is null");
      assertNotNull(response.getJwksUri(), "The jwksUri is null");
      assertNotNull(response.getRegistrationEndpoint(), "The registrationEndpoint is null");
      assertNotNull(response.getIntrospectionEndpoint(), "The introspectionEndpoint is null");
      assertNotNull(response.getIdGenerationEndpoint(), "The idGenerationEndpoint is null");

      assertTrue(response.getScopesSupported().size() > 0, "The scopesSupported is empty");
      assertTrue(response.getScopeToClaimsMapping().size() > 0, "The scope to claims mapping is empty");
      assertTrue(response.getResponseTypesSupported().size() > 0, "The responseTypesSupported is empty");
      assertTrue(response.getResponseModesSupported().size() > 0, "The responseModesSupported is empty");
      assertTrue(response.getGrantTypesSupported().size() > 0, "The grantTypesSupported is empty");
      assertTrue(response.getAcrValuesSupported().size() >= 0, "The acrValuesSupported is empty");
      assertTrue(response.getSubjectTypesSupported().size() > 0, "The subjectTypesSupported is empty");
      assertTrue(response.getUserInfoSigningAlgValuesSupported().size() > 0, "The userInfoSigningAlgValuesSupported is empty");
      assertTrue(response.getUserInfoEncryptionAlgValuesSupported().size() > 0, "The userInfoEncryptionAlgValuesSupported is empty");
      assertTrue(response.getUserInfoEncryptionEncValuesSupported().size() > 0, "The userInfoEncryptionEncValuesSupported is empty");
      assertTrue(response.getIdTokenSigningAlgValuesSupported().size() > 0, "The idTokenSigningAlgValuesSupported is empty");
      assertTrue(response.getIdTokenEncryptionAlgValuesSupported().size() > 0, "The idTokenEncryptionAlgValuesSupported is empty");
      assertTrue(response.getIdTokenEncryptionEncValuesSupported().size() > 0, "The idTokenEncryptionEncValuesSupported is empty");
      assertTrue(response.getRequestObjectSigningAlgValuesSupported().size() > 0, "The requestObjectSigningAlgValuesSupported is empty");
      assertTrue(response.getRequestObjectEncryptionAlgValuesSupported().size() > 0, "The requestObjectEncryptionAlgValuesSupported is empty");
      assertTrue(response.getRequestObjectEncryptionEncValuesSupported().size() > 0, "The requestObjectEncryptionEncValuesSupported is empty");
      assertTrue(response.getTokenEndpointAuthMethodsSupported().size() > 0, "The tokenEndpointAuthMethodsSupported is empty");
      assertTrue(response.getTokenEndpointAuthSigningAlgValuesSupported().size() > 0, "The tokenEndpointAuthSigningAlgValuesSupported is empty");

      assertTrue(response.getDisplayValuesSupported().size() > 0, "The displayValuesSupported is empty");
      assertTrue(response.getClaimTypesSupported().size() > 0, "The claimTypesSupported is empty");
      assertTrue(response.getClaimsSupported().size() > 0, "The claimsSupported is empty");
      assertNotNull(response.getServiceDocumentation(), "The serviceDocumentation is null");
      assertTrue(response.getClaimsLocalesSupported().size() > 0, "The claimsLocalesSupported is empty");
      assertTrue(response.getUiLocalesSupported().size() > 0, "The uiLocalesSupported is empty");
      assertTrue(response.getClaimsParameterSupported(), "The claimsParameterSupported is false");
      assertTrue(response.getRequestParameterSupported(), "The requestParameterSupported is false");
      assertTrue(response.getRequestUriParameterSupported(), "The requestUriParameterSupported is false");
      assertFalse(response.getRequireRequestUriRegistration(), "The requireRequestUriRegistration is true");
      assertNotNull(response.getOpPolicyUri(), "The opPolicyUri is null");
      assertNotNull(response.getOpTosUri(), "The opTosUri is null");

      // oxAuth #917: Add dynamic scopes and claims to discovery
      Map<String, List<String>> scopeToClaims = response.getScopeToClaimsMapping();
      List<String> scopesSupported = response.getScopesSupported();
      List<String> claimsSupported = response.getClaimsSupported();
      for (Map.Entry<String, List<String>> scopeEntry : scopeToClaims.entrySet()) {
          assertTrue(scopesSupported.contains(scopeEntry.getKey()),
                  "The scopes supported list does not contain the scope: " + scopeEntry.getKey());
          for (String claimEntry : scopeEntry.getValue()) {
              assertTrue(claimsSupported.contains(claimEntry),
                      "The claims supported list does not contain the claim: " + claimEntry);
          }
      }
  }
 
Example #8
Source File: BaseTest.java    From oxAuth with MIT License 4 votes vote down vote up
public static ClientExecutor clientExecutor(boolean trustAll) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
    if (trustAll) {
        return new ApacheHttpClient4Executor(createHttpClientTrustAll());
    }
    return ClientRequest.getDefaultExecutor();
}
 
Example #9
Source File: HttpService.java    From oxd with Apache License 2.0 4 votes vote down vote up
public ClientExecutor getClientExecutor() {
    return new ApacheHttpClient4Executor(getHttpClient());
}