Search in sources :

Example 1 with OrcidAccessControlException

use of org.orcid.core.exception.OrcidAccessControlException in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_KeywordsTest method testReadPublicScope_Keywords.

@Test
public void testReadPublicScope_Keywords() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    // Public works
    Response r = serviceDelegator.viewKeywords(ORCID);
    assertNotNull(r);
    assertEquals(Keywords.class.getName(), r.getEntity().getClass().getName());
    Keywords k = (Keywords) r.getEntity();
    assertNotNull(k);
    Utils.verifyLastModified(k.getLastModifiedDate());
    assertEquals(3, k.getKeywords().size());
    boolean found1 = false, found2 = false, found3 = false;
    for (Keyword element : k.getKeywords()) {
        Utils.verifyLastModified(element.getLastModifiedDate());
        if (element.getPutCode() == 9) {
            found1 = true;
        } else if (element.getPutCode() == 10) {
            found2 = true;
        } else if (element.getPutCode() == 11) {
            found3 = true;
        } else {
            fail("Invalid put code " + element.getPutCode());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    r = serviceDelegator.viewKeyword(ORCID, 9L);
    assertNotNull(r);
    assertEquals(Keyword.class.getName(), r.getEntity().getClass().getName());
    // Limited where am the source of should work
    serviceDelegator.viewKeyword(ORCID, 10L);
    // Limited where am not the source of should fail
    try {
        serviceDelegator.viewKeyword(ORCID, 12L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    // Private where am the source of should work
    serviceDelegator.viewKeyword(ORCID, 11L);
    // Private where am not the source of should fail
    try {
        serviceDelegator.viewKeyword(ORCID, 13L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) Keywords(org.orcid.jaxb.model.record_v2.Keywords) Keyword(org.orcid.jaxb.model.record_v2.Keyword) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) NoResultException(javax.persistence.NoResultException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) WrongSourceException(org.orcid.core.exception.WrongSourceException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 2 with OrcidAccessControlException

use of org.orcid.core.exception.OrcidAccessControlException in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_FundingTest method testReadPublicScope_Funding.

@Test
public void testReadPublicScope_Funding() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    // Public works
    Response r = serviceDelegator.viewFunding(ORCID, 10L);
    assertNotNull(r);
    assertEquals(Funding.class.getName(), r.getEntity().getClass().getName());
    r = serviceDelegator.viewFundingSummary(ORCID, 10L);
    assertNotNull(r);
    assertEquals(FundingSummary.class.getName(), r.getEntity().getClass().getName());
    // Limited that am the source of should work
    serviceDelegator.viewFunding(ORCID, 11L);
    serviceDelegator.viewFundingSummary(ORCID, 11L);
    // Limited that am not the source of should fail
    try {
        serviceDelegator.viewFunding(ORCID, 13L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        serviceDelegator.viewFundingSummary(ORCID, 13L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    // Private that am the source of should work
    serviceDelegator.viewFunding(ORCID, 12L);
    serviceDelegator.viewFundingSummary(ORCID, 12L);
    // Private am not the source of should fail
    try {
        serviceDelegator.viewFunding(ORCID, 14L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        serviceDelegator.viewFundingSummary(ORCID, 14L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) Funding(org.orcid.jaxb.model.record_v2.Funding) FundingSummary(org.orcid.jaxb.model.record.summary_v2.FundingSummary) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) NoResultException(javax.persistence.NoResultException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) WrongSourceException(org.orcid.core.exception.WrongSourceException) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 3 with OrcidAccessControlException

use of org.orcid.core.exception.OrcidAccessControlException in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_PeerReviewsTest method testReadPublicScope_PeerReview.

@Test
public void testReadPublicScope_PeerReview() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    // Public works
    Response r = serviceDelegator.viewPeerReview(ORCID, 9L);
    assertNotNull(r);
    assertEquals(PeerReview.class.getName(), r.getEntity().getClass().getName());
    r = serviceDelegator.viewPeerReviewSummary(ORCID, 9L);
    assertNotNull(r);
    assertEquals(PeerReviewSummary.class.getName(), r.getEntity().getClass().getName());
    // Limited where am the source of should work
    serviceDelegator.viewPeerReview(ORCID, 10L);
    serviceDelegator.viewPeerReviewSummary(ORCID, 10L);
    // Limited where am not the source of should fail
    try {
        serviceDelegator.viewPeerReview(ORCID, 12L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        serviceDelegator.viewPeerReviewSummary(ORCID, 12L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    // Limited where am the source of should work
    serviceDelegator.viewPeerReview(ORCID, 11L);
    serviceDelegator.viewPeerReviewSummary(ORCID, 11L);
    // Limited where am not the source of should fail
    try {
        serviceDelegator.viewPeerReview(ORCID, 13L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        serviceDelegator.viewPeerReviewSummary(ORCID, 13L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) PeerReviewSummary(org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) NoResultException(javax.persistence.NoResultException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) WrongSourceException(org.orcid.core.exception.WrongSourceException) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) OrcidDuplicatedActivityException(org.orcid.core.exception.OrcidDuplicatedActivityException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 4 with OrcidAccessControlException

use of org.orcid.core.exception.OrcidAccessControlException in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_AddressesTest method testReadPublicScope_Address.

@Test
public void testReadPublicScope_Address() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    // Public works
    Response r = serviceDelegator.viewAddresses(ORCID);
    assertNotNull(r);
    assertEquals(Addresses.class.getName(), r.getEntity().getClass().getName());
    Addresses a = (Addresses) r.getEntity();
    assertNotNull(a);
    assertEquals("/0000-0000-0000-0003/address", a.getPath());
    Utils.verifyLastModified(a.getLastModifiedDate());
    assertEquals(3, a.getAddress().size());
    boolean found9 = false, found10 = false, found11 = false;
    for (Address address : a.getAddress()) {
        if (address.getPutCode() == 9) {
            found9 = true;
        } else if (address.getPutCode() == 10) {
            found10 = true;
        } else if (address.getPutCode() == 11) {
            found11 = true;
        } else {
            fail("Invalid put code " + address.getPutCode());
        }
    }
    assertTrue(found9);
    assertTrue(found10);
    assertTrue(found11);
    r = serviceDelegator.viewAddress(ORCID, 9L);
    assertNotNull(r);
    assertEquals(Address.class.getName(), r.getEntity().getClass().getName());
    // Limited where am the source should work
    serviceDelegator.viewAddress(ORCID, 10L);
    try {
        // Limited am not the source should fail
        serviceDelegator.viewAddress(ORCID, 12L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    // Private where am the source should work
    serviceDelegator.viewAddress(ORCID, 11L);
    try {
        // Private am not the source should fail
        serviceDelegator.viewAddress(ORCID, 13L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) Addresses(org.orcid.jaxb.model.record_v2.Addresses) Address(org.orcid.jaxb.model.record_v2.Address) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) NoResultException(javax.persistence.NoResultException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) WrongSourceException(org.orcid.core.exception.WrongSourceException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 5 with OrcidAccessControlException

use of org.orcid.core.exception.OrcidAccessControlException in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_EducationsTest method testReadPublicScope_Educations.

@Test
public void testReadPublicScope_Educations() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    Response r = serviceDelegator.viewEducation(ORCID, 20L);
    assertNotNull(r);
    assertEquals(Education.class.getName(), r.getEntity().getClass().getName());
    r = serviceDelegator.viewEducationSummary(ORCID, 20L);
    assertNotNull(r);
    assertEquals(EducationSummary.class.getName(), r.getEntity().getClass().getName());
    // Limited that am the source of should work
    serviceDelegator.viewEducation(ORCID, 21L);
    serviceDelegator.viewEducationSummary(ORCID, 21L);
    // Limited that am not the source of should fail
    try {
        serviceDelegator.viewEducation(ORCID, 23L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        serviceDelegator.viewEducationSummary(ORCID, 23L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    // Private that am the source of should work
    serviceDelegator.viewEducation(ORCID, 22L);
    serviceDelegator.viewEducationSummary(ORCID, 22L);
    // Private that am not the source of should fails
    try {
        serviceDelegator.viewEducation(ORCID, 24L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
    try {
        serviceDelegator.viewEducationSummary(ORCID, 24L);
        fail();
    } catch (OrcidAccessControlException e) {
    } catch (Exception e) {
        fail();
    }
}
Also used : Response(javax.ws.rs.core.Response) Education(org.orcid.jaxb.model.record_v2.Education) EducationSummary(org.orcid.jaxb.model.record.summary_v2.EducationSummary) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) NoResultException(javax.persistence.NoResultException) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) OrcidVisibilityException(org.orcid.core.exception.OrcidVisibilityException) OrcidUnauthorizedException(org.orcid.core.exception.OrcidUnauthorizedException) WrongSourceException(org.orcid.core.exception.WrongSourceException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

OrcidAccessControlException (org.orcid.core.exception.OrcidAccessControlException)31 NoResultException (javax.persistence.NoResultException)25 Response (javax.ws.rs.core.Response)25 Test (org.junit.Test)25 OrcidUnauthorizedException (org.orcid.core.exception.OrcidUnauthorizedException)25 OrcidVisibilityException (org.orcid.core.exception.OrcidVisibilityException)25 VisibilityMismatchException (org.orcid.core.exception.VisibilityMismatchException)25 WrongSourceException (org.orcid.core.exception.WrongSourceException)25 DBUnitTest (org.orcid.test.DBUnitTest)25 OrcidDuplicatedActivityException (org.orcid.core.exception.OrcidDuplicatedActivityException)9 OrcidValidationException (org.orcid.core.exception.OrcidValidationException)7 ActivityIdentifierValidationException (org.orcid.core.exception.ActivityIdentifierValidationException)6 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)4 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExceedMaxNumberOfPutCodesException (org.orcid.core.exception.ExceedMaxNumberOfPutCodesException)2 OrcidNoResultException (org.orcid.core.exception.OrcidNoResultException)2 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)2 Filterable (org.orcid.jaxb.model.common_v2.Filterable)1