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));
}
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())));
}
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);
}
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());
}
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));
}
Aggregations