Search in sources :

Example 26 with CreateNodeParams

use of com.enonic.xp.node.CreateNodeParams 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 27 with CreateNodeParams

use of com.enonic.xp.node.CreateNodeParams 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)

Example 28 with CreateNodeParams

use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.

the class GetNodeByIdAndVersionIdCommandTest method testExecute_NonRootNode.

@Test
public void testExecute_NonRootNode() {
    final CreateNodeParams createNodeParams = CreateNodeParams.create().name("child-node").parent(NodePath.ROOT).build();
    final Node createdNode = createNode(createNodeParams);
    final Node result = GetNodeByIdAndVersionIdCommand.create().nodeId(createdNode.id()).versionId(createdNode.getNodeVersionId()).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    assertNotNull(result);
    assertEquals(createdNode, result);
}
Also used : Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Example 29 with CreateNodeParams

use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.

the class GetNodeByPathAndVersionIdCommandTest method testExecute_NonRootNode.

@Test
public void testExecute_NonRootNode() {
    final CreateNodeParams createNodeParams = CreateNodeParams.create().name("child-node").parent(NodePath.ROOT).build();
    final Node createdNode = createNode(createNodeParams);
    final Node result = GetNodeByPathAndVersionIdCommand.create().nodePath(createdNode.path()).versionId(createdNode.getNodeVersionId()).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    assertNotNull(result);
    assertEquals(createdNode, result);
}
Also used : Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Example 30 with CreateNodeParams

use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.

the class GetNodeByIdCommandTest method get_by_id_no_access.

@Test
public void get_by_id_no_access() throws Exception {
    final CreateNodeParams createNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).permissions(AccessControlList.create().add(AccessControlEntry.create().deny(Permission.READ).principal(PrincipalKey.ofAnonymous()).build()).add(AccessControlEntry.create().allow(Permission.READ).principal(PrincipalKey.from("user:system:rmy")).build()).build()).build();
    final Node createdNode = createNode(createNodeParams);
    final Node fetchedNode = GetNodeByIdCommand.create().indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).id(createdNode.id()).build().execute();
    assertNull(fetchedNode);
}
Also used : Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Aggregations

CreateNodeParams (com.enonic.xp.node.CreateNodeParams)46 Node (com.enonic.xp.node.Node)32 Test (org.junit.jupiter.api.Test)28 PropertyTree (com.enonic.xp.data.PropertyTree)18 BinaryReference (com.enonic.xp.util.BinaryReference)9 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)8 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)7 NodeId (com.enonic.xp.node.NodeId)4 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)4 AccessControlList (com.enonic.xp.security.acl.AccessControlList)4 ByteSource (com.google.common.io.ByteSource)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 NodeBinaryReferenceException (com.enonic.xp.node.NodeBinaryReferenceException)3 NodeIdExistsException (com.enonic.xp.node.NodeIdExistsException)3 NodePath (com.enonic.xp.node.NodePath)3 PrincipalAlreadyExistsException (com.enonic.xp.security.PrincipalAlreadyExistsException)3 ByteStreams (com.google.common.io.ByteStreams)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)3