Search in sources :

Example 36 with User

use of com.enonic.xp.security.User in project xp by enonic.

the class AuthenticationInfo method readObject.

private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
    this.authenticated = ois.readBoolean();
    this.principals = PrincipalKeys.from(ois.readUTF().split(","));
    final User deserializedUser = deserializeUser(ois);
    this.user = this.authenticated ? deserializedUser : null;
}
Also used : User(com.enonic.xp.security.User)

Example 37 with User

use of com.enonic.xp.security.User in project xp by enonic.

the class IssueInitializer method initIssueNode.

private void initIssueNode() {
    LOG.info("Issue root-node not found, creating");
    final User user = ContextAccessor.current().getAuthInfo().getUser();
    PropertyTree data = new PropertyTree();
    data.setString(IssuePropertyNames.TITLE, "Root issue");
    data.setString(IssuePropertyNames.CREATOR, user.getKey().toString());
    data.setInstant(ContentPropertyNames.CREATED_TIME, Instant.now());
    final Node issueRoot = nodeService.create(CreateNodeParams.create().data(data).name(IssueConstants.ISSUE_ROOT_NAME).parent(NodePath.ROOT).permissions(Objects.requireNonNullElse(accessControlList, ISSUE_ROOT_DEFAULT_ACL)).childOrder(IssueConstants.DEFAULT_CHILD_ORDER).build());
    LOG.info("Created issue root-node: " + issueRoot.path());
    nodeService.refresh(RefreshMode.ALL);
    nodeService.push(NodeIds.from(issueRoot.id()), ContentConstants.BRANCH_MASTER);
}
Also used : User(com.enonic.xp.security.User) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node)

Example 38 with User

use of com.enonic.xp.security.User in project xp by enonic.

the class NodeServiceImplTest method createRootNode.

@Test
public void createRootNode() {
    final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("User 1").modifiedTime(Instant.now()).email("user1@enonic.com").login("user1").build();
    this.nodeService.createRootNode(CreateRootNodeParams.create().childOrder(ChildOrder.from("_name ASC")).permissions(AccessControlList.of(AccessControlEntry.create().allowAll().principal(user.getKey()).build())).build());
    printContentRepoIndex();
    final Context context = ContextBuilder.create().authInfo(AuthenticationInfo.create().user(user).principals(RoleKeys.CONTENT_MANAGER_ADMIN).build()).branch(WS_DEFAULT).repositoryId(TEST_REPO_ID).build();
    context.runWith(() -> assertNotNull(this.nodeService.getByPath(NodePath.ROOT)));
    context.runWith(() -> assertNotNull(this.nodeService.getRoot()));
}
Also used : Context(com.enonic.xp.context.Context) User(com.enonic.xp.security.User) Test(org.junit.jupiter.api.Test)

Example 39 with User

use of com.enonic.xp.security.User in project xp by enonic.

the class NodeServiceImplTest method test_commit.

