Search in sources :

Example 1 with ClientExecutor

use of org.jboss.resteasy.client.ClientExecutor in project oxAuth by GluuFederation.

the class TestSessionWorkflow method test.

@Parameters({ "userId", "userSecret", "clientId", "clientSecret", "redirectUri" })
@Test
public void test(final String userId, final String userSecret, final String clientId, final String clientSecret, final String redirectUri) throws Exception {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    try {
        CookieStore cookieStore = new BasicCookieStore();
        httpClient.setCookieStore(cookieStore);
        ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient);
        ////////////////////////////////////////////////
        //             TV side. Code 1                //
        ////////////////////////////////////////////////
        AuthorizationRequest authorizationRequest1 = new AuthorizationRequest(Arrays.asList(ResponseType.CODE), clientId, Arrays.asList("openid", "profile", "email"), redirectUri, null);
        authorizationRequest1.setAuthUsername(userId);
        authorizationRequest1.setAuthPassword(userSecret);
        authorizationRequest1.getPrompts().add(Prompt.NONE);
        authorizationRequest1.setState("af0ifjsldkj");
        authorizationRequest1.setRequestSessionState(true);
        AuthorizeClient authorizeClient1 = new AuthorizeClient(authorizationEndpoint);
        authorizeClient1.setRequest(authorizationRequest1);
        AuthorizationResponse authorizationResponse1 = authorizeClient1.exec(clientExecutor);
        //        showClient(authorizeClient1, cookieStore);
        String code1 = authorizationResponse1.getCode();
        String sessionState = authorizationResponse1.getSessionState();
        Assert.assertNotNull("code1 is null", code1);
        Assert.assertNotNull("sessionState is null", sessionState);
        // TV sends the code to the Backend
        // We don't use httpClient and cookieStore during this call
        ////////////////////////////////////////////////
        //             Backend  1 side. Code 1        //
        ////////////////////////////////////////////////
        // Get the access token
        TokenClient tokenClient1 = new TokenClient(tokenEndpoint);
        TokenResponse tokenResponse1 = tokenClient1.execAuthorizationCode(code1, redirectUri, clientId, clientSecret);
        String accessToken1 = tokenResponse1.getAccessToken();
        Assert.assertNotNull("accessToken1 is null", accessToken1);
        // Get the user's claims
        UserInfoClient userInfoClient1 = new UserInfoClient(userInfoEndpoint);
        UserInfoResponse userInfoResponse1 = userInfoClient1.execUserInfo(accessToken1);
        Assert.assertTrue("userInfoResponse1.getStatus() is not 200", userInfoResponse1.getStatus() == 200);
        //        System.out.println(userInfoResponse1.getEntity());
        ////////////////////////////////////////////////
        //             TV side. Code 2                //
        ////////////////////////////////////////////////
        AuthorizationRequest authorizationRequest2 = new AuthorizationRequest(Arrays.asList(ResponseType.CODE), clientId, Arrays.asList("openid", "profile", "email"), redirectUri, null);
        authorizationRequest2.getPrompts().add(Prompt.NONE);
        authorizationRequest2.setState("af0ifjsldkj");
        authorizationRequest2.setSessionState(sessionState);
        AuthorizeClient authorizeClient2 = new AuthorizeClient(authorizationEndpoint);
        authorizeClient2.setRequest(authorizationRequest2);
        AuthorizationResponse authorizationResponse2 = authorizeClient2.exec(clientExecutor);
        //        showClient(authorizeClient2, cookieStore);
        String code2 = authorizationResponse2.getCode();
        Assert.assertNotNull("code2 is null", code2);
        // TV sends the code to the Backend
        // We don't use httpClient and cookieStore during this call
        ////////////////////////////////////////////////
        //             Backend  2 side. Code 2        //
        ////////////////////////////////////////////////
        // Get the access token
        TokenClient tokenClient2 = new TokenClient(tokenEndpoint);
        TokenResponse tokenResponse2 = tokenClient2.execAuthorizationCode(code2, redirectUri, clientId, clientSecret);
        String accessToken2 = tokenResponse2.getAccessToken();
        Assert.assertNotNull("accessToken2 is null", accessToken2);
        // Get the user's claims
        UserInfoClient userInfoClient2 = new UserInfoClient(userInfoEndpoint);
        UserInfoResponse userInfoResponse2 = userInfoClient2.execUserInfo(accessToken2);
        Assert.assertTrue("userInfoResponse1.getStatus() is not 200", userInfoResponse2.getStatus() == 200);
    //        System.out.println(userInfoResponse2.getEntity());
    } finally {
        if (httpClient != null) {
            httpClient.getConnectionManager().shutdown();
        }
    }
}
Also used : ApacheHttpClient4Executor(org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor) ClientExecutor(org.jboss.resteasy.client.ClientExecutor) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) CookieStore(org.apache.http.client.CookieStore) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 2 with ClientExecutor

