Search in sources :

Example 31 with Client

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());
}
Also used : Client(org.orcid.jaxb.model.client_v2.Client) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 32 with Client

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;
}
Also used : ClientRedirectUri(org.orcid.jaxb.model.client_v2.ClientRedirectUri) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Client(org.orcid.jaxb.model.client_v2.Client) HashSet(java.util.HashSet)

Example 33 with 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());
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) Test(org.junit.Test) Http11Test(com.predic8.membrane.integration.Http11Test)

Example 34 with Client

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());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Test(org.junit.Test)

Example 35 with Client

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();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response)

Aggregations

Test (org.junit.Test)27 Client (org.orcid.jaxb.model.client_v2.Client)18 Exchange (com.predic8.membrane.core.exchange.Exchange)12 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)10 IOException (java.io.IOException)8 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)6 Outcome (com.predic8.membrane.core.interceptor.Outcome)6 HashSet (java.util.HashSet)6 BaseTest (org.orcid.core.BaseTest)6 ClientRedirectUri (org.orcid.jaxb.model.client_v2.ClientRedirectUri)6 URISyntaxException (java.net.URISyntaxException)5 HttpClient (org.apache.commons.httpclient.HttpClient)5 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)5 Request (com.predic8.membrane.core.http.Request)4 Response (com.predic8.membrane.core.http.Response)4 Process2 (com.predic8.membrane.examples.Process2)4 Http11Test (com.predic8.membrane.integration.Http11Test)4 SessionManager (com.predic8.membrane.core.interceptor.authentication.session.SessionManager)3 Client (com.predic8.membrane.core.interceptor.oauth2.Client)3 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)3