use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.
the class ProjectServiceImplTest method create_with_root_content_permissions.
@Test
void create_with_root_content_permissions() {
final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
final ProjectName projectName = ProjectName.from(projectRepoId);
doCreateProjectAsAdmin(projectName);
List.of(ContextBuilder.from(adminContext()).branch(ContentConstants.BRANCH_DRAFT).repositoryId(projectRepoId).build(), ContextBuilder.from(adminContext()).branch(ContentConstants.BRANCH_MASTER).repositoryId(projectRepoId).build()).forEach(context -> context.runWith(() -> {
final Node rootContentNode = nodeService.getByPath(ContentConstants.CONTENT_ROOT_PATH);
final AccessControlList rootContentPermissions = rootContentNode.getPermissions();
assertTrue(rootContentPermissions.getEntry(RoleKeys.ADMIN).isAllowedAll());
assertTrue(rootContentPermissions.getEntry(RoleKeys.CONTENT_MANAGER_ADMIN).isAllowedAll());
assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.owner")).isAllowedAll());
assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.editor")).isAllowedAll());
assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.author")).isAllowed(Permission.READ, Permission.CREATE, Permission.MODIFY, Permission.DELETE));
assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.contributor")).isAllowed(Permission.READ));
assertTrue(rootContentPermissions.getEntry(PrincipalKey.ofRole("cms.project.test-project.viewer")).isAllowed(Permission.READ));
assertNull(rootContentPermissions.getEntry(RoleKeys.EVERYONE));
}));
}
use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.
the class ProjectServiceImplTest method create_with_root_issues_permissions.
@Test
void create_with_root_issues_permissions() {
final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
final ProjectName projectName = ProjectName.from(projectRepoId);
doCreateProjectAsAdmin(projectName);
ContextBuilder.from(adminContext()).branch(ContentConstants.BRANCH_DRAFT).repositoryId(projectRepoId).build().runWith(() -> {
final Node rootIssuesNode = nodeService.getByPath(NodePath.create(NodePath.ROOT, "issues").build());
final AccessControlList rootContentPermissions = rootIssuesNode.getPermissions();
assertAll(() -> assertTrue(rootContentPermissions.getEntry(RoleKeys.ADMIN).isAllowedAll()), () -> assertTrue(rootContentPermissions.getEntry(RoleKeys.CONTENT_MANAGER_ADMIN).isAllowedAll()), () -> assertTrue(rootContentPermissions.isAllowedFor(PrincipalKey.ofRole("cms.project.test-project.viewer"), Permission.READ)));
PrincipalKeys.from(PrincipalKey.ofRole("cms.project.test-project.owner"), PrincipalKey.ofRole("cms.project.test-project.editor"), PrincipalKey.ofRole("cms.project.test-project.contributor"), PrincipalKey.ofRole("cms.project.test-project.author")).forEach(principalKey -> assertTrue(rootContentPermissions.isAllowedFor(principalKey, Permission.READ, Permission.CREATE, Permission.MODIFY, Permission.DELETE)));
});
}
use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.
the class ProjectServiceImplTest method create_project_with_public_readAccess.
@Test
void create_project_with_public_readAccess() {
final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
final ProjectName projectName = ProjectName.from(projectRepoId);
adminContext().callWith(() -> doCreateProject(projectName, null, false, null, AccessControlList.create().add(AccessControlEntry.create().principal(RoleKeys.EVERYONE).allow(Permission.READ).build()).build()));
ContextBuilder.from(adminContext()).branch(ContentConstants.BRANCH_DRAFT).repositoryId(projectRepoId).build().runWith(() -> {
final Node rootContentNode = nodeService.getByPath(ContentConstants.CONTENT_ROOT_PATH);
final AccessControlList rootContentPermissions = rootContentNode.getPermissions();
assertTrue(rootContentPermissions.getEntry(RoleKeys.EVERYONE).isAllowed(Permission.READ));
});
}
use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.
the class CreateContentCommandTest method mockNodeServiceCreate.
private Node mockNodeServiceCreate(final InvocationOnMock invocation) throws Throwable {
CreateNodeParams params = (CreateNodeParams) invocation.getArguments()[0];
final AccessControlList permissions = AccessControlList.create().add(AccessControlEntry.create().allowAll().principal(PrincipalKey.ofAnonymous()).build()).build();
return Node.create().id(params.getNodeId() != null ? params.getNodeId() : new NodeId()).parentPath(params.getParent()).name(NodeName.from(params.getName())).data(params.getData()).indexConfigDocument(params.getIndexConfigDocument()).childOrder(params.getChildOrder() != null ? params.getChildOrder() : ChildOrder.defaultOrder()).permissions(permissions).inheritPermissions(params.inheritPermissions()).nodeType(params.getNodeType() != null ? params.getNodeType() : NodeType.DEFAULT_NODE_COLLECTION).timestamp(Instant.now()).build();
}
use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.
the class CreateNodeCommand method execute.
public Node execute() {
Preconditions.checkNotNull(params.getParent(), "Path of parent Node must be specified");
Preconditions.checkArgument(params.getParent().isAbsolute(), "Path to parent Node must be absolute: " + params.getParent());
NodeHelper.runAsAdmin(this::verifyNotExistsAlready);
final Node parentNode = NodeHelper.runAsAdmin(this::verifyParentExists);
if (parentNode == null) {
throw new NodeNotFoundException("Parent node to node with name '" + params.getName() + "' with parent path '" + params.getParent() + "' not found");
}
requireContextUserPermission(Permission.CREATE, parentNode);
final PrincipalKey user = getCurrentPrincipalKey();
final AccessControlList permissions = getAccessControlEntries(user);
final Long manualOrderValue = NodeHelper.runAsAdmin(() -> resolvePotentialManualOrderValue(parentNode));
final AttachedBinaries attachedBinaries = storeAndAttachBinaries();
final Node.Builder nodeBuilder = Node.create().id(this.params.getNodeId() != null ? params.getNodeId() : new NodeId()).parentPath(params.getParent()).name(NodeName.from(params.getName())).data(params.getData()).indexConfigDocument(params.getIndexConfigDocument()).childOrder(params.getChildOrder() != null ? params.getChildOrder() : ChildOrder.defaultOrder()).manualOrderValue(manualOrderValue).permissions(permissions).inheritPermissions(params.inheritPermissions()).nodeType(params.getNodeType() != null ? params.getNodeType() : NodeType.DEFAULT_NODE_COLLECTION).attachedBinaries(attachedBinaries).timestamp(this.timestamp != null ? this.timestamp : Instant.now(CLOCK));
final Node newNode = nodeBuilder.build();
return StoreNodeCommand.create(this).node(newNode).updateMetadataOnly(false).build().execute();
}
Aggregations