Search in sources :

Example 26 with NodePath

use of com.enonic.xp.node.NodePath in project xp by enonic.

the class BranchServiceImplTest method path_fetched_from_cache_after_stored.

@Test
public void path_fetched_from_cache_after_stored() throws Exception {
    final InternalContext context = InternalContext.create().branch(Branch.from("myBranch")).repositoryId(RepositoryId.from("my-repo")).build();
    final NodePath path = NodePath.create(NodePath.ROOT, "fisk").build();
    Mockito.when(this.storageDao.store(Mockito.isA(StoreRequest.class))).thenReturn("123_myBranch");
    this.branchService.store(NodeBranchEntry.create().nodeId(NodeId.from("123")).nodePath(path).nodeState(NodeState.DEFAULT).nodeVersionId(NodeVersionId.from("nodeVersionId")).nodeVersionKey(NodeVersionKey.from("nodeBlobKey", "indexConfigBlobKey", "accessControlBlobKey")).timestamp(Instant.now()).build(), context);
    Mockito.when(this.storageDao.getById(Mockito.isA(GetByIdRequest.class))).thenReturn(GetResult.create().id("123_myBranch").resultFieldValues(ReturnValues.create().add(BranchIndexPath.PATH.getPath(), "/fisk").add(BranchIndexPath.STATE.getPath(), "default").add(BranchIndexPath.VERSION_ID.getPath(), "nodeVersionId").add(BranchIndexPath.NODE_BLOB_KEY.getPath(), "nodeBlobKey").add(BranchIndexPath.INDEX_CONFIG_BLOB_KEY.getPath(), "indexConfigBlobKey").add(BranchIndexPath.ACCESS_CONTROL_BLOB_KEY.getPath(), "accessControlBlobKey").add(BranchIndexPath.NODE_ID.getPath(), "123").add(BranchIndexPath.TIMESTAMP.getPath(), Instant.now().toString()).build()).build());
    Mockito.when(this.searchDao.search(Mockito.isA(SearchRequest.class))).thenReturn(SearchResult.create().build());
    final NodeBranchEntry fetchEntry = this.branchService.get(path, context);
    assertNotNull(fetchEntry);
}
Also used : SearchRequest(com.enonic.xp.repo.impl.search.SearchRequest) InternalContext(com.enonic.xp.repo.impl.InternalContext) StoreRequest(com.enonic.xp.repo.impl.storage.StoreRequest) GetByIdRequest(com.enonic.xp.repo.impl.storage.GetByIdRequest) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 27 with NodePath

use of com.enonic.xp.node.NodePath in project xp by enonic.

the class SecurityServiceImpl method getIdProvider.

@Override
public IdProvider getIdProvider(final IdProviderKey idProviderKey) {
    final NodePath idProviderNodePath = IdProviderNodeTranslator.toIdProviderNodePath(idProviderKey);
    final Node node = callWithContext(() -> this.nodeService.getByPath(idProviderNodePath));
    return node == null ? null : IdProviderNodeTranslator.fromNode(node);
}
Also used : Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath)

Example 28 with NodePath

use of com.enonic.xp.node.NodePath in project xp by enonic.

the class SecurityServiceImpl method getIdProviderPermissions.

@Override
public IdProviderAccessControlList getIdProviderPermissions(final IdProviderKey idProviderKey) {
    final NodePath idProviderNodePath = IdProviderNodeTranslator.toIdProviderNodePath(idProviderKey);
    final NodePath usersNodePath = IdProviderNodeTranslator.toIdProviderUsersNodePath(idProviderKey);
    final NodePath groupsNodePath = IdProviderNodeTranslator.toIdProviderGroupsNodePath(idProviderKey);
    final Node idProviderNode = callWithContext(() -> this.nodeService.getByPath(idProviderNodePath));
    final Node usersNode = callWithContext(() -> this.nodeService.getByPath(usersNodePath));
    final Node groupsNode = callWithContext(() -> this.nodeService.getByPath(groupsNodePath));
    return IdProviderNodeTranslator.idProviderPermissionsFromNode(idProviderNode, usersNode, groupsNode);
}
Also used : Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath)

Example 29 with NodePath

use of com.enonic.xp.node.NodePath 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 30 with NodePath

use of com.enonic.xp.node.NodePath in project xp by enonic.

the class SecurityServiceImpl method removeRelationships.

private void removeRelationships(final IdProviderKey from) {
    callWithContext(() -> {
        final NodePath idProviderNodePath = IdProviderNodeTranslator.toIdProviderNodePath(from);
        final Node node = this.nodeService.getByPath(idProviderNodePath);
        final UpdateNodeParams updateNodeParams = IdProviderNodeTranslator.removeAllRelationshipsToUpdateNodeParams(node);
        nodeService.update(updateNodeParams);
        this.nodeService.refresh(RefreshMode.SEARCH);
        return null;
    });
}
Also used : Node(com.enonic.xp.node.Node) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodePath(com.enonic.xp.node.NodePath)

Aggregations

NodePath (com.enonic.xp.node.NodePath)54 Node (com.enonic.xp.node.Node)27 Test (org.junit.jupiter.api.Test)20 NodeId (com.enonic.xp.node.NodeId)15 InternalContext (com.enonic.xp.repo.impl.InternalContext)12 Content (com.enonic.xp.content.Content)7 Event (com.enonic.xp.event.Event)7 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)4 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)4 NodeVersionId (com.enonic.xp.node.NodeVersionId)4 ChildOrder (com.enonic.xp.index.ChildOrder)3 NodeIds (com.enonic.xp.node.NodeIds)3 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 ContentId (com.enonic.xp.content.ContentId)2 ContentPath (com.enonic.xp.content.ContentPath)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)2 Context (com.enonic.xp.context.Context)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)2 NodeVersion (com.enonic.xp.node.NodeVersion)2