use of org.orcid.jaxb.model.clientgroup.RedirectUri 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.clientgroup.RedirectUri in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerTest method testAddUpdaterToPremiumInstitutionGroup.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddUpdaterToPremiumInstitutionGroup() {
final OrcidClientGroup group = new OrcidClientGroup();
group.setGroupName("Elsevier");
group.setEmail("premium-institution-member@elsevier.com" + System.currentTimeMillis());
group.setType(MemberType.PREMIUM_INSTITUTION);
OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {
public OrcidClientGroup doInTransaction(TransactionStatus status) {
return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
}
});
RedirectUris redirectUris = new RedirectUris();
RedirectUri redirectUri = new RedirectUri("http://uri.com");
redirectUris.getRedirectUri().add(redirectUri);
OrcidClient client1 = new OrcidClient();
client1.setDisplayName("Name");
client1.setRedirectUris(redirectUris);
client1.setShortDescription("Description");
client1.setType(ClientType.UPDATER);
client1.setWebsite("http://site.com");
// Add one creator client to a premium group should fail
try {
OrcidClient orcidClient = orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client1);
assertEquals(orcidClient.getType(), ClientType.PREMIUM_CREATOR);
} catch (OrcidClientGroupManagementException e) {
}
}
use of org.orcid.jaxb.model.clientgroup.RedirectUri 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);
}
}
}
use of org.orcid.jaxb.model.clientgroup.RedirectUri in project ORCID-Source by ORCID.
the class SetUpClientsAndUsers method createClient.
private void createClient(Map<String, String> params, ClientType clientType) {
Set<String> clientResourceIds = new HashSet<String>();
clientResourceIds.add("orcid");
Set<String> clientAuthorizedGrantTypes = new HashSet<String>();
clientAuthorizedGrantTypes.add("client_credentials");
clientAuthorizedGrantTypes.add("authorization_code");
clientAuthorizedGrantTypes.add("refresh_token");
if (client1ClientId.equals(params.get(CLIENT_ID))) {
clientAuthorizedGrantTypes.add("implicit");
}
Set<RedirectUri> redirectUrisToAdd = new HashSet<RedirectUri>();
RedirectUri redirectUri = new RedirectUri(params.get(REDIRECT_URI));
if (clientType.equals(ClientType.PUBLIC_CLIENT)) {
redirectUri.setType(RedirectUriType.SSO_AUTHENTICATION);
} else {
redirectUri.setType(RedirectUriType.DEFAULT);
}
redirectUrisToAdd.add(redirectUri);
List<String> clientGrantedAuthorities = new ArrayList<String>();
clientGrantedAuthorities.add("ROLE_CLIENT");
String name = params.get(CLIENT_NAME);
String description = params.get(CLIENT_DESCRIPTION);
String website = params.get(CLIENT_WEBSITE);
String clientId = params.get(CLIENT_ID);
String clientSecret = encryptionManager.encryptForInternalUse(params.get(CLIENT_SECRET));
String memberId = params.get(MEMBER_ID);
Set<String> scopes = getScopes(params, clientType);
clientDetailsManager.populateClientDetailsEntity(clientId, memberId, name, description, null, website, clientSecret, clientType, scopes, clientResourceIds, clientAuthorizedGrantTypes, redirectUrisToAdd, clientGrantedAuthorities, true);
}
use of org.orcid.jaxb.model.clientgroup.RedirectUri in project ORCID-Source by ORCID.
the class ClientDetailsManagerTest method testCreateClientDetailsWithRandomSecret.
@Test
@Rollback
@Transactional
public void testCreateClientDetailsWithRandomSecret() throws Exception {
Set<String> clientScopes = new HashSet<String>();
clientScopes.add("/orcid-profile/create");
Set<String> clientResourceIds = new HashSet<String>();
clientResourceIds.add("orcid-t2-api");
Set<String> clientAuthorizedGrantTypes = new HashSet<String>();
clientAuthorizedGrantTypes.add("client_credentials");
clientAuthorizedGrantTypes.add("authorization_code");
clientAuthorizedGrantTypes.add("refresh_token");
Set<RedirectUri> clientRegisteredRedirectUris = new HashSet<RedirectUri>();
clientRegisteredRedirectUris.add(new RedirectUri("http://www.google.com/"));
List<String> clientGrantedAuthorities = new ArrayList<String>();
clientGrantedAuthorities.add("ROLE_ADMIN");
ClientDetailsEntity clientDetails = clientDetailsManager.createClientDetails("4444-4444-4444-4446", CLIENT_NAME, CLIENT_DESCRIPTION, null, CLIENT_WEBSITE, ClientType.CREATOR, clientScopes, clientResourceIds, clientAuthorizedGrantTypes, clientRegisteredRedirectUris, clientGrantedAuthorities, true);
assertNotNull(clientDetails);
checkClientDetails(clientDetails);
}
Aggregations