Search in sources :

Example 16 with ProfileEntity

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

the class DefaultPermissionCheckerTest method testCheckUserPermissionsAuthenticationScopesOrcidAndOrcidMessageWhenWrongUser.

@Test(expected = AccessControlException.class)
@Transactional
@Rollback
public void testCheckUserPermissionsAuthenticationScopesOrcidAndOrcidMessageWhenWrongUser() throws Exception {
    Set<String> resourceIds = new HashSet<String>(Arrays.asList("orcid"));
    HashSet<GrantedAuthority> grantedAuthorities = new HashSet<GrantedAuthority>(Arrays.asList(new SimpleGrantedAuthority("ROLE_CLIENT")));
    AuthorizationRequest request = new AuthorizationRequest("4444-4444-4444-4441", Arrays.asList("/orcid-bio/external-identifiers/create"));
    request.setAuthorities(grantedAuthorities);
    request.setResourceIds(resourceIds);
    ProfileEntity entity = profileEntityManager.findByOrcid("4444-4444-4444-4445");
    OrcidOauth2UserAuthentication oauth2UserAuthentication = new OrcidOauth2UserAuthentication(entity, true);
    OAuth2Authentication oAuth2Authentication = new OrcidOAuth2Authentication(request, oauth2UserAuthentication, "made-up-token");
    ScopePathType requiredScope = ScopePathType.ORCID_BIO_EXTERNAL_IDENTIFIERS_CREATE;
    OrcidMessage orcidMessage = getOrcidMessage();
    String messageOrcid = orcidMessage.getOrcidProfile().getOrcidIdentifier().getPath();
    defaultPermissionChecker.checkPermissions(oAuth2Authentication, requiredScope, messageOrcid, orcidMessage);
}
Also used : AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidOauth2UserAuthentication(org.orcid.core.oauth.OrcidOauth2UserAuthentication) HashSet(java.util.HashSet) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with ProfileEntity

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

the class ContributorUtilsTest method testFilterContributorPrivateDataForFundingWithPrivateName.

@Test
public void testFilterContributorPrivateDataForFundingWithPrivateName() {
    when(profileEntityManager.orcidExists(anyString())).thenReturn(true);
    when(profileEntityCacheManager.retrieve(anyString())).thenReturn(new ProfileEntity());
    when(cacheManager.getPublicCreditName(any(ProfileEntity.class))).thenReturn(null);
    Funding funding = getFundingWithOrcidContributor();
    contributorUtils.filterContributorPrivateData(funding);
    FundingContributor contributor = funding.getContributors().getContributor().get(0);
    assertNull(contributor.getContributorEmail());
    assertEquals("", contributor.getCreditName().getContent());
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) FundingContributor(org.orcid.jaxb.model.record_v2.FundingContributor) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test)

Example 18 with ProfileEntity

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

the class OrcidTokenStoreServiceTest method createAccessToken.

private OrcidOauth2TokenDetail createAccessToken(String tokenValue, String scope, String clientId, String userOrcid, boolean disabled) {
    OrcidOauth2TokenDetail token = new OrcidOauth2TokenDetail();
    token.setApproved(true);
    token.setClientDetailsId(clientId);
    token.setDateCreated(new Date());
    token.setProfile(new ProfileEntity(userOrcid));
    token.setScope(scope);
    token.setTokenDisabled(disabled);
    token.setTokenValue(tokenValue);
    orcidOauth2TokenDetailService.saveOrUpdate(token);
    return token;
}
Also used : OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 19 with ProfileEntity

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

the class ContributorUtilsTest method testFilterContributorPrivateDataForFundingWithPublicName.

@Test
public void testFilterContributorPrivateDataForFundingWithPublicName() {
    when(profileEntityManager.orcidExists(anyString())).thenReturn(true);
    when(profileEntityCacheManager.retrieve(anyString())).thenReturn(new ProfileEntity());
    when(cacheManager.getPublicCreditName(any(ProfileEntity.class))).thenReturn("a public name");
    Funding funding = getFundingWithOrcidContributor();
    contributorUtils.filterContributorPrivateData(funding);
    FundingContributor contributor = funding.getContributors().getContributor().get(0);
    assertNull(contributor.getContributorEmail());
    assertEquals("a public name", contributor.getCreditName().getContent());
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) FundingContributor(org.orcid.jaxb.model.record_v2.FundingContributor) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test)

Example 20 with ProfileEntity

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

the class ProfileDaoImpl method remove.

@Override
public void remove(String giverOrcid, String receiverOrcid) {
    ProfileEntity profileEntity = find(giverOrcid);
    if (profileEntity != null) {
        if (profileEntity.getGivenPermissionTo() != null) {
            Set<GivenPermissionToEntity> filtered = new HashSet<GivenPermissionToEntity>();
            for (GivenPermissionToEntity givenPermissionToEntity : profileEntity.getGivenPermissionTo()) {
                if (!receiverOrcid.equals(givenPermissionToEntity.getReceiver().getId())) {
                    filtered.add(givenPermissionToEntity);
                }
            }
            profileEntity.setGivenPermissionTo(filtered);
        }
    }
}
Also used : GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) HashSet(java.util.HashSet)

Aggregations

ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)374 Date (java.util.Date)107 Test (org.junit.Test)107 HashMap (java.util.HashMap)74 Transactional (org.springframework.transaction.annotation.Transactional)74 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)71 DBUnitTest (org.orcid.test.DBUnitTest)65 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)48 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)37 HashSet (java.util.HashSet)35 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)35 Locale (java.util.Locale)34 Rollback (org.springframework.test.annotation.Rollback)27 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)26 ArrayList (java.util.ArrayList)25 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)21 Set (java.util.Set)17 Authentication (org.springframework.security.core.Authentication)17 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)16