Search in sources :

Example 46 with ScopePathType

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

the class ClientsController method getAvailableRedirectUriScopes.

@RequestMapping(value = "/get-available-scopes.json", method = RequestMethod.GET)
@Produces(value = { MediaType.APPLICATION_JSON })
@ResponseBody
public List<String> getAvailableRedirectUriScopes() {
    List<String> scopes = new ArrayList<String>();
    // Ignore these scopes
    List<ScopePathType> ignoreScopes = new ArrayList<ScopePathType>(Arrays.asList(ScopePathType.ORCID_PATENTS_CREATE, ScopePathType.ORCID_PATENTS_READ_LIMITED, ScopePathType.ORCID_PATENTS_UPDATE, ScopePathType.WEBHOOK, ScopePathType.ORCID_PROFILE_CREATE, ScopePathType.FUNDING_READ_LIMITED, ScopePathType.AFFILIATIONS_READ_LIMITED, ScopePathType.READ_PUBLIC));
    for (ScopePathType t : ScopePathType.values()) {
        if (!ignoreScopes.contains(t))
            scopes.add(t.value());
    }
    Collections.sort(scopes);
    return scopes;
}
Also used : ScopePathType(org.orcid.jaxb.model.message.ScopePathType) ArrayList(java.util.ArrayList) Produces(javax.ws.rs.Produces) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 47 with ScopePathType

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

the class AddScopesToExistingClients method updateScopes.

private void updateScopes(ClientDetailsEntity clientDetails) {
    for (ScopePathType scope : scopes) {
        boolean alreadyHaveScope = false;
        for (ClientScopeEntity existingScope : clientDetails.getClientScopes()) {
            if (scope.value().equals(existingScope.getScopeType())) {
                alreadyHaveScope = true;
                break;
            }
        }
        if (!alreadyHaveScope) {
            ClientScopeEntity clientScope = new ClientScopeEntity();
            clientScope.setClientDetailsEntity(clientDetails);
            clientScope.setScopeType(scope.value());
            clientScope.setDateCreated(new Date());
            clientScope.setLastModified(new Date());
            clientDetails.getClientScopes().add(clientScope);
            clientDetailsManager.merge(clientDetails);
            clientsUpdated += 1;
            System.out.println("Client " + clientDetails.getId() + " has been updated");
        } else {
            System.out.println("Client " + clientDetails.getId() + " already have the " + scope.value() + " scope");
        }
    }
}
Also used : ClientScopeEntity(org.orcid.persistence.jpa.entities.ClientScopeEntity) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Date(java.util.Date)

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