Search in sources :

Example 1 with RedirectUri

use of org.orcid.jaxb.model.clientgroup.RedirectUri in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerImpl method createClientDetails.

private ClientDetailsEntity createClientDetails(String groupOrcid, OrcidClient orcidClient, 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");
    Set<RedirectUri> redirectUrisToAdd = new HashSet<RedirectUri>();
    if (orcidClient.getRedirectUris() != null) {
        redirectUrisToAdd.addAll(orcidClient.getRedirectUris().getRedirectUri());
    }
    List<String> clientGrantedAuthorities = new ArrayList<String>();
    clientGrantedAuthorities.add("ROLE_CLIENT");
    String name = orcidClient.getDisplayName();
    String description = orcidClient.getShortDescription();
    String website = orcidClient.getWebsite();
    String idp = orcidClient.getIdp();
    Boolean allowAutoDeprecate = orcidClient.getAllowAutoDeprecate();
    ClientDetailsEntity clientDetails = clientDetailsManager.createClientDetails(groupOrcid, name, description, idp, website, clientType, createScopes(clientType), clientResourceIds, clientAuthorizedGrantTypes, redirectUrisToAdd, clientGrantedAuthorities, allowAutoDeprecate);
    return clientDetails;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ArrayList(java.util.ArrayList) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) HashSet(java.util.HashSet)

Example 2 with RedirectUri

use of org.orcid.jaxb.model.clientgroup.RedirectUri in project ORCID-Source by ORCID.

the class OrcidSSOManagerImpl method populateClientRedirectUri.

private RedirectUri populateClientRedirectUri(String redirectUri) {
    RedirectUri clientRedirectUri = new RedirectUri();
    clientRedirectUri.setValue(redirectUri);
    clientRedirectUri.setType(RedirectUriType.SSO_AUTHENTICATION);
    return clientRedirectUri;
}
Also used : RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri)

Example 3 with RedirectUri

use of org.orcid.jaxb.model.clientgroup.RedirectUri in project ORCID-Source by ORCID.

the class OrcidSSOManagerImpl method getClientRegisteredRedirectUris.

private Set<RedirectUri> getClientRegisteredRedirectUris(Set<String> redirectUris) {
    Set<RedirectUri> clientRedirectUris = new HashSet<>();
    for (String redirectUri : redirectUris) {
        RedirectUri clientRedirectUriEntity = populateClientRedirectUri(redirectUri);
        clientRedirectUris.add(clientRedirectUriEntity);
    }
    return clientRedirectUris;
}
Also used : RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) HashSet(java.util.HashSet)

Example 4 with RedirectUri

use of org.orcid.jaxb.model.clientgroup.RedirectUri in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerTest method testCreateOrcidCreatorClientGroup.

@Test
public void testCreateOrcidCreatorClientGroup() {
    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());
    // 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-profile/read-limited"));
    assertTrue(clientScopeTypes.contains("/orcid-bio/read-limited"));
    assertTrue(clientScopeTypes.contains("/orcid-works/read-limited"));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) 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 5 with RedirectUri

use of org.orcid.jaxb.model.clientgroup.RedirectUri in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerTest method testAddCreatorToPremiumGroup.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddCreatorToPremiumGroup() {
    final OrcidClientGroup group = new OrcidClientGroup();
    group.setGroupName("Elsevier");
    group.setEmail("premium-member@elsevier.com" + System.currentTimeMillis());
    group.setType(MemberType.PREMIUM);
    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.CREATOR);
    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_UPDATER);
    } catch (OrcidClientGroupManagementException e) {
    }
}
Also used : OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) TransactionStatus(org.springframework.transaction.TransactionStatus) RedirectUris(org.orcid.jaxb.model.clientgroup.RedirectUris) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RedirectUri (org.orcid.jaxb.model.clientgroup.RedirectUri)21 Test (org.junit.Test)11 OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)11 BaseTest (org.orcid.core.BaseTest)9 OrcidClientGroup (org.orcid.jaxb.model.clientgroup.OrcidClientGroup)9 Transactional (org.springframework.transaction.annotation.Transactional)9 RedirectUris (org.orcid.jaxb.model.clientgroup.RedirectUris)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 OrcidClientGroupManagementException (org.orcid.core.exception.OrcidClientGroupManagementException)6 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)6 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)5 ClientRedirectUriEntity (org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)5 HashMap (java.util.HashMap)3 TreeSet (java.util.TreeSet)2 DBUnitTest (org.orcid.test.DBUnitTest)2 Rollback (org.springframework.test.annotation.Rollback)2 ClientType (org.orcid.jaxb.model.clientgroup.ClientType)1