use of com.enonic.xp.security.User in project xp by enonic.
the class UserNodeTranslatorTest method toUser.
@Test
public void toUser() throws Exception {
final PrincipalKey userKey = PrincipalKey.ofUser(IdProviderKey.system(), "i-am-a-user");
final PropertyTree rootDataSet = new PropertyTree();
rootDataSet.setString(PrincipalPropertyNames.LOGIN_KEY, "loginkey");
rootDataSet.setString(PrincipalPropertyNames.EMAIL_KEY, "rmy@enonic.com");
rootDataSet.setString(PrincipalPropertyNames.DISPLAY_NAME_KEY, "displayname");
rootDataSet.setString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY, userKey.getType().toString());
rootDataSet.setString(PrincipalPropertyNames.ID_PROVIDER_KEY, userKey.getIdProviderKey().toString());
rootDataSet.setString(PrincipalPropertyNames.AUTHENTICATION_HASH_KEY, "clear:password");
final Node node = Node.create().id(NodeId.from("id")).name(PrincipalKeyNodeTranslator.toNodeName(userKey)).data(rootDataSet).build();
final User user = (User) PrincipalNodeTranslator.fromNode(node);
assertEquals("loginkey", user.getLogin());
assertEquals("rmy@enonic.com", user.getEmail());
assertEquals(userKey, user.getKey());
assertEquals("clear:password", user.getAuthenticationHash());
}
use of com.enonic.xp.security.User in project xp by enonic.
the class ContentServiceImplTest_duplicate method some_metadata_reset_on_duplicate.
@Test
public void some_metadata_reset_on_duplicate() throws Exception {
final User otherUser = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "fisk")).login("fisk").build();
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("rootContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).permissions(AccessControlList.create().add(AccessControlEntry.create().principal(otherUser.getKey()).allowAll().build()).build()).build();
final Content rootContent = this.contentService.create(createContentParams);
final Context duplicateContext = ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().user(otherUser).principals(RoleKeys.CONTENT_MANAGER_ADMIN).build()).build();
final Content duplicateContent = duplicateContext.callWith(() -> doDuplicateContent(rootContent));
assertTrue(rootContent.getModifiedTime().isBefore(duplicateContent.getModifiedTime()));
assertTrue(rootContent.getCreatedTime().isBefore(duplicateContent.getCreatedTime()));
assertEquals(otherUser.getKey(), duplicateContent.getModifier());
assertEquals(otherUser.getKey(), duplicateContent.getOwner());
assertEquals(otherUser.getKey(), duplicateContent.getCreator());
}
use of com.enonic.xp.security.User in project xp by enonic.
the class IssueServiceImplTest_deleteComment method setup.
@BeforeEach
public void setup() {
this.issue = this.createIssue(CreateIssueParams.create().title("issue-1"));
final User creator = User.ANONYMOUS;
this.comment = this.createComment(creator, "Comment One");
}
use of com.enonic.xp.security.User in project xp by enonic.
the class ProjectServiceImplTest method modify_permissions.
@Test
void modify_permissions() {
final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
adminContext().runWith(() -> {
final User user1 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("user1").login("user1").build());
final User user2 = securityService.createUser(CreateUserParams.create().userKey(PrincipalKey.ofUser(IdProviderKey.system(), "user2")).displayName("user2").login("user2").build());
doCreateProjectAsAdmin(ProjectName.from(projectRepoId), ProjectPermissions.create().addOwner(user1.getKey()).build());
projectService.modifyPermissions(ProjectName.from("test-project"), ProjectPermissions.create().addOwner(user2.getKey()).build());
final PrincipalRelationships principalRelationships = securityService.getRelationships(PrincipalKey.ofRole("cms.project.test-project.owner"));
assertEquals(1, principalRelationships.getSize());
assertEquals(principalRelationships.get(0).getTo(), user2.getKey());
});
}
use of com.enonic.xp.security.User in project xp by enonic.
the class SchedulerServiceImplTest method modify.
@Test
void modify() throws Exception {
final ScheduledJobName name = ScheduledJobName.from("test");
adminContext().callWith(() -> schedulerService.create(CreateScheduledJobParams.create().name(name).descriptor(DescriptorKey.from(ApplicationKey.from("com.enonic.app.test"), "task1")).calendar(calendarService.cron("* * * * *", TimeZone.getTimeZone("GMT+5:30"))).config(new PropertyTree()).build()));
final Instant now = Instant.now();
Thread.sleep(100);
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).displayName("User 1").email("user1@enonic.com").login("user1").build();
final Context adminContext = adminContext();
final Context userAdminContext = ContextBuilder.from(adminContext).authInfo(AuthenticationInfo.copyOf(adminContext.getAuthInfo()).user(user).build()).build();
final ScheduledJob modifiedJob = userAdminContext.callWith(() -> schedulerService.modify(ModifyScheduledJobParams.create().name(name).editor(edit -> {
edit.enabled = true;
edit.description = "new description";
edit.descriptor = DescriptorKey.from(ApplicationKey.from("com.enonic.app.test"), "task2");
edit.config.addString("string", "value");
edit.user = PrincipalKey.from("user:provider:user");
edit.calendar = calendarService.oneTime(Instant.parse("2021-02-25T10:44:33.170079900Z"));
}).build()));
assertEquals(name, modifiedJob.getName());
assertEquals(DescriptorKey.from(ApplicationKey.from("com.enonic.app.test"), "task2"), modifiedJob.getDescriptor());
assertEquals("new description", modifiedJob.getDescription());
assertEquals("2021-02-25T10:44:33.170079900Z", ((OneTimeCalendar) modifiedJob.getCalendar()).getValue().toString());
assertEquals(ScheduleCalendarType.ONE_TIME, modifiedJob.getCalendar().getType());
assertEquals("value", modifiedJob.getConfig().getString("string"));
assertEquals(PrincipalKey.from("user:provider:user"), modifiedJob.getUser());
assertEquals(PrincipalKey.from("user:system:repo-test-user"), modifiedJob.getCreator());
assertEquals(PrincipalKey.from("user:system:user1"), modifiedJob.getModifier());
assertEquals(user.getKey(), modifiedJob.getModifier());
assertTrue(now.isBefore(modifiedJob.getModifiedTime()));
assertTrue(Instant.now().isAfter(modifiedJob.getModifiedTime()));
assertTrue(Instant.now().isAfter(modifiedJob.getCreatedTime()));
}
Aggregations