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