Search in sources :

Example 11 with AccessControlList

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

the class NodeServiceImplTest method create.

@Test
public void create() throws Exception {
    final ChildOrder childOrder = ChildOrder.create().add(FieldOrderExpr.create(NodeIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).add(FieldOrderExpr.create(NodeIndexPath.NAME, OrderExpr.Direction.ASC)).build();
    final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.from("user:myidprovider:rmy")).allow(Permission.READ).build()).build();
    final CreateNodeParams params = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).permissions(aclList).childOrder(childOrder).build();
    final Node node = this.nodeService.create(params);
    refresh();
    assertTrue(node.getPermissions() != null);
    assertEquals(aclList, node.getPermissions());
    assertEquals(childOrder, node.getChildOrder());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) ChildOrder(com.enonic.xp.index.ChildOrder) Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Example 12 with AccessControlList

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

the class ImportNodeCommandTest method keep_permissions_on_update.

@Test
public void keep_permissions_on_update() throws Exception {
    importNode(Node.create().id(NodeId.from("abc")).name("myNode").parentPath(NodePath.ROOT).data(new PropertyTree()).build());
    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(), true, true).getNode();
    assertEquals(aclList, updatedNode.getPermissions());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 13 with AccessControlList

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

the class SecurityServiceImpl method updateIdProvider.

@Override
public IdProvider updateIdProvider(final UpdateIdProviderParams updateIdProviderParams) {
    return callWithContext(() -> {
        final NodePath idProviderNodePath = IdProviderNodeTranslator.toIdProviderNodePath(updateIdProviderParams.getKey());
        final Node node = this.nodeService.getByPath(idProviderNodePath);
        if (node == null) {
            return null;
        }
        final IdProvider existingIdProvider = IdProviderNodeTranslator.fromNode(node);
        final IdProvider idProviderToUpdate = updateIdProviderParams.update(existingIdProvider);
        final UpdateNodeParams updateNodeParams = IdProviderNodeTranslator.toUpdateNodeParams(idProviderToUpdate, node.id());
        final Node idProviderNode = nodeService.update(updateNodeParams);
        if (updateIdProviderParams.getIdProviderPermissions() != null) {
            final Node usersNode = nodeService.getByPath(IdProviderNodeTranslator.toIdProviderUsersNodePath(updateIdProviderParams.getKey()));
            final Node groupsNode = nodeService.getByPath(IdProviderNodeTranslator.toIdProviderGroupsNodePath(updateIdProviderParams.getKey()));
            final IdProviderAccessControlList permissions = updateIdProviderParams.getIdProviderPermissions();
            AccessControlList idProviderNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToIdProviderNodePermissions(permissions);
            AccessControlList usersNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToUsersNodePermissions(permissions);
            AccessControlList groupsNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToGroupsNodePermissions(permissions);
            final Node rootNode = nodeService.getRoot();
            idProviderNodePermissions = mergeWithRootPermissions(idProviderNodePermissions, rootNode.getPermissions());
            usersNodePermissions = mergeWithRootPermissions(usersNodePermissions, rootNode.getPermissions());
            groupsNodePermissions = mergeWithRootPermissions(groupsNodePermissions, rootNode.getPermissions());
            setNodePermissions(idProviderNode.id(), idProviderNodePermissions);
            setNodePermissions(usersNode.id(), usersNodePermissions);
            setNodePermissions(groupsNode.id(), groupsNodePermissions);
            final ApplyNodePermissionsParams applyPermissions = ApplyNodePermissionsParams.create().nodeId(idProviderNode.id()).overwriteChildPermissions(false).build();
            nodeService.applyPermissions(applyPermissions);
        }
        this.nodeService.refresh(RefreshMode.SEARCH);
        return IdProviderNodeTranslator.fromNode(idProviderNode);
    });
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) ApplyNodePermissionsParams(com.enonic.xp.node.ApplyNodePermissionsParams) Node(com.enonic.xp.node.Node) IdProvider(com.enonic.xp.security.IdProvider) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) NodePath(com.enonic.xp.node.NodePath)

Example 14 with AccessControlList

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

the class SecurityServiceImpl method createIdProvider.

