Search in sources :

Example 31 with ScopePathType

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;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) ClientSecretEntity(org.orcid.persistence.jpa.entities.ClientSecretEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with ScopePathType

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;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ArrayList(java.util.ArrayList) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) RedirectUris(org.orcid.jaxb.model.clientgroup.RedirectUris) ClientRedirectUriEntity(org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)

Example 33 with ScopePathType

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"));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) HashMap(java.util.HashMap) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 34 with ScopePathType

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));
}
Also used : OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) HashMap(java.util.HashMap) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) TransactionStatus(org.springframework.transaction.TransactionStatus) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with ScopePathType

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);
        }
    }
}
Also used : ScopePathType(org.orcid.jaxb.model.message.ScopePathType) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) ClientRedirectUriEntity(org.orcid.persistence.jpa.entities.ClientRedirectUriEntity) HashSet(java.util.HashSet)

Aggregations

ScopePathType (org.orcid.jaxb.model.message.ScopePathType)47 HashSet (java.util.HashSet)25 Test (org.junit.Test)12 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)9 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)9 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)9 Transactional (org.springframework.transaction.annotation.Transactional)9 ArrayList (java.util.ArrayList)7 ClientRedirectUri (org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri)7 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)7 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)7 Date (java.util.Date)6 RedirectUri (org.orcid.jaxb.model.clientgroup.RedirectUri)6 GrantedAuthority (org.springframework.security.core.GrantedAuthority)6 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)6 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)6 BaseTest (org.orcid.core.BaseTest)5 Client (org.orcid.jaxb.model.client_v2.Client)5 ClientRedirectUri (org.orcid.jaxb.model.client_v2.ClientRedirectUri)5 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)5