Search in sources :

Example 36 with ScopePathType

use of org.orcid.jaxb.model.message.ScopePathType in project ORCID-Source by ORCID.

the class ProfileEntityManagerImpl method getApplications.

@Override
public List<ApplicationSummary> getApplications(String orcid) {
    List<OrcidOauth2TokenDetail> tokenDetails = orcidOauth2TokenService.findByUserName(orcid);
    List<ApplicationSummary> applications = new ArrayList<ApplicationSummary>();
    Map<Pair<String, Set<ScopePathType>>, ApplicationSummary> existingApplications = new HashMap<Pair<String, Set<ScopePathType>>, ApplicationSummary>();
    if (tokenDetails != null && !tokenDetails.isEmpty()) {
        for (OrcidOauth2TokenDetail token : tokenDetails) {
            if (token.getTokenDisabled() == null || !token.getTokenDisabled()) {
                ClientDetailsEntity client = clientDetailsEntityCacheManager.retrieve(token.getClientDetailsId());
                if (client != null) {
                    ApplicationSummary applicationSummary = new ApplicationSummary();
                    // Check the scopes
                    Set<ScopePathType> scopesGrantedToClient = ScopePathType.getScopesFromSpaceSeparatedString(token.getScope());
                    Map<ScopePathType, String> scopePathMap = new HashMap<ScopePathType, String>();
                    String scopeFullPath = ScopePathType.class.getName() + ".";
                    for (ScopePathType tempScope : scopesGrantedToClient) {
                        try {
                            scopePathMap.put(tempScope, localeManager.resolveMessage(scopeFullPath + tempScope.toString()));
                        } catch (NoSuchMessageException e) {
                            LOGGER.warn("No message to display for scope " + tempScope.toString());
                        }
                    }
                    // the application summary element
                    if (!scopePathMap.isEmpty()) {
                        applicationSummary.setScopePaths(scopePathMap);
                        applicationSummary.setOrcidHost(orcidUrlManager.getBaseHost());
                        applicationSummary.setOrcidUri(orcidUrlManager.getBaseUriHttp() + "/" + client.getId());
                        applicationSummary.setOrcidPath(client.getId());
                        applicationSummary.setName(client.getClientName());
                        applicationSummary.setWebsiteValue(client.getClientWebsite());
                        applicationSummary.setApprovalDate(token.getDateCreated());
                        applicationSummary.setTokenId(String.valueOf(token.getId()));
                        // Add member information
                        if (!PojoUtil.isEmpty(client.getGroupProfileId())) {
                            ProfileEntity member = profileEntityCacheManager.retrieve(client.getGroupProfileId());
                            applicationSummary.setGroupOrcidPath(member.getId());
                            applicationSummary.setGroupName(getMemberDisplayName(member));
                        }
                        if (shouldBeAddedToTheApplicationsList(applicationSummary, scopesGrantedToClient, existingApplications)) {
                            applications.add(applicationSummary);
                        }
                    }
                }
            }
        }
    }
    return applications;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) NoSuchMessageException(org.springframework.context.NoSuchMessageException) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ApplicationSummary(org.orcid.pojo.ApplicationSummary) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) Pair(org.apache.commons.lang3.tuple.Pair)

Example 37 with ScopePathType

use of org.orcid.jaxb.model.message.ScopePathType in project ORCID-Source by ORCID.

the class JpaJaxbClientAdapterTest method getClient.

private Client getClient() {
    Client client = new Client();
    client.setAllowAutoDeprecate(true);
    client.setPersistentTokensEnabled(true);
    client.setClientType(ClientType.CREATOR);
    client.setDescription("description");
    client.setGroupProfileId("group-profile-id");
    client.setId("id");
    client.setName("client-name");
    client.setWebsite("client-website");
    client.setAuthenticationProviderId("authentication-provider-id");
    Set<ClientRedirectUri> clientRedirectUris = new HashSet<ClientRedirectUri>();
    ClientRedirectUri rUri1 = new ClientRedirectUri();
    Set<ScopePathType> scopes1 = new HashSet<ScopePathType>();
    scopes1.add(ScopePathType.ACTIVITIES_READ_LIMITED);
    rUri1.setPredefinedClientScopes(scopes1);
    rUri1.setRedirectUri("redirect-uri-1");
    rUri1.setRedirectUriType("type-1");
    rUri1.setUriActType("uri-act-type-1");
    rUri1.setUriGeoArea("uri-geo-area-1");
    ClientRedirectUri rUri2 = new ClientRedirectUri();
    Set<ScopePathType> scopes2 = new HashSet<ScopePathType>();
    scopes2.add(ScopePathType.ACTIVITIES_UPDATE);
    rUri2.setPredefinedClientScopes(scopes2);
    rUri2.setRedirectUri("redirect-uri-2");
    rUri2.setRedirectUriType("type-2");
    rUri2.setUriActType("uri-act-type-2");
    rUri2.setUriGeoArea("uri-geo-area-2");
    ClientRedirectUri rUri3 = new ClientRedirectUri();
    Set<ScopePathType> scopes3 = new HashSet<ScopePathType>();
    scopes3.add(ScopePathType.AFFILIATIONS_CREATE);
    rUri3.setPredefinedClientScopes(scopes3);
    rUri3.setRedirectUri("redirect-uri-3");
    rUri3.setRedirectUriType("type-3");
    rUri3.setUriActType("uri-act-type-3");
    rUri3.setUriGeoArea("uri-geo-area-3");
    clientRedirectUris.add(rUri1);
    clientRedirectUris.add(rUri2);
    clientRedirectUris.add(rUri3);
    client.setClientRedirectUris(clientRedirectUris);
    return client;
}
Also used : ClientRedirectUri(org.orcid.jaxb.model.client_v2.ClientRedirectUri) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Client(org.orcid.jaxb.model.client_v2.Client) HashSet(java.util.HashSet)

