Search in sources :

Example 51 with AccessControlList

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

the class NodePermissionsResolverTest method system_admin_has_permission.

@Test
public void system_admin_has_permission() throws Exception {
    final AuthenticationInfo authInfo = AuthenticationInfo.create().user(User.create().key(USER_A).login("usera").build()).principals(RoleKeys.ADMIN).build();
    final AccessControlList nodePermissions = AccessControlList.create().add(AccessControlEntry.create().principal(USER_A).allow(READ).build()).add(AccessControlEntry.create().principal(GROUP_B).allow(CREATE).build()).add(AccessControlEntry.create().principal(ROLE_C).allow(MODIFY).build()).build();
    assertTrue(NodePermissionsResolver.userHasPermission(authInfo, READ, nodePermissions));
    assertTrue(NodePermissionsResolver.userHasPermission(authInfo, CREATE, nodePermissions));
    assertTrue(NodePermissionsResolver.userHasPermission(authInfo, MODIFY, nodePermissions));
    assertTrue(NodePermissionsResolver.userHasPermission(authInfo, PUBLISH, nodePermissions));
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Test(org.junit.jupiter.api.Test)

Example 52 with AccessControlList

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

the class NodePermissionsResolverTest method hasPermissionEmptyACL.

@Test
public void hasPermissionEmptyACL() throws Exception {
    final AuthenticationInfo authInfo = AuthenticationInfo.create().user(User.ANONYMOUS).principals(PrincipalKey.ofAnonymous()).build();
    final AccessControlList nodePermissions = AccessControlList.create().add(AccessControlEntry.create().principal(USER_A).allow(READ).build()).add(AccessControlEntry.create().principal(GROUP_B).allow(CREATE).build()).add(AccessControlEntry.create().principal(ROLE_C).allow(MODIFY).build()).build();
    assertFalse(NodePermissionsResolver.userHasPermission(authInfo, READ, nodePermissions));
    assertFalse(NodePermissionsResolver.userHasPermission(authInfo, CREATE, nodePermissions));
    assertFalse(NodePermissionsResolver.userHasPermission(authInfo, MODIFY, nodePermissions));
    assertFalse(NodePermissionsResolver.userHasPermission(authInfo, PUBLISH, nodePermissions));
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Test(org.junit.jupiter.api.Test)

Example 53 with AccessControlList

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

the class SetRootPermissionsHandlerTest method example.

@Test
public void example() {
    final AccessControlList acl = AccessControlList.create().add(AccessControlEntry.create().principal(RoleKeys.ADMIN).allowAll().build()).build();
    Mockito.when(this.repositoryService.get(RepositoryId.from("com.enonic.cms.default"))).thenReturn(Repository.create().id(RepositoryId.from("com.enonic.cms.default")).branches(Branches.from(ContentConstants.BRANCH_DRAFT, ContentConstants.BRANCH_MASTER)).build());
    Mockito.when(this.nodeService.setRootPermissions(acl, true)).thenReturn(Node.create().permissions(acl).inheritPermissions(true).build());
    runScript("/lib/xp/examples/node/modifyRootPermissions.js");
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) 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