Search in sources :

Example 76 with AccessControlException

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

the class AccessControlListTest method testAddAccessControlEntryInvalidPrivilege.

public void testAddAccessControlEntryInvalidPrivilege() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    try {
        Privilege[] invalidPrivs = new Privilege[] { new Privilege() {

            public String getName() {
                return null;
            }

            public boolean isAbstract() {
                return false;
            }

            public boolean isAggregate() {
                return false;
            }

            public Privilege[] getDeclaredAggregatePrivileges() {
                return new Privilege[0];
            }

            public Privilege[] getAggregatePrivileges() {
                return new Privilege[0];
            }
        } };
        AccessControlList acl = getList(acMgr, path);
        acl.addAccessControlEntry(testPrincipal, invalidPrivs);
        fail("Adding an entry with an invalid privilege must throw AccessControlException.");
    } catch (AccessControlException e) {
    // success.
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) AccessControlException(javax.jcr.security.AccessControlException) Privilege(javax.jcr.security.Privilege)

Example 77 with AccessControlException

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

the class AccessControlListTest method testAddAccessControlEntryInvalidPrincipal.

public void testAddAccessControlEntryInvalidPrincipal() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    try {
        Principal invalidPrincipal = getHelper().getUnknownPrincipal(superuser);
        AccessControlList acl = getList(acMgr, path);
        acl.addAccessControlEntry(invalidPrincipal, privs);
        fail("Adding an entry with an unknown principal must throw AccessControlException.");
    } catch (AccessControlException e) {
    // success.
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) AccessControlException(javax.jcr.security.AccessControlException) Principal(java.security.Principal)

Example 78 with AccessControlException

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

the class AccessControlListTest method testRemoveIllegalAccessControlEntry.

public void testRemoveIllegalAccessControlEntry() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    try {
        AccessControlEntry entry = new AccessControlEntry() {

            public Principal getPrincipal() {
                return testPrincipal;
            }

            public Privilege[] getPrivileges() {
                return privs;
            }
        };
        AccessControlList acl = getList(acMgr, path);
        acl.removeAccessControlEntry(entry);
        fail("AccessControlManager.removeAccessControlEntry with an unknown entry must throw AccessControlException.");
    } catch (AccessControlException e) {
    // ok
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) AccessControlEntry(javax.jcr.security.AccessControlEntry) AccessControlException(javax.jcr.security.AccessControlException) Privilege(javax.jcr.security.Privilege)

Example 79 with AccessControlException

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

the class AccessControlListTest method testAddAccessControlEntryEmptyPrivilegeArray.

public void testAddAccessControlEntryEmptyPrivilegeArray() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    try {
        Privilege[] invalidPrivs = new Privilege[0];
        AccessControlList acl = getList(acMgr, path);
        acl.addAccessControlEntry(testPrincipal, invalidPrivs);
        fail("Adding an entry with an invalid privilege array must throw AccessControlException.");
    } catch (AccessControlException e) {
    // success.
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) AccessControlException(javax.jcr.security.AccessControlException) Privilege(javax.jcr.security.Privilege)

Example 80 with AccessControlException

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

the class AccessControlListTest method testAddAbstractPrivilege.

public void testAddAbstractPrivilege() throws NotExecutableException, RepositoryException {
    checkCanModifyAc(path);
    Privilege abstractPriv = null;
    Privilege[] allPrivs = acMgr.privilegeFromName(Privilege.JCR_ALL).getAggregatePrivileges();
    for (int i = 0; i < allPrivs.length; i++) {
        if (allPrivs[i].isAbstract()) {
            abstractPriv = allPrivs[i];
            break;
        }
    }
    if (abstractPriv == null) {
        throw new NotExecutableException("No abstract privilege found.");
    }
    AccessControlList acl = getList(acMgr, path);
    try {
        acl.addAccessControlEntry(testPrincipal, new Privilege[] { abstractPriv });
        fail("Adding an ACE with an abstract privilege must fail.");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlException(javax.jcr.security.AccessControlException) Privilege(javax.jcr.security.Privilege)

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