Search in sources :

Example 1 with ClientAuthorisedGrantTypeEntity

use of org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity in project ORCID-Source by ORCID.

the class AddGrantTypeToExistingClients method updateGrantTypes.

private void updateGrantTypes(ClientDetailsEntity clientDetails) {
    for (String grantType : grantTypes) {
        boolean alreadyHaveGrantType = false;
        for (String existingGrantType : clientDetails.getAuthorizedGrantTypes()) {
            if (grantType.equals(existingGrantType)) {
                alreadyHaveGrantType = true;
                break;
            }
        }
        if (!alreadyHaveGrantType) {
            ClientAuthorisedGrantTypeEntity newGrantType = new ClientAuthorisedGrantTypeEntity();
            newGrantType.setGrantType(grantType);
            newGrantType.setClientDetailsEntity(clientDetails);
            clientDetails.getClientAuthorizedGrantTypes().add(newGrantType);
            clientDetailsManager.merge(clientDetails);
            clientsUpdated += 1;
            System.out.println("Client " + clientDetails.getId() + " has been updated");
        } else {
            System.out.println("Client " + clientDetails.getId() + " already have the " + grantType + " scope");
        }
    }
}
Also used : ClientAuthorisedGrantTypeEntity(org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity)

Example 2 with ClientAuthorisedGrantTypeEntity

use of org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity in project ORCID-Source by ORCID.

the class OrcidSSOManagerImplTest method testGrantSSOAccessToUser.

@Test
@Rollback(true)
public void testGrantSSOAccessToUser() {
    HashSet<String> uris = new HashSet<String>();
    uris.add("http://1.com");
    uris.add("http://2.com");
    orcidSSOManager.grantSSOAccess(orcid1, "My App", "My Description", "MyWebsite", uris);
    ClientDetailsEntity clientDetails = orcidSSOManager.getUserCredentials(orcid1);
    assertNotNull(clientDetails);
    assertNotNull(clientDetails.getAuthorizedGrantTypes());
    assertTrue(clientDetails.getAuthorizedGrantTypes().contains("authorization_code"));
    assertNotNull(clientDetails.getClientRegisteredRedirectUris());
    assertEquals(clientDetails.getClientRegisteredRedirectUris().size(), 2);
    for (ClientRedirectUriEntity redirectUri : clientDetails.getClientRegisteredRedirectUris()) {
        assertTrue(redirectUri.getRedirectUri().equals("http://1.com") || redirectUri.getRedirectUri().equals("http://2.com"));
        assertTrue(redirectUri.getRedirectUriType().equals(RedirectUriType.SSO_AUTHENTICATION.value()));
    }
    Set<ClientAuthorisedGrantTypeEntity> grantTypeList = clientDetails.getClientAuthorizedGrantTypes();
    assertEquals(3, grantTypeList.size());
    Set<String> grantTypes = clientDetails.getAuthorizedGrantTypes();
    assertTrue(grantTypes.contains("authorization_code"));
    assertTrue(grantTypes.contains("client_credentials"));
    assertTrue(grantTypes.contains("refresh_token"));
    List<ClientGrantedAuthorityEntity> grantedAuthList = clientDetails.getClientGrantedAuthorities();
    assertEquals(1, grantedAuthList.size());
    for (ClientGrantedAuthorityEntity grantedAuth : grantedAuthList) {
        assertEquals(grantedAuth.getAuthority(), "ROLE_PUBLIC");
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ClientAuthorisedGrantTypeEntity(org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity) ClientGrantedAuthorityEntity(org.orcid.persistence.jpa.entities.ClientGrantedAuthorityEntity) ClientRedirectUriEntity(org.orcid.persistence.jpa.entities.ClientRedirectUriEntity) HashSet(java.util.HashSet) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 3 with ClientAuthorisedGrantTypeEntity

use of org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity in project ORCID-Source by ORCID.

the class ClientDetailsManagerImpl method getClientAuthorizedGrantTypes.

private Set<ClientAuthorisedGrantTypeEntity> getClientAuthorizedGrantTypes(Set<String> clientAuthorizedGrantTypes, ClientDetailsEntity clientDetailsEntity) {
    Set<ClientAuthorisedGrantTypeEntity> clientAuthorisedGrantTypeEntities = new HashSet<ClientAuthorisedGrantTypeEntity>(clientAuthorizedGrantTypes.size());
    for (String clientAuthorisedGrantType : clientAuthorizedGrantTypes) {
        ClientAuthorisedGrantTypeEntity grantTypeEntity = new ClientAuthorisedGrantTypeEntity();
        grantTypeEntity.setClientDetailsEntity(clientDetailsEntity);
        grantTypeEntity.setGrantType(clientAuthorisedGrantType);
        clientAuthorisedGrantTypeEntities.add(grantTypeEntity);
    }
    return clientAuthorisedGrantTypeEntities;
}
Also used : ClientAuthorisedGrantTypeEntity(org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity) HashSet(java.util.HashSet)

Aggregations

ClientAuthorisedGrantTypeEntity (org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity)3 HashSet (java.util.HashSet)2 Test (org.junit.Test)1 BaseTest (org.orcid.core.BaseTest)1 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)1 ClientGrantedAuthorityEntity (org.orcid.persistence.jpa.entities.ClientGrantedAuthorityEntity)1 ClientRedirectUriEntity (org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)1 Rollback (org.springframework.test.annotation.Rollback)1