@Test
public void test_commit() {
    // Create and update node
    final Node createdNode = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build());
    final NodeId nodeId = createdNode.id();
    final UpdateNodeParams updateNodeParams = UpdateNodeParams.create().id(nodeId).editor(toBeEdited -> {
        toBeEdited.data.addString("newField", "fisk");
    }).build();
    final Node updatedNode = updateNode(updateNodeParams);
    nodeService.refresh(RefreshMode.STORAGE);
    // Check that the two versions have no commit ID by default
    final NodeVersionsMetadata versionsMetadata = getVersionsMetadata(nodeId);
    assertEquals(2, versionsMetadata.size());
    final Iterator<NodeVersionMetadata> versionMetadataIterator = versionsMetadata.iterator();
    final NodeVersionMetadata latestVersionMetadata = versionMetadataIterator.next();
    final NodeVersionMetadata firstVersionMetadata = versionMetadataIterator.next();
    assertNull(latestVersionMetadata.getNodeCommitId());
    assertNull(firstVersionMetadata.getNodeCommitId());
    // Call commit with node ID
    final NodeCommitEntry commitEntry = NodeCommitEntry.create().message("Commit message").build();
    final NodeCommitEntry returnedCommitEntry = nodeService.commit(commitEntry, NodeIds.from(nodeId));
    nodeService.refresh(RefreshMode.STORAGE);
    // Check created commit entry
    final NodeCommitId nodeCommitId = returnedCommitEntry.getNodeCommitId();
    assertNotNull(nodeCommitId);
    assertEquals("Commit message", returnedCommitEntry.getMessage());
    assertNotNull(returnedCommitEntry.getTimestamp());
    assertEquals("user:system:test-user", returnedCommitEntry.getCommitter().toString());
    // Check that only the latest version has a commit ID
    final NodeVersionsMetadata versionsMetadata2 = getVersionsMetadata(nodeId);
    assertEquals(2, versionsMetadata2.size());
    final Iterator<NodeVersionMetadata> versionMetadataIterator2 = versionsMetadata2.iterator();
    final NodeVersionMetadata latestVersionMetadata2 = versionMetadataIterator2.next();
    final NodeVersionMetadata firstVersionMetadata2 = versionMetadataIterator2.next();
    assertEquals(nodeCommitId, latestVersionMetadata2.getNodeCommitId());
    assertNull(firstVersionMetadata2.getNodeCommitId());
    // Call commit with the node version ID of the first version
    final NodeCommitEntry commitEntry2 = NodeCommitEntry.create().message("Commit message 2").build();
    final RoutableNodeVersionId routableNodeVersionId = RoutableNodeVersionId.from(nodeId, firstVersionMetadata2.getNodeVersionId());
    final NodeCommitEntry returnedCommitEntry2 = nodeService.commit(commitEntry, RoutableNodeVersionIds.from(routableNodeVersionId));
    nodeService.refresh(RefreshMode.STORAGE);
    // Check that only the first version has been impacted
    final NodeVersionsMetadata versionsMetadata3 = getVersionsMetadata(nodeId);
    assertEquals(2, versionsMetadata3.size());
    final Iterator<NodeVersionMetadata> versionMetadataIterator3 = versionsMetadata3.iterator();
    final NodeVersionMetadata latestVersionMetadata3 = versionMetadataIterator3.next();
    final NodeVersionMetadata firstVersionMetadata3 = versionMetadataIterator3.next();
    assertEquals(nodeCommitId, latestVersionMetadata3.getNodeCommitId());
    assertEquals(returnedCommitEntry2.getNodeCommitId(), firstVersionMetadata3.getNodeCommitId());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IdProviderKey(com.enonic.xp.security.IdProviderKey) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Permission(com.enonic.xp.security.acl.Permission) NodeCommitId(com.enonic.xp.node.NodeCommitId) ContextAccessor(com.enonic.xp.context.ContextAccessor) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) ContextBuilder(com.enonic.xp.context.ContextBuilder) BinaryReference(com.enonic.xp.util.BinaryReference) User(com.enonic.xp.security.User) NodeIndexPath(com.enonic.xp.node.NodeIndexPath) CreateRootNodeParams(com.enonic.xp.node.CreateRootNodeParams) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) RenameNodeParams(com.enonic.xp.node.RenameNodeParams) Test(org.junit.jupiter.api.Test) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) OrderExpr(com.enonic.xp.query.expr.OrderExpr) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) ReorderChildNodesResult(com.enonic.xp.node.ReorderChildNodesResult) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) ChildOrder(com.enonic.xp.index.ChildOrder) RefreshMode(com.enonic.xp.node.RefreshMode) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) EventPublisher(com.enonic.xp.event.EventPublisher) RoutableNodeVersionIds(com.enonic.xp.node.RoutableNodeVersionIds) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) DuplicateNodeParams(com.enonic.xp.node.DuplicateNodeParams) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) ReorderChildNodesParams(com.enonic.xp.node.ReorderChildNodesParams) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) FieldOrderExpr(com.enonic.xp.query.expr.FieldOrderExpr) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) Iterator(java.util.Iterator) NodePath(com.enonic.xp.node.NodePath) IOException(java.io.IOException) ReorderChildNodeParams(com.enonic.xp.node.ReorderChildNodeParams) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) GetNodeVersionsParams(com.enonic.xp.node.GetNodeVersionsParams) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Mockito(org.mockito.Mockito) NodeName(com.enonic.xp.node.NodeName) BranchNotFoundException(com.enonic.xp.repository.BranchNotFoundException) PrincipalKey(com.enonic.xp.security.PrincipalKey) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) NodeIds(com.enonic.xp.node.NodeIds) RepositoryNotFoundException(com.enonic.xp.repository.RepositoryNotFoundException) NodeVersionsMetadata(com.enonic.xp.node.NodeVersionsMetadata) RoutableNodeVersionId(com.enonic.xp.node.RoutableNodeVersionId) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Node(com.enonic.xp.node.Node) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodeId(com.enonic.xp.node.NodeId) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) NodeCommitId(com.enonic.xp.node.NodeCommitId) Test(org.junit.jupiter.api.Test)

Example 40 with User

use of com.enonic.xp.security.User in project xp by enonic.

the class AbstractNodeTest method createTestRepository.

