Search in sources :

Example 31 with RepositoryId

use of com.enonic.xp.repository.RepositoryId 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));
    }));
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) ProjectName(com.enonic.xp.project.ProjectName) Node(com.enonic.xp.node.Node) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 32 with RepositoryId

use of com.enonic.xp.repository.RepositoryId in project xp by enonic.

the class ProjectServiceImplTest method create_with_custom_permissions.

@Test
void create_with_custom_permissions() {
    final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
    contentCustomManagerContext().runWith(() -> {
        final RuntimeException ex = Assertions.assertThrows(RuntimeException.class, () -> doCreateProject(ProjectName.from(projectRepoId)));
        assertEquals("Denied [user:system:custom-user] user access for [create] operation", ex.getMessage());
    });
}
Also used : RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 33 with RepositoryId

use of com.enonic.xp.repository.RepositoryId 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)));
    });
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) ProjectName(com.enonic.xp.project.ProjectName) Node(com.enonic.xp.node.Node) RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 34 with RepositoryId

use of com.enonic.xp.repository.RepositoryId in project xp by enonic.

the class ProjectServiceImplTest method modify_permissions.

@Test
void modify_permissions() {
    final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
    adminContext().runWith(() -> {
        final User user1 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("user1").login("user1").build());
        final User user2 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user2")).displayName("user2").login("user2").build());
        doCreateProjectAsAdmin(ProjectName.from(projectRepoId), ProjectPermissions.create().addOwner(user1.getKey()).build());
        projectService.modifyPermissions(ProjectName.from("test-project"), ProjectPermissions.create().addOwner(user2.getKey()).build());
        final PrincipalRelationships principalRelationships = securityService.getRelationships(PrincipalKey.ofRole("cms.project.test-project.owner"));
        assertEquals(1, principalRelationships.getSize());
        assertEquals(principalRelationships.get(0).getTo(), user2.getKey());
    });
}
Also used : User(com.enonic.xp.security.User) RepositoryId(com.enonic.xp.repository.RepositoryId) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 35 with RepositoryId

use of com.enonic.xp.repository.RepositoryId in project xp by enonic.

the class ProjectServiceImplTest method modify_with_deleted_role.

@Test
void modify_with_deleted_role() {
    final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
    doCreateProjectAsAdmin(ProjectName.from(projectRepoId));
    adminContext().runWith(() -> {
        securityService.deletePrincipal(PrincipalKey.ofRole("cms.project.test-project.owner"));
        projectService.modify(ModifyProjectParams.create().name(ProjectName.from("test-project")).description("new description").displayName("new display name").build());
    });
    assertFalse(securityService.getRole(PrincipalKey.ofRole("cms.project.test-project.owner")).isPresent());
}
Also used : RepositoryId(com.enonic.xp.repository.RepositoryId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

RepositoryId (com.enonic.xp.repository.RepositoryId)61 Test (org.junit.jupiter.api.Test)21 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)19 Branch (com.enonic.xp.branch.Branch)14 Repository (com.enonic.xp.repository.Repository)11 Node (com.enonic.xp.node.Node)9 ByteSource (com.google.common.io.ByteSource)8 IOException (java.io.IOException)7 PropertyTree (com.enonic.xp.data.PropertyTree)6 Segment (com.enonic.xp.blob.Segment)5 Context (com.enonic.xp.context.Context)5 ContextAccessor (com.enonic.xp.context.ContextAccessor)5 ContextBuilder (com.enonic.xp.context.ContextBuilder)5 BlobKey (com.enonic.xp.blob.BlobKey)4 EventPublisher (com.enonic.xp.event.EventPublisher)4 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)4 Project (com.enonic.xp.project.Project)4 DumpConstants (com.enonic.xp.repo.impl.dump.DumpConstants)4 DumpBlobRecord (com.enonic.xp.repo.impl.dump.blobstore.DumpBlobRecord)4 RepositoryIds (com.enonic.xp.repository.RepositoryIds)4