Search in sources :

Example 41 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class RepositoryServiceImpl method pushRootNode.

private void pushRootNode(final Repository currentRepo, final Branch branch) {
    final Context context = ContextAccessor.current();
    final InternalContext internalContext = InternalContext.create(context).branch(RepositoryConstants.MASTER_BRANCH).build();
    final Node rootNode = this.nodeStorageService.get(Node.ROOT_UUID, internalContext);
    if (rootNode == null) {
        throw new NodeNotFoundException("Cannot find root-node in repository [" + currentRepo + "]");
    }
    this.nodeStorageService.push(rootNode, branch, internalContext);
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) InternalContext(com.enonic.xp.repo.impl.InternalContext) Node(com.enonic.xp.node.Node)

Example 42 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class RepositoryServiceImpl method getRootNode.

private Node getRootNode(final RepositoryId repositoryId, final Branch branch) {
    final Context rootNodeContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(repositoryId).branch(branch).build();
    final InternalContext rootNodeInternalContext = InternalContext.create(rootNodeContext).build();
    return this.nodeStorageService.get(Node.ROOT_UUID, rootNodeInternalContext);
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) InternalContext(com.enonic.xp.repo.impl.InternalContext)

Example 43 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class GetActiveNodeVersionsCommandTest method updateNode.

private void updateNode(final Node node, Context context) {
    UpdateNodeParams updateNodeParams = UpdateNodeParams.create().id(node.id()).editor(toBeEdited -> toBeEdited.data.setString("myString", "edit")).build();
    context.runWith(() -> UpdateNodeCommand.create().params(updateNodeParams).indexServiceInternal(this.indexServiceInternal).binaryService(this.binaryService).storageService(this.storageService).searchService(this.searchService).build().execute());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath) Branches(com.enonic.xp.branch.Branches) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Test(org.junit.jupiter.api.Test) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Context(com.enonic.xp.context.Context) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeIds(com.enonic.xp.node.NodeIds) PropertyTree(com.enonic.xp.data.PropertyTree) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams)

Example 44 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class JsonExceptionMapper method createContextJson.

private static ObjectNode createContextJson() {
    final Context context = ContextAccessor.current();
    final AuthenticationInfo authInfo = context.getAuthInfo();
    final ObjectNode node = JsonNodeFactory.instance.objectNode();
    node.put("authenticated", (authInfo != null) && authInfo.isAuthenticated());
    final ArrayNode principals = node.putArray("principals");
    if (authInfo != null) {
        for (final PrincipalKey principal : authInfo.getPrincipals()) {
            principals.add(principal.toString());
        }
    }
    return node;
}
Also used : Context(com.enonic.xp.context.Context) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PrincipalKey(com.enonic.xp.security.PrincipalKey) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo)

Example 45 with Context

use of com.enonic.xp.context.Context in project xp by enonic.

the class IdProviderControllerServiceImpl method runWithAdminRole.

private <T> T runWithAdminRole(final Callable<T> callable) {
    final Context context = ContextAccessor.current();
    final AuthenticationInfo authenticationInfo = AuthenticationInfo.copyOf(context.getAuthInfo()).principals(RoleKeys.ADMIN).build();
    return ContextBuilder.from(context).authInfo(authenticationInfo).build().callWith(callable);
}
Also used : Context(com.enonic.xp.context.Context) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo)

Aggregations

Context (com.enonic.xp.context.Context)101 Test (org.junit.jupiter.api.Test)35 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)21 Node (com.enonic.xp.node.Node)16 InternalContext (com.enonic.xp.repo.impl.InternalContext)16 User (com.enonic.xp.security.User)13 Content (com.enonic.xp.content.Content)11 PropertyTree (com.enonic.xp.data.PropertyTree)11 PrincipalKey (com.enonic.xp.security.PrincipalKey)10 Branch (com.enonic.xp.branch.Branch)9 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)9 ContextAccessor (com.enonic.xp.context.ContextAccessor)8 NodePath (com.enonic.xp.node.NodePath)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)7 ContentId (com.enonic.xp.content.ContentId)6 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)6 Repository (com.enonic.xp.repository.Repository)6 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)5 ProcessUpdateParams (com.enonic.xp.content.processor.ProcessUpdateParams)5 NodeComparison (com.enonic.xp.node.NodeComparison)5