Search in sources :

Example 51 with AccessControlList

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

the class PentahoACLProvider method updateRootAcl.

/**
 * Adds ACE so that everyone can read access control. This allows Jackrabbit's default collectAcls to work without
 * change. Otherwise, you have to be an admin to call acMgr.getEffectivePolicies.
 */
protected void updateRootAcl(SessionImpl systemSession, ACLEditor editor) throws RepositoryException {
    String rootPath = session.getRootNode().getPath();
    AccessControlPolicy[] acls = editor.getPolicies(rootPath);
    if (acls.length > 0) {
        PrincipalManager pMgr = systemSession.getPrincipalManager();
        AccessControlManager acMgr = session.getAccessControlManager();
        Principal everyone = pMgr.getEveryone();
        Privilege[] privs = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
        AccessControlList acList = (AccessControlList) acls[0];
        AccessControlEntry[] acEntries = acList.getAccessControlEntries();
        for (AccessControlEntry acEntry : acEntries) {
            if (acEntry.getPrincipal().equals(everyone)) {
                acList.removeAccessControlEntry(acEntry);
            }
        }
        acList.addAccessControlEntry(everyone, privs);
        editor.setPolicy(rootPath, acList);
        session.save();
    }
}
Also used : PrincipalManager(org.apache.jackrabbit.api.security.principal.PrincipalManager) AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessControlPolicy(javax.jcr.security.AccessControlPolicy) AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege) Principal(java.security.Principal)

Example 52 with AccessControlList

use of javax.jcr.security.AccessControlList in project vorto by eclipse.

the class ModelPolicyManager method addPolicyEntry.

@Override
public void addPolicyEntry(ModelId modelId, PolicyEntry... newEntries) {
    doInSession(session -> {
        try {
            ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
            Node nodeToAddPolicy = session.getNode(modelIdHelper.getFullPath());
            AccessControlManager acm = session.getAccessControlManager();
            AccessControlList acl = getAccessControlList(nodeToAddPolicy, acm);
            final AccessControlList _acl = acl;
            // put all existing ACE that are in newEntries to existingEntries
            List<AccessControlEntry> existingEntries = putAllExistingACEFromNewEntriesToExistingEntries(acl, newEntries);
            // remove all existingEntries, entries that are in newEntries
            removeAllExistingEntries(_acl, existingEntries);
            // create ACE for every entry in newEntries
            createAceForEveryEntryInNewEntries(acm, _acl, newEntries);
            acm.setPolicy(nodeToAddPolicy.getPath(), _acl);
            session.save();
            return null;
        } catch (AccessDeniedException ex) {
            throw new NotAuthorizedException(modelId);
        }
    });
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessDeniedException(javax.jcr.AccessDeniedException) ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) Node(javax.jcr.Node) AccessControlEntry(javax.jcr.security.AccessControlEntry) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException)

Example 53 with AccessControlList

use of javax.jcr.security.AccessControlList in project vorto by eclipse.

the class ModelPolicyManager method getPolicyEntries.

@Override
public Collection<PolicyEntry> getPolicyEntries(ModelId modelId) {
    return doInSession(session -> {
        try {
            ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
            Node nodeToGetPolicies = session.getNode(modelIdHelper.getFullPath());
            AccessControlManager acm = session.getAccessControlManager();
            AccessControlList acl = getAccessControlList(nodeToGetPolicies, acm);
            return convertAccessControlEntriesToPolicyEntries(acl);
        } catch (AccessDeniedException ex) {
            LOGGER.warn(String.format("No policy entry found for model ID [%s] with current user. Returning empty collection.", modelId));
            return Collections.emptyList();
        }
    });
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessDeniedException(javax.jcr.AccessDeniedException) ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) Node(javax.jcr.Node)

Example 54 with AccessControlList

use of javax.jcr.security.AccessControlList in project vorto by eclipse.

the class ModelPolicyManager method removePolicyEntry.

