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();
}
}
}
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);
}
}
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);
}
}
}
Aggregations