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()));
}
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;
});
}
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();
}
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());
}
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();
}
Aggregations