use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.
the class ImportNodeCommandTest method keep_permissions_on_create.
@Test
public void keep_permissions_on_create() throws Exception {
final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.ofAnonymous()).allowAll().deny(Permission.DELETE).build()).add(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().deny(Permission.DELETE).build()).build();
final Node importNode = Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(new PropertyTree()).permissions(aclList).build();
final ImportNodeResult importNodeResult = importNode(importNode);
final Node abc = getNodeById(NodeId.from("abc"));
assertNotNull(abc);
assertEquals(aclList, abc.getPermissions());
assertEquals(importNodeResult.getNode().getPermissions(), abc.getPermissions());
assertFalse(importNodeResult.isPreExisting());
}
use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.
the class ImportNodeCommandTest method skip_permissions_on_update.
@Test
public void skip_permissions_on_update() throws Exception {
final Node createdNode = importNode(Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(new PropertyTree()).build()).getNode();
final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().deny(Permission.DELETE).build()).build();
final Node updatedNode = importNode(Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(new PropertyTree()).permissions(aclList).build()).getNode();
assertEquals(createdNode.getPermissions(), updatedNode.getPermissions());
}
use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.
the class NodeHandler method setRootPermissions.
@SuppressWarnings("unused")
public Object setRootPermissions(final ScriptValue value) {
final ScriptValueTranslatorResult translatorResult = new ScriptValueTranslator(false).create(value);
final PropertyTree asPropertyTree = translatorResult.getPropertyTree();
final Iterable<PropertySet> asPropertySets = asPropertyTree.getSets("_permissions");
final boolean inheritPermissions = asPropertyTree.getBoolean("_inheritsPermissions") != null ? asPropertyTree.getBoolean("_inheritsPermissions") : true;
if (asPropertySets == null) {
throw new IllegalArgumentException("Did not find parameter [_permissions]");
}
final AccessControlList permissions = new PermissionsFactory(asPropertySets).create();
return execute(SetRootPermissionsHandler.create().permissions(permissions).inheritPermissions(inheritPermissions).nodeService(this.nodeService).build());
}
use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.
the class AccessControlTest method role_system_admin_can_access_everything.
@Test
public void role_system_admin_can_access_everything() throws Exception {
final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.from("user:myidprovider:rmy")).allow(Permission.READ).build()).add(AccessControlEntry.create().principal(PrincipalKey.from("user:myidprovider:tsi")).allow(Permission.READ).build()).build();
final CreateNodeParams params = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).permissions(aclList).build();
final Node node = this.nodeService.create(params);
final Context anonContext = ContextBuilder.from(ctxDefault()).authInfo(AuthenticationInfo.create().user(User.ANONYMOUS).build()).build();
assertNull(anonContext.callWith(() -> getNode(node.id())));
final Context anonContextWithAdminUserRole = ContextBuilder.from(ctxDefault()).authInfo(AuthenticationInfo.create().principals(RoleKeys.ADMIN).user(User.ANONYMOUS).build()).build();
assertNotNull(anonContextWithAdminUserRole.callWith(() -> getNode(node.id())));
}
use of com.enonic.xp.security.acl.AccessControlList in project xp by enonic.
the class AccessControlTest method index_has_read.
@Test
public void index_has_read() throws Exception {
final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.from("user:myidprovider:rmy")).allow(Permission.READ).build()).add(AccessControlEntry.create().principal(PrincipalKey.from("user:myidprovider:tsi")).allow(Permission.READ).build()).build();
final CreateNodeParams params = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).permissions(aclList).build();
this.nodeService.create(params);
refresh();
}
Aggregations