use of com.predic8.membrane.core.interceptor.oauth2.Client in project ORCID-Source by ORCID.
the class ClientManagerTest method resetClientSecret.
@Test
public void resetClientSecret() {
String clientId = "APP-5555555555555556";
// Get an existing client
Client client = clientManagerReadOnly.get(clientId);
assertNotNull(client);
assertNotNull(client.getDecryptedSecret());
assertFalse(PojoUtil.isEmpty(client.getDecryptedSecret()));
assertTrue(client.getDecryptedSecret().length() > 1);
String secret1 = client.getDecryptedSecret();
// Reset it one time
clientManager.resetClientSecret(clientId);
client = clientManagerReadOnly.get(clientId);
assertFalse(PojoUtil.isEmpty(client.getDecryptedSecret()));
assertTrue(client.getDecryptedSecret().length() > 1);
assertNotEquals(secret1, client.getDecryptedSecret());
String secret2 = client.getDecryptedSecret();
// Reset it the second time
clientManager.resetClientSecret(clientId);
client = clientManagerReadOnly.get(clientId);
assertFalse(PojoUtil.isEmpty(client.getDecryptedSecret()));
assertTrue(client.getDecryptedSecret().length() > 1);
assertNotEquals(secret1, client.getDecryptedSecret());
assertNotEquals(secret2, client.getDecryptedSecret());
String secret3 = client.getDecryptedSecret();
// Update the client and fetch secret again to confirm it doesn't changed
client.setName("Updated name");
clientManager.edit(client, false);
client = clientManagerReadOnly.get(clientId);
assertEquals("Updated name", client.getName());
assertFalse(PojoUtil.isEmpty(client.getDecryptedSecret()));
assertTrue(client.getDecryptedSecret().length() > 1);
assertEquals(secret3, client.getDecryptedSecret());
}
use of com.predic8.membrane.core.interceptor.oauth2.Client in project ORCID-Source by ORCID.
the class ClientManagerTest method getClient.
private Client getClient(String randomString, String memberId) {
Client client = new Client();
client.setAllowAutoDeprecate(true);
client.setAuthenticationProviderId("authentication-provider-id " + randomString);
client.setClientType(ClientType.CREATOR);
client.setDescription("description " + randomString);
client.setEmailAccessReason("email-access-reason " + randomString);
client.setGroupProfileId(memberId);
client.setId(randomString);
client.setName("client-name " + randomString);
client.setPersistentTokensEnabled(true);
client.setWebsite("client-website " + randomString);
Set<ClientRedirectUri> clientRedirectUris = new HashSet<ClientRedirectUri>();
ClientRedirectUri rUri1 = new ClientRedirectUri();
Set<ScopePathType> scopes1 = new HashSet<ScopePathType>();
scopes1.add(ScopePathType.ACTIVITIES_READ_LIMITED);
rUri1.setPredefinedClientScopes(scopes1);
rUri1.setRedirectUri("redirect-uri-1 " + randomString);
rUri1.setRedirectUriType("type-1 " + randomString);
rUri1.setUriActType("uri-act-type-1 " + randomString);
rUri1.setUriGeoArea("uri-geo-area-1 " + randomString);
ClientRedirectUri rUri2 = new ClientRedirectUri();
Set<ScopePathType> scopes2 = new HashSet<ScopePathType>();
scopes2.add(ScopePathType.ACTIVITIES_UPDATE);
rUri2.setPredefinedClientScopes(scopes2);
rUri2.setRedirectUri("redirect-uri-2 " + randomString);
rUri2.setRedirectUriType("type-2 " + randomString);
rUri2.setUriActType("uri-act-type-2 " + randomString);
rUri2.setUriGeoArea("uri-geo-area-2 " + randomString);
ClientRedirectUri rUri3 = new ClientRedirectUri();
Set<ScopePathType> scopes3 = new HashSet<ScopePathType>();
scopes3.add(ScopePathType.AFFILIATIONS_CREATE);
rUri3.setPredefinedClientScopes(scopes3);
rUri3.setRedirectUri("redirect-uri-3 " + randomString);
rUri3.setRedirectUriType("type-3 " + randomString);
rUri3.setUriActType("uri-act-type-3 " + randomString);
rUri3.setUriGeoArea("uri-geo-area-3 " + randomString);
clientRedirectUris.add(rUri1);
clientRedirectUris.add(rUri2);
clientRedirectUris.add(rUri3);
client.setClientRedirectUris(clientRedirectUris);
return client;
}
use of com.predic8.membrane.core.interceptor.oauth2.Client in project service-proxy by membrane.
the class LoadBalancingInterceptorTest method testRoundRobinDispachingStrategy.
@Test
public void testRoundRobinDispachingStrategy() throws Exception {
balancingInterceptor.setDispatchingStrategy(roundRobinStrategy);
HttpClient client = new HttpClient();
client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
PostMethod vari = getPostMethod();
int status = client.executeMethod(vari);
// System.out.println(new String(vari.getResponseBody()));
assertEquals(200, status);
assertEquals(1, mockInterceptor1.getCount());
assertEquals(0, mockInterceptor2.getCount());
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(1, mockInterceptor1.getCount());
assertEquals(1, mockInterceptor2.getCount());
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(2, mockInterceptor1.getCount());
assertEquals(1, mockInterceptor2.getCount());
assertEquals(200, client.executeMethod(getPostMethod()));
assertEquals(2, mockInterceptor1.getCount());
assertEquals(2, mockInterceptor2.getCount());
}
use of com.predic8.membrane.core.interceptor.oauth2.Client in project service-proxy by membrane.
the class HttpKeepAliveTest method testConnectionClose.
@Test
public void testConnectionClose() throws Exception {
HttpClient client = createHttpClient(500);
sp1.getInterceptors().add(0, new AbstractInterceptor() {
@Override
public Outcome handleResponse(Exchange exc) throws Exception {
exc.getResponse().getHeader().add(Header.KEEP_ALIVE, "max=2");
return Outcome.CONTINUE;
}
});
// opens connection 1
assertEquals(200, issueRequest(client));
assertEquals(1, set.size());
assertEquals(1, client.getConnectionManager().getNumberInPool());
// connection closer did not yet run
Thread.sleep(600);
// connection 1 is now dead, but still in pool
assertEquals(1, client.getConnectionManager().getNumberInPool());
// opens connection 2
assertEquals(200, issueRequest(client));
assertEquals(2, set.size());
// connection closer runs and closes both
Thread.sleep(600);
assertEquals(0, client.getConnectionManager().getNumberInPool());
}
use of com.predic8.membrane.core.interceptor.oauth2.Client in project service-proxy by membrane.
the class HttpKeepAliveTest method issueRequest.
private int issueRequest(HttpClient client) throws IOException, Exception {
Exchange exchange = createExchange();
Response response = client.call(exchange).getResponse();
response.readBody();
return response.getStatusCode();
}
Aggregations