Search in sources :

Example 26 with OrcidOauth2TokenDetail

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()));
    }
}
Also used : OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) Date(java.util.Date) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with OrcidOauth2TokenDetail

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());
    }
}
Also used : OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with OrcidOauth2TokenDetail

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;
}
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 29 with OrcidOauth2TokenDetail

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();
}
Also used : OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 30 with OrcidOauth2TokenDetail

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")));
    }
}
Also used : DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

OrcidOauth2TokenDetail (org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail)45 Date (java.util.Date)29 Test (org.junit.Test)27 DBUnitTest (org.orcid.test.DBUnitTest)26 Transactional (org.springframework.transaction.annotation.Transactional)13 Rollback (org.springframework.test.annotation.Rollback)12 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)10 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)9 InvalidTokenException (org.springframework.security.oauth2.common.exceptions.InvalidTokenException)8 InvalidScopeException (org.springframework.security.oauth2.common.exceptions.InvalidScopeException)7 NoResultException (javax.persistence.NoResultException)6 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)5 ArrayList (java.util.ArrayList)4 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)4 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)4 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)3 ApplicationSummary (org.orcid.pojo.ApplicationSummary)3 HashSet (java.util.HashSet)2 OrcidOauth2UserAuthentication (org.orcid.core.oauth.OrcidOauth2UserAuthentication)2 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)2