Search in sources :

Example 36 with AccessControlList

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

the class DeleteNodeByIdCommandTest method delete_with_children_require_permission.

@Test
public void delete_with_children_require_permission() throws Exception {
    final AccessControlList noDeletePermission = AccessControlList.create().add(AccessControlEntry.create().allowAll().deny(Permission.DELETE).principal(TEST_DEFAULT_USER.getKey()).build()).add(AccessControlEntry.create().allowAll().deny(Permission.DELETE).principal(RoleKeys.AUTHENTICATED).build()).build();
    final Node parentNode = createNode(CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").build());
    refresh();
    createNode(CreateNodeParams.create().parent(parentNode.path()).name("my-node").permissions(noDeletePermission).build());
    refresh();
    assertThrows(NodeAccessException.class, () -> doDeleteNode(parentNode.id()));
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 37 with AccessControlList

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

the class AbstractNodeTest method createTestRepository.

private void createTestRepository() {
    final AccessControlList rootPermissions = AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().build());
    ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().principals(RoleKeys.ADMIN).user(User.ANONYMOUS).build()).build().callWith(() -> {
        this.repositoryService.createRepository(CreateRepositoryParams.create().repositoryId(TEST_REPO_ID).rootPermissions(rootPermissions).build());
        TEST_REPO_BRANCHES.stream().filter(branch -> !RepositoryConstants.MASTER_BRANCH.equals(branch)).forEach(branch -> {
            final CreateBranchParams createBranchParams = CreateBranchParams.from(branch.toString());
            this.repositoryService.createBranch(createBranchParams);
        });
        refresh();
        return null;
    });
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) BeforeEach(org.junit.jupiter.api.BeforeEach) Nodes(com.enonic.xp.node.Nodes) Arrays(java.util.Arrays) IdProviderKey(com.enonic.xp.security.IdProviderKey) QueryParser(com.enonic.xp.query.parser.QueryParser) IndexServiceInternalImpl(com.enonic.xp.repo.impl.elasticsearch.IndexServiceInternalImpl) SystemRepoInitializer(com.enonic.xp.repo.impl.repository.SystemRepoInitializer) Segment(com.enonic.xp.blob.Segment) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) NodeRepositoryServiceImpl(com.enonic.xp.repo.impl.repository.NodeRepositoryServiceImpl) SchedulerConstants(com.enonic.xp.scheduler.SchedulerConstants) Branch(com.enonic.xp.branch.Branch) IndexDataServiceImpl(com.enonic.xp.repo.impl.storage.IndexDataServiceImpl) CommitServiceImpl(com.enonic.xp.repo.impl.commit.CommitServiceImpl) RepositoryId(com.enonic.xp.repository.RepositoryId) ContextAccessor(com.enonic.xp.context.ContextAccessor) IndexServiceImpl(com.enonic.xp.repo.impl.index.IndexServiceImpl) ContextBuilder(com.enonic.xp.context.ContextBuilder) StorageDaoImpl(com.enonic.xp.repo.impl.elasticsearch.storage.StorageDaoImpl) Path(java.nio.file.Path) PushNodesResult(com.enonic.xp.node.PushNodesResult) IndexNameResolver(com.enonic.xp.repo.impl.repository.IndexNameResolver) User(com.enonic.xp.security.User) CreateRootNodeParams(com.enonic.xp.node.CreateRootNodeParams) AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) CreateRepositoryParams(com.enonic.xp.repository.CreateRepositoryParams) IndexType(com.enonic.xp.index.IndexType) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) SearchDaoImpl(com.enonic.xp.repo.impl.elasticsearch.search.SearchDaoImpl) VersionServiceImpl(com.enonic.xp.repo.impl.version.VersionServiceImpl) TempDir(org.junit.jupiter.api.io.TempDir) NodeStorageServiceImpl(com.enonic.xp.repo.impl.storage.NodeStorageServiceImpl) BinaryServiceImpl(com.enonic.xp.repo.impl.binary.BinaryServiceImpl) NodeSearchServiceImpl(com.enonic.xp.repo.impl.search.NodeSearchServiceImpl) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) RepositoryConstants(com.enonic.xp.repository.RepositoryConstants) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) ContentConstants(com.enonic.xp.content.ContentConstants) EventPublisher(com.enonic.xp.event.EventPublisher) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) RepositoryServiceImpl(com.enonic.xp.repo.impl.repository.RepositoryServiceImpl) SchedulerRepoInitializer(com.enonic.xp.impl.scheduler.SchedulerRepoInitializer) SegmentLevel(com.enonic.xp.blob.SegmentLevel) CreateBranchParams(com.enonic.xp.repository.CreateBranchParams) AuditLogRepoInitializer(com.enonic.xp.core.impl.audit.AuditLogRepoInitializer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeQuery(com.enonic.xp.node.NodeQuery) RepositoryEntryServiceImpl(com.enonic.xp.repo.impl.repository.RepositoryEntryServiceImpl) PropertyTree(com.enonic.xp.data.PropertyTree) RepoConfiguration(com.enonic.xp.repo.impl.config.RepoConfiguration) RepositorySegmentUtils(com.enonic.xp.repository.RepositorySegmentUtils) Iterator(java.util.Iterator) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodePath(com.enonic.xp.node.NodePath) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Branches(com.enonic.xp.branch.Branches) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Mockito(org.mockito.Mockito) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) NodeVersionServiceImpl(com.enonic.xp.repo.impl.node.dao.NodeVersionServiceImpl) PrincipalKey(com.enonic.xp.security.PrincipalKey) Reference(com.enonic.xp.util.Reference) AuditLogConstants(com.enonic.xp.core.impl.audit.AuditLogConstants) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) MemoryBlobStore(com.enonic.xp.internal.blobstore.MemoryBlobStore) NodeIds(com.enonic.xp.node.NodeIds) BranchServiceImpl(com.enonic.xp.repo.impl.branch.storage.BranchServiceImpl) CreateBranchParams(com.enonic.xp.repository.CreateBranchParams)

