Search in sources :

Example 31 with Client

use of com.aliyun.dysmsapi20170525.Client in project ORCID-Source by ORCID.

the class JpaJaxbClientAdapterTest method getClient.

private Client getClient() {
    Client client = new Client();
    client.setAllowAutoDeprecate(true);
    client.setPersistentTokensEnabled(true);
    client.setClientType(ClientType.CREATOR);
    client.setDescription("description");
    client.setGroupProfileId("group-profile-id");
    client.setId("id");
    client.setName("client-name");
    client.setWebsite("client-website");
    client.setAuthenticationProviderId("authentication-provider-id");
    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");
    rUri1.setRedirectUriType("type-1");
    rUri1.setUriActType("uri-act-type-1");
    rUri1.setUriGeoArea("uri-geo-area-1");
    ClientRedirectUri rUri2 = new ClientRedirectUri();
    Set<ScopePathType> scopes2 = new HashSet<ScopePathType>();
    scopes2.add(ScopePathType.ACTIVITIES_UPDATE);
    rUri2.setPredefinedClientScopes(scopes2);
    rUri2.setRedirectUri("redirect-uri-2");
    rUri2.setRedirectUriType("type-2");
    rUri2.setUriActType("uri-act-type-2");
    rUri2.setUriGeoArea("uri-geo-area-2");
    ClientRedirectUri rUri3 = new ClientRedirectUri();
    Set<ScopePathType> scopes3 = new HashSet<ScopePathType>();
    scopes3.add(ScopePathType.AFFILIATIONS_CREATE);
    rUri3.setPredefinedClientScopes(scopes3);
    rUri3.setRedirectUri("redirect-uri-3");
    rUri3.setRedirectUriType("type-3");
    rUri3.setUriActType("uri-act-type-3");
    rUri3.setUriGeoArea("uri-geo-area-3");
    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 32 with Client

use of com.aliyun.dysmsapi20170525.Client in project ORCID-Source by ORCID.

the class ClientManagerReadOnlyTest method getClientsTest.

@Test
public void getClientsTest() {
    String seed1 = RandomStringUtils.randomAlphanumeric(30);
    String seed2 = RandomStringUtils.randomAlphanumeric(30);
    String seed3 = RandomStringUtils.randomAlphanumeric(30);
    List<ClientDetailsEntity> clients = new ArrayList<ClientDetailsEntity>();
    clients.add(getClientDetailsEntity(seed1));
    clients.add(getClientDetailsEntity(seed2));
    clients.add(getClientDetailsEntity(seed3));
    when(daoMock.findByGroupId(anyString())).thenReturn(clients);
    Set<Client> results = clientManagerReadOnly.getClients("anything");
    assertEquals(3, results.size());
    for (Client client : results) {
        if (client.getId().equals(seed1)) {
            assertEquals(getClient(seed1), client);
        } else if (client.getId().equals(seed2)) {
            assertEquals(getClient(seed2), client);
        } else if (client.getId().equals(seed3)) {
            assertEquals(getClient(seed3), client);
        } else {
            fail("Unknown id " + client.getId());
        }
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Client(org.orcid.jaxb.model.client_v2.Client) Test(org.junit.Test)

Example 33 with Client

use of com.aliyun.dysmsapi20170525.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 34 with Client

use of com.aliyun.dysmsapi20170525.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 35 with Client

use of com.aliyun.dysmsapi20170525.Client in project service-proxy by membrane.

the class RefreshTokenFlow method processWithParameters.

@Override
protected Response processWithParameters() throws Exception {
    if (!verifyClientThroughParams())
        return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "unauthorized_client");
    String username;
    try {
        username = authServer.getRefreshTokenGenerator().getUsername(getRefreshToken());
    } catch (NoSuchElementException ex) {
        return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_request");
    }
    params.put(ParamNames.USERNAME, username);
    try {
        authServer.getRefreshTokenGenerator().invalidateToken(getRefreshToken(), getClientId(), getClientSecret());
    } catch (NoSuchElementException ex) {
        return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_grant");
    }
    // TODO check if scope is "narrower" than before
    Client client;
    try {
        synchronized (authServer.getClientList()) {
            client = authServer.getClientList().getClient(getClientId());
        }
    } catch (Exception e) {
        return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_client");
    }
    String grantTypes = client.getGrantTypes();
    if (!grantTypes.contains(getGrantType())) {
        return OAuth2Util.createParameterizedJsonErrorResponse(exc, jsonGen, "error", "invalid_grant_type");
    }
    scope = getScope();
    token = authServer.getTokenGenerator().getToken(getUsername(), getClientId(), getClientSecret());
    refreshToken = authServer.getRefreshTokenGenerator().getToken(getUsername(), getClientId(), getClientSecret());
    SessionManager.Session session = getSessionForAuthorizedUserWithParams();
    synchronized (session) {
        session.getUserAttributes().put(ACCESS_TOKEN, token);
    }
    authServer.getSessionFinder().addSessionForToken(token, session);
    if (OAuth2Util.isOpenIdScope(scope)) {
        idToken = createSignedIdToken(session, username, client);
    }
    return new NoResponse();
}
Also used : SessionManager(com.predic8.membrane.core.interceptor.authentication.session.SessionManager) Client(com.predic8.membrane.core.interceptor.oauth2.Client) NoResponse(com.predic8.membrane.core.interceptor.oauth2.request.NoResponse) NoSuchElementException(java.util.NoSuchElementException) JoseException(org.jose4j.lang.JoseException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

Client (org.orcid.jaxb.model.client_v2.Client)18 Test (org.junit.Test)13 Client (com.aliyun.dysmsapi20170525.Client)12 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)10 Client (com.predic8.membrane.core.interceptor.oauth2.Client)9 Config (com.aliyun.teaopenapi.models.Config)7 HashSet (java.util.HashSet)6 ClientRedirectUri (org.orcid.jaxb.model.client_v2.ClientRedirectUri)6 SessionManager (com.predic8.membrane.core.interceptor.authentication.session.SessionManager)5 BaseTest (org.orcid.core.BaseTest)5 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)5 SendSmsRequest (com.aliyun.dysmsapi20170525.models.SendSmsRequest)3 NoResponse (com.predic8.membrane.core.interceptor.oauth2.request.NoResponse)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 SendSmsResponse (com.aliyun.dysmsapi20170525.models.SendSmsResponse)2 Client (com.aliyun.ons20190214.Client)2 OnsTopicListRequest (com.aliyun.ons20190214.models.OnsTopicListRequest)2 OnsTopicListResponse (com.aliyun.ons20190214.models.OnsTopicListResponse)2