use of org.orcid.jaxb.model.message.ScopePathType in project ORCID-Source by ORCID.
the class OrcidSSOManagerImpl method grantSSOAccess.
@Override
@Transactional
public ClientDetailsEntity grantSSOAccess(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");
}
String clientId = null;
ClientDetailsEntity existingPublicClient = clientDetailsManager.getPublicClient(orcid);
// If it already have SSO client credentials, just return them
if (existingPublicClient != null) {
clientId = existingPublicClient.getId();
} else {
Set<String> clientScopes = new HashSet<>();
for (ScopePathType publicClientScope : PUBLIC_CLIENT_SCOPES) {
clientScopes.add(publicClientScope.getContent());
}
Set<String> clientResourceIds = new HashSet<>();
clientResourceIds.add(RESOURCE_ID);
Set<String> redirectUrisSet = new HashSet<String>();
for (String uri : redirectUris) {
redirectUrisSet.add(uri);
}
ClientDetailsEntity clientDetailsEntity = clientDetailsManager.createClientDetails(orcid, name, description, null, website, ClientType.PUBLIC_CLIENT, clientScopes, clientResourceIds, getClientAuthorizedGrantTypes(), getClientRegisteredRedirectUris(redirectUrisSet), getClientGrantedAuthorities(), false);
clientId = clientDetailsEntity.getId();
}
ClientDetailsEntity clientDetailsEntity = clientDetailsManager.findByClientId(clientId);
if (clientDetailsEntity.getClientSecrets() != null) {
for (ClientSecretEntity updatedClientSecret : clientDetailsEntity.getClientSecrets()) {
updatedClientSecret.setDecryptedClientSecret(encryptionManager.decryptForInternalUse(updatedClientSecret.getClientSecret()));
}
}
return clientDetailsEntity;
}
use of org.orcid.jaxb.model.message.ScopePathType 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;
}
use of org.orcid.jaxb.model.message.ScopePathType in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerTest method testCreateOrcidClientGroup.
@Test
public void testCreateOrcidClientGroup() {
OrcidClientGroup createdGroup = orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
assertNotNull(createdGroup);
assertEquals(group.getGroupName(), createdGroup.getGroupName());
assertEquals(group.getEmail(), createdGroup.getEmail());
assertNotNull(createdGroup.getGroupOrcid());
List<OrcidClient> createdClients = createdGroup.getOrcidClient();
assertNotNull(createdClients);
assertEquals(2, createdClients.size());
Map<String, OrcidClient> createdClientsMappedByName = new HashMap<String, OrcidClient>();
for (OrcidClient createdClient : createdClients) {
assertNotNull(createdClient.getClientId());
assertNotNull(createdClient.getClientSecret());
assertNotNull(createdClient.getIdp());
createdClientsMappedByName.put(createdClient.getDisplayName(), createdClient);
}
OrcidClient complexityClient = createdClientsMappedByName.get("Ecological Complexity");
assertNotNull(complexityClient);
assertEquals("http://www.journals.elsevier.com/ecological-complexity", complexityClient.getWebsite());
assertEquals("An International Journal on Biocomplexity in the Environment and Theoretical Ecology", complexityClient.getShortDescription());
List<RedirectUri> createdRedirectUris = complexityClient.getRedirectUris().getRedirectUri();
assertNotNull(createdRedirectUris);
assertEquals(1, createdRedirectUris.size());
assertEquals("http://www.journals.elsevier.com/ecological-complexity/orcid-callback", createdRedirectUris.get(0).getValue());
assertEquals("grant-read-wizard", createdRedirectUris.get(0).getType().value());
List<ScopePathType> scopesForRedirect = createdRedirectUris.get(0).getScope();
assertTrue(scopesForRedirect.size() == 2);
assertTrue(scopesForRedirect.contains(ScopePathType.ORCID_PROFILE_CREATE) && scopesForRedirect.contains(ScopePathType.ORCID_BIO_READ_LIMITED));
assertEquals("http://www.journals.elsevier.com/ecological-complexity/orcid-callback", createdRedirectUris.get(0).getValue());
assertEquals("grant-read-wizard", createdRedirectUris.get(0).getType().value());
// Look up client details directly to check scopes
ClientDetailsEntity complexityEntity = clientDetailsManager.findByClientId(complexityClient.getClientId());
Set<String> clientScopeTypes = complexityEntity.getScope();
assertNotNull(clientScopeTypes);
assertTrue(clientScopeTypes.contains("/orcid-bio/update"));
assertTrue(clientScopeTypes.contains("/orcid-bio/read-limited"));
assertTrue(clientScopeTypes.contains("/orcid-works/read-limited"));
assertFalse(clientScopeTypes.contains("/orcid-profile/create"));
assertTrue(clientScopeTypes.contains("/authenticate"));
}
use of org.orcid.jaxb.model.message.ScopePathType in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerTest method testUpdateOrcidClientGroup.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testUpdateOrcidClientGroup() {
OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {
public OrcidClientGroup doInTransaction(TransactionStatus status) {
return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
}
});
createdGroup.setEmail("admin@somethingelse.com");
for (OrcidClient createdClient : createdGroup.getOrcidClient()) {
if ("Ecological Complexity".equals(createdClient.getDisplayName())) {
createdClient.setWebsite("wwww.ecologicalcomplexity.com");
}
}
OrcidClientGroup updatedGroup = orcidClientGroupManager.createOrUpdateOrcidClientGroup(createdGroup);
assertNotNull(updatedGroup);
assertEquals("Elsevier", updatedGroup.getGroupName());
assertEquals("admin@somethingelse.com", updatedGroup.getEmail());
assertNotNull(updatedGroup.getGroupOrcid());
List<OrcidClient> updatedClients = updatedGroup.getOrcidClient();
assertNotNull(updatedClients);
assertEquals(2, updatedClients.size());
Map<String, OrcidClient> updatedClientsMappedByName = new HashMap<String, OrcidClient>();
for (OrcidClient upatedClient : updatedClients) {
assertNotNull(upatedClient.getClientId());
assertNotNull(upatedClient.getClientSecret());
updatedClientsMappedByName.put(upatedClient.getDisplayName(), upatedClient);
}
OrcidClient complexityClient = updatedClientsMappedByName.get("Ecological Complexity");
assertNotNull(complexityClient);
assertEquals("wwww.ecologicalcomplexity.com", complexityClient.getWebsite());
assertEquals("An International Journal on Biocomplexity in the Environment and Theoretical Ecology", complexityClient.getShortDescription());
List<RedirectUri> updatedRedirectUris = complexityClient.getRedirectUris().getRedirectUri();
assertNotNull(updatedRedirectUris);
assertEquals(1, updatedRedirectUris.size());
Collections.sort(updatedRedirectUris, new Comparator<RedirectUri>() {
public int compare(RedirectUri redirectUri1, RedirectUri redirectUri2) {
return ((String) redirectUri1.getValue()).compareToIgnoreCase((String) redirectUri1.getValue());
}
});
assertEquals("http://www.journals.elsevier.com/ecological-complexity/orcid-callback", updatedRedirectUris.get(0).getValue());
List<ScopePathType> scopesForRedirect = updatedRedirectUris.get(0).getScope();
assertTrue(scopesForRedirect.size() == 2);
assertTrue(scopesForRedirect.contains(ScopePathType.ORCID_PROFILE_CREATE) && scopesForRedirect.contains(ScopePathType.ORCID_BIO_READ_LIMITED));
}
use of org.orcid.jaxb.model.message.ScopePathType in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerImpl method updateClientDetailsEntityFromClient.
/**
* Updates an existing profile entity with the information that comes in a
* OrcidClient
*
* @param client
* The OrcidClient that contains the new information
* @param clientDetailsEntity
* The client profile entity that will be updated
* @param isUpdate
* Indicates if this will be an update or is a new client
*/
private void updateClientDetailsEntityFromClient(OrcidClient client, ClientDetailsEntity clientDetailsEntity, boolean isUpdate) {
clientDetailsEntity.setClientType(client.getType());
clientDetailsEntity.setClientName(client.getDisplayName());
clientDetailsEntity.setClientDescription(client.getShortDescription());
clientDetailsEntity.setClientWebsite(client.getWebsite());
clientDetailsEntity.setPersistentTokensEnabled(client.isPersistentTokenEnabled());
clientDetailsEntity.setAuthenticationProviderId(client.getIdp());
clientDetailsEntity.setAllowAutoDeprecate(client.getAllowAutoDeprecate());
Set<ClientRedirectUriEntity> clientRedirectUriEntities = clientDetailsEntity.getClientRegisteredRedirectUris();
Map<String, ClientRedirectUriEntity> clientRedirectUriEntitiesMap = ClientRedirectUriEntity.mapByUriAndType(clientRedirectUriEntities);
clientRedirectUriEntities.clear();
Set<RedirectUri> redirectUrisToAdd = new HashSet<RedirectUri>();
redirectUrisToAdd.addAll(client.getRedirectUris().getRedirectUri());
for (RedirectUri redirectUri : redirectUrisToAdd) {
String rUriKey = ClientRedirectUriEntity.getUriAndTypeKey(redirectUri);
// If there is a redirect uri with the same uri
if (clientRedirectUriEntitiesMap.containsKey(rUriKey)) {
// Check if it have the same scope and update it
// If it doesnt have the same scope
ClientRedirectUriEntity existingEntity = clientRedirectUriEntitiesMap.get(rUriKey);
// Update the scopes
List<ScopePathType> clientPredefinedScopes = redirectUri.getScope();
if (clientPredefinedScopes != null) {
existingEntity.setPredefinedClientScope(ScopePathType.getScopesAsSingleString(clientPredefinedScopes));
}
existingEntity.setUriActType(redirectUri.getActType());
existingEntity.setUriGeoArea(redirectUri.getGeoArea());
// Add to the list
clientRedirectUriEntities.add(existingEntity);
} else {
ClientRedirectUriEntity clientRedirectUriEntity = new ClientRedirectUriEntity(redirectUri.getValue(), clientDetailsEntity);
List<ScopePathType> clientPredefinedScopes = redirectUri.getScope();
clientRedirectUriEntity.setRedirectUriType(redirectUri.getType().value());
String allPreDefScopes = null;
if (clientPredefinedScopes != null) {
allPreDefScopes = ScopePathType.getScopesAsSingleString(clientPredefinedScopes);
}
clientRedirectUriEntity.setPredefinedClientScope(allPreDefScopes);
clientRedirectUriEntity.setUriActType(redirectUri.getActType());
clientRedirectUriEntity.setUriGeoArea(redirectUri.getGeoArea());
clientRedirectUriEntities.add(clientRedirectUriEntity);
}
}
}
Aggregations