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);
}
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());
}
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;
}
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.");
}
}
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());
}
Aggregations