Search in sources :

Example 1 with RedirectUris

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

the class Client method valueOf.

public static Client valueOf(OrcidClient orcidClient) {
    Client client = new Client();
    client.setClientId(Text.valueOf(orcidClient.getClientId()));
    client.setClientSecret(Text.valueOf(orcidClient.getClientSecret()));
    client.setDisplayName(Text.valueOf(orcidClient.getDisplayName()));
    client.setShortDescription(Text.valueOf(orcidClient.getShortDescription()));
    if (orcidClient.getType() != null)
        client.setType(Text.valueOf(orcidClient.getType().value()));
    client.setWebsite(Text.valueOf(orcidClient.getWebsite()));
    Checkbox persistentTokenEnabled = new Checkbox();
    persistentTokenEnabled.setValue(orcidClient.isPersistentTokenEnabled());
    client.setPersistentTokenEnabled(persistentTokenEnabled);
    List<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
    RedirectUris orcidRedirectUris = orcidClient.getRedirectUris();
    if (orcidRedirectUris != null && orcidRedirectUris.getRedirectUri() != null) {
        for (org.orcid.jaxb.model.clientgroup.RedirectUri orcidRedirectUri : orcidRedirectUris.getRedirectUri()) {
            redirectUris.add(RedirectUri.toRedirectUri(orcidRedirectUri));
        }
    }
    if (orcidClient.getIdp() != null) {
        client.setAuthenticationProviderId(Text.valueOf(orcidClient.getIdp()));
    }
    client.setRedirectUris(redirectUris);
    client.setAllowAutoDeprecate(Checkbox.valueOf(orcidClient.getAllowAutoDeprecate()));
    return client;
}
Also used : ArrayList(java.util.ArrayList) RedirectUris(org.orcid.jaxb.model.clientgroup.RedirectUris) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient)

Example 2 with RedirectUris

use of org.orcid.jaxb.model.clientgroup.RedirectUris 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)

Example 3 with RedirectUris

use of org.orcid.jaxb.model.clientgroup.RedirectUris 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 4 with RedirectUris

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

the class Client method toOrcidClient.

public OrcidClient toOrcidClient() {
    OrcidClient orcidClient = new OrcidClient();
    orcidClient.setDisplayName(this.displayName.getValue());
    orcidClient.setWebsite(this.website.getValue());
    orcidClient.setShortDescription(this.shortDescription.getValue());
    orcidClient.setClientId(this.clientId.getValue());
    if (this.getAuthenticationProviderId() != null) {
        orcidClient.setIdp(this.getAuthenticationProviderId().getValue());
    }
    if (!PojoUtil.isEmpty(this.clientSecret))
        orcidClient.setClientSecret(this.clientSecret.getValue());
    if (!PojoUtil.isEmpty(this.type))
        orcidClient.setType(ClientType.fromValue(this.type.getValue()));
    RedirectUris redirectUris = new RedirectUris();
    for (RedirectUri redirectUri : this.redirectUris) {
        redirectUris.getRedirectUri().add(redirectUri.toRedirectUri());
    }
    orcidClient.setRedirectUris(redirectUris);
    if (persistentTokenEnabled != null)
        orcidClient.setPersistentTokenEnabled(persistentTokenEnabled.getValue());
    orcidClient.setAllowAutoDeprecate(this.getAllowAutoDeprecate() == null ? false : this.getAllowAutoDeprecate().getValue());
    return orcidClient;
}
Also used : OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) RedirectUris(org.orcid.jaxb.model.clientgroup.RedirectUris)

Example 5 with RedirectUris

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

the class Jpa2JaxbAdapterImpl method toOrcidClient.

@Override
public OrcidClient toOrcidClient(ClientDetailsEntity clientDetailsEntity) {
    OrcidClient client = new OrcidClient();
    client.setClientId(clientDetailsEntity.getId());
    client.setType(clientDetailsEntity.getClientType());
    if (clientDetailsEntity != null) {
        client.setClientSecret(clientDetailsEntity.getClientSecretForJpa());
        client.setDisplayName(clientDetailsEntity.getClientName());
        client.setShortDescription(clientDetailsEntity.getClientDescription());
        client.setWebsite(clientDetailsEntity.getClientWebsite());
        client.setPersistentTokenEnabled(clientDetailsEntity.isPersistentTokensEnabled());
        client.setIdp(clientDetailsEntity.getAuthenticationProviderId());
        client.setAllowAutoDeprecate(clientDetailsEntity.getAllowAutoDeprecate());
        Set<ClientRedirectUriEntity> redirectUriEntities = clientDetailsEntity.getClientRegisteredRedirectUris();
        RedirectUris redirectUris = new RedirectUris();
        client.setRedirectUris(redirectUris);
        for (ClientRedirectUriEntity redirectUriEntity : redirectUriEntities) {
            RedirectUri redirectUri = new RedirectUri(redirectUriEntity.getRedirectUri());
            redirectUri.setType(RedirectUriType.fromValue(redirectUriEntity.getRedirectUriType()));
            String predefinedScope = redirectUriEntity.getPredefinedClientScope();
            if (StringUtils.isNotBlank(predefinedScope)) {
                List<ScopePathType> scopePathType = new ArrayList<ScopePathType>(ScopePathType.getScopesFromSpaceSeparatedString(predefinedScope));
                redirectUri.setScope(scopePathType);
            }
            redirectUri.setActType(redirectUriEntity.getUriActType());
            redirectUri.setGeoArea(redirectUriEntity.getUriGeoArea());
            redirectUris.getRedirectUri().add(redirectUri);
        }
    }
    return client;
}
Also used : OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ArrayList(java.util.ArrayList) RedirectUris(org.orcid.jaxb.model.clientgroup.RedirectUris) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) ClientRedirectUriEntity(org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)

Aggregations

OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)10 RedirectUris (org.orcid.jaxb.model.clientgroup.RedirectUris)10 RedirectUri (org.orcid.jaxb.model.clientgroup.RedirectUri)8 Test (org.junit.Test)6 BaseTest (org.orcid.core.BaseTest)6 OrcidClientGroupManagementException (org.orcid.core.exception.OrcidClientGroupManagementException)6 OrcidClientGroup (org.orcid.jaxb.model.clientgroup.OrcidClientGroup)6 TransactionStatus (org.springframework.transaction.TransactionStatus)6 Transactional (org.springframework.transaction.annotation.Transactional)6 ArrayList (java.util.ArrayList)3 ClientRedirectUriEntity (org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)2 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)1 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)1