Example 38 with ScopePathType

use of org.orcid.jaxb.model.message.ScopePathType in project ORCID-Source by ORCID.

the class Client method toModelObject.

public org.orcid.jaxb.model.v3.dev1.client.Client toModelObject() {
    org.orcid.jaxb.model.v3.dev1.client.Client modelObject = new org.orcid.jaxb.model.v3.dev1.client.Client();
    if (this.getAllowAutoDeprecate() != null) {
        modelObject.setAllowAutoDeprecate(this.getAllowAutoDeprecate().getValue());
    }
    if (this.getAuthenticationProviderId() != null) {
        modelObject.setAuthenticationProviderId(this.getAuthenticationProviderId().getValue());
    }
    if (this.getClientId() != null) {
        modelObject.setId(this.getClientId().getValue());
    }
    if (this.getDisplayName() != null) {
        modelObject.setName(this.getDisplayName().getValue());
    }
    if (this.getMemberId() != null) {
        modelObject.setGroupProfileId(this.getMemberId().getValue());
    }
    if (this.getPersistentTokenEnabled() != null) {
        modelObject.setPersistentTokensEnabled(this.getPersistentTokenEnabled().getValue());
    }
    if (this.getRedirectUris() != null) {
        Set<ClientRedirectUri> redirectUriSet = new HashSet<ClientRedirectUri>();
        for (RedirectUri rUri : this.getRedirectUris()) {
            ClientRedirectUri redirectUri = new ClientRedirectUri();
            if (rUri.getScopes() != null) {
                Set<ScopePathType> scopes = new HashSet<ScopePathType>();
                for (String scope : rUri.getScopes()) {
                    scopes.add(ScopePathType.fromValue(scope));
                }
                redirectUri.setPredefinedClientScopes(scopes);
            }
            redirectUri.setRedirectUri(rUri.getValue().getValue());
            redirectUri.setRedirectUriType(rUri.getType().getValue());
            if (rUri.getActType() != null) {
                redirectUri.setUriActType(rUri.getActType().getValue());
            }
            if (rUri.getGeoArea() != null) {
                redirectUri.setUriGeoArea(rUri.getGeoArea().getValue());
            }
            redirectUriSet.add(redirectUri);
        }
        modelObject.setClientRedirectUris(redirectUriSet);
    }
    if (this.getShortDescription() != null) {
        modelObject.setDescription(this.getShortDescription().getValue());
    }
    if (this.getWebsite() != null) {
        modelObject.setWebsite(this.getWebsite().getValue());
    }
    return modelObject;
}
Also used : ClientRedirectUri(org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri) ClientRedirectUri(org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) HashSet(java.util.HashSet)

Example 39 with ScopePathType

use of org.orcid.jaxb.model.message.ScopePathType in project ORCID-Source by ORCID.

the class RedirectUri method fromModelObject.

public static RedirectUri fromModelObject(ClientRedirectUri modelObject) {
    RedirectUri redirectUri = new RedirectUri();
    if (modelObject.getPredefinedClientScopes() != null) {
        for (ScopePathType scope : modelObject.getPredefinedClientScopes()) {
            redirectUri.getScopes().add(scope.value());
        }
    }
    redirectUri.setValue(Text.valueOf(modelObject.getRedirectUri()));
    redirectUri.setType(Text.valueOf(modelObject.getRedirectUriType()));
    redirectUri.setActType(Text.valueOf(modelObject.getUriActType()));
    redirectUri.setGeoArea(Text.valueOf(modelObject.getUriGeoArea()));
    return redirectUri;
}
Also used : ScopePathType(org.orcid.jaxb.model.message.ScopePathType) ClientRedirectUri(org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri)

Example 40 with ScopePathType

use of org.orcid.jaxb.model.message.ScopePathType in project ORCID-Source by ORCID.

the class RedirectUri method fromModelObject.

public static RedirectUri fromModelObject(org.orcid.jaxb.model.client_v2.ClientRedirectUri modelObject) {
    RedirectUri redirectUri = new RedirectUri();
    if (modelObject.getPredefinedClientScopes() != null) {
        for (ScopePathType scope : modelObject.getPredefinedClientScopes()) {
            redirectUri.getScopes().add(scope.value());
        }
    }
    redirectUri.setValue(Text.valueOf(modelObject.getRedirectUri()));
    redirectUri.setType(Text.valueOf(modelObject.getRedirectUriType()));
    redirectUri.setActType(Text.valueOf(modelObject.getUriActType()));
    redirectUri.setGeoArea(Text.valueOf(modelObject.getUriGeoArea()));
    return redirectUri;
}
Also used : ScopePathType(org.orcid.jaxb.model.message.ScopePathType) ClientRedirectUri(org.orcid.jaxb.model.v3.dev1.client.ClientRedirectUri)

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