@Override
public void removePolicyEntry(ModelId modelId, PolicyEntry entryToRemove) {
    entryToRemove.setPermission(null);
    this.addPolicyEntry(modelId, entryToRemove);
    if (this.getPolicyEntries(modelId).isEmpty()) {
        doInSession(session -> {
            try {
                ModelIdHelper modelIdHelper = new ModelIdHelper(modelId);
                Node nodeToRemovePolicy = session.getNode(modelIdHelper.getFullPath());
                AccessControlManager acm = session.getAccessControlManager();
                AccessControlList acl = getAccessControlList(nodeToRemovePolicy, acm);
                acm.removePolicy(nodeToRemovePolicy.getPath(), acl);
                session.save();
                return null;
            } catch (AccessDeniedException ex) {
                throw new NotAuthorizedException(modelId);
            }
        });
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) AccessDeniedException(javax.jcr.AccessDeniedException) ModelIdHelper(org.eclipse.vorto.repository.core.impl.utils.ModelIdHelper) Node(javax.jcr.Node) NotAuthorizedException(org.eclipse.vorto.repository.web.core.exceptions.NotAuthorizedException)

Example 55 with AccessControlList

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

the class AbstractCugTest method setupCugsAndAcls.

void setupCugsAndAcls() throws Exception {
    UserManager uMgr = getUserManager(root);
    Principal testGroupPrincipal = getTestGroupPrincipal();
    User testUser2 = uMgr.createUser(TEST_USER2_ID, TEST_USER2_ID);
    ((Group) uMgr.getAuthorizable(testGroupPrincipal)).addMember(testUser2);
    root.commit();
    User testUser = getTestUser();
    // add more child nodes
    NodeUtil n = new NodeUtil(root.getTree(SUPPORTED_PATH));
    n.addChild("a", NT_OAK_UNSTRUCTURED).addChild("b", NT_OAK_UNSTRUCTURED).addChild("c", NT_OAK_UNSTRUCTURED);
    n.addChild("aa", NT_OAK_UNSTRUCTURED).addChild("bb", NT_OAK_UNSTRUCTURED).addChild("cc", NT_OAK_UNSTRUCTURED);
    // create cugs
    // - /content/a     : allow testGroup, deny everyone
    // - /content/aa/bb : allow testGroup, deny everyone
    // - /content/a/b/c : allow everyone,  deny testGroup (isolated)
    // - /content2      : allow everyone,  deny testGroup (isolated)
    createCug("/content/a", testGroupPrincipal);
    createCug("/content/aa/bb", testGroupPrincipal);
    createCug("/content/a/b/c", EveryonePrincipal.getInstance());
    createCug("/content2", EveryonePrincipal.getInstance());
    // setup regular acl at /content:
    // - testUser  ; allow ; jcr:read
    // - testGroup ; allow ; jcr:read, jcr:write, jcr:readAccessControl
    AccessControlManager acMgr = getAccessControlManager(root);
    AccessControlList acl = AccessControlUtils.getAccessControlList(acMgr, "/content");
    acl.addAccessControlEntry(testUser.getPrincipal(), privilegesFromNames(PrivilegeConstants.JCR_READ));
    acl.addAccessControlEntry(testGroupPrincipal, privilegesFromNames(PrivilegeConstants.JCR_READ, PrivilegeConstants.REP_WRITE, PrivilegeConstants.JCR_READ_ACCESS_CONTROL));
    acMgr.setPolicy("/content", acl);
    root.commit();
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) AccessControlList(javax.jcr.security.AccessControlList) Group(org.apache.jackrabbit.api.security.user.Group) User(org.apache.jackrabbit.api.security.user.User) UserManager(org.apache.jackrabbit.api.security.user.UserManager) EveryonePrincipal(org.apache.jackrabbit.oak.spi.security.principal.EveryonePrincipal) Principal(java.security.Principal) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil)

Aggregations

AccessControlList (javax.jcr.security.AccessControlList)97 AccessControlEntry (javax.jcr.security.AccessControlEntry)49 AccessControlManager (javax.jcr.security.AccessControlManager)49 AccessControlPolicy (javax.jcr.security.AccessControlPolicy)39 Privilege (javax.jcr.security.Privilege)25 Node (javax.jcr.Node)17 RepositoryException (javax.jcr.RepositoryException)17 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)17 AccessControlPolicyIterator (javax.jcr.security.AccessControlPolicyIterator)15 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)15 Test (org.junit.Test)13 Principal (java.security.Principal)12 AccessDeniedException (javax.jcr.AccessDeniedException)12 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)6 AccessControlException (javax.jcr.security.AccessControlException)6 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)6 NodeImpl (org.apache.jackrabbit.core.NodeImpl)6 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)5 AccessControlException (java.security.AccessControlException)5