Search in sources :

Example 1 with ClientScopeEntity

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

the class OrcidClientCredentialsCheckerTest method setupMocks.

private void setupMocks(String clientId, String memberId) {
    ClientDetailsEntity clientDetailsEntity = new ClientDetailsEntity();
    Set<ClientScopeEntity> scopes = new HashSet<ClientScopeEntity>(3);
    scopes.add(new ClientScopeEntity(ScopePathType.ORCID_WORKS_UPDATE.value()));
    scopes.add(new ClientScopeEntity(ScopePathType.ORCID_BIO_READ_LIMITED.value()));
    scopes.add(new ClientScopeEntity(ScopePathType.ORCID_PROFILE_CREATE.value()));
    clientDetailsEntity.setClientScopes(scopes);
    clientDetailsEntity.setGroupProfileId(memberId);
    ProfileEntity profile = new ProfileEntity(memberId);
    profile.setRecordLocked(false);
    when(clientDetailsService.loadClientByClientId(clientId)).thenReturn(clientDetailsEntity);
    when(clientDetailsEntityCacheManager.retrieve(clientId)).thenReturn(clientDetailsEntity);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ClientScopeEntity(org.orcid.persistence.jpa.entities.ClientScopeEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) HashSet(java.util.HashSet)

Example 2 with ClientScopeEntity

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

the class ClientDetailsManagerImpl method getClientScopeEntities.

private Set<ClientScopeEntity> getClientScopeEntities(Set<String> clientScopeStrings, ClientDetailsEntity clientDetailsEntity) {
    Set<ClientScopeEntity> clientScopeEntities = new HashSet<ClientScopeEntity>(clientScopeStrings.size());
    for (String clientScope : clientScopeStrings) {
        ClientScopeEntity clientScopeEntity = new ClientScopeEntity();
        clientScopeEntity.setClientDetailsEntity(clientDetailsEntity);
        clientScopeEntity.setScopeType(clientScope);
        clientScopeEntities.add(clientScopeEntity);
    }
    return clientScopeEntities;
}
Also used : ClientScopeEntity(org.orcid.persistence.jpa.entities.ClientScopeEntity) HashSet(java.util.HashSet)

Example 3 with ClientScopeEntity

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

the class ClientManagerImpl method create.

private Client create(Client newClient, boolean publicClient) {
    String memberId = sourceManager.retrieveSourceOrcid();
    ProfileEntity memberEntity = profileEntityCacheManager.retrieve(memberId);
    // Verify if the member type allow him to create another client
    if (publicClient) {
        ClientDetailsEntity existingPublicClient = clientDetailsDao.getPublicClient(memberId);
        if (existingPublicClient != null) {
            return jpaJaxbClientAdapter.toClient(existingPublicClient);
        }
    } else {
        validateCreateClientRequest(memberId);
    }
    ClientDetailsEntity newEntity = jpaJaxbClientAdapter.toEntity(newClient);
    Date now = new Date();
    newEntity.setDateCreated(now);
    newEntity.setLastModified(now);
    newEntity.setId(appIdGenerationManager.createNewAppId());
    newEntity.setClientSecretForJpa(encryptionManager.encryptForInternalUse(UUID.randomUUID().toString()), true);
    newEntity.setGroupProfileId(memberId);
    // Set persistent tokens enabled by default
    newEntity.setPersistentTokensEnabled(true);
    // Set authentication provider id
    newEntity.setAuthenticationProviderId(newClient.getAuthenticationProviderId());
    // Set ClientType
    if (!publicClient) {
        newEntity.setClientType(getClientType(memberEntity.getGroupType()));
    } else {
        newEntity.setClientType(ClientType.PUBLIC_CLIENT);
    }
    // Set ClientResourceIdEntity
    Set<ClientResourceIdEntity> clientResourceIdEntities = new HashSet<ClientResourceIdEntity>();
    ClientResourceIdEntity clientResourceIdEntity = new ClientResourceIdEntity();
    clientResourceIdEntity.setClientDetailsEntity(newEntity);
    clientResourceIdEntity.setResourceId("orcid");
    clientResourceIdEntities.add(clientResourceIdEntity);
    newEntity.setClientResourceIds(clientResourceIdEntities);
    // Set ClientAuthorisedGrantTypeEntity
    Set<ClientAuthorisedGrantTypeEntity> clientAuthorisedGrantTypeEntities = new HashSet<ClientAuthorisedGrantTypeEntity>();
    for (String clientAuthorisedGrantType : Arrays.asList("client_credentials", "authorization_code", "refresh_token", "implicit")) {
        ClientAuthorisedGrantTypeEntity grantTypeEntity = new ClientAuthorisedGrantTypeEntity();
        grantTypeEntity.setClientDetailsEntity(newEntity);
        grantTypeEntity.setGrantType(clientAuthorisedGrantType);
        clientAuthorisedGrantTypeEntities.add(grantTypeEntity);
    }
    newEntity.setClientAuthorizedGrantTypes(clientAuthorisedGrantTypeEntities);
    // Set ClientGrantedAuthorityEntity
    List<ClientGrantedAuthorityEntity> clientGrantedAuthorityEntities = new ArrayList<ClientGrantedAuthorityEntity>();
    ClientGrantedAuthorityEntity clientGrantedAuthorityEntity = new ClientGrantedAuthorityEntity();
    clientGrantedAuthorityEntity.setClientDetailsEntity(newEntity);
    if (publicClient) {
        clientGrantedAuthorityEntity.setAuthority("ROLE_PUBLIC");
    } else {
        clientGrantedAuthorityEntity.setAuthority("ROLE_CLIENT");
    }
    clientGrantedAuthorityEntities.add(clientGrantedAuthorityEntity);
    newEntity.setClientGrantedAuthorities(clientGrantedAuthorityEntities);
    // Set ClientScopeEntity
    Set<ClientScopeEntity> clientScopeEntities = new HashSet<ClientScopeEntity>();
    for (String clientScope : ClientType.getScopes(newEntity.getClientType())) {
        ClientScopeEntity clientScopeEntity = new ClientScopeEntity();
        clientScopeEntity.setClientDetailsEntity(newEntity);
        clientScopeEntity.setScopeType(clientScope);
        clientScopeEntities.add(clientScopeEntity);
    }
    newEntity.setClientScopes(clientScopeEntities);
    try {
        clientDetailsDao.persist(newEntity);
    } catch (Exception e) {
        LOGGER.error("Unable to client client with id {}", newEntity.getId(), e);
        throw e;
    }
    return jpaJaxbClientAdapter.toClient(newEntity);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ClientGrantedAuthorityEntity(org.orcid.persistence.jpa.entities.ClientGrantedAuthorityEntity) ArrayList(java.util.ArrayList) ClientResourceIdEntity(org.orcid.persistence.jpa.entities.ClientResourceIdEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) ClientScopeEntity(org.orcid.persistence.jpa.entities.ClientScopeEntity) ClientAuthorisedGrantTypeEntity(org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity) HashSet(java.util.HashSet)

Example 4 with ClientScopeEntity

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

the class ClientManagerReadOnlyTest method getClientDetailsEntity.

private ClientDetailsEntity getClientDetailsEntity(String randomString) {
    Date now = new Date();
    ClientDetailsEntity entity = new ClientDetailsEntity();
    entity.setAllowAutoDeprecate(true);
    entity.setAuthenticationProviderId("authentication-provider-id " + randomString);
    entity.setClientDescription("description " + randomString);
    entity.setClientName("client-name " + randomString);
    entity.setClientType(ClientType.CREATOR);
    entity.setClientWebsite("client-website " + randomString);
    entity.setDateCreated(now);
    entity.setEmailAccessReason("email-access-reason " + randomString);
    entity.setGroupProfileId("group-profile-id " + randomString);
    entity.setId(randomString);
    entity.setLastModified(now);
    entity.setPersistentTokensEnabled(true);
    entity.setClientSecretForJpa("secret-1 " + randomString);
    entity.setClientSecretForJpa("secret-2 " + randomString);
    entity.setClientSecretForJpa("secret-3 " + randomString);
    HashSet<ClientAuthorisedGrantTypeEntity> clientAuthorisedGrantTypeEntities = new HashSet<ClientAuthorisedGrantTypeEntity>();
    ClientAuthorisedGrantTypeEntity cagt1 = new ClientAuthorisedGrantTypeEntity();
    cagt1.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    cagt1.setDateCreated(now);
    cagt1.setGrantType("grant-type-1 " + randomString);
    cagt1.setLastModified(now);
    ClientAuthorisedGrantTypeEntity cagt2 = new ClientAuthorisedGrantTypeEntity();
    cagt2.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    cagt2.setDateCreated(now);
    cagt2.setGrantType("grant-type-2 " + randomString);
    cagt2.setLastModified(now);
    ClientAuthorisedGrantTypeEntity cagt3 = new ClientAuthorisedGrantTypeEntity();
    cagt3.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    cagt3.setDateCreated(now);
    cagt3.setGrantType("grant-type-3 " + randomString);
    cagt3.setLastModified(now);
    clientAuthorisedGrantTypeEntities.add(cagt1);
    clientAuthorisedGrantTypeEntities.add(cagt2);
    clientAuthorisedGrantTypeEntities.add(cagt3);
    entity.setClientAuthorizedGrantTypes(clientAuthorisedGrantTypeEntities);
    List<ClientGrantedAuthorityEntity> clientGrantedAuthorityEntities = new ArrayList<ClientGrantedAuthorityEntity>();
    ClientGrantedAuthorityEntity cga1 = new ClientGrantedAuthorityEntity();
    cga1.setAuthority("authority-1 " + randomString);
    cga1.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    cga1.setDateCreated(now);
    cga1.setLastModified(now);
    ClientGrantedAuthorityEntity cga2 = new ClientGrantedAuthorityEntity();
    cga2.setAuthority("authority-2 " + randomString);
    cga2.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    cga2.setDateCreated(now);
    cga2.setLastModified(now);
    ClientGrantedAuthorityEntity cga3 = new ClientGrantedAuthorityEntity();
    cga3.setAuthority("authority-3 " + randomString);
    cga3.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    cga3.setDateCreated(now);
    cga3.setLastModified(now);
    clientGrantedAuthorityEntities.add(cga1);
    clientGrantedAuthorityEntities.add(cga2);
    clientGrantedAuthorityEntities.add(cga3);
    entity.setClientGrantedAuthorities(clientGrantedAuthorityEntities);
    SortedSet<ClientRedirectUriEntity> clientRegisteredRedirectUris = new TreeSet<ClientRedirectUriEntity>();
    ClientRedirectUriEntity rUri1 = new ClientRedirectUriEntity();
    rUri1.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    rUri1.setDateCreated(now);
    rUri1.setLastModified(now);
    rUri1.setPredefinedClientScope(ScopePathType.ACTIVITIES_READ_LIMITED.value());
    rUri1.setRedirectUri("redirect-uri-1 " + randomString);
    rUri1.setRedirectUriType("type-1 " + randomString);
    rUri1.setUriActType("uri-act-type-1 " + randomString);
    rUri1.setUriGeoArea("uri-geo-area-1 " + randomString);
    ClientRedirectUriEntity rUri2 = new ClientRedirectUriEntity();
    rUri2.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    rUri2.setDateCreated(now);
    rUri2.setLastModified(now);
    rUri2.setPredefinedClientScope(ScopePathType.ACTIVITIES_UPDATE.value());
    rUri2.setRedirectUri("redirect-uri-2 " + randomString);
    rUri2.setRedirectUriType("type-2 " + randomString);
    rUri2.setUriActType("uri-act-type-2 " + randomString);
    rUri2.setUriGeoArea("uri-geo-area-2 " + randomString);
    ClientRedirectUriEntity rUri3 = new ClientRedirectUriEntity();
    rUri3.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    rUri3.setDateCreated(now);
    rUri3.setLastModified(now);
    rUri3.setPredefinedClientScope(ScopePathType.AFFILIATIONS_CREATE.value());
    rUri3.setRedirectUri("redirect-uri-3 " + randomString);
    rUri3.setRedirectUriType("type-3 " + randomString);
    rUri3.setUriActType("uri-act-type-3 " + randomString);
    rUri3.setUriGeoArea("uri-geo-area-3 " + randomString);
    clientRegisteredRedirectUris.add(rUri1);
    clientRegisteredRedirectUris.add(rUri2);
    clientRegisteredRedirectUris.add(rUri3);
    entity.setClientRegisteredRedirectUris(clientRegisteredRedirectUris);
    Set<ClientResourceIdEntity> clientResourceIds = new HashSet<ClientResourceIdEntity>();
    ClientResourceIdEntity cri1 = new ClientResourceIdEntity();
    cri1.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    cri1.setDateCreated(now);
    cri1.setLastModified(now);
    cri1.setResourceId("resource-id-1 " + randomString);
    ClientResourceIdEntity cri2 = new ClientResourceIdEntity();
    cri2.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    cri2.setDateCreated(now);
    cri2.setLastModified(now);
    cri2.setResourceId("resource-id-2 " + randomString);
    ClientResourceIdEntity cri3 = new ClientResourceIdEntity();
    cri3.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    cri3.setDateCreated(now);
    cri3.setLastModified(now);
    cri3.setResourceId("resource-id-3 " + randomString);
    clientResourceIds.add(cri1);
    clientResourceIds.add(cri2);
    clientResourceIds.add(cri3);
    entity.setClientResourceIds(clientResourceIds);
    Set<ClientScopeEntity> clientScopes = new HashSet<ClientScopeEntity>();
    ClientScopeEntity cs1 = new ClientScopeEntity();
    cs1.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    cs1.setDateCreated(now);
    cs1.setLastModified(now);
    cs1.setScopeType("scope-type-1 " + randomString);
    ClientScopeEntity cs2 = new ClientScopeEntity();
    cs2.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    cs2.setDateCreated(now);
    cs2.setLastModified(now);
    cs2.setScopeType("scope-type-2 " + randomString);
    ClientScopeEntity cs3 = new ClientScopeEntity();
    cs3.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    cs3.setDateCreated(now);
    cs3.setLastModified(now);
    cs3.setScopeType("scope-type-3 " + randomString);
    clientScopes.add(cs1);
    clientScopes.add(cs2);
    clientScopes.add(cs3);
    entity.setClientScopes(clientScopes);
    Set<CustomEmailEntity> customEmails = new HashSet<CustomEmailEntity>();
    CustomEmailEntity ce1 = new CustomEmailEntity();
    ce1.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    ce1.setContent("content-1 " + randomString);
    ce1.setDateCreated(now);
    ce1.setEmailType(EmailType.ACCOUNT_DEPRECATED);
    ce1.setHtml(true);
    ce1.setLastModified(now);
    ce1.setSender("sender-1 " + randomString);
    ce1.setSubject("subject-1 " + randomString);
    CustomEmailEntity ce2 = new CustomEmailEntity();
    ce2.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    ce2.setContent("content-2 " + randomString);
    ce2.setDateCreated(now);
    ce2.setEmailType(EmailType.ACCOUNT_DEPRECATED);
    ce2.setHtml(true);
    ce2.setLastModified(now);
    ce2.setSender("sender-2 " + randomString);
    ce2.setSubject("subject-2 " + randomString);
    CustomEmailEntity ce3 = new CustomEmailEntity();
    ce3.setClientDetailsEntity(new ClientDetailsEntity(randomString));
    ce3.setContent("content-3 " + randomString);
    ce3.setDateCreated(now);
    ce3.setEmailType(EmailType.ACCOUNT_DEPRECATED);
    ce3.setHtml(true);
    ce3.setLastModified(now);
    ce3.setSender("sender-3 " + randomString);
    ce3.setSubject("subject-3 " + randomString);
    customEmails.add(ce1);
    customEmails.add(ce2);
    customEmails.add(ce3);
    entity.setCustomEmails(customEmails);
    return entity;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) ClientGrantedAuthorityEntity(org.orcid.persistence.jpa.entities.ClientGrantedAuthorityEntity) ArrayList(java.util.ArrayList) ClientResourceIdEntity(org.orcid.persistence.jpa.entities.ClientResourceIdEntity) Date(java.util.Date) ClientRedirectUriEntity(org.orcid.persistence.jpa.entities.ClientRedirectUriEntity) ClientScopeEntity(org.orcid.persistence.jpa.entities.ClientScopeEntity) ClientAuthorisedGrantTypeEntity(org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity) TreeSet(java.util.TreeSet) CustomEmailEntity(org.orcid.persistence.jpa.entities.CustomEmailEntity) HashSet(java.util.HashSet)

Example 5 with ClientScopeEntity

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

the class ClientManagerTest method validateClientConfigSettings.

private void validateClientConfigSettings(ClientDetailsEntity entity, Date lastTimeEntityWasModified) {
    assertNotNull(entity.getAuthorizedGrantTypes());
    assertEquals(4, entity.getClientAuthorizedGrantTypes().size());
    boolean found1 = false, found2 = false, found3 = false, found4 = false;
    for (ClientAuthorisedGrantTypeEntity cagt : entity.getClientAuthorizedGrantTypes()) {
        assertNotNull(cagt.getDateCreated());
        assertTrue(lastTimeEntityWasModified == null ? true : lastTimeEntityWasModified.after(cagt.getDateCreated()));
        assertNotNull(cagt.getLastModified());
        assertTrue(lastTimeEntityWasModified == null ? true : lastTimeEntityWasModified.after(cagt.getLastModified()));
        if (cagt.getGrantType().equals("authorization_code")) {
            found1 = true;
        } else if (cagt.getGrantType().equals("client_credentials")) {
            found2 = true;
        } else if (cagt.getGrantType().equals("refresh_token")) {
            found3 = true;
        } else if (cagt.getGrantType().equals("implicit")) {
            found4 = true;
        } else {
            fail("Invalid authorized grant type: " + cagt.getGrantType());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    assertTrue(found4);
    assertNotNull(entity.getClientGrantedAuthorities());
    for (ClientGrantedAuthorityEntity cga : entity.getClientGrantedAuthorities()) {
        assertNotNull(cga.getDateCreated());
        assertTrue(lastTimeEntityWasModified == null ? true : lastTimeEntityWasModified.after(cga.getDateCreated()));
        assertNotNull(cga.getLastModified());
        assertTrue(lastTimeEntityWasModified == null ? true : lastTimeEntityWasModified.after(cga.getLastModified()));
        assertEquals("ROLE_CLIENT", cga.getAuthority());
    }
    assertNotNull(entity.getClientResourceIds());
    assertEquals(1, entity.getClientResourceIds().size());
    for (ClientResourceIdEntity cri : entity.getClientResourceIds()) {
        assertNotNull(cri.getDateCreated());
        assertTrue(lastTimeEntityWasModified == null ? true : lastTimeEntityWasModified.after(cri.getLastModified()));
        assertNotNull(cri.getLastModified());
        assertTrue(lastTimeEntityWasModified == null ? true : lastTimeEntityWasModified.after(cri.getLastModified()));
        assertEquals("orcid", cri.getResourceId());
    }
    Set<String> scopes = ClientType.getScopes(entity.getClientType());
    assertFalse(scopes.isEmpty());
    assertNotNull(entity.getClientScopes());
    for (ClientScopeEntity cs : entity.getClientScopes()) {
        assertNotNull(cs.getDateCreated());
        assertTrue(lastTimeEntityWasModified == null ? true : lastTimeEntityWasModified.after(cs.getLastModified()));
        assertNotNull(cs.getLastModified());
        assertTrue(lastTimeEntityWasModified == null ? true : lastTimeEntityWasModified.after(cs.getLastModified()));
        assertTrue(scopes.contains(cs.getScopeType()));
        // Remove it after finding it so we check there are no duplicates as well
        scopes.remove(cs.getScopeType());
    }
    assertTrue(scopes.isEmpty());
    assertNotNull(entity.getClientSecrets());
    assertEquals(1, entity.getClientSecrets().size());
    for (ClientSecretEntity cs : entity.getClientSecrets()) {
        assertNotNull(cs.getDateCreated());
        assertTrue(lastTimeEntityWasModified == null ? true : lastTimeEntityWasModified.after(cs.getLastModified()));
        assertNotNull(cs.getLastModified());
        assertTrue(lastTimeEntityWasModified == null ? true : lastTimeEntityWasModified.after(cs.getLastModified()));
        assertTrue(cs.isPrimary());
        assertFalse(PojoUtil.isEmpty(cs.getClientSecret()));
    }
    assertNotNull(entity.getCustomEmails());
}
Also used : ClientScopeEntity(org.orcid.persistence.jpa.entities.ClientScopeEntity) ClientAuthorisedGrantTypeEntity(org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity) ClientSecretEntity(org.orcid.persistence.jpa.entities.ClientSecretEntity) ClientGrantedAuthorityEntity(org.orcid.persistence.jpa.entities.ClientGrantedAuthorityEntity) ClientResourceIdEntity(org.orcid.persistence.jpa.entities.ClientResourceIdEntity)

Aggregations

ClientScopeEntity (org.orcid.persistence.jpa.entities.ClientScopeEntity)16 Date (java.util.Date)11 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)11 HashSet (java.util.HashSet)10 ClientAuthorisedGrantTypeEntity (org.orcid.persistence.jpa.entities.ClientAuthorisedGrantTypeEntity)7 ClientGrantedAuthorityEntity (org.orcid.persistence.jpa.entities.ClientGrantedAuthorityEntity)7 ClientResourceIdEntity (org.orcid.persistence.jpa.entities.ClientResourceIdEntity)7 ArrayList (java.util.ArrayList)6 TreeSet (java.util.TreeSet)4 ClientRedirectUriEntity (org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)4 CustomEmailEntity (org.orcid.persistence.jpa.entities.CustomEmailEntity)4 ClientType (org.orcid.jaxb.model.clientgroup.ClientType)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 Test (org.junit.Test)1 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)1 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)1 ClientSecretEntity (org.orcid.persistence.jpa.entities.ClientSecretEntity)1 DBUnitTest (org.orcid.test.DBUnitTest)1 Transactional (org.springframework.transaction.annotation.Transactional)1