Search in sources :

Example 11 with AccessControlManager

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

the class ConcurrentReadAccessControlledTreeTest method beforeSuite.

@Override
protected void beforeSuite() throws Exception {
    super.beforeSuite();
    ItemVisitor visitor = new TraversingItemVisitor.Default() {

        int counter = 0;

        @Override
        protected void entering(Node node, int level) throws RepositoryException {
            if (++counter == 10) {
                addPolicy(node);
                counter = 0;
            }
            super.entering(node, level);
        }

        private void addPolicy(Node node) throws RepositoryException {
            AccessControlManager acMgr = node.getSession().getAccessControlManager();
            String path = node.getPath();
            AccessControlPolicyIterator acIterator = acMgr.getApplicablePolicies(path);
            if (acIterator.hasNext()) {
                AccessControlPolicy policy = acIterator.nextAccessControlPolicy();
                if (policy instanceof AccessControlList) {
                    AccessControlList acl = (AccessControlList) policy;
                    Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
                    if (acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privileges)) {
                        acMgr.setPolicy(path, acl);
                        node.getSession().save();
                    }
                }
            }
        }
    };
    visitor.visit(testRoot);
    for (int i = 0; i < bgReaders; i++) {
        addBackgroundJob(new RandomRead(loginReader(), false));
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) ItemVisitor(javax.jcr.ItemVisitor) TraversingItemVisitor(javax.jcr.util.TraversingItemVisitor) Node(javax.jcr.Node) AccessControlPolicyIterator(javax.jcr.security.AccessControlPolicyIterator) Privilege(javax.jcr.security.Privilege)

Example 12 with AccessControlManager

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

the class AceCreationTest method afterTest.

@Override
protected void afterTest() throws Exception {
    Session session = createOrGetSystemSession();
    AccessControlManager acm = session.getAccessControlManager();
    for (AccessControlPolicy policy : acm.getPolicies(nodePath)) {
        acm.removePolicy(nodePath, policy);
    }
    save(session, transientWrites);
    super.afterTest();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) Session(javax.jcr.Session)

Example 13 with AccessControlManager

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

the class AceCreationTest method createAce.

private void createAce(Session session, int count) throws RepositoryException {
    AccessControlManager acManager = session.getAccessControlManager();
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acManager, nodePath);
    for (int i = 0; i < count; i++) {
        ImmutableMap<String, Value> restrictions = ImmutableMap.of(AccessControlConstants.REP_GLOB, session.getValueFactory().createValue(i + ""));
        acl.addEntry(EveryonePrincipal.getInstance(), AccessControlUtils.privilegesFromNames(acManager, Privilege.JCR_ADD_CHILD_NODES), true, restrictions);
    }
    acManager.setPolicy(nodePath, acl);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Value(javax.jcr.Value) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 14 with AccessControlManager

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

the class CompositeAuthorizationConfigurationTest method testSingleGetAccessControlManager.

@Test
public void testSingleGetAccessControlManager() {
    CompositeAuthorizationConfiguration cc = getCompositeConfiguration(new AuthorizationConfigurationImpl(getSecurityProvider()));
    AccessControlManager accessControlManager = cc.getAccessControlManager(root, NamePathMapper.DEFAULT);
    assertFalse(accessControlManager instanceof CompositeAccessControlManager);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AuthorizationConfigurationImpl(org.apache.jackrabbit.oak.security.authorization.AuthorizationConfigurationImpl) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 15 with AccessControlManager

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

the class ACLProvider method initRootACL.

/**
     * Set-up minimal permissions for the workspace:
     *
     * <ul>
     * <li>'adminstrators' principal -> all privileges</li>
     * <li>'everyone' -> read privilege</li>
     * </ul>
     *
     * @param session to the workspace to set-up initial ACL to
     * @param editor for the specified session.
     * @throws RepositoryException If an error occurs.
     */
private static void initRootACL(SessionImpl session, AccessControlEditor editor) throws RepositoryException {
    try {
        log.debug("Install initial ACL:...");
        String rootPath = session.getRootNode().getPath();
        AccessControlPolicy[] acls = editor.editAccessControlPolicies(rootPath);
        if (acls.length > 0) {
            ACLTemplate acl = (ACLTemplate) acls[0];
            PrincipalManager pMgr = session.getPrincipalManager();
            AccessControlManager acMgr = session.getAccessControlManager();
            String pName = SecurityConstants.ADMINISTRATORS_NAME;
            if (pMgr.hasPrincipal(pName)) {
                Principal administrators = pMgr.getPrincipal(pName);
                log.debug("... Privilege.ALL for administrators.");
                Privilege[] privs = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_ALL) };
                acl.addAccessControlEntry(administrators, privs);
            } else {
                log.info("Administrators principal group is missing -> omitting initialization of default permissions.");
            }
            Principal everyone = pMgr.getEveryone();
            log.debug("... Privilege.READ for everyone.");
            Privilege[] privs = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ) };
            acl.addAccessControlEntry(everyone, privs);
            editor.setPolicy(rootPath, acl);
            session.save();
        } else {
            log.info("No applicable ACL available for the root node -> skip initialization of the root node's ACL.");
        }
    } catch (RepositoryException e) {
        log.error("Failed to set-up minimal access control for root node of workspace " + session.getWorkspace().getName());
        session.getRootNode().refresh(false);
    }
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) RepositoryException(javax.jcr.RepositoryException) Privilege(javax.jcr.security.Privilege) Principal(java.security.Principal)

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