Search in sources :

Example 46 with AccessControlPolicy

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

the class AccessControlPolicyTest method testSetPolicyIsTransient.

public void testSetPolicyIsTransient() throws RepositoryException, AccessDeniedException, NotExecutableException {
    checkCanModifyAc(path);
    List<AccessControlPolicy> currentPolicies = Arrays.asList(acMgr.getPolicies(path));
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path);
    if (it.hasNext()) {
        AccessControlPolicy policy = it.nextAccessControlPolicy();
        acMgr.setPolicy(path, policy);
        superuser.refresh(false);
        String mgs = "Reverting 'setPolicy' must change back the return value of getPolicies.";
        if (currentPolicies.isEmpty()) {
            assertTrue(mgs, acMgr.getPolicies(path).length == 0);
        } else {
            assertEquals(mgs, currentPolicies, Arrays.asList(acMgr.getPolicies(path)));
        }
    } else {
        throw new NotExecutableException();
    }
}
Also used : NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 47 with AccessControlPolicy

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

the class CugAccessControlManagerTest method testGetEffectivePoliciesNotEnabled.

@Test
public void testGetEffectivePoliciesNotEnabled() throws Exception {
    cugAccessControlManager.setPolicy(SUPPORTED_PATH, createCug(SUPPORTED_PATH));
    root.commit();
    ConfigurationParameters config = ConfigurationParameters.of(AuthorizationConfiguration.NAME, ConfigurationParameters.of(CugConstants.PARAM_CUG_SUPPORTED_PATHS, SUPPORTED_PATHS, CugConstants.PARAM_CUG_ENABLED, false));
    CugAccessControlManager acMgr = new CugAccessControlManager(root, NamePathMapper.DEFAULT, new CugSecurityProvider(config), ImmutableSet.copyOf(SUPPORTED_PATHS));
    AccessControlPolicy[] policies = acMgr.getEffectivePolicies(SUPPORTED_PATH);
    assertEquals(0, policies.length);
    AccessControlPolicy[] effectiveOnChild = acMgr.getEffectivePolicies(SUPPORTED_PATH + "/subtree");
    assertEquals(0, policies.length);
    assertEquals(policies.length, effectiveOnChild.length);
}
Also used : JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) ConfigurationParameters(org.apache.jackrabbit.oak.spi.security.ConfigurationParameters) Test(org.junit.Test)

Example 48 with AccessControlPolicy

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

the class CugAccessControlManagerTest method testSetPolicy.

@Test
public void testSetPolicy() throws Exception {
    CugPolicy cug = getApplicableCug(SUPPORTED_PATH);
    cug.addPrincipals(EveryonePrincipal.getInstance());
    cugAccessControlManager.setPolicy(SUPPORTED_PATH, cug);
    AccessControlPolicy[] policies = cugAccessControlManager.getPolicies(SUPPORTED_PATH);
    assertEquals(1, policies.length);
    AccessControlPolicy policy = policies[0];
    assertTrue(policy instanceof CugPolicyImpl);
    Set<Principal> principals = ((CugPolicy) policy).getPrincipals();
    assertEquals(1, principals.size());
    assertEquals(EveryonePrincipal.getInstance(), principals.iterator().next());
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) NamedAccessControlPolicy(javax.jcr.security.NamedAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Principal(java.security.Principal) Test(org.junit.Test)

Example 49 with AccessControlPolicy

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

the class CugAccessControlManagerTest method testRemoveInvalidPolicy.

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

        public String getName() {
            return "name";
        }
    }, InvalidCug.INSTANCE);
    for (AccessControlPolicy policy : invalidPolicies) {
        try {
            cugAccessControlManager.removePolicy(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 50 with AccessControlPolicy

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

the class CompositeAccessControlManager method getEffectivePolicies.

@Override
public AccessControlPolicy[] getEffectivePolicies(String absPath) throws RepositoryException {
    ImmutableList.Builder<AccessControlPolicy> privs = ImmutableList.builder();
    for (AccessControlManager acMgr : acMgrs) {
        privs.add(acMgr.getEffectivePolicies(absPath));
    }
    List<AccessControlPolicy> l = privs.build();
    return l.toArray(new AccessControlPolicy[l.size()]);
}
Also used : AbstractAccessControlManager(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AbstractAccessControlManager) AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

AccessControlPolicy (javax.jcr.security.AccessControlPolicy)182 Test (org.junit.Test)67 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)66 AccessControlManager (javax.jcr.security.AccessControlManager)62 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)52 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)52 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)49 AccessControlEntry (javax.jcr.security.AccessControlEntry)40 AccessControlList (javax.jcr.security.AccessControlList)32 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)32 NamedAccessControlPolicy (javax.jcr.security.NamedAccessControlPolicy)28 Privilege (javax.jcr.security.Privilege)28 Principal (java.security.Principal)24 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)23 NodeImpl (org.apache.jackrabbit.core.NodeImpl)18 TestACL (org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.TestACL)18 Node (javax.jcr.Node)17 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)17 Root (org.apache.jackrabbit.oak.api.Root)14 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)14