Search in sources :

Example 16 with CugPolicy

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

the class CugPolicyImplTest method testAddInvalidPrincipalsIgnore.

@Test
public void testAddInvalidPrincipalsIgnore() throws Exception {
    CugPolicy cug = new CugPolicyImpl(path, NamePathMapper.DEFAULT, principalManager, ImportBehavior.IGNORE, principals);
    assertTrue(cug.addPrincipals(new PrincipalImpl("unknown"), EveryonePrincipal.getInstance()));
    Set<Principal> principalSet = cug.getPrincipals();
    assertEquals(2, principalSet.size());
    assertFalse(principalSet.contains(new PrincipalImpl("unknown")));
    assertFalse(principalSet.contains(new PrincipalImpl("")));
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) PrincipalImpl(org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 17 with CugPolicy

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

the class AbstractCugTest method createCug.

void createCug(@Nonnull String absPath, @Nonnull Principal principal) throws RepositoryException {
    AccessControlManager acMgr = getAccessControlManager(root);
    AccessControlPolicyIterator it = acMgr.getApplicablePolicies(absPath);
    while (it.hasNext()) {
        AccessControlPolicy policy = it.nextAccessControlPolicy();
        if (policy instanceof CugPolicy) {
            ((CugPolicy) policy).addPrincipals(principal);
            acMgr.setPolicy(absPath, policy);
            return;
        }
    }
    throw new IllegalStateException("Unable to create CUG at " + absPath);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 18 with CugPolicy

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

the class CugAccessControlManagerTest method testGetPoliciesAfterManualCreation.

@Test
public void testGetPoliciesAfterManualCreation() throws Exception {
    NodeUtil n = new NodeUtil(root.getTree(SUPPORTED_PATH));
    NodeUtil cug = n.addChild(REP_CUG_POLICY, NT_REP_CUG_POLICY);
    AccessControlPolicy[] policies = cugAccessControlManager.getPolicies(SUPPORTED_PATH);
    assertEquals(1, policies.length);
    assertTrue(policies[0] instanceof CugPolicy);
    CugPolicy cugPolicy = (CugPolicy) policies[0];
    assertTrue(cugPolicy.getPrincipals().isEmpty());
    cug.setStrings(REP_PRINCIPAL_NAMES, "unknownPrincipalName", EveryonePrincipal.NAME);
    policies = cugAccessControlManager.getPolicies(SUPPORTED_PATH);
    cugPolicy = (CugPolicy) policies[0];
    assertEquals(2, cugPolicy.getPrincipals().size());
}
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) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 19 with CugPolicy

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

the class CugAccessControlManagerTest method testRemovePolicy.

@Test
public void testRemovePolicy() throws Exception {
    CugPolicy cug = getApplicableCug(SUPPORTED_PATH);
    cugAccessControlManager.setPolicy(SUPPORTED_PATH, cug);
    cugAccessControlManager.removePolicy(SUPPORTED_PATH, cugAccessControlManager.getPolicies(SUPPORTED_PATH)[0]);
    assertArrayEquals(new AccessControlPolicy[0], cugAccessControlManager.getPolicies(SUPPORTED_PATH));
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) Test(org.junit.Test)

Example 20 with CugPolicy

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

the class CugAccessControlManagerTest method testSetPolicyPersisted.

@Test
public void testSetPolicyPersisted() throws Exception {
    CugPolicy cug = getApplicableCug(SUPPORTED_PATH);
    cug.addPrincipals(EveryonePrincipal.getInstance());
    cugAccessControlManager.setPolicy(SUPPORTED_PATH, cug);
    root.commit();
    Tree tree = root.getTree(SUPPORTED_PATH);
    assertTrue(TreeUtil.isNodeType(tree, CugConstants.MIX_REP_CUG_MIXIN, root.getTree(NodeTypeConstants.NODE_TYPES_PATH)));
    Tree cugTree = tree.getChild(CugConstants.REP_CUG_POLICY);
    assertTrue(cugTree.exists());
    assertEquals(CugConstants.NT_REP_CUG_POLICY, TreeUtil.getPrimaryTypeName(cugTree));
    PropertyState prop = cugTree.getProperty(CugConstants.REP_PRINCIPAL_NAMES);
    assertNotNull(prop);
    assertTrue(prop.isArray());
    assertEquals(Type.STRINGS, prop.getType());
    assertEquals(1, prop.count());
    assertEquals(EveryonePrincipal.NAME, prop.getValue(Type.STRING, 0));
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) Tree(org.apache.jackrabbit.oak.api.Tree) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) 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