Search in sources :

Example 81 with AccessControlException

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

the class AccessControlPolicyTest method testSetIllegalPolicy.

public void testSetIllegalPolicy() throws RepositoryException, AccessDeniedException, NotExecutableException {
    checkCanModifyAc(path);
    try {
        acMgr.setPolicy(path, new AccessControlPolicy() {
        });
        fail("SetPolicy with an unknown policy should throw AccessControlException.");
    } catch (AccessControlException e) {
    // success.
    }
}
Also used : NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlException(javax.jcr.security.AccessControlException)

Example 82 with AccessControlException

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

the class AbstractACLTemplateTest method testAddInvalidEntry.

public void testAddInvalidEntry() throws RepositoryException, NotExecutableException {
    Principal unknownPrincipal;
    if (!principalMgr.hasPrincipal("an unknown principal")) {
        unknownPrincipal = new TestPrincipal("an unknown principal");
    } else {
        throw new NotExecutableException();
    }
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    try {
        pt.addAccessControlEntry(unknownPrincipal, privilegesFromName(Privilege.JCR_READ));
        fail("Adding an ACE with an unknown principal should fail");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlException(javax.jcr.security.AccessControlException) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 83 with AccessControlException

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

the class AbstractACLTemplateTest method testRemoveInvalidEntry2.

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

            public boolean isAllow() {
                return false;
            }

            public int getPrivilegeBits() {
                return 0;
            }

            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() {
                return new Privilege[0];
            }
        });
        fail("Passing a ACE with invalid privileges 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) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 84 with AccessControlException

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

the class AbstractACLTemplateTest method testRemoveNonExisting.

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

            public Principal getPrincipal() {
                return testPrincipal;
            }

            public Privilege[] getPrivileges() {
                return new Privilege[0];
            }
        });
        fail("Attemt to remove a non-existing, custom ACE must throw AccessControlException.");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) AccessControlEntry(javax.jcr.security.AccessControlEntry) AccessControlException(javax.jcr.security.AccessControlException) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 85 with AccessControlException

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

the class AbstractEntryTest method testInvalidPrivilege.

public void testInvalidPrivilege() throws RepositoryException, NotExecutableException {
    Privilege invalidPriv = new Privilege() {

        public String getName() {
            return "";
        }

        public boolean isAbstract() {
            return false;
        }

        public boolean isAggregate() {
            return false;
        }

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

        public Privilege[] getAggregatePrivileges() {
            return new Privilege[0];
        }
    };
    try {
        Privilege[] privs = new Privilege[] { invalidPriv, privilegesFromName(Privilege.JCR_READ)[0] };
        createEntry(testPrincipal, privs, true);
        fail("Principal must not be null");
    } catch (AccessControlException e) {
    // success
    }
}
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