Search in sources :

Example 6 with RedirectUri

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

the class OrcidClientGroupManagerTest method testAddMoreThanOneClientToBasicInstitutionGroup.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddMoreThanOneClientToBasicInstitutionGroup() {
    final OrcidClientGroup group = new OrcidClientGroup();
    group.setGroupName("Elsevier");
    group.setEmail("basic-institution-member@elsevier.com" + System.currentTimeMillis());
    group.setType(MemberType.BASIC_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.CREATOR);
    client1.setWebsite("http://site.com");
    // Add one client
    try {
        orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client1);
    } catch (OrcidClientGroupManagementException e) {
        fail();
    }
    OrcidClient client2 = new OrcidClient();
    client2.setDisplayName("Name");
    client2.setRedirectUris(redirectUris);
    client2.setShortDescription("Description");
    client2.setType(ClientType.CREATOR);
    client2.setWebsite("http://site.com");
    // Add other client should fail
    try {
        orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client2);
        fail();
    } 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)

Example 7 with RedirectUri

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

the class ClientDetailsManagerImpl method getClientRegisteredRedirectUris.

private SortedSet<ClientRedirectUriEntity> getClientRegisteredRedirectUris(Set<RedirectUri> clientRegisteredRedirectUris, ClientDetailsEntity clientDetailsEntity) {
    SortedSet<ClientRedirectUriEntity> clientRedirectUriEntities = new TreeSet<ClientRedirectUriEntity>();
    for (RedirectUri clientRegisteredRedirectUri : clientRegisteredRedirectUris) {
        ClientRedirectUriEntity clientRedirectUriEntity = new ClientRedirectUriEntity();
        clientRedirectUriEntity.setClientDetailsEntity(clientDetailsEntity);
        clientRedirectUriEntity.setRedirectUri(clientRegisteredRedirectUri.getValue());
        clientRedirectUriEntity.setRedirectUriType(clientRegisteredRedirectUri.getType().value());
        List<ScopePathType> scopesForRedirect = clientRegisteredRedirectUri.getScope();
        String clientPredefinedScopes = scopesForRedirect != null ? ScopePathType.getScopesAsSingleString(scopesForRedirect) : null;
        clientRedirectUriEntity.setPredefinedClientScope(clientPredefinedScopes);
        clientRedirectUriEntity.setUriActType(clientRegisteredRedirectUri.getActType());
        clientRedirectUriEntity.setUriGeoArea(clientRegisteredRedirectUri.getGeoArea());
        clientRedirectUriEntities.add(clientRedirectUriEntity);
    }
    return clientRedirectUriEntities;
}
Also used : ScopePathType(org.orcid.jaxb.model.message.ScopePathType) TreeSet(java.util.TreeSet) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) ClientRedirectUriEntity(org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)

Example 8 with RedirectUri

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

the class ClientDetailsManagerImpl method getClientRegisteredRedirectUris.

private SortedSet<ClientRedirectUriEntity> getClientRegisteredRedirectUris(Set<RedirectUri> clientRegisteredRedirectUris, ClientDetailsEntity clientDetailsEntity) {
    SortedSet<ClientRedirectUriEntity> clientRedirectUriEntities = new TreeSet<ClientRedirectUriEntity>();
    for (RedirectUri clientRegisteredRedirectUri : clientRegisteredRedirectUris) {
        ClientRedirectUriEntity clientRedirectUriEntity = new ClientRedirectUriEntity();
        clientRedirectUriEntity.setClientDetailsEntity(clientDetailsEntity);
        clientRedirectUriEntity.setRedirectUri(clientRegisteredRedirectUri.getValue());
        clientRedirectUriEntity.setRedirectUriType(clientRegisteredRedirectUri.getType().value());
        List<ScopePathType> scopesForRedirect = clientRegisteredRedirectUri.getScope();
        String clientPredefinedScopes = scopesForRedirect != null ? ScopePathType.getScopesAsSingleString(scopesForRedirect) : null;
        clientRedirectUriEntity.setPredefinedClientScope(clientPredefinedScopes);
        clientRedirectUriEntity.setUriActType(clientRegisteredRedirectUri.getActType());
        clientRedirectUriEntity.setUriGeoArea(clientRegisteredRedirectUri.getGeoArea());
        clientRedirectUriEntities.add(clientRedirectUriEntity);
    }
    return clientRedirectUriEntities;
}
Also used : ScopePathType(org.orcid.jaxb.model.message.ScopePathType) TreeSet(java.util.TreeSet) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) ClientRedirectUriEntity(org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)

Example 9 with RedirectUri

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

the class ClientDetailsManagerTest method testCreateClientDetailsWithNonExistentOrcid.

@Test(expected = IllegalArgumentException.class)
@Rollback
@Transactional
public void testCreateClientDetailsWithNonExistentOrcid() 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");
    clientDetailsManager.createClientDetails("8888-9999-9999-9999", CLIENT_NAME, CLIENT_DESCRIPTION, null, CLIENT_WEBSITE, ClientType.CREATOR, clientScopes, clientResourceIds, clientAuthorizedGrantTypes, clientRegisteredRedirectUris, clientGrantedAuthorities, true);
}
Also used : ArrayList(java.util.ArrayList) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) HashSet(java.util.HashSet) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with RedirectUri

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) {
    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");
    ClientType clientType = ClientType.PREMIUM_CREATOR;
    if (params.containsKey(CLIENT_TYPE)) {
        clientType = ClientType.fromValue(params.get(CLIENT_TYPE));
    }
    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 = null;
    if (clientType.equals(ClientType.PUBLIC_CLIENT)) {
        scopes = new HashSet<String>(Arrays.asList(ScopePathType.AUTHENTICATE.value(), ScopePathType.READ_PUBLIC.value()));
    } else {
        scopes = orcidClientGroupManager.premiumCreatorScopes();
        if (params.containsKey(ADD_ORCID_INTERNAL_SCOPES)) {
            scopes.add(ScopePathType.INTERNAL_PERSON_LAST_MODIFIED.value());
        }
        //Add scopes to allow group read and update
        scopes.add(ScopePathType.GROUP_ID_RECORD_READ.value());
        scopes.add(ScopePathType.GROUP_ID_RECORD_UPDATE.value());
        //Add notifications scope
        scopes.add(ScopePathType.PREMIUM_NOTIFICATION.value());
        //Add openid scope
        scopes.add(ScopePathType.OPENID.value());
    }
    clientDetailsManager.populateClientDetailsEntity(clientId, memberId, name, description, null, website, clientSecret, clientType, scopes, clientResourceIds, clientAuthorizedGrantTypes, redirectUrisToAdd, clientGrantedAuthorities, true);
}
Also used : ClientType(org.orcid.jaxb.model.clientgroup.ClientType) ArrayList(java.util.ArrayList) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) HashSet(java.util.HashSet)

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