Search in sources :

Example 1 with ApacheHttpClient4Executor

use of org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor in project oxAuth by GluuFederation.

the class UmaMultithreadTest method before.

@BeforeClass
public void before() {
    ClientConnectionManager connectoinManager = new PoolingClientConnectionManager();
    final DefaultHttpClient defaultHttpClient = new DefaultHttpClient(connectoinManager);
    final ApacheHttpClient4Executor clientExecutor = new ApacheHttpClient4Executor(defaultHttpClient);
    String url = serverUri + "/oxauth/seam/resource/restv1/oxauth/uma-configuration";
    service = UmaClientFactory.instance().createMetaDataConfigurationService(url, clientExecutor);
}
Also used : PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) ApacheHttpClient4Executor(org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with ApacheHttpClient4Executor

use of org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor 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 ApacheHttpClient4Executor

use of org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor in project oxTrust by GluuFederation.

the class UmaPermissionService method init.

@PostConstruct
public void init() {
    if (this.umaMetadataConfiguration != 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.resourceSetPermissionRegistrationService = UmaClientFactory.instance().createResourceSetPermissionRegistrationService(this.umaMetadataConfiguration, clientExecutor);
            this.rptStatusService = UmaClientFactory.instance().createRptStatusService(this.umaMetadataConfiguration, clientExecutor);
        } else {
            this.resourceSetPermissionRegistrationService = UmaClientFactory.instance().createResourceSetPermissionRegistrationService(this.umaMetadataConfiguration);
            this.rptStatusService = UmaClientFactory.instance().createRptStatusService(this.umaMetadataConfiguration);
        }
    }
}
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)

Example 4 with ApacheHttpClient4Executor

use of org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor 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 5 with ApacheHttpClient4Executor

use of org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor in project oxAuth by GluuFederation.

the class BaseTest method discovery.

@BeforeTest
public void discovery(ITestContext context) throws Exception {
    // Load Form Interaction
    loginFormUsername = context.getCurrentXmlTest().getParameter("loginFormUsername");
    loginFormPassword = context.getCurrentXmlTest().getParameter("loginFormPassword");
    loginFormLoginButton = context.getCurrentXmlTest().getParameter("loginFormLoginButton");
    authorizeFormAllowButton = context.getCurrentXmlTest().getParameter("authorizeFormAllowButton");
    authorizeFormDoNotAllowButton = context.getCurrentXmlTest().getParameter("authorizeFormDoNotAllowButton");
    String resource = context.getCurrentXmlTest().getParameter("swdResource");
    if (StringUtils.isNotBlank(resource)) {
        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);
        configurationEndpoint = openIdConnectDiscoveryResponse.getLinks().get(0).getHref() + "/.well-known/openid-configuration";
        System.out.println("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.getUserInfoEndpoint(), "The userInfoEndPoint is null");
        assertNotNull(response.getJwksUri(), "The jwksUri is null");
        assertNotNull(response.getRegistrationEndpoint(), "The registrationEndpoint 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.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.getIdTokenSigningAlgValuesSupported().size() > 0, "The idTokenSigningAlgValuesSupported is empty");
        assertTrue(response.getRequestObjectSigningAlgValuesSupported().size() > 0, "The requestObjectSigningAlgValuesSupported is empty");
        assertTrue(response.getTokenEndpointAuthMethodsSupported().size() > 0, "The tokenEndpointAuthMethodsSupported is empty");
        assertTrue(response.getClaimsSupported().size() > 0, "The claimsSupported is empty");
        authorizationEndpoint = response.getAuthorizationEndpoint();
        tokenEndpoint = response.getTokenEndpoint();
        userInfoEndpoint = response.getUserInfoEndpoint();
        clientInfoEndpoint = response.getClientInfoEndpoint();
        checkSessionIFrame = response.getCheckSessionIFrame();
        endSessionEndpoint = response.getEndSessionEndpoint();
        jwksUri = response.getJwksUri();
        registrationEndpoint = response.getRegistrationEndpoint();
        idGenEndpoint = response.getIdGenerationEndpoint();
        introspectionEndpoint = response.getIntrospectionEndpoint();
        scopeToClaimsMapping = response.getScopeToClaimsMapping();
        gluuConfigurationEndpoint = determineGluuConfigurationEndpoint(openIdConnectDiscoveryResponse.getLinks().get(0).getHref());
    } else {
        showTitle("Loading configuration endpoints from properties file");
        authorizationEndpoint = context.getCurrentXmlTest().getParameter("authorizationEndpoint");
        tokenEndpoint = context.getCurrentXmlTest().getParameter("tokenEndpoint");
        userInfoEndpoint = context.getCurrentXmlTest().getParameter("userInfoEndpoint");
        clientInfoEndpoint = context.getCurrentXmlTest().getParameter("clientInfoEndpoint");
        checkSessionIFrame = context.getCurrentXmlTest().getParameter("checkSessionIFrame");
        endSessionEndpoint = context.getCurrentXmlTest().getParameter("endSessionEndpoint");
        jwksUri = context.getCurrentXmlTest().getParameter("jwksUri");
        registrationEndpoint = context.getCurrentXmlTest().getParameter("registrationEndpoint");
        configurationEndpoint = context.getCurrentXmlTest().getParameter("configurationEndpoint");
        idGenEndpoint = context.getCurrentXmlTest().getParameter("idGenEndpoint");
        introspectionEndpoint = context.getCurrentXmlTest().getParameter("introspectionEndpoint");
        scopeToClaimsMapping = new HashMap<String, List<String>>();
    }
    authorizationPageEndpoint = determineAuthorizationPageEndpoint(authorizationEndpoint);
}
Also used : ApacheHttpClient4Executor(org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor) List(java.util.List) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

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