Search in sources :

Example 86 with AccessControlManager

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

the class CompositeAccessControlManager method getSupportedPrivileges.

//-----------------------------------------------< AccessControlManager >---
@Nonnull
@Override
public Privilege[] getSupportedPrivileges(String absPath) throws RepositoryException {
    ImmutableSet.Builder<Privilege> privs = ImmutableSet.builder();
    for (AccessControlManager acMgr : acMgrs) {
        privs.add(acMgr.getSupportedPrivileges(absPath));
    }
    Set<Privilege> s = privs.build();
    return s.toArray(new Privilege[s.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) ImmutableSet(com.google.common.collect.ImmutableSet) Privilege(javax.jcr.security.Privilege) Nonnull(javax.annotation.Nonnull)

Example 87 with AccessControlManager

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

the class CompositeAccessControlManager method getApplicablePolicies.

//-------------------------------------< JackrabbitAccessControlManager >---
@Override
public JackrabbitAccessControlPolicy[] getApplicablePolicies(Principal principal) throws RepositoryException {
    ImmutableList.Builder<JackrabbitAccessControlPolicy> policies = ImmutableList.builder();
    for (AccessControlManager acMgr : acMgrs) {
        if (acMgr instanceof JackrabbitAccessControlManager && acMgr instanceof PolicyOwner) {
            policies.add(((JackrabbitAccessControlManager) acMgr).getApplicablePolicies(principal));
        }
    }
    List<JackrabbitAccessControlPolicy> l = policies.build();
    return l.toArray(new JackrabbitAccessControlPolicy[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) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) ImmutableList(com.google.common.collect.ImmutableList) JackrabbitAccessControlPolicy(org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy) PolicyOwner(org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.PolicyOwner)

Example 88 with AccessControlManager

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

the class Jr2CompatibilityTest method after.

@Override
@After
public void after() throws Exception {
    try {
        AccessControlManager acMgr = getAccessControlManager(root);
        JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/");
        if (acl != null) {
            boolean modified = false;
            for (AccessControlEntry entry : acl.getAccessControlEntries()) {
                if (entry.getPrincipal().equals(getTestUser().getPrincipal())) {
                    acl.removeAccessControlEntry(entry);
                    modified = true;
                }
            }
            if (modified) {
                acMgr.setPolicy("/", acl);
                root.commit();
            }
        }
    } finally {
        super.after();
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlEntry(javax.jcr.security.AccessControlEntry) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) After(org.junit.After)

Example 89 with AccessControlManager

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

the class AccessControlActionTest method assertAcAction.

private void assertAcAction(Authorizable a, String expectedPrivName) throws Exception {
    AccessControlManager acMgr = getAccessControlManager(root);
    AccessControlPolicy[] policies = acMgr.getPolicies(a.getPath());
    assertEquals(1, policies.length);
    assertTrue(policies[0] instanceof AccessControlList);
    AccessControlList acl = (AccessControlList) policies[0];
    assertEquals(1, acl.getAccessControlEntries().length);
    assertArrayEquals(new Privilege[] { getPrivilegeManager(root).getPrivilege(expectedPrivName) }, acl.getAccessControlEntries()[0].getPrivileges());
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy)

Example 90 with AccessControlManager

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

the class L4_EffectivePoliciesTest method testSessionGetEffectivePolicies.

public void testSessionGetEffectivePolicies() throws Exception {
    // grant 'testUser' READ + WRITE privileges at the test root
    setupPolicy(testRoot, testPrivileges, testPrincipal);
    // grant 'testUser' READ + READ_AC privileges at child path
    Privilege[] privileges = AccessControlUtils.privilegesFromNames(acMgr, Privilege.JCR_READ, Privilege.JCR_READ_ACCESS_CONTROL);
    setupPolicy(childPath, privileges, testPrincipal);
    superuser.save();
    testSession = getTestSession();
    AccessControlManager testAcMgr = testSession.getAccessControlManager();
    AccessControlPolicy[] effective = testAcMgr.getEffectivePolicies(childPath);
    // EXERCISE
    int expectedLength = -1;
    assertEquals(expectedLength, effective.length);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) JackrabbitAccessControlManager(org.apache.jackrabbit.api.security.JackrabbitAccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Privilege(javax.jcr.security.Privilege)

Aggregations

AccessControlManager (javax.jcr.security.AccessControlManager)192 Privilege (javax.jcr.security.Privilege)82 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)77 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)62 Session (javax.jcr.Session)47 Test (org.junit.Test)45 AccessControlEntry (javax.jcr.security.AccessControlEntry)39 Node (javax.jcr.Node)33 AccessControlList (javax.jcr.security.AccessControlList)32 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)32 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)23 Principal (java.security.Principal)22 Value (javax.jcr.Value)17 HashMap (java.util.HashMap)14 JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)14 Group (org.apache.jackrabbit.api.security.user.Group)14 ValueFactory (javax.jcr.ValueFactory)13 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)13 NodeImpl (org.apache.jackrabbit.core.NodeImpl)13 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)12