Search in sources :

Example 51 with AccessControlException

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

the class AccessControlManagerImplTest method testGetPoliciesInvalidPrincipal.

@Test
public void testGetPoliciesInvalidPrincipal() throws Exception {
    Principal unknown = getPrincipalManager(root).getPrincipal("unknown");
    int i = 0;
    while (unknown != null) {
        unknown = getPrincipalManager(root).getPrincipal("unknown" + i);
    }
    unknown = new InvalidTestPrincipal("unknown" + i);
    try {
        acMgr.getPolicies(unknown);
        fail("Unknown principal should be detected.");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : AccessControlException(javax.jcr.security.AccessControlException) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 52 with AccessControlException

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

the class AbstractRestrictionProviderTest method testValidateRestrictionsMissingMandatory.

@Test
public void testValidateRestrictionsMissingMandatory() throws Exception {
    Restriction glob = restrictionProvider.createRestriction(testPath, REP_GLOB, globValue);
    try {
        restrictionProvider.validateRestrictions(testPath, getAceTree(glob));
        fail("missing mandatory restriction");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) AccessControlException(javax.jcr.security.AccessControlException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 53 with AccessControlException

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

the class AbstractRestrictionProviderTest method testValidateRestrictionsUnsupportedPath.

@Test
public void testValidateRestrictionsUnsupportedPath() throws Exception {
    // empty restrictions => must succeed
    restrictionProvider.validateRestrictions(null, getAceTree());
    // non-empty restrictions => must fail
    try {
        Restriction restr = restrictionProvider.createRestriction(testPath, REP_GLOB, globValue);
        restrictionProvider.validateRestrictions(null, getAceTree(restr));
        fail();
    } catch (AccessControlException e) {
    // success
    }
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) AccessControlException(javax.jcr.security.AccessControlException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 54 with AccessControlException

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

the class AbstractRestrictionProviderTest method testValidateRestrictionsWrongType.

@Test
public void testValidateRestrictionsWrongType() throws Exception {
    Restriction mand = restrictionProvider.createRestriction(testPath, "mandatory", valueFactory.createValue(true));
    try {
        Tree ace = getAceTree(mand);
        new NodeUtil(ace).getChild(REP_RESTRICTIONS).setBoolean(REP_GLOB, true);
        restrictionProvider.validateRestrictions(testPath, ace);
        fail("wrong type with restriction 'rep:glob");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) Tree(org.apache.jackrabbit.oak.api.Tree) AccessControlException(javax.jcr.security.AccessControlException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 55 with AccessControlException

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

the class AbstractRestrictionProviderTest method testValidateRestrictionsUnsupportedRestriction.

@Test
public void testValidateRestrictionsUnsupportedRestriction() throws Exception {
    Restriction mand = restrictionProvider.createRestriction(testPath, "mandatory", valueFactory.createValue(true));
    try {
        Tree ace = getAceTree(mand);
        new NodeUtil(ace).getChild(REP_RESTRICTIONS).setString("Unsupported", "value");
        restrictionProvider.validateRestrictions(testPath, ace);
        fail("wrong type with restriction 'rep:glob");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : Restriction(org.apache.jackrabbit.oak.spi.security.authorization.restriction.Restriction) Tree(org.apache.jackrabbit.oak.api.Tree) AccessControlException(javax.jcr.security.AccessControlException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) 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