use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class OrcidOauth2AuthorizationDetailsDaoTest method testFindByRefreshTokenValue.
@Test
@Transactional
@Rollback
public void testFindByRefreshTokenValue() throws Exception {
List<OrcidOauth2TokenDetail> all = orcidOauth2TokenDetailDao.getAll();
assertEquals(5, all.size());
for (OrcidOauth2TokenDetail detail : all) {
String refreshToken = detail.getRefreshTokenValue();
OrcidOauth2TokenDetail another = orcidOauth2TokenDetailDao.findByRefreshTokenValue(refreshToken);
assertNotNull(another);
assertEquals(refreshToken, another.getRefreshTokenValue());
assertTrue(detail.getTokenExpiration().after(new Date()));
assertTrue(another.getRefreshTokenExpiration().after(new Date()));
}
}
use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class OrcidOauth2AuthorizationDetailsDaoTest method testFindByClientId.
@Test
@Transactional
@Rollback
public void testFindByClientId() throws Exception {
List<OrcidOauth2TokenDetail> all = orcidOauth2TokenDetailDao.getAll();
assertEquals(5, all.size());
for (OrcidOauth2TokenDetail detail : all) {
List<OrcidOauth2TokenDetail> allForClient = orcidOauth2TokenDetailDao.findByClientId(detail.getClientDetailsId());
assertEquals(1, allForClient.size());
}
}
use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail 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.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class DefaultPermissionCheckerTest method checkRemoveUserGrantWriteScopePastValitityForNonPersistentTokens.
@Test
@Transactional
@Rollback
public void checkRemoveUserGrantWriteScopePastValitityForNonPersistentTokens() {
OrcidOauth2TokenDetail token = tokenDetailService.findIgnoringDisabledByTokenValue("00000001-d80f-4afc-8f95-9b48d28aaadb");
DefaultPermissionChecker customPermissionChecker = (DefaultPermissionChecker) defaultPermissionChecker;
if (!customPermissionChecker.removeUserGrantWriteScopePastValitity(token))
fail();
}
use of org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail in project ORCID-Source by ORCID.
the class OrcidTokenStoreServiceTest method testDisabledTokensAreNotReturnedWhenLookingByClientAndUserName.
@Test
public void testDisabledTokensAreNotReturnedWhenLookingByClientAndUserName() {
String clientId = "4444-4444-4444-4441";
String userId = "0000-0000-0000-0001";
OrcidOauth2TokenDetail token1 = createAccessToken("enabled-1", "/read-limited", clientId, userId, false);
assertNotNull(token1);
assertNotNull(token1.getId());
OrcidOauth2TokenDetail token2 = createAccessToken("enabled-2", "/read-limited", clientId, userId, false);
assertNotNull(token2);
assertNotNull(token2.getId());
OrcidOauth2TokenDetail token3 = createAccessToken("enabled-3", "/read-limited", clientId, userId, false);
assertNotNull(token3);
assertNotNull(token3.getId());
OrcidOauth2TokenDetail disabledToken1 = createAccessToken("disabled-1", "/read-limited", clientId, userId, true);
assertNotNull(disabledToken1);
assertNotNull(disabledToken1.getId());
OrcidOauth2TokenDetail disabledToken2 = createAccessToken("disabled-2", "/read-limited", clientId, userId, true);
assertNotNull(disabledToken2);
assertNotNull(disabledToken2.getId());
OrcidOauth2TokenDetail disabledToken3 = createAccessToken("disabled-3", "/read-limited", clientId, userId, true);
assertNotNull(disabledToken3);
assertNotNull(disabledToken3.getId());
Collection<OAuth2AccessToken> tokens = orcidTokenStoreService.findTokensByClientIdAndUserName(clientId, userId);
assertNotNull(tokens);
assertEquals(3, tokens.size());
for (OAuth2AccessToken token : tokens) {
assertThat(token.getValue(), anyOf(is("enabled-1"), is("enabled-2"), is("enabled-3")));
}
}
Aggregations