Search in sources :

Example 11 with CugPolicy

use of org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy 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 12 with CugPolicy

use of org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy in project jackrabbit-oak by apache.

the class CugAccessControlManagerTest method testRemovePolicyPersisted.

@Test
public void testRemovePolicyPersisted() throws Exception {
    CugPolicy cug = getApplicableCug(SUPPORTED_PATH);
    cugAccessControlManager.setPolicy(SUPPORTED_PATH, cug);
    root.commit();
    cugAccessControlManager.removePolicy(SUPPORTED_PATH, cugAccessControlManager.getPolicies(SUPPORTED_PATH)[0]);
    root.commit();
    Tree tree = root.getTree(SUPPORTED_PATH);
    assertFalse(tree.hasChild(CugConstants.REP_CUG_POLICY));
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) Tree(org.apache.jackrabbit.oak.api.Tree) Test(org.junit.Test)

Example 13 with CugPolicy

use of org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy in project jackrabbit-oak by apache.

the class CugPolicyImplTest method testAddContainedPrincipal.

@Test
public void testAddContainedPrincipal() throws Exception {
    CugPolicy cug = new CugPolicyImpl(path, NamePathMapper.DEFAULT, principalManager, ImportBehavior.BESTEFFORT, principals);
    assertFalse(cug.addPrincipals(new PrincipalImpl("test")));
    assertEquals(principals, cug.getPrincipals());
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 14 with CugPolicy

use of org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy in project jackrabbit-oak by apache.

the class CugPolicyImplTest method testAddPrincipals.

@Test
public void testAddPrincipals() throws Exception {
    CugPolicy empty = createEmptyCugPolicy();
    assertTrue(empty.addPrincipals(EveryonePrincipal.getInstance()));
    assertFalse(empty.addPrincipals(EveryonePrincipal.getInstance()));
    CugPolicy cug = createCugPolicy(principals);
    assertTrue(cug.addPrincipals(EveryonePrincipal.getInstance()));
    assertFalse(cug.addPrincipals(EveryonePrincipal.getInstance()));
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 15 with CugPolicy

use of org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy in project jackrabbit-oak by apache.

the class CugPolicyImplTest method testGetPath.

@Test
public void testGetPath() {
    CugPolicy empty = createEmptyCugPolicy();
    assertEquals(path, empty.getPath());
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

CugPolicy (org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy)20 Test (org.junit.Test)18 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)12 PrincipalImpl (org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl)6 Principal (java.security.Principal)4 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)4 EveryonePrincipal (org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal)4 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)3 NamedAccessControlPolicy (javax.jcr.security.NamedAccessControlPolicy)2 Tree (org.apache.jackrabbit.oak.api.Tree)2 ArrayList (java.util.ArrayList)1 AccessControlManager (javax.jcr.security.AccessControlManager)1 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)1 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)1 Root (org.apache.jackrabbit.oak.api.Root)1 LocalNameMapper (org.apache.jackrabbit.oak.namepath.LocalNameMapper)1 NamePathMapper (org.apache.jackrabbit.oak.namepath.NamePathMapper)1 NamePathMapperImpl (org.apache.jackrabbit.oak.namepath.NamePathMapperImpl)1 ReadOnlyNodeTypeManager (org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager)1 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)1