@Override
public IdProvider createIdProvider(final CreateIdProviderParams createIdProviderParams) {
    final PropertyTree data = new PropertyTree();
    data.setString(IdProviderPropertyNames.DISPLAY_NAME_KEY, createIdProviderParams.getDisplayName());
    data.setString(IdProviderPropertyNames.DESCRIPTION_KEY, createIdProviderParams.getDescription());
    final IdProviderConfig idProviderConfig = createIdProviderParams.getIdProviderConfig();
    if (idProviderConfig != null) {
        data.setString(IdProviderPropertyNames.ID_PROVIDER_APPLICATION_KEY, idProviderConfig.getApplicationKey().toString());
        data.setSet(IdProviderPropertyNames.ID_PROVIDER_CONFIG_FORM_KEY, idProviderConfig.getConfig().getRoot());
    }
    try {
        final Node node = callWithContext(() -> {
            final IdProviderAccessControlList permissions = createIdProviderParams.getIdProviderPermissions();
            AccessControlList idProviderNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToIdProviderNodePermissions(permissions);
            AccessControlList usersNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToUsersNodePermissions(permissions);
            AccessControlList groupsNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToGroupsNodePermissions(permissions);
            final Node rootNode = nodeService.getRoot();
            idProviderNodePermissions = mergeWithRootPermissions(idProviderNodePermissions, rootNode.getPermissions());
            usersNodePermissions = mergeWithRootPermissions(usersNodePermissions, rootNode.getPermissions());
            groupsNodePermissions = mergeWithRootPermissions(groupsNodePermissions, rootNode.getPermissions());
            final Node idProviderNode = nodeService.create(CreateNodeParams.create().parent(IdProviderNodeTranslator.getIdProvidersParentPath()).name(createIdProviderParams.getKey().toString()).data(data).permissions(idProviderNodePermissions).build());
            nodeService.create(CreateNodeParams.create().parent(idProviderNode.path()).name(IdProviderNodeTranslator.USER_FOLDER_NODE_NAME).permissions(usersNodePermissions).build());
            nodeService.create(CreateNodeParams.create().parent(idProviderNode.path()).name(IdProviderNodeTranslator.GROUP_FOLDER_NODE_NAME).permissions(groupsNodePermissions).build());
            final ApplyNodePermissionsParams applyPermissions = ApplyNodePermissionsParams.create().nodeId(rootNode.id()).overwriteChildPermissions(false).build();
            nodeService.applyPermissions(applyPermissions);
            this.nodeService.refresh(RefreshMode.SEARCH);
            return idProviderNode;
        });
        return IdProviderNodeTranslator.fromNode(node);
    } catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
        throw new IdProviderAlreadyExistsException(createIdProviderParams.getKey());
    }
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) ApplyNodePermissionsParams(com.enonic.xp.node.ApplyNodePermissionsParams) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) IdProviderAlreadyExistsException(com.enonic.xp.security.IdProviderAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) IdProviderConfig(com.enonic.xp.security.IdProviderConfig)

Example 15 with AccessControlList

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

the class XmlNodeSerializerTest method doCreateNode.

