Search in sources :

Example 6 with ApacheHttpClient43Engine

use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine in project eap-additional-testsuite by jboss-set.

the class ApacheHttpClient432TestCase method apacheHttpClient4EngineServletTest.

@Test
@OperateOnDeployment(DEPLOYMENT)
public void apacheHttpClient4EngineServletTest(@ArquillianResource URL url) throws Exception {
    SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).setSoReuseAddress(true).build();
    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
    connManager.setMaxTotal(100);
    connManager.setDefaultMaxPerRoute(100);
    connManager.setDefaultSocketConfig(socketConfig);
    RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(2000).setConnectTimeout(100).setConnectionRequestTimeout(3000).setStaleConnectionCheckEnabled(true).build();
    CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).setConnectionManager(connManager).build();
    final ClientHttpEngine executor;
    executor = new ApacheHttpClient43Engine(httpClient);
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(executor).build();
    final ApacheHttpClient43Resource proxy = client.target("http://127.0.0.1:8080/" + ApacheHttpClient432TestCase.class.getSimpleName()).proxy(ApacheHttpClient43Resource.class);
    WebTarget target = client.target("http://127.0.0.1:8080/" + ApacheHttpClient432TestCase.class.getSimpleName() + "/test2");
    Response response = target.request().get();
    Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
    try {
        Response s = proxy.get();
        assertEquals(200, s.getStatus());
    } catch (ProcessingException e) {
        logger.warn("Exception occured." + e);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) SocketConfig(org.apache.http.config.SocketConfig) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Response(javax.ws.rs.core.Response) ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) ApacheHttpClient43Resource(org.jboss.additional.testsuite.jdkall.present.jaxrs.client.resource.ApacheHttpClient43Resource) WebTarget(javax.ws.rs.client.WebTarget) ProcessingException(javax.ws.rs.ProcessingException) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 7 with ApacheHttpClient43Engine

use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine in project eap-additional-testsuite by jboss-set.

the class ApacheHttpClient43TestCase method createEngine.

@SuppressWarnings(value = "unchecked")
private ResteasyClient createEngine(Class engine) {
    RequestConfig reqConfig = // apache HttpClient specific
    RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).setConnectionRequestTimeout(5000).build();
    CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(reqConfig).setMaxConnTotal(3).build();
    final ClientHttpEngine executor;
    if (engine.isAssignableFrom(ApacheHttpClient43Engine.class)) {
        executor = new ApacheHttpClient43Engine(httpClient);
    } else {
        executor = new URLConnectionEngine();
    }
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(executor).build();
    return client;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine) URLConnectionEngine(org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine)

Example 8 with ApacheHttpClient43Engine

use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine in project oxAuth by GluuFederation.

the class ConfigurationRestWebServiceHttpTest method requestOpenIdConfiguration.

@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 ApacheHttpClient43Engine(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);
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) OpenIdConnectDiscoveryClient(org.gluu.oxauth.client.OpenIdConnectDiscoveryClient) OpenIdConfigurationClient(org.gluu.oxauth.client.OpenIdConfigurationClient) OpenIdConnectDiscoveryResponse(org.gluu.oxauth.client.OpenIdConnectDiscoveryResponse) OpenIdConfigurationResponse(org.gluu.oxauth.client.OpenIdConfigurationResponse) List(java.util.List) Map(java.util.Map) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine) Parameters(org.testng.annotations.Parameters) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Example 9 with ApacheHttpClient43Engine

use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine in project oxAuth by GluuFederation.

the class TokenBindingHttpTest method requestAuthorization.

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 ApacheHttpClient43Engine(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;
}
Also used : AuthorizationRequest(org.gluu.oxauth.client.AuthorizationRequest) AuthorizeClient(org.gluu.oxauth.client.AuthorizeClient) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine) AuthorizationResponse(org.gluu.oxauth.client.AuthorizationResponse)

Example 10 with ApacheHttpClient43Engine

use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine in project oxAuth by GluuFederation.

the class TokenBindingHttpTest method registerClient.

private RegisterResponse registerClient(final String redirectUris, final List<ResponseType> responseTypes, final List<GrantType> grantTypes, final String sectorIdentifierUri) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setResponseTypes(responseTypes);
    registerRequest.setGrantTypes(grantTypes);
    registerRequest.addCustomAttribute("oxAuthTrustedClient", "true");
    // token binding hash for cnf
    registerRequest.setIdTokenTokenBindingCnf(JwtClaimName.TOKEN_BINDING_HASH);
    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setExecutor(new ApacheHttpClient43Engine(createHttpClientTrustAll()));
    registerClient.setRequest(registerRequest);
    RegisterResponse registerResponse = registerClient.exec();
    showClient(registerClient);
    assertEquals(registerResponse.getStatus(), 200, "Unexpected response code: " + registerResponse.getEntity());
    assertNotNull(registerResponse.getClientId());
    assertNotNull(registerResponse.getClientSecret());
    assertNotNull(registerResponse.getRegistrationAccessToken());
    assertNotNull(registerResponse.getClientIdIssuedAt());
    assertNotNull(registerResponse.getClientSecretExpiresAt());
    return registerResponse;
}
Also used : RegisterRequest(org.gluu.oxauth.client.RegisterRequest) RegisterResponse(org.gluu.oxauth.client.RegisterResponse) RegisterClient(org.gluu.oxauth.client.RegisterClient) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine)

Aggregations

ApacheHttpClient43Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine)12 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)5 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)4 RequestConfig (org.apache.http.client.config.RequestConfig)3 BaseTest (org.gluu.oxauth.BaseTest)3 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)3 Parameters (org.testng.annotations.Parameters)3 IOException (java.io.IOException)2 HttpClient (org.apache.http.client.HttpClient)2 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)2 AuthorizationRequest (org.gluu.oxauth.client.AuthorizationRequest)2 AuthorizationResponse (org.gluu.oxauth.client.AuthorizationResponse)2 AuthorizeClient (org.gluu.oxauth.client.AuthorizeClient)2 OpenIdConfigurationClient (org.gluu.oxauth.client.OpenIdConfigurationClient)2 OpenIdConfigurationResponse (org.gluu.oxauth.client.OpenIdConfigurationResponse)2 OpenIdConnectDiscoveryClient (org.gluu.oxauth.client.OpenIdConnectDiscoveryClient)2 OpenIdConnectDiscoveryResponse (org.gluu.oxauth.client.OpenIdConnectDiscoveryResponse)2 TokenClient (org.gluu.oxauth.client.TokenClient)2 TokenResponse (org.gluu.oxauth.client.TokenResponse)2 ClientHttpEngine (org.jboss.resteasy.client.jaxrs.ClientHttpEngine)2