Search in sources :

Example 1 with ClientGrantedAuthorityEntity

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

the class ClientDetailsManagerImpl method getClientGrantedAuthorities.

private List<ClientGrantedAuthorityEntity> getClientGrantedAuthorities(List<String> clientGrantedAuthorities, ClientDetailsEntity clientDetailsEntity) {
    List<ClientGrantedAuthorityEntity> clientGrantedAuthorityEntities = new ArrayList<ClientGrantedAuthorityEntity>(clientGrantedAuthorities.size());
    for (String clientGrantedAuthority : clientGrantedAuthorities) {
        ClientGrantedAuthorityEntity clientGrantedAuthorityEntity = new ClientGrantedAuthorityEntity();
        clientGrantedAuthorityEntity.setClientDetailsEntity(clientDetailsEntity);
        clientGrantedAuthorityEntity.setAuthority(clientGrantedAuthority);
        clientGrantedAuthorityEntities.add(clientGrantedAuthorityEntity);
    }
    return clientGrantedAuthorityEntities;
}
Also used : ArrayList(java.util.ArrayList) ClientGrantedAuthorityEntity(org.orcid.persistence.jpa.entities.ClientGrantedAuthorityEntity)

Example 2 with ClientGrantedAuthorityEntity

use of org.orcid.persistence.jpa.entities.ClientGrantedAuthorityEntity 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)

Aggregations

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