Search in sources :

Example 41 with AccessControlList

use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.

the class ApplyNodePermissionsCommand method applyPermissionsToChildren.

private void applyPermissionsToChildren(final Node parent) {
    final AccessControlList parentPermissions = parent.getPermissions();
    final FindNodesByParentParams findByParentParams = FindNodesByParentParams.create().parentPath(parent.path()).size(NodeSearchService.GET_ALL_SIZE_FLAG).build();
    final FindNodesByParentResult result = doFindNodesByParent(findByParentParams);
    final Nodes children = GetNodesByIdsCommand.create(this).ids(result.getNodeIds()).build().execute();
    for (Node child : children) {
        applyPermissions(parentPermissions, child);
    }
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) Node(com.enonic.xp.node.Node) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) Nodes(com.enonic.xp.node.Nodes)

Example 42 with AccessControlList

use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.

the class ApplyNodePermissionsCommand method storePermissions.

private Node storePermissions(final AccessControlList permissions, final Node node) {
    final Node updatedNode;
    final boolean isParent = node.id().equals(params.getNodeId());
    if (params.isOverwriteChildPermissions() || node.inheritsPermissions() || isParent) {
        updatedNode = createUpdatedNode(node, permissions, !isParent || params.isInheritPermissions());
    } else {
        final AccessControlList mergedPermissions = mergingStrategy.mergePermissions(node.getPermissions(), permissions);
        updatedNode = createUpdatedNode(node, mergedPermissions, false);
    }
    final Node result = StoreNodeCommand.create(this).node(updatedNode).updateMetadataOnly(false).build().execute();
    return result;
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) Node(com.enonic.xp.node.Node)

Example 43 with AccessControlList

use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.

the class AccessControlListIndexDocumentFactoryTest method single_user.

@Test
public void single_user() throws Exception {
    final AccessControlList acl = AccessControlList.create().add(AccessControlEntry.create().allow(Permission.READ).principal(PrincipalKey.from("user:myidprovider:rmy")).build()).build();
    final List<IndexItem> aclStoreDocumentItems = AccessControlListStoreDocumentFactory.create(acl);
    assertEquals(1, aclStoreDocumentItems.size());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IndexItem(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem) Test(org.junit.jupiter.api.Test)

Example 44 with AccessControlList

use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.

the class AccessControlListIndexDocumentFactoryTest method multiple_user.

@Test
public void multiple_user() throws Exception {
    final AccessControlList acl = AccessControlList.create().add(AccessControlEntry.create().allow(Permission.READ).principal(PrincipalKey.from("user:myidprovider:rmy")).build()).add(AccessControlEntry.create().allow(Permission.READ).principal(PrincipalKey.from("user:myidprovider:tsi")).build()).add(AccessControlEntry.create().allow(Permission.READ).allow(Permission.DELETE).principal(PrincipalKey.from("user:myidprovider:aro")).build()).add(AccessControlEntry.create().allow(Permission.DELETE).principal(PrincipalKey.from("user:myidprovider:srs")).build()).build();
    final List<IndexItem> aclStoreDocumentItems = AccessControlListStoreDocumentFactory.create(acl);
    assertEquals(5, aclStoreDocumentItems.size());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IndexItem(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem) Test(org.junit.jupiter.api.Test)

Example 45 with AccessControlList

use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.

the class AccessControlListIndexDocumentFactoryTest method single_user_all_permissions.

@Test
public void single_user_all_permissions() throws Exception {
    final AccessControlList acl = AccessControlList.create().add(AccessControlEntry.create().allow(Permission.READ).allow(Permission.PUBLISH).allow(Permission.WRITE_PERMISSIONS).allow(Permission.READ_PERMISSIONS).allow(Permission.MODIFY).allow(Permission.CREATE).allow(Permission.DELETE).principal(PrincipalKey.from("user:myidprovider:rmy")).build()).build();
    final List<IndexItem> aclStoreDocumentItems = AccessControlListStoreDocumentFactory.create(acl);
    assertEquals(7, aclStoreDocumentItems.size());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IndexItem(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem) Test(org.junit.jupiter.api.Test)

Aggregations

AccessControlList (com.enonic.xp.security.acl.AccessControlList)53 Test (org.junit.jupiter.api.Test)35 Node (com.enonic.xp.node.Node)26 PropertyTree (com.enonic.xp.data.PropertyTree)15 PrincipalKey (com.enonic.xp.security.PrincipalKey)8 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)6 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)6 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)6 AccessControlEntry (com.enonic.xp.security.acl.AccessControlEntry)5 Content (com.enonic.xp.content.Content)4 Context (com.enonic.xp.context.Context)4 PropertySet (com.enonic.xp.data.PropertySet)4 ApplyNodePermissionsParams (com.enonic.xp.node.ApplyNodePermissionsParams)4 NodeId (com.enonic.xp.node.NodeId)4 NodePath (com.enonic.xp.node.NodePath)4 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)3 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)3 ImportNodeResult (com.enonic.xp.node.ImportNodeResult)3 Nodes (com.enonic.xp.node.Nodes)3 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)3