Search in sources :

Example 71 with Context

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

the class SystemRepoInitializer method initRepositoryFolder.

private void initRepositoryFolder() {
    final Context currentContext = ContextAccessor.current();
    final Node node = Node.create(new NodeId()).childOrder(ChildOrder.defaultOrder()).parentPath(RepositoryConstants.REPOSITORY_STORAGE_PARENT_PATH.getParentPath()).name(RepositoryConstants.REPOSITORY_STORAGE_PARENT_PATH.getName()).permissions(SystemConstants.SYSTEM_REPO_DEFAULT_ACL).build();
    this.nodeStorageService.store(node, InternalContext.from(currentContext));
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) Context(com.enonic.xp.context.Context) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId)

Example 72 with Context

use of com.enonic.xp.context.Context 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())));
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) Context(com.enonic.xp.context.Context) Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Example 73 with Context

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

the class ApplyNodePermissionsCommandTest method runAs.

private void runAs(final PrincipalKey principal, final Runnable runnable) {
    final Context context = ContextAccessor.current();
    final AuthenticationInfo authInfo = context.getAuthInfo();
    ContextBuilder.from(context).authInfo(AuthenticationInfo.copyOf(authInfo).principals(principal, PrincipalKey.ofGroup(USK, "group1")).build()).build().runWith(runnable);
}
Also used : Context(com.enonic.xp.context.Context) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo)

Example 74 with Context

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

the class IndexServiceImplTest method reindex_system_repo.

@Test
public void reindex_system_repo() throws Exception {
    final Context systemRepoContext = ContextBuilder.from(ContextAccessor.current()).repositoryId(SystemConstants.SYSTEM_REPO_ID).branch(SystemConstants.BRANCH_SYSTEM).build();
    systemRepoContext.callWith(this::createDefaultRootNode);
    systemRepoContext.callWith(() -> createNode(CreateNodeParams.create().setNodeId(NodeId.from("su")).name("su").parent(NodePath.ROOT).build()));
    refresh();
    final long nodesInSystemRepoCount = systemRepoContext.callWith(this::findAllNodes).getHits();
    this.indexService.purgeSearchIndex(new PurgeIndexParams(systemRepoContext.getRepositoryId()));
    assertEquals(0, systemRepoContext.callWith(this::findAllNodes).getHits());
    this.indexService.reindex(ReindexParams.create().addBranch(systemRepoContext.getBranch()).repositoryId(systemRepoContext.getRepositoryId()).initialize(true).build());
    refresh();
    assertEquals(nodesInSystemRepoCount, systemRepoContext.callWith(this::findAllNodes).getHits());
}
Also used : Context(com.enonic.xp.context.Context) PurgeIndexParams(com.enonic.xp.index.PurgeIndexParams) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 75 with Context

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

the class RepositoryServiceImplTest method create_branch_creates_in_repo.

@Test
void create_branch_creates_in_repo() {
    doCreateRepo("fisk");
    Branch branch = Branch.from("myBranch");
    Context mockCurrentContext = ContextBuilder.create().branch("master").repositoryId("fisk").authInfo(REPO_TEST_DEFAULT_USER_AUTHINFO).build();
    mockCurrentContext.callWith(() -> repositoryService.createBranch(CreateBranchParams.from(branch)));
    final Repository persistedRepo = getPersistedRepoWithoutCache("fisk");
    assertTrue(persistedRepo.getBranches().contains(branch));
}
Also used : Context(com.enonic.xp.context.Context) Repository(com.enonic.xp.repository.Repository) Branch(com.enonic.xp.branch.Branch) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

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