Search in sources :

Example 11 with OrcidClient

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

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

the class OrcidClientGroupManagerImpl method createOrUpdateOrcidClientGroup.

@Override
@Transactional
public OrcidClient createOrUpdateOrcidClientGroup(String groupOrcid, OrcidClient orcidClient) {
    OrcidClient result = null;
    // Use the profile DAO to link the clients to the group, so get the
    // group profile entity.
    ProfileEntity groupProfileEntity = profileDao.find(groupOrcid);
    SortedSet<ClientDetailsEntity> clientDetailsEntities = groupProfileEntity.getClients();
    if (clientDetailsEntities == null) {
        clientDetailsEntities = new TreeSet<>(new OrcidEntityIdComparator<String>());
        groupProfileEntity.setClients(clientDetailsEntities);
    }
    processClient(groupOrcid, clientDetailsEntities, orcidClient, getClientType(groupProfileEntity.getGroupType()));
    OrcidClientGroup group = retrieveOrcidClientGroup(groupOrcid);
    for (OrcidClient populatedClient : group.getOrcidClient()) {
        if (compareClients(orcidClient, populatedClient))
            result = populatedClient;
    }
    // Regenerate client group and return.
    return result;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidEntityIdComparator(org.orcid.persistence.jpa.entities.OrcidEntityIdComparator) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with OrcidClient

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

the class WorkspaceController method getSourceGrantReadWizard.

@RequestMapping(value = "/my-orcid/sourceGrantReadWizard.json", method = RequestMethod.GET)
@ResponseBody
public ThirdPartyRedirect getSourceGrantReadWizard() {
    ThirdPartyRedirect tpr = new ThirdPartyRedirect();
    ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
    if (profile.getSource() == null || profile.getSource().getSourceId() == null) {
        return tpr;
    }
    String sourcStr = profile.getSource().getSourceId();
    // Check that the cache is up to date
    evictThirdPartyLinkManagerCacheIfNeeded();
    // Get list of clients
    List<OrcidClient> orcidClients = thirdPartyLinkManager.findOrcidClientsWithPredefinedOauthScopeReadAccess();
    for (OrcidClient orcidClient : orcidClients) {
        if (sourcStr.equals(orcidClient.getClientId())) {
            RedirectUri ru = orcidClient.getRedirectUris().getRedirectUri().get(0);
            String redirect = getBaseUri() + "/oauth/authorize?client_id=" + orcidClient.getClientId() + "&response_type=code&scope=" + ru.getScopeAsSingleString() + "&redirect_uri=" + ru.getValue();
            tpr.setUrl(redirect);
            tpr.setDisplayName(orcidClient.getDisplayName());
            tpr.setShortDescription(orcidClient.getShortDescription());
            return tpr;
        }
    }
    return tpr;
}
Also used : OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ThirdPartyRedirect(org.orcid.pojo.ThirdPartyRedirect) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 14 with OrcidClient

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

Example 15 with OrcidClient

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

the class Jpa2JaxbAdapterImpl method toOrcidClientGroup.

@Override
public OrcidClientGroup toOrcidClientGroup(ProfileEntity profileEntity) {
    OrcidClientGroup group = new OrcidClientGroup();
    group.setGroupOrcid(profileEntity.getId());
    if (profileEntity.getRecordNameEntity() != null) {
        group.setGroupName(profileEntity.getRecordNameEntity().getCreditName());
    }
    group.setType(profileEntity.getGroupType());
    Set<EmailEntity> emailEntities = profileEntity.getEmails();
    for (EmailEntity emailEntity : emailEntities) {
        group.setEmail(emailEntity.getId());
    }
    for (ClientDetailsEntity clientDetailsEntity : profileEntity.getClients()) {
        OrcidClient client = toOrcidClient(clientDetailsEntity);
        group.getOrcidClient().add(client);
    }
    return group;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity)

Aggregations

OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)22 OrcidClientGroup (org.orcid.jaxb.model.clientgroup.OrcidClientGroup)13 RedirectUri (org.orcid.jaxb.model.clientgroup.RedirectUri)12 OrcidClientGroupManagementException (org.orcid.core.exception.OrcidClientGroupManagementException)10 RedirectUris (org.orcid.jaxb.model.clientgroup.RedirectUris)10 Transactional (org.springframework.transaction.annotation.Transactional)10 Test (org.junit.Test)9 BaseTest (org.orcid.core.BaseTest)9 TransactionStatus (org.springframework.transaction.TransactionStatus)7 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)6 ArrayList (java.util.ArrayList)4 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 HashMap (java.util.HashMap)3 Produces (javax.ws.rs.Produces)3 ErrorDesc (org.orcid.jaxb.model.message.ErrorDesc)3 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)3 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)3 ClientRedirectUriEntity (org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)2