Search in sources :

Example 66 with AccessControlPolicyIterator

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

the class AccessControlManagerImplTest method testGetPolicesAfterSetPoliciesCall.

/**
 * Tests the binding state of a policy.
 * @throws Exception
 */
public void testGetPolicesAfterSetPoliciesCall() throws Exception {
    try {
        AccessControlPolicyIterator policies = acMgr.getApplicablePolicies(testRoot);
        AccessControlPolicy policy = null;
        while (policies.hasNext()) {
            policy = policies.nextAccessControlPolicy();
            acMgr.setPolicy(testRoot, policy);
            AccessControlPolicy[] acl = acMgr.getPolicies(testRoot);
            assertNotNull(acl);
        }
    } finally {
        superuser.refresh(false);
    }
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Example 67 with AccessControlPolicyIterator

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

the class AccessControlImporterTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    if (!(superuser instanceof SessionImpl)) {
        throw new NotExecutableException("SessionImpl expected");
    }
    sImpl = (SessionImpl) superuser;
    // make sure the repository provides resource based policies.
    AccessControlPolicyIterator it = sImpl.getAccessControlManager().getApplicablePolicies("/");
    if (!it.hasNext()) {
        AccessControlPolicy[] pcs = sImpl.getAccessControlManager().getPolicies("/");
        if (pcs == null || pcs.length == 0) {
            throw new NotExecutableException();
        }
    }
// ok resource based acl
}
Also used : AccessControlPolicy(javax.jcr.security.AccessControlPolicy) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Example 68 with AccessControlPolicyIterator

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

the class AccessControlAction method setAC.

// ------------------------------------------------------------< private >---
private void setAC(Authorizable authorizable, Session session) throws RepositoryException {
    Node aNode;
    String path = authorizable.getPath();
    JackrabbitAccessControlList acl = null;
    AccessControlManager acMgr = session.getAccessControlManager();
    for (AccessControlPolicyIterator it = acMgr.getApplicablePolicies(path); it.hasNext(); ) {
        AccessControlPolicy plc = it.nextAccessControlPolicy();
        if (plc instanceof JackrabbitAccessControlList) {
            acl = (JackrabbitAccessControlList) plc;
            break;
        }
    }
    if (acl == null) {
        log.warn("Cannot process AccessControlAction: no applicable ACL at " + path);
    } else {
        // setup acl according to configuration.
        Principal principal = new UnknownPrincipal(authorizable.getPrincipal().getName());
        boolean modified = false;
        if (authorizable.isGroup()) {
            // new authorizable is a Group
            if (groupPrivilegeNames.length > 0) {
                modified = acl.addAccessControlEntry(principal, getPrivileges(groupPrivilegeNames, acMgr));
            }
        } else {
            // new authorizable is a User
            if (userPrivilegeNames.length > 0) {
                modified = acl.addAccessControlEntry(principal, getPrivileges(userPrivilegeNames, acMgr));
            }
        }
        if (modified) {
            acMgr.setPolicy(path, acl);
        }
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Node(javax.jcr.Node) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) UnknownPrincipal(org.apache.jackrabbit.core.security.principal.UnknownPrincipal) Principal(java.security.Principal) UnknownPrincipal(org.apache.jackrabbit.core.security.principal.UnknownPrincipal)

Example 69 with AccessControlPolicyIterator

use of javax.jcr.security.AccessControlPolicyIterator in project pentaho-platform by pentaho.

the class JcrRepositoryFileAclDao method getAccessControlList.

private AccessControlList getAccessControlList(final AccessControlManager acMgr, final String path) throws RepositoryException {
    AccessControlPolicyIterator applicablePolicies = acMgr.getApplicablePolicies(path);
    while (applicablePolicies.hasNext()) {
        AccessControlPolicy policy = applicablePolicies.nextAccessControlPolicy();
        if (policy instanceof AccessControlList) {
            return (AccessControlList) policy;
        }
    }
    AccessControlPolicy[] policies = acMgr.getPolicies(path);
    for (int i = 0; i < policies.length; i++) {
        if (policies[i] instanceof AccessControlList) {
            return (AccessControlList) policies[i];
        }
    }
    throw new IllegalStateException("no access control list applies or is bound to node");
}
Also used : AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator)

Aggregations

AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)69 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)54 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)22 Test (org.junit.Test)16 NamedAccessControlPolicy (javax.jcr.security.NamedAccessControlPolicy)15 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)15 AccessControlList (javax.jcr.security.AccessControlList)14 AccessControlManager (javax.jcr.security.AccessControlManager)13 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)11 Node (javax.jcr.Node)7 Privilege (javax.jcr.security.Privilege)6 JackrabbitAccessControlPolicy (org.apache.jackrabbit.api.security.JackrabbitAccessControlPolicy)6 AccessControlEntry (javax.jcr.security.AccessControlEntry)5 Principal (java.security.Principal)3 HashSet (java.util.HashSet)3 Item (javax.jcr.Item)3 RepositoryException (javax.jcr.RepositoryException)3 JackrabbitAccessControlManager (org.apache.jackrabbit.api.security.JackrabbitAccessControlManager)3 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2