use of com.predic8.membrane.core.interceptor.oauth2.Client in project ORCID-Source by ORCID.
the class ClientManagerReadOnlyTest method getClient.
private Client getClient(String randomString) {
Client client = new Client();
client.setAllowAutoDeprecate(true);
client.setPersistentTokensEnabled(true);
client.setClientType(ClientType.CREATOR);
client.setDescription("description " + randomString);
client.setGroupProfileId("group-profile-id " + randomString);
client.setId(randomString);
client.setName("client-name " + randomString);
client.setWebsite("client-website " + randomString);
client.setAuthenticationProviderId("authentication-provider-id " + 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 ORCID-Source by ORCID.
the class ClientManagerReadOnlyTest method getClientTest.
@Test
public void getClientTest() {
String seed = RandomStringUtils.randomAlphanumeric(30);
when(daoMock.findByClientId(anyString(), anyLong())).thenReturn(getClientDetailsEntity(seed));
Client client = clientManagerReadOnly.get(seed);
assertEquals(getClient(seed), client);
}
use of com.predic8.membrane.core.interceptor.oauth2.Client in project ORCID-Source by ORCID.
the class ClientManagerTest method editWithoutUpdatingConfigValues.
@Test
public void editWithoutUpdatingConfigValues() {
String seed = RandomStringUtils.randomAlphanumeric(15);
Client originalClient = getClient(seed, MEMBER_ID);
assertFalse(originalClient.getId().startsWith("APP-"));
// Create the client
Client client = clientManager.create(originalClient);
String initialClientSecret = client.getDecryptedSecret();
// Update some fields
client.setAllowAutoDeprecate(false);
client.setAuthenticationProviderId("updated-authentication-provider-id");
client.setDescription("updated-desciption");
client.setEmailAccessReason("updated-email-access-reason");
client.setName("updated-client-name");
client.setPersistentTokensEnabled(false);
client.setWebsite("updated-website");
// Change group id, which should not be persisted
client.setGroupProfileId("0000-0000-0000-0000");
// Change client type, which should not be persisted
client.setClientType(ClientType.UPDATER);
// Add a new redirect uri
ClientRedirectUri rUri = new ClientRedirectUri();
Set<ScopePathType> scopes = new HashSet<ScopePathType>();
scopes.add(ScopePathType.READ_LIMITED);
scopes.add(ScopePathType.ACTIVITIES_UPDATE);
rUri.setPredefinedClientScopes(scopes);
rUri.setRedirectUri("new-redirect-uri");
rUri.setRedirectUriType(RedirectUriType.IMPORT_WORKS_WIZARD.value());
rUri.setUriActType("updated-uri-act-type");
rUri.setUriGeoArea("updated-geo-area");
client.getClientRedirectUris().add(rUri);
// Edit the client
Date editTime = new Date();
clientManager.edit(client, false);
// Verify new data is there
ClientDetailsEntity entityClient = clientDetailsDao.find(client.getId());
assertEquals(MEMBER_ID, entityClient.getGroupProfileId());
assertEquals("updated-desciption", entityClient.getClientDescription());
assertEquals("updated-client-name", entityClient.getClientName());
assertEquals("updated-website", entityClient.getClientWebsite());
assertEquals(initialClientSecret, encryptionManager.decryptForInternalUse(entityClient.getClientSecretForJpa()));
assertFalse(entityClient.isAllowAutoDeprecate());
// Verify authentication provider id doesn't changed
assertNotEquals(originalClient.getAuthenticationProviderId(), client.getAuthenticationProviderId());
assertEquals(originalClient.getAuthenticationProviderId(), entityClient.getAuthenticationProviderId());
// Verify enable persistent tokens doesn't changed
assertNotEquals(originalClient.isPersistentTokensEnabled(), client.isPersistentTokensEnabled());
assertEquals(originalClient.isPersistentTokensEnabled(), entityClient.isPersistentTokensEnabled());
// Verify config data doesn't changed
validateClientConfigSettings(entityClient, editTime);
}
use of com.predic8.membrane.core.interceptor.oauth2.Client in project ORCID-Source by ORCID.
the class ClientManagerTest method editWithInvalidClientId.
@Test(expected = IllegalArgumentException.class)
public void editWithInvalidClientId() {
Client client = new Client();
client.setId("APP-0");
clientManager.edit(client, false);
fail();
}
use of com.predic8.membrane.core.interceptor.oauth2.Client in project ORCID-Source by ORCID.
the class ClientManagerTest method createClientTest.
@Test
public void createClientTest() {
String seed = RandomStringUtils.randomAlphanumeric(15);
Client client = getClient(seed, MEMBER_ID);
assertFalse(client.getId().startsWith("APP-"));
client = clientManager.create(client);
assertTrue(client.getId().startsWith("APP-"));
ClientDetailsEntity newEntity = clientDetailsDao.find(client.getId());
assertNotNull(newEntity);
assertNotNull(newEntity.getDateCreated());
assertNotNull(newEntity.getLastModified());
assertEquals(client.getId(), newEntity.getId());
assertEquals(MEMBER_ID, newEntity.getGroupProfileId());
assertNotNull(newEntity.getAccessTokenValiditySeconds());
assertTrue(newEntity.isAllowAutoDeprecate());
assertEquals("description " + seed, newEntity.getClientDescription());
assertEquals("client-name " + seed, newEntity.getClientName());
assertEquals(ClientType.PREMIUM_CREATOR, newEntity.getClientType());
assertEquals("client-website " + seed, newEntity.getClientWebsite());
assertNotNull(newEntity.getClientRegisteredRedirectUris());
assertEquals(3, newEntity.getClientRegisteredRedirectUris().size());
boolean found1 = false, found2 = false, found3 = false;
for (ClientRedirectUriEntity rUri : newEntity.getClientRegisteredRedirectUris()) {
assertNotNull(rUri.getRedirectUri());
assertNotNull(rUri.getDateCreated());
assertNotNull(rUri.getLastModified());
if (rUri.getRedirectUri().equals("redirect-uri-1 " + seed)) {
assertEquals(ScopePathType.ACTIVITIES_READ_LIMITED.value(), rUri.getPredefinedClientScope());
assertEquals("type-1 " + seed, rUri.getRedirectUriType());
assertEquals("uri-act-type-1 " + seed, rUri.getUriActType());
assertEquals("uri-geo-area-1 " + seed, rUri.getUriGeoArea());
found1 = true;
} else if (rUri.getRedirectUri().equals("redirect-uri-2 " + seed)) {
assertEquals(ScopePathType.ACTIVITIES_UPDATE.value(), rUri.getPredefinedClientScope());
assertEquals("type-2 " + seed, rUri.getRedirectUriType());
assertEquals("uri-act-type-2 " + seed, rUri.getUriActType());
assertEquals("uri-geo-area-2 " + seed, rUri.getUriGeoArea());
found2 = true;
} else if (rUri.getRedirectUri().equals("redirect-uri-3 " + seed)) {
assertEquals(ScopePathType.AFFILIATIONS_CREATE.value(), rUri.getPredefinedClientScope());
assertEquals("type-3 " + seed, rUri.getRedirectUriType());
assertEquals("uri-act-type-3 " + seed, rUri.getUriActType());
assertEquals("uri-geo-area-3 " + seed, rUri.getUriGeoArea());
found3 = true;
} else {
fail("Invalid redirect uri: " + rUri.getRedirectUri());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
validateClientConfigSettings(newEntity, null);
}
Aggregations