use of org.jboss.resteasy.client.ClientExecutor in project oxAuth by GluuFederation.

the class OpenIdConnectDiscoveryAction method exec.

public void exec() {
    try {
        ClientExecutor clientExecutor = null;
        if (acceptUntrustedCertificate) {
            HttpClient httpClient = new SslDefaultHttpClient(new TrustAllTrustManager());
            clientExecutor = new ApacheHttpClient4Executor(httpClient);
        }
        OpenIdConnectDiscoveryRequest openIdConnectDiscoveryRequest = new OpenIdConnectDiscoveryRequest(resource);
        host = openIdConnectDiscoveryRequest.getHost();
        rel = REL_VALUE;
        OpenIdConnectDiscoveryClient openIdConnectDiscoveryClient = new OpenIdConnectDiscoveryClient(resource);
        OpenIdConnectDiscoveryResponse openIdConnectDiscoveryResponse;
        if (clientExecutor == null) {
            openIdConnectDiscoveryResponse = openIdConnectDiscoveryClient.exec();
        } else {
            openIdConnectDiscoveryResponse = openIdConnectDiscoveryClient.exec(clientExecutor);
        }
        showResults = true;
        requestString1 = openIdConnectDiscoveryClient.getRequestAsString();
        responseString1 = openIdConnectDiscoveryClient.getResponseAsString();
        if (openIdConnectDiscoveryResponse.getStatus() == 200) {
            String openIdConfigurationUrl = openIdConnectDiscoveryResponse.getLinks().get(0).getHref() + "/.well-known/openid-configuration";
            OpenIdConfigurationClient openIdConfigurationClient = new OpenIdConfigurationClient(openIdConfigurationUrl);
            OpenIdConfigurationResponse openIdConfigurationResponse;
            if (clientExecutor == null) {
                openIdConfigurationResponse = openIdConfigurationClient.execOpenIdConfiguration();
            } else {
                openIdConfigurationResponse = openIdConfigurationClient.execOpenIdConfiguration(clientExecutor);
            }
            requestString2 = openIdConfigurationClient.getRequestAsString();
            responseString2 = openIdConfigurationClient.getResponseAsString();
            registrationAction.setRegistrationEndpoint(openIdConfigurationResponse.getRegistrationEndpoint());
            authorizationAction.setAuthorizationEndpoint(openIdConfigurationResponse.getAuthorizationEndpoint());
            authorizationAction.setJwksUri(openIdConfigurationResponse.getJwksUri());
            tokenAction.setTokenEndpoint(openIdConfigurationResponse.getTokenEndpoint());
            userInfoAction.setUserInfoEndpoint(openIdConfigurationResponse.getUserInfoEndpoint());
            checkSessionAction.setCheckSessionEndpoint(openIdConfigurationResponse.getCheckSessionIFrame());
            endSessionAction.setEndSessionEndpoint(openIdConfigurationResponse.getEndSessionEndpoint());
        }
    } catch (IllegalArgumentException e) {
        log.error(e.getMessage(), e);
    } catch (URISyntaxException e) {
        log.error(e.getMessage(), e);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : SslDefaultHttpClient(org.xdi.net.SslDefaultHttpClient) ApacheHttpClient4Executor(org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor) OpenIdConnectDiscoveryClient(org.xdi.oxauth.client.OpenIdConnectDiscoveryClient) ClientExecutor(org.jboss.resteasy.client.ClientExecutor) OpenIdConnectDiscoveryResponse(org.xdi.oxauth.client.OpenIdConnectDiscoveryResponse) TrustAllTrustManager(org.xdi.net.TrustAllTrustManager) URISyntaxException(java.net.URISyntaxException) URISyntaxException(java.net.URISyntaxException) OpenIdConnectDiscoveryRequest(org.xdi.oxauth.client.OpenIdConnectDiscoveryRequest) OpenIdConfigurationClient(org.xdi.oxauth.client.OpenIdConfigurationClient) SslDefaultHttpClient(org.xdi.net.SslDefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) OpenIdConfigurationResponse(org.xdi.oxauth.client.OpenIdConfigurationResponse)

Example 3 with ClientExecutor

use of org.jboss.resteasy.client.ClientExecutor in project oxTrust by GluuFederation.

the class UmaPermissionService method init.

@PostConstruct
public void init() {
    if (this.umaMetadata != null) {
        if (appConfiguration.isRptConnectionPoolUseConnectionPooling()) {
            // For more information about PoolingHttpClientConnectionManager, please see:
            // http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/index.html?org/apache/http/impl/conn/PoolingHttpClientConnectionManager.html
            log.info("##### Initializing custom ClientExecutor...");
            PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
            connectionManager.setMaxTotal(appConfiguration.getRptConnectionPoolMaxTotal());
            connectionManager.setDefaultMaxPerRoute(appConfiguration.getRptConnectionPoolDefaultMaxPerRoute());
            connectionManager.setValidateAfterInactivity(appConfiguration.getRptConnectionPoolValidateAfterInactivity() * 1000);
            CloseableHttpClient client = HttpClients.custom().setKeepAliveStrategy(connectionKeepAliveStrategy).setConnectionManager(connectionManager).build();
            ClientExecutor clientExecutor = new ApacheHttpClient4Executor(client);
            log.info("##### Initializing custom ClientExecutor DONE");
            this.permissionService = UmaClientFactory.instance().createPermissionService(this.umaMetadata, clientExecutor);
            this.rptStatusService = UmaClientFactory.instance().createRptStatusService(this.umaMetadata, clientExecutor);
        } else {
            this.permissionService = UmaClientFactory.instance().createPermissionService(this.umaMetadata);
            this.rptStatusService = UmaClientFactory.instance().createRptStatusService(this.umaMetadata);
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ApacheHttpClient4Executor(org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor) ClientExecutor(org.jboss.resteasy.client.ClientExecutor) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ClientExecutor (org.jboss.resteasy.client.ClientExecutor)3 ApacheHttpClient4Executor (org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor)3 URISyntaxException (java.net.URISyntaxException)1 PostConstruct (javax.annotation.PostConstruct)1 CookieStore (org.apache.http.client.CookieStore)1 HttpClient (org.apache.http.client.HttpClient)1 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1 SslDefaultHttpClient (org.xdi.net.SslDefaultHttpClient)1 TrustAllTrustManager (org.xdi.net.TrustAllTrustManager)1 BaseTest (org.xdi.oxauth.BaseTest)1 OpenIdConfigurationClient (org.xdi.oxauth.client.OpenIdConfigurationClient)1 OpenIdConfigurationResponse (org.xdi.oxauth.client.OpenIdConfigurationResponse)1 OpenIdConnectDiscoveryClient (org.xdi.oxauth.client.OpenIdConnectDiscoveryClient)1 OpenIdConnectDiscoveryRequest (org.xdi.oxauth.client.OpenIdConnectDiscoveryRequest)1 OpenIdConnectDiscoveryResponse (org.xdi.oxauth.client.OpenIdConnectDiscoveryResponse)1