Search in sources :

Example 31 with AccessControlList

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

the class ImportNodeCommandTest method keep_permissions_on_create.

@Test
public void keep_permissions_on_create() throws Exception {
    final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.ofAnonymous()).allowAll().deny(Permission.DELETE).build()).add(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().deny(Permission.DELETE).build()).build();
    final Node importNode = Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(new PropertyTree()).permissions(aclList).build();
    final ImportNodeResult importNodeResult = importNode(importNode);
    final Node abc = getNodeById(NodeId.from("abc"));
    assertNotNull(abc);
    assertEquals(aclList, abc.getPermissions());
    assertEquals(importNodeResult.getNode().getPermissions(), abc.getPermissions());
    assertFalse(importNodeResult.isPreExisting());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) Node(com.enonic.xp.node.Node) PropertyTree(com.enonic.xp.data.PropertyTree) ImportNodeResult(com.enonic.xp.node.ImportNodeResult) Test(org.junit.jupiter.api.Test)

Example 32 with AccessControlList

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

the class ImportNodeCommandTest method skip_permissions_on_update.

@Test
public void skip_permissions_on_update() throws Exception {
    final Node createdNode = importNode(Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(new PropertyTree()).build()).getNode();
    final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().deny(Permission.DELETE).build()).build();
    final Node updatedNode = importNode(Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(new PropertyTree()).permissions(aclList).build()).getNode();
    assertEquals(createdNode.getPermissions(), updatedNode.getPermissions());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) Node(com.enonic.xp.node.Node) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 33 with AccessControlList

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

the class NodeHandler method setRootPermissions.

@SuppressWarnings("unused")
public Object setRootPermissions(final ScriptValue value) {
    final ScriptValueTranslatorResult translatorResult = new ScriptValueTranslator(false).create(value);
    final PropertyTree asPropertyTree = translatorResult.getPropertyTree();
    final Iterable<PropertySet> asPropertySets = asPropertyTree.getSets("_permissions");
    final boolean inheritPermissions = asPropertyTree.getBoolean("_inheritsPermissions") != null ? asPropertyTree.getBoolean("_inheritsPermissions") : true;
    if (asPropertySets == null) {
        throw new IllegalArgumentException("Did not find parameter [_permissions]");
    }
    final AccessControlList permissions = new PermissionsFactory(asPropertySets).create();
    return execute(SetRootPermissionsHandler.create().permissions(permissions).inheritPermissions(inheritPermissions).nodeService(this.nodeService).build());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) ScriptValueTranslatorResult(com.enonic.xp.lib.value.ScriptValueTranslatorResult) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) ScriptValueTranslator(com.enonic.xp.lib.value.ScriptValueTranslator)

Example 34 with AccessControlList

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

the class AccessControlTest method role_system_admin_can_access_everything.

@Test
public void role_system_admin_can_access_everything() throws Exception {
    final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.from("user:myidprovider:rmy")).allow(Permission.READ).build()).add(AccessControlEntry.create().principal(PrincipalKey.from("user:myidprovider:tsi")).allow(Permission.READ).build()).build();
    final CreateNodeParams params = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).permissions(aclList).build();
    final Node node = this.nodeService.create(params);
    final Context anonContext = ContextBuilder.from(ctxDefault()).authInfo(AuthenticationInfo.create().user(User.ANONYMOUS).build()).build();
    assertNull(anonContext.callWith(() -> getNode(node.id())));
    final Context anonContextWithAdminUserRole = ContextBuilder.from(ctxDefault()).authInfo(AuthenticationInfo.create().principals(RoleKeys.ADMIN).user(User.ANONYMOUS).build()).build();
    assertNotNull(anonContextWithAdminUserRole.callWith(() -> getNode(node.id())));
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) Context(com.enonic.xp.context.Context) Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Example 35 with AccessControlList

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

the class AccessControlTest method index_has_read.

@Test
public void index_has_read() throws Exception {
    final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.from("user:myidprovider:rmy")).allow(Permission.READ).build()).add(AccessControlEntry.create().principal(PrincipalKey.from("user:myidprovider:tsi")).allow(Permission.READ).build()).build();
    final CreateNodeParams params = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).permissions(aclList).build();
    this.nodeService.create(params);
    refresh();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) 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