Search in sources :

Example 31 with AccessControlException

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

the class AbstractACLTemplateTest method testAddInvalidEntry2.

public void testAddInvalidEntry2() throws RepositoryException {
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    try {
        pt.addAccessControlEntry(testPrincipal, new Privilege[0]);
        fail("Adding an ACE with invalid privileges should fail");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : AccessControlException(javax.jcr.security.AccessControlException) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 32 with AccessControlException

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

the class AbstractACLTemplateTest method testRemoveInvalidEntry.

public void testRemoveInvalidEntry() throws RepositoryException {
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    try {
        pt.removeAccessControlEntry(new JackrabbitAccessControlEntry() {

            public boolean isAllow() {
                return false;
            }

            public String[] getRestrictionNames() {
                return new String[0];
            }

            public Value getRestriction(String restrictionName) {
                return null;
            }

            public Value[] getRestrictions(String restrictionName) throws RepositoryException {
                return null;
            }

            @Override
            public PrivilegeCollection getPrivilegeCollection() throws RepositoryException {
                throw new UnsupportedRepositoryOperationException();
            }

            public Principal getPrincipal() {
                return testPrincipal;
            }

            public Privilege[] getPrivileges() {
                try {
                    return privilegesFromName(Privilege.JCR_READ);
                } catch (Exception e) {
                    return new Privilege[0];
                }
            }
        });
        fail("Passing an unknown ACE should fail");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) PrivilegeCollection(org.apache.jackrabbit.api.security.authorization.PrivilegeCollection) Value(javax.jcr.Value) AccessControlException(javax.jcr.security.AccessControlException) RepositoryException(javax.jcr.RepositoryException) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal) AccessControlException(javax.jcr.security.AccessControlException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) RepositoryException(javax.jcr.RepositoryException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException)

Example 33 with AccessControlException

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

the class AbstractACLTemplateTest method testReorderInvalidElements.

public void testReorderInvalidElements() throws Exception {
    Privilege[] read = privilegesFromName(Privilege.JCR_READ);
    Privilege[] write = privilegesFromName(Privilege.JCR_WRITE);
    Principal p2 = getSecondPrincipal();
    AbstractACLTemplate acl = (AbstractACLTemplate) createEmptyTemplate(getTestPath());
    acl.addAccessControlEntry(testPrincipal, read);
    acl.addAccessControlEntry(p2, write);
    AbstractACLTemplate acl2 = (AbstractACLTemplate) createEmptyTemplate(getTestPath());
    acl2.addEntry(testPrincipal, write, false);
    AccessControlEntry invalid = acl2.getEntries().get(0);
    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) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 34 with AccessControlException

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

the class PrivilegeRegistryTest method testGetBitsFromInvalidAggregatePrivilege.

public void testGetBitsFromInvalidAggregatePrivilege() throws RepositoryException {
    Privilege p = buildUnregisteredPrivilege("anyName", privilegeRegistry.getPrivilege(Privilege.JCR_WRITE));
    try {
        PrivilegeRegistry.getBits(new Privilege[] { p });
        fail("Retrieving bits from unknown privilege should fail.");
    } catch (AccessControlException e) {
    // ok
    }
}
Also used : AccessControlException(javax.jcr.security.AccessControlException) Privilege(javax.jcr.security.Privilege)

Example 35 with AccessControlException

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

the class PrivilegeManagerImplTest method testGetBitsFromCustomAggregatePrivilege.

public void testGetBitsFromCustomAggregatePrivilege() throws RepositoryException {
    Privilege p = buildCustomPrivilege("anyName", privilegeMgr.getPrivilege(Privilege.JCR_WRITE));
    try {
        getPrivilegeManagerImpl().getBits(p);
        fail("Retrieving bits from unknown privilege should fail.");
    } catch (AccessControlException e) {
    // ok
    }
}
Also used : 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