Search in sources :

Example 96 with ClientDetailsEntity

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

the class SetUpClientsAndUsers method before.

@Before
public void before() throws Exception {
    // Create admin user
    Map<String, String> adminParams = getParams(adminOrcidId);
    OrcidProfile adminProfile = orcidProfileManager.retrieveOrcidProfile(adminOrcidId);
    if (adminProfile == null) {
        createUser(adminParams);
    } else {
        clearRegistry(adminProfile, adminParams);
    }
    // Create user 1
    Map<String, String> user1Params = getParams(user1OrcidId);
    OrcidProfile user1Profile = orcidProfileManager.retrieveOrcidProfile(user1OrcidId);
    if (user1Profile == null) {
        createUser(user1Params);
    } else {
        clearRegistry(user1Profile, user1Params);
    }
    // Create user 2
    Map<String, String> user2Params = getParams(user2OrcidId);
    OrcidProfile user2Profile = orcidProfileManager.retrieveOrcidProfile(user2OrcidId);
    if (user2Profile == null) {
        createUser(user2Params);
    } else {
        clearRegistry(user2Profile, user2Params);
    }
    // Create member 1
    Map<String, String> member1Params = getParams(member1Orcid);
    OrcidProfile member1Profile = orcidProfileManager.retrieveOrcidProfile(member1Orcid);
    if (member1Profile == null) {
        createUser(member1Params);
    } else {
        clearRegistry(member1Profile, member1Params);
    }
    // Create public client
    Map<String, String> publicClientParams = getParams(publicClientId);
    ClientDetailsEntity publicClient = clientDetailsManager.findByClientId(publicClientId);
    if (publicClient == null) {
        createClient(publicClientParams);
    }
    // Create client 1
    Map<String, String> client1Params = getParams(client1ClientId);
    ClientDetailsEntity client1 = clientDetailsManager.findByClientId(client1ClientId);
    if (client1 == null) {
        createClient(client1Params);
    }
    // Create client 2
    Map<String, String> client2Params = getParams(client2ClientId);
    ClientDetailsEntity client2 = clientDetailsManager.findByClientId(client2ClientId);
    if (client2 == null) {
        createClient(client2Params);
    }
    //Ensure persistent tokens is disabled for client # 2
    clientDetailsDao.changePersistenceTokensProperty(client2ClientId, false);
    setUpDelegates(user1OrcidId, user2OrcidId);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Before(org.junit.Before)

Example 97 with ClientDetailsEntity

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

the class MigrateEncryptedData method migrateClientDetails.

private void migrateClientDetails() {
    Date start = new Date();
    @SuppressWarnings("unchecked") List<ClientDetailsEntity> clientDetailsEntities = Collections.EMPTY_LIST;
    do {
        clientDetailsEntities = clientDetailsDao.findLastModifiedBefore(start, CHUNK_SIZE);
        for (final ClientDetailsEntity clientDetails : clientDetailsEntities) {
            LOG.info("Migrating secret for client: {}", clientDetails.getClientId());
            transactionTemplate.execute(new TransactionCallbackWithoutResult() {

                @Override
                protected void doInTransactionWithoutResult(TransactionStatus status) {
                    ClientDetailsEntity retrievedClientDetails = clientDetailsDao.find(clientDetails.getClientId());
                    String unencryptedClientSecret = retrievedClientDetails.getClientSecret();
                    String encryptedClientSecret = encryptionManager.encryptForInternalUse(unencryptedClientSecret);
                    retrievedClientDetails.setClientSecretForJpa(encryptedClientSecret);
                    retrievedClientDetails.setLastModified(new Date());
                    clientDetailsDao.merge(retrievedClientDetails);
                }
            });
        }
    } while (!clientDetailsEntities.isEmpty());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) TransactionStatus(org.springframework.transaction.TransactionStatus) Date(java.util.Date) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 98 with ClientDetailsEntity

use of org.orcid.persistence.jpa.entities.ClientDetailsEntity 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());
                        }
                    }
                    //If there is at least one scope in this token, fill 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 99 with ClientDetailsEntity

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

