Search in sources :

Example 1 with CugPolicy

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

the class CugAccessControlManager method getEffectivePolicies.

@Override
public AccessControlPolicy[] getEffectivePolicies(String absPath) throws RepositoryException {
    String oakPath = getOakPath(absPath);
    getTree(oakPath, Permissions.READ_ACCESS_CONTROL, true);
    boolean enabled = config.getConfigValue(CugConstants.PARAM_CUG_ENABLED, false);
    if (enabled) {
        Root r = getRoot().getContentSession().getLatestRoot();
        List<AccessControlPolicy> effective = new ArrayList<>();
        while (oakPath != null) {
            if (isSupportedPath(oakPath)) {
                CugPolicy cug = getCugPolicy(oakPath, r.getTree(oakPath));
                if (cug != null) {
                    effective.add(cug);
                }
            }
            oakPath = (PathUtils.denotesRoot(oakPath)) ? null : PathUtils.getAncestorPath(oakPath, 1);
        }
        return effective.toArray(new AccessControlPolicy[effective.size()]);
    } else {
        return new AccessControlPolicy[0];
    }
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Root(org.apache.jackrabbit.oak.api.Root) ArrayList(java.util.ArrayList)

Example 2 with CugPolicy

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

the class CugPolicyImplTest method testAddNullPrincipalName.

@Test(expected = AccessControlException.class)
public void testAddNullPrincipalName() throws Exception {
    CugPolicy cug = new CugPolicyImpl(path, NamePathMapper.DEFAULT, principalManager, ImportBehavior.BESTEFFORT);
    cug.addPrincipals(new Principal() {

        @Override
        public String getName() {
            return null;
        }
    });
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) Principal(java.security.Principal) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 3 with CugPolicy

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

the class CugPolicyImplTest method testRemoveNullPrincipal.

@Test
public void testRemoveNullPrincipal() throws Exception {
    CugPolicy cug = new CugPolicyImpl(path, NamePathMapper.DEFAULT, principalManager, ImportBehavior.ABORT, principals);
    assertTrue(cug.removePrincipals(testPrincipal, null));
    assertTrue(cug.getPrincipals().isEmpty());
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 4 with CugPolicy

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

the class CugPolicyImplTest method testAddNullPrincipal.

@Test
public void testAddNullPrincipal() throws Exception {
    CugPolicy cug = new CugPolicyImpl(path, NamePathMapper.DEFAULT, principalManager, ImportBehavior.ABORT, principals);
    assertTrue(cug.addPrincipals(EveryonePrincipal.getInstance(), null));
    assertTrue(cug.getPrincipals().contains(EveryonePrincipal.getInstance()));
    assertTrue(cug.getPrincipals().contains(testPrincipal));
}
Also used : CugPolicy(org.apache.jackrabbit.oak.spi.security.authorization.cug.CugPolicy) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 5 with CugPolicy

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

the class CugPolicyImplTest method testAddInvalidPrincipalsBestEffort.

@Test
public void testAddInvalidPrincipalsBestEffort() throws Exception {
    CugPolicy cug = new CugPolicyImpl(path, NamePathMapper.DEFAULT, principalManager, ImportBehavior.BESTEFFORT, principals);
    assertTrue(cug.addPrincipals(EveryonePrincipal.getInstance(), new PrincipalImpl("unknown")));
    Set<Principal> principalSet = cug.getPrincipals();
    assertEquals(3, principalSet.size());
}
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)

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