Search in sources :

Example 41 with AccessControlException

use of javax.jcr.security.AccessControlException in project jackrabbit-oak by apache.

the class CugAccessControlManagerTest method testSetInvalidPolicy.

@Test
public void testSetInvalidPolicy() throws Exception {
    List<AccessControlPolicy> invalidPolicies = ImmutableList.of(new AccessControlPolicy() {
    }, new NamedAccessControlPolicy() {

        public String getName() {
            return "name";
        }
    }, InvalidCug.INSTANCE);
    for (AccessControlPolicy policy : invalidPolicies) {
        try {
            cugAccessControlManager.setPolicy(SUPPORTED_PATH, policy);
            fail("Invalid cug policy must be detected.");
        } catch (AccessControlException e) {
        // success
        }
    }
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlException(javax.jcr.security.AccessControlException) NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) Test(org.junit.Test)

Example 42 with AccessControlException

use of javax.jcr.security.AccessControlException in project jackrabbit-oak by apache.

the class AdminPrincipalsBaseTest method testAdminAuthInfoPrincipals.

@Test
public void testAdminAuthInfoPrincipals() throws Exception {
    try {
        for (Principal p : adminSession.getAuthInfo().getPrincipals()) {
            if (p instanceof AdminPrincipal) {
                boolean success = acl.addAccessControlEntry(p, privilegesFromNames(PrivilegeConstants.JCR_READ));
                assertResult(success);
            }
        }
    } catch (AccessControlException e) {
        assertException();
    }
}
Also used : AdminPrincipal(org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal) AccessControlException(javax.jcr.security.AccessControlException) SystemPrincipal(org.apache.jackrabbit.oak.spi.security.principal.SystemPrincipal) AdminPrincipal(org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal) Principal(java.security.Principal) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 43 with AccessControlException

use of javax.jcr.security.AccessControlException in project jackrabbit-oak by apache.

the class ACLTest method testReorderInvalidEntries.

@Test
public void testReorderInvalidEntries() throws Exception {
    Privilege[] read = privilegesFromNames(JCR_READ, JCR_READ_ACCESS_CONTROL);
    Privilege[] write = privilegesFromNames(JCR_WRITE);
    acl.addAccessControlEntry(testPrincipal, read);
    acl.addAccessControlEntry(EveryonePrincipal.getInstance(), write);
    AccessControlEntry invalid = createEntry(testPrincipal, false, null, JCR_WRITE);
    try {
        acl.orderBefore(invalid, acl.getEntries().get(0));
        fail("src entry not contained in list -> reorder should fail.");
    } catch (AccessControlException e) {
    // success
    }
    try {
        acl.orderBefore(acl.getEntries().get(0), invalid);
        fail("dest entry not contained in list -> reorder should fail.");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) AccessControlException(javax.jcr.security.AccessControlException) Privilege(javax.jcr.security.Privilege) Test(org.junit.Test)

Example 44 with AccessControlException

use of javax.jcr.security.AccessControlException in project jackrabbit-oak by apache.

the class ACLTest method testUnknownPrincipal.

@Test
public void testUnknownPrincipal() throws Exception {
    Principal unknownPrincipal = new InvalidTestPrincipal("unknown");
    try {
        acl.addAccessControlEntry(unknownPrincipal, privilegesFromNames(JCR_READ));
        fail("Adding an ACE with an unknown principal should fail");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : AccessControlException(javax.jcr.security.AccessControlException) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Test(org.junit.Test)

Example 45 with AccessControlException

use of javax.jcr.security.AccessControlException in project jackrabbit-oak by apache.

the class ACLTest method testEmptyPrincipal.

@Test
public void testEmptyPrincipal() throws Exception {
    try {
        acl.addAccessControlEntry(new PrincipalImpl(""), privilegesFromNames(JCR_READ));
        fail("Adding an ACE with empty-named principal should fail");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : AccessControlException(javax.jcr.security.AccessControlException) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Test(org.junit.Test)

Aggregations

AccessControlException (javax.jcr.security.AccessControlException)86 Test (org.junit.Test)32 Privilege (javax.jcr.security.Privilege)20 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)19 Principal (java.security.Principal)17 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)11 Tree (org.apache.jackrabbit.oak.api.Tree)11 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)9 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)8 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)8 RepositoryException (javax.jcr.RepositoryException)6 Value (javax.jcr.Value)6 TestPrincipal (org.apache.jackrabbit.core.security.TestPrincipal)6 Restriction (org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction)6 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)6 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)6 AccessControlEntry (javax.jcr.security.AccessControlEntry)5 AccessControlList (javax.jcr.security.AccessControlList)5 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)5 PrivilegeManager (org.apache.jackrabbit.api.security.authorization.PrivilegeManager)4