Example 38 with AccessControlList

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

the class AbstractNodeTest method createDefaultRootNode.

protected Node createDefaultRootNode() {
    final AccessControlList rootPermissions = AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().build());
    final CreateRootNodeParams createRootParams = CreateRootNodeParams.create().permissions(rootPermissions).build();
    return CreateRootNodeCommand.create().params(createRootParams).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) CreateRootNodeParams(com.enonic.xp.node.CreateRootNodeParams)

Example 39 with AccessControlList

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

the class RepositoryServiceImplTest method create_default_acl.

@Test
void create_default_acl() {
    final Repository repo = doCreateRepo("fisk");
    assertNotNull(repo);
    assertEquals(RepositoryId.from("fisk"), repo.getId());
    final Node rootNode = createAdminContext().callWith(() -> this.nodeService.getRoot());
    final AccessControlList acl = rootNode.getPermissions();
    System.out.println(acl.toString());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) Repository(com.enonic.xp.repository.Repository) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 40 with AccessControlList

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

the class DefaultPermissionsMergingStrategy method mergePermissions.

@Override
public AccessControlList mergePermissions(final AccessControlList childAcl, final AccessControlList parentAcl) {
    final AccessControlList.Builder effective = AccessControlList.create();
    // apply parent entries
    for (AccessControlEntry parentEntry : parentAcl) {
        final PrincipalKey principal = parentEntry.getPrincipal();
        if (childAcl.contains(principal)) {
            final AccessControlEntry childEntry = childAcl.getEntry(principal);
            final AccessControlEntry mergedEntry = mergeAccessControlEntries(childEntry, parentEntry);
            effective.add(mergedEntry);
        } else {
            effective.add(parentEntry);
        }
    }
    // apply child entries not in parent
    for (AccessControlEntry childEntry : childAcl) {
        if (!parentAcl.contains(childEntry.getPrincipal())) {
            effective.add(childEntry);
        }
    }
    return effective.build();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) PrincipalKey(com.enonic.xp.security.PrincipalKey)

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