private void createTestRepository() {
    final AccessControlList rootPermissions = AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().build());
    ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().principals(RoleKeys.ADMIN).user(User.ANONYMOUS).build()).build().callWith(() -> {
        this.repositoryService.createRepository(CreateRepositoryParams.create().repositoryId(TEST_REPO_ID).rootPermissions(rootPermissions).build());
        TEST_REPO_BRANCHES.stream().filter(branch -> !RepositoryConstants.MASTER_BRANCH.equals(branch)).forEach(branch -> {
            final CreateBranchParams createBranchParams = CreateBranchParams.from(branch.toString());
            this.repositoryService.createBranch(createBranchParams);
        });
        refresh();
        return null;
    });
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) BeforeEach(org.junit.jupiter.api.BeforeEach) Nodes(com.enonic.xp.node.Nodes) Arrays(java.util.Arrays) IdProviderKey(com.enonic.xp.security.IdProviderKey) QueryParser(com.enonic.xp.query.parser.QueryParser) IndexServiceInternalImpl(com.enonic.xp.repo.impl.elasticsearch.IndexServiceInternalImpl) SystemRepoInitializer(com.enonic.xp.repo.impl.repository.SystemRepoInitializer) Segment(com.enonic.xp.blob.Segment) AbstractElasticsearchIntegrationTest(com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest) NodeRepositoryServiceImpl(com.enonic.xp.repo.impl.repository.NodeRepositoryServiceImpl) SchedulerConstants(com.enonic.xp.scheduler.SchedulerConstants) Branch(com.enonic.xp.branch.Branch) IndexDataServiceImpl(com.enonic.xp.repo.impl.storage.IndexDataServiceImpl) CommitServiceImpl(com.enonic.xp.repo.impl.commit.CommitServiceImpl) RepositoryId(com.enonic.xp.repository.RepositoryId) ContextAccessor(com.enonic.xp.context.ContextAccessor) IndexServiceImpl(com.enonic.xp.repo.impl.index.IndexServiceImpl) ContextBuilder(com.enonic.xp.context.ContextBuilder) StorageDaoImpl(com.enonic.xp.repo.impl.elasticsearch.storage.StorageDaoImpl) Path(java.nio.file.Path) PushNodesResult(com.enonic.xp.node.PushNodesResult) IndexNameResolver(com.enonic.xp.repo.impl.repository.IndexNameResolver) User(com.enonic.xp.security.User) CreateRootNodeParams(com.enonic.xp.node.CreateRootNodeParams) AccessControlList(com.enonic.xp.security.acl.AccessControlList) NodeId(com.enonic.xp.node.NodeId) CreateRepositoryParams(com.enonic.xp.repository.CreateRepositoryParams) IndexType(com.enonic.xp.index.IndexType) NodeCommitEntry(com.enonic.xp.node.NodeCommitEntry) SearchDaoImpl(com.enonic.xp.repo.impl.elasticsearch.search.SearchDaoImpl) VersionServiceImpl(com.enonic.xp.repo.impl.version.VersionServiceImpl) TempDir(org.junit.jupiter.api.io.TempDir) NodeStorageServiceImpl(com.enonic.xp.repo.impl.storage.NodeStorageServiceImpl) BinaryServiceImpl(com.enonic.xp.repo.impl.binary.BinaryServiceImpl) NodeSearchServiceImpl(com.enonic.xp.repo.impl.search.NodeSearchServiceImpl) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) RepositoryConstants(com.enonic.xp.repository.RepositoryConstants) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) ContentConstants(com.enonic.xp.content.ContentConstants) EventPublisher(com.enonic.xp.event.EventPublisher) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) RepositoryServiceImpl(com.enonic.xp.repo.impl.repository.RepositoryServiceImpl) SchedulerRepoInitializer(com.enonic.xp.impl.scheduler.SchedulerRepoInitializer) SegmentLevel(com.enonic.xp.blob.SegmentLevel) CreateBranchParams(com.enonic.xp.repository.CreateBranchParams) AuditLogRepoInitializer(com.enonic.xp.core.impl.audit.AuditLogRepoInitializer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeQuery(com.enonic.xp.node.NodeQuery) RepositoryEntryServiceImpl(com.enonic.xp.repo.impl.repository.RepositoryEntryServiceImpl) PropertyTree(com.enonic.xp.data.PropertyTree) RepoConfiguration(com.enonic.xp.repo.impl.config.RepoConfiguration) RepositorySegmentUtils(com.enonic.xp.repository.RepositorySegmentUtils) Iterator(java.util.Iterator) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodePath(com.enonic.xp.node.NodePath) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Branches(com.enonic.xp.branch.Branches) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Mockito(org.mockito.Mockito) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) NodeVersionServiceImpl(com.enonic.xp.repo.impl.node.dao.NodeVersionServiceImpl) PrincipalKey(com.enonic.xp.security.PrincipalKey) Reference(com.enonic.xp.util.Reference) AuditLogConstants(com.enonic.xp.core.impl.audit.AuditLogConstants) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) MemoryBlobStore(com.enonic.xp.internal.blobstore.MemoryBlobStore) NodeIds(com.enonic.xp.node.NodeIds) BranchServiceImpl(com.enonic.xp.repo.impl.branch.storage.BranchServiceImpl) CreateBranchParams(com.enonic.xp.repository.CreateBranchParams)

Aggregations

User (com.enonic.xp.security.User)63 Test (org.junit.jupiter.api.Test)40 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)22 PropertyTree (com.enonic.xp.data.PropertyTree)17 PrincipalKey (com.enonic.xp.security.PrincipalKey)17 Context (com.enonic.xp.context.Context)14 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)11 CreateUserParams (com.enonic.xp.security.CreateUserParams)10 IdProviderKey (com.enonic.xp.security.IdProviderKey)10 Node (com.enonic.xp.node.Node)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 ContextBuilder (com.enonic.xp.context.ContextBuilder)6 UpdateUserParams (com.enonic.xp.security.UpdateUserParams)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Mockito (org.mockito.Mockito)6 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)4 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)4 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)4 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)4 TaskId (com.enonic.xp.task.TaskId)4