the class OrcidSecurityManagerImpl method checkClientType.

private void checkClientType() {
    String clientId = sourceManager.retrieveSourceOrcid();
    ClientDetailsEntity client = clientDetailsEntityCacheManager.retrieve(clientId);
    if (client.getClientType() == null || ClientType.PUBLIC_CLIENT.equals(client.getClientType())) {
        throw new OrcidUnauthorizedException("The client application is forbidden to perform the action.");
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException)

Example 100 with ClientDetailsEntity

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

the class SourceInActivitiesTest method sourceDoesntChange_Work_Test.

@Test
public void sourceDoesntChange_Work_Test() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
    Work work1 = getWork(userOrcid);
    assertNotNull(work1);
    assertNotNull(work1.getWorkTitle());
    assertNotNull(work1.getWorkTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(work1.getWorkTitle().getTitle().getContent()));
    assertNotNull(work1.getSource());
    assertNotNull(work1.getSource().retrieveSourcePath());
    assertEquals(userOrcid, work1.getSource().retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Work work2 = getWork(userOrcid);
    assertNotNull(work2);
    assertNotNull(work2.getWorkTitle());
    assertNotNull(work2.getWorkTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(work2.getWorkTitle().getTitle().getContent()));
    assertNotNull(work2.getSource());
    assertNotNull(work2.getSource().retrieveSourcePath());
    assertEquals(CLIENT_1_ID, work2.getSource().retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_2_ID)));
    Work work3 = getWork(userOrcid);
    assertNotNull(work3);
    assertNotNull(work3.getWorkTitle());
    assertNotNull(work3.getWorkTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(work3.getWorkTitle().getTitle().getContent()));
    assertNotNull(work3.getSource());
    assertNotNull(work3.getSource().retrieveSourcePath());
    assertEquals(CLIENT_2_ID, work3.getSource().retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
    Work work4 = getWork(userOrcid);
    assertNotNull(work4);
    assertNotNull(work4.getWorkTitle());
    assertNotNull(work4.getWorkTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(work4.getWorkTitle().getTitle().getContent()));
    assertNotNull(work4.getSource());
    assertNotNull(work4.getSource().retrieveSourcePath());
    assertEquals(userOrcid, work4.getSource().retrieveSourcePath());
    Work fromDb1 = workManager.getWork(userOrcid, work1.getPutCode(), 0L);
    assertNotNull(fromDb1);
    assertEquals(userOrcid, fromDb1.getSource().retrieveSourcePath());
    Work fromDb2 = workManager.getWork(userOrcid, work2.getPutCode(), 0L);
    assertNotNull(fromDb2);
    assertEquals(CLIENT_1_ID, fromDb2.getSource().retrieveSourcePath());
    Work fromDb3 = workManager.getWork(userOrcid, work3.getPutCode(), 0L);
    assertNotNull(fromDb3);
    assertEquals(CLIENT_2_ID, fromDb3.getSource().retrieveSourcePath());
    Work fromDb4 = workManager.getWork(userOrcid, work4.getPutCode(), 0L);
    assertNotNull(fromDb4);
    assertEquals(userOrcid, fromDb4.getSource().retrieveSourcePath());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Work(org.orcid.jaxb.model.record_v2.Work) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test)

Aggregations

ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)149 Test (org.junit.Test)75 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)57 BaseTest (org.orcid.core.BaseTest)51 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)33 Date (java.util.Date)23 Transactional (org.springframework.transaction.annotation.Transactional)16 HashSet (java.util.HashSet)15 DBUnitTest (org.orcid.test.DBUnitTest)15 HashMap (java.util.HashMap)14 Authentication (org.springframework.security.core.Authentication)13 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)13 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)11 Work (org.orcid.jaxb.model.record_v2.Work)9 Before (org.junit.Before)8 ArrayList (java.util.ArrayList)7 OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)7 ClientSecretEntity (org.orcid.persistence.jpa.entities.ClientSecretEntity)7 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)6 Funding (org.orcid.jaxb.model.record_v2.Funding)6