private Node doCreateNode(final Instant instant) {
    final PropertyTree propertyTree = new PropertyTree();
    propertyTree.addString("myString", "myStringValue");
    propertyTree.addString("myString", "myStringValue2");
    propertyTree.addString("myEmptyString", "");
    propertyTree.addBoolean("myBoolean", true);
    propertyTree.addDouble("myDouble", 123.1);
    propertyTree.addLong("myLong", 111L);
    propertyTree.addXml("myXml", "<car><color>Arctic Grey<color><car>");
    propertyTree.addString("myHtmlEncoded", "<p><a href=\"/naringsliv/tema/forsikrings-og-pensjonspakker\" data-event=\"{&quot;event_category&quot;: &quot;button&quot;, &quot;event_action&quot;: &quot;click&quot;,&quot;event_label&quot;: &quot;se-php&quot;}\">Se pakkene her</a></p>");
    propertyTree.addGeoPoint("myGeoPoint", GeoPoint.from("8,4"));
    // Date & Time
    propertyTree.addInstant("myInstant", instant);
    propertyTree.addLocalTime("myLocalTime", LocalTime.of(21, 42, 0));
    propertyTree.addLocalDate("myLocalDate", LocalDate.of(2014, 11, 28));
    propertyTree.addLocalDateTime("myLocalDateTime", LocalDateTime.of(2014, 11, 28, 21, 0, 0, 0));
    // Links and ref
    propertyTree.addReference("myRef", Reference.from("abcd"));
    propertyTree.addLink("myLink", Link.from("/root/parent/child"));
    // Binary refs
    propertyTree.addBinaryReference("myBinaryRef1", BinaryReference.from("image.jpg"));
    propertyTree.addBinaryReference("myBinaryRef2", BinaryReference.from("image2.jpg"));
    // Property-set
    final PropertySet mySubset = propertyTree.addSet("mySet");
    mySubset.setString("myString", "myStringValue");
    mySubset.setBoolean("myBoolean", true);
    // Property-set in set
    final PropertySet mySubSubset = mySubset.addSet("mySet");
    mySubSubset.setString("myString", "myStringValue");
    mySubSubset.setBoolean("myBoolean", true);
    // Null values
    propertyTree.addString("myString", null);
    propertyTree.addBoolean("myBoolean", null);
    propertyTree.addDouble("myDouble", null);
    propertyTree.addLong("myLong", null);
    propertyTree.addXml("myXml", null);
    propertyTree.addGeoPoint("myGeoPoint", null);
    propertyTree.addInstant("myInstant", null);
    propertyTree.addLocalTime("myLocalTime", null);
    propertyTree.addLocalDate("myLocalDate", null);
    propertyTree.addLocalDateTime("myLocalDateTime", null);
    propertyTree.addReference("myRef", null);
    propertyTree.addLink("myLink", null);
    propertyTree.addBinaryReference("myBinaryRef2", null);
    propertyTree.addSet("nullSet", null);
    // Index configs
    final IndexConfig indexConfig = IndexConfig.create().enabled(true).fulltext(true).nGram(true).decideByType(false).includeInAllText(true).addIndexValueProcessor(IndexValueProcessors.HTML_STRIPPER).addLanguage("en").build();
    final PatternIndexConfigDocument.Builder indexConfigDocumentBuilder = PatternIndexConfigDocument.create();
    indexConfigDocumentBuilder.analyzer("no");
    indexConfigDocumentBuilder.add("mydata", indexConfig);
    indexConfigDocumentBuilder.addAllTextConfigLanguage("en");
    // Permissions
    final Permission createPermission = Permission.CREATE;
    final Permission publishPermission = Permission.PUBLISH;
    final PrincipalKey systemPrincipalKey = PrincipalKey.from("role:system.admin");
    final PrincipalKey cmsPrincipalKey = PrincipalKey.from("role:cms.admin");
    final AccessControlEntry systemAccessControlEntry = AccessControlEntry.create().principal(systemPrincipalKey).allowAll().build();
    final AccessControlEntry cmsAccessControlEntry = AccessControlEntry.create().principal(cmsPrincipalKey).allow(createPermission).deny(publishPermission).build();
    final AccessControlList accessControlList = AccessControlList.of(systemAccessControlEntry, cmsAccessControlEntry);
    return Node.create().id(NodeId.from("abc")).name(NodeName.from("my-node-name")).parentPath(NodePath.ROOT).childOrder(ChildOrder.manualOrder()).nodeType(NodeType.from("content")).data(propertyTree).indexConfigDocument(indexConfigDocumentBuilder.build()).permissions(accessControlList).inheritPermissions(false).attachedBinaries(AttachedBinaries.create().add(new AttachedBinary(BinaryReference.from("image.jpg"), "a")).add(new AttachedBinary(BinaryReference.from("image2.jpg"), "b")).build()).build();
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IndexConfig(com.enonic.xp.index.IndexConfig) PropertyTree(com.enonic.xp.data.PropertyTree) Permission(com.enonic.xp.security.acl.Permission) PropertySet(com.enonic.xp.data.PropertySet) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) PrincipalKey(com.enonic.xp.security.PrincipalKey) AttachedBinary(com.enonic.xp.node.AttachedBinary)

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