use of org.orcid.persistence.jpa.entities.ClientRedirectUriEntity 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);
}
use of org.orcid.persistence.jpa.entities.ClientRedirectUriEntity in project ORCID-Source by ORCID.
the class JpaJaxbClientAdapterTest method getClientDetailsEntity.
private ClientDetailsEntity getClientDetailsEntity() {
Date now = new Date();
ClientDetailsEntity entity = new ClientDetailsEntity();
entity.setAllowAutoDeprecate(true);
entity.setAuthenticationProviderId("authentication-provider-id");
entity.setClientDescription("description");
entity.setClientName("client-name");
entity.setClientType(ClientType.CREATOR);
entity.setClientWebsite("client-website");
entity.setDateCreated(now);
entity.setEmailAccessReason("email-access-reason");
entity.setGroupProfileId("group-profile-id");
entity.setId("id");
entity.setLastModified(now);
entity.setPersistentTokensEnabled(true);
entity.setClientSecretForJpa("secret-1");
entity.setClientSecretForJpa("secret-2");
entity.setClientSecretForJpa("secret-3");
HashSet<ClientAuthorisedGrantTypeEntity> clientAuthorisedGrantTypeEntities = new HashSet<ClientAuthorisedGrantTypeEntity>();
ClientAuthorisedGrantTypeEntity cagt1 = new ClientAuthorisedGrantTypeEntity();
cagt1.setClientDetailsEntity(new ClientDetailsEntity("id"));
cagt1.setDateCreated(now);
cagt1.setGrantType("grant-type-1");
cagt1.setLastModified(now);
ClientAuthorisedGrantTypeEntity cagt2 = new ClientAuthorisedGrantTypeEntity();
cagt2.setClientDetailsEntity(new ClientDetailsEntity("id"));
cagt2.setDateCreated(now);
cagt2.setGrantType("grant-type-2");
cagt2.setLastModified(now);
ClientAuthorisedGrantTypeEntity cagt3 = new ClientAuthorisedGrantTypeEntity();
cagt3.setClientDetailsEntity(new ClientDetailsEntity("id"));
cagt3.setDateCreated(now);
cagt3.setGrantType("grant-type-3");
cagt3.setLastModified(now);
clientAuthorisedGrantTypeEntities.add(cagt1);
clientAuthorisedGrantTypeEntities.add(cagt2);
clientAuthorisedGrantTypeEntities.add(cagt3);
entity.setClientAuthorizedGrantTypes(clientAuthorisedGrantTypeEntities);
List<ClientGrantedAuthorityEntity> clientGrantedAuthorityEntities = new ArrayList<ClientGrantedAuthorityEntity>();
ClientGrantedAuthorityEntity cga1 = new ClientGrantedAuthorityEntity();
cga1.setAuthority("authority-1");
cga1.setClientDetailsEntity(new ClientDetailsEntity("id"));
cga1.setDateCreated(now);
cga1.setLastModified(now);
ClientGrantedAuthorityEntity cga2 = new ClientGrantedAuthorityEntity();
cga2.setAuthority("authority-2");
cga2.setClientDetailsEntity(new ClientDetailsEntity("id"));
cga2.setDateCreated(now);
cga2.setLastModified(now);
ClientGrantedAuthorityEntity cga3 = new ClientGrantedAuthorityEntity();
cga3.setAuthority("authority-3");
cga3.setClientDetailsEntity(new ClientDetailsEntity("id"));
cga3.setDateCreated(now);
cga3.setLastModified(now);
clientGrantedAuthorityEntities.add(cga1);
clientGrantedAuthorityEntities.add(cga2);
clientGrantedAuthorityEntities.add(cga3);
entity.setClientGrantedAuthorities(clientGrantedAuthorityEntities);
SortedSet<ClientRedirectUriEntity> clientRegisteredRedirectUris = new TreeSet<ClientRedirectUriEntity>();
ClientRedirectUriEntity rUri1 = new ClientRedirectUriEntity();
rUri1.setClientDetailsEntity(new ClientDetailsEntity("id"));
rUri1.setDateCreated(now);
rUri1.setLastModified(now);
rUri1.setPredefinedClientScope(ScopePathType.ACTIVITIES_READ_LIMITED.value());
rUri1.setRedirectUri("redirect-uri-1");
rUri1.setRedirectUriType("type-1");
rUri1.setUriActType("uri-act-type-1");
rUri1.setUriGeoArea("uri-geo-area-1");
ClientRedirectUriEntity rUri2 = new ClientRedirectUriEntity();
rUri2.setClientDetailsEntity(new ClientDetailsEntity("id"));
rUri2.setDateCreated(now);
rUri2.setLastModified(now);
rUri2.setPredefinedClientScope(ScopePathType.ACTIVITIES_UPDATE.value());
rUri2.setRedirectUri("redirect-uri-2");
rUri2.setRedirectUriType("type-2");
rUri2.setUriActType("uri-act-type-2");
rUri2.setUriGeoArea("uri-geo-area-2");
ClientRedirectUriEntity rUri3 = new ClientRedirectUriEntity();
rUri3.setClientDetailsEntity(new ClientDetailsEntity("id"));
rUri3.setDateCreated(now);
rUri3.setLastModified(now);
rUri3.setPredefinedClientScope(ScopePathType.AFFILIATIONS_CREATE.value());
rUri3.setRedirectUri("redirect-uri-3");
rUri3.setRedirectUriType("type-3");
rUri3.setUriActType("uri-act-type-3");
rUri3.setUriGeoArea("uri-geo-area-3");
clientRegisteredRedirectUris.add(rUri1);
clientRegisteredRedirectUris.add(rUri2);
clientRegisteredRedirectUris.add(rUri3);
entity.setClientRegisteredRedirectUris(clientRegisteredRedirectUris);
Set<ClientResourceIdEntity> clientResourceIds = new HashSet<ClientResourceIdEntity>();
ClientResourceIdEntity cri1 = new ClientResourceIdEntity();
cri1.setClientDetailsEntity(new ClientDetailsEntity("id"));
cri1.setDateCreated(now);
cri1.setLastModified(now);
cri1.setResourceId("resource-id-1");
ClientResourceIdEntity cri2 = new ClientResourceIdEntity();
cri2.setClientDetailsEntity(new ClientDetailsEntity("id"));
cri2.setDateCreated(now);
cri2.setLastModified(now);
cri2.setResourceId("resource-id-2");
ClientResourceIdEntity cri3 = new ClientResourceIdEntity();
cri3.setClientDetailsEntity(new ClientDetailsEntity("id"));
cri3.setDateCreated(now);
cri3.setLastModified(now);
cri3.setResourceId("resource-id-3");
clientResourceIds.add(cri1);
clientResourceIds.add(cri2);
clientResourceIds.add(cri3);
entity.setClientResourceIds(clientResourceIds);
Set<ClientScopeEntity> clientScopes = new HashSet<ClientScopeEntity>();
ClientScopeEntity cs1 = new ClientScopeEntity();
cs1.setClientDetailsEntity(new ClientDetailsEntity("id"));
cs1.setDateCreated(now);
cs1.setLastModified(now);
cs1.setScopeType("scope-type-1");
ClientScopeEntity cs2 = new ClientScopeEntity();
cs2.setClientDetailsEntity(new ClientDetailsEntity("id"));
cs2.setDateCreated(now);
cs2.setLastModified(now);
cs2.setScopeType("scope-type-2");
ClientScopeEntity cs3 = new ClientScopeEntity();
cs3.setClientDetailsEntity(new ClientDetailsEntity("id"));
cs3.setDateCreated(now);
cs3.setLastModified(now);
cs3.setScopeType("scope-type-3");
clientScopes.add(cs1);
clientScopes.add(cs2);
clientScopes.add(cs3);
entity.setClientScopes(clientScopes);
Set<CustomEmailEntity> customEmails = new HashSet<CustomEmailEntity>();
CustomEmailEntity ce1 = new CustomEmailEntity();
ce1.setClientDetailsEntity(new ClientDetailsEntity("id"));
ce1.setContent("content-1");
ce1.setDateCreated(now);
ce1.setEmailType(EmailType.ACCOUNT_DEPRECATED);
ce1.setHtml(true);
ce1.setLastModified(now);
ce1.setSender("sender-1");
ce1.setSubject("subject-1");
CustomEmailEntity ce2 = new CustomEmailEntity();
ce2.setClientDetailsEntity(new ClientDetailsEntity("id"));
ce2.setContent("content-2");
ce2.setDateCreated(now);
ce2.setEmailType(EmailType.ACCOUNT_DEPRECATED);
ce2.setHtml(true);
ce2.setLastModified(now);
ce2.setSender("sender-2");
ce2.setSubject("subject-2");
CustomEmailEntity ce3 = new CustomEmailEntity();
ce3.setClientDetailsEntity(new ClientDetailsEntity("id"));
ce3.setContent("content-3");
ce3.setDateCreated(now);
ce3.setEmailType(EmailType.ACCOUNT_DEPRECATED);
ce3.setHtml(true);
ce3.setLastModified(now);
ce3.setSender("sender-3");
ce3.setSubject("subject-3");
customEmails.add(ce1);
customEmails.add(ce2);
customEmails.add(ce3);
entity.setCustomEmails(customEmails);
return entity;
}
use of org.orcid.persistence.jpa.entities.ClientRedirectUriEntity in project ORCID-Source by ORCID.
the class OrcidSSOManagerImpl method updateUserCredentials.
@Override
@Transactional
public ClientDetailsEntity updateUserCredentials(String orcid, String name, String description, String website, Set<String> redirectUris) {
ProfileEntity profileEntity = profileEntityCacheManager.retrieve(orcid);
if (profileEntity == null) {
throw new IllegalArgumentException("ORCID does not exist for " + orcid + " cannot continue");
} else {
ClientDetailsEntity existingPublicClient = clientDetailsManager.getPublicClient(orcid);
if (existingPublicClient != null) {
// Set the decrypted secret
existingPublicClient.setDecryptedClientSecret(encryptionManager.decryptForInternalUse(existingPublicClient.getClientSecretForJpa()));
// Update the name
existingPublicClient.setClientName(name);
// Update the description
existingPublicClient.setClientDescription(description);
// Update the website if needed
existingPublicClient.setClientWebsite(website);
// Get the existing redirect uris
SortedSet<ClientRedirectUriEntity> clientRedirectUriEntities = existingPublicClient.getClientRegisteredRedirectUris();
// Create a set with the redirect uris that are not SSO and the
// ones that wasnt modified
Set<ClientRedirectUriEntity> redirectUrisToAdd = new HashSet<ClientRedirectUriEntity>();
for (ClientRedirectUriEntity existingEntity : clientRedirectUriEntities) {
// Add to the set all non SSO redirect uris
if (!SSO_REDIRECT_URI_TYPE.equals(existingEntity.getRedirectUriType())) {
redirectUrisToAdd.add(existingEntity);
} else {
// set of redirect uris, leave it
if (redirectUris.contains(existingEntity.getRedirectUri())) {
redirectUrisToAdd.add(existingEntity);
}
}
}
Map<String, ClientRedirectUriEntity> existingClientRedirectUriEntitiesMap = ClientRedirectUriEntity.mapByUri(redirectUrisToAdd);
// add them
for (String redirectUri : redirectUris) {
if (!existingClientRedirectUriEntitiesMap.containsKey(redirectUri)) {
// Add the new key
ClientRedirectUriEntity newRedirectUri = populateClientRedirectUriEntity(redirectUri, existingPublicClient);
redirectUrisToAdd.add(newRedirectUri);
}
}
// Clear the set for orphan removal
clientRedirectUriEntities.clear();
// Fill the collection with the redirect uris that should be
// kept
clientRedirectUriEntities.addAll(redirectUrisToAdd);
existingPublicClient = clientDetailsManager.merge(existingPublicClient);
if (existingPublicClient.getClientSecrets() != null) {
for (ClientSecretEntity updatedClientSecret : existingPublicClient.getClientSecrets()) {
updatedClientSecret.setDecryptedClientSecret(encryptionManager.decryptForInternalUse(updatedClientSecret.getClientSecret()));
}
}
return existingPublicClient;
}
}
return null;
}
use of org.orcid.persistence.jpa.entities.ClientRedirectUriEntity in project ORCID-Source by ORCID.
the class OrcidSSOManagerImplTest method testGrantSSOAccessToUser.
@Test
@Rollback(true)
public void testGrantSSOAccessToUser() {
HashSet<String> uris = new HashSet<String>();
uris.add("http://1.com");
uris.add("http://2.com");
orcidSSOManager.grantSSOAccess(orcid1, "My App", "My Description", "MyWebsite", uris);
ClientDetailsEntity clientDetails = orcidSSOManager.getUserCredentials(orcid1);
assertNotNull(clientDetails);
assertNotNull(clientDetails.getAuthorizedGrantTypes());
assertTrue(clientDetails.getAuthorizedGrantTypes().contains("authorization_code"));
assertNotNull(clientDetails.getClientRegisteredRedirectUris());
assertEquals(clientDetails.getClientRegisteredRedirectUris().size(), 2);
for (ClientRedirectUriEntity redirectUri : clientDetails.getClientRegisteredRedirectUris()) {
assertTrue(redirectUri.getRedirectUri().equals("http://1.com") || redirectUri.getRedirectUri().equals("http://2.com"));
assertTrue(redirectUri.getRedirectUriType().equals(RedirectUriType.SSO_AUTHENTICATION.value()));
}
Set<ClientAuthorisedGrantTypeEntity> grantTypeList = clientDetails.getClientAuthorizedGrantTypes();
assertEquals(3, grantTypeList.size());
Set<String> grantTypes = clientDetails.getAuthorizedGrantTypes();
assertTrue(grantTypes.contains("authorization_code"));
assertTrue(grantTypes.contains("client_credentials"));
assertTrue(grantTypes.contains("refresh_token"));
List<ClientGrantedAuthorityEntity> grantedAuthList = clientDetails.getClientGrantedAuthorities();
assertEquals(1, grantedAuthList.size());
for (ClientGrantedAuthorityEntity grantedAuth : grantedAuthList) {
assertEquals(grantedAuth.getAuthority(), "ROLE_PUBLIC");
}
}
use of org.orcid.persistence.jpa.entities.ClientRedirectUriEntity in project ORCID-Source by ORCID.
the class ThirdPartyLinkManagerImpl method getClients.
private List<OrcidClient> getClients(RedirectUriType rut) {
List<OrcidClient> orcidClients = new ArrayList<OrcidClient>();
List<ClientRedirectUriEntity> entitiesWithPredefinedScopes = clientRedirectDao.findClientDetailsWithRedirectScope();
for (ClientRedirectUriEntity entity : entitiesWithPredefinedScopes) {
if (rut.value().equals(entity.getRedirectUriType())) {
ClientDetailsEntity clientDetails = entity.getClientDetailsEntity();
RedirectUri redirectUri = new RedirectUri(entity.getRedirectUri());
String prefefinedScopes = entity.getPredefinedClientScope();
redirectUri.setScope(new ArrayList<ScopePathType>(ScopePathType.getScopesFromSpaceSeparatedString(prefefinedScopes)));
redirectUri.setType(RedirectUriType.fromValue(entity.getRedirectUriType()));
redirectUri.setActType(entity.getUriActType());
redirectUri.setGeoArea(entity.getUriGeoArea());
RedirectUris redirectUris = new RedirectUris();
redirectUris.getRedirectUri().add(redirectUri);
OrcidClient minimalClientDetails = new OrcidClient();
minimalClientDetails.setDisplayName(clientDetails.getClientName());
minimalClientDetails.setShortDescription(clientDetails.getClientDescription());
minimalClientDetails.setClientId(clientDetails.getClientId());
minimalClientDetails.setRedirectUris(redirectUris);
orcidClients.add(minimalClientDetails);
}
}
return orcidClients;
}
Aggregations