Search in sources :

Example 31 with User

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());
}
Also used : User(com.enonic.xp.security.User) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test)

Example 32 with User

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());
}
Also used : Context(com.enonic.xp.context.Context) User(com.enonic.xp.security.User) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 33 with User

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");
}
Also used : User(com.enonic.xp.security.User) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 34 with User

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());
    });
}
Also used : User(com.enonic.xp.security.User) RepositoryId(com.enonic.xp.repository.RepositoryId) PrincipalRelationships(com.enonic.xp.security.PrincipalRelationships) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 35 with User

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()));
}
Also used : Context(com.enonic.xp.context.Context) SchedulerExecutorService(com.enonic.xp.impl.scheduler.SchedulerExecutorService) BeforeEach(org.junit.jupiter.api.BeforeEach) IdProviderKey(com.enonic.xp.security.IdProviderKey) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) OneTimeCalendar(com.enonic.xp.scheduler.OneTimeCalendar) SchedulerConstants(com.enonic.xp.scheduler.SchedulerConstants) UpdateLastRunCommand(com.enonic.xp.impl.scheduler.UpdateLastRunCommand) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ContextAccessor(com.enonic.xp.context.ContextAccessor) SchedulerServiceImpl(com.enonic.xp.impl.scheduler.SchedulerServiceImpl) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) ContextBuilder(com.enonic.xp.context.ContextBuilder) User(com.enonic.xp.security.User) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) TimeZone(java.util.TimeZone) Set(java.util.Set) SchedulerConfig(com.enonic.xp.impl.scheduler.SchedulerConfig) Instant(java.time.Instant) ScheduleAuditLogSupportImpl(com.enonic.xp.impl.scheduler.ScheduleAuditLogSupportImpl) TaskId(com.enonic.xp.task.TaskId) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) CronCalendar(com.enonic.xp.scheduler.CronCalendar) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) ScheduleCalendar(com.enonic.xp.scheduler.ScheduleCalendar) Mockito.mock(org.mockito.Mockito.mock) Strictness(org.mockito.quality.Strictness) ScheduleAuditLogExecutorImpl(com.enonic.xp.impl.scheduler.ScheduleAuditLogExecutorImpl) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) ModifyScheduledJobParams(com.enonic.xp.scheduler.ModifyScheduledJobParams) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) ScheduleCalendarType(com.enonic.xp.scheduler.ScheduleCalendarType) AuditLogService(com.enonic.xp.audit.AuditLogService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PropertyTree(com.enonic.xp.data.PropertyTree) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CalendarServiceImpl(com.enonic.xp.impl.scheduler.CalendarServiceImpl) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ApplicationKey(com.enonic.xp.app.ApplicationKey) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) PrincipalKey(com.enonic.xp.security.PrincipalKey) DescriptorKey(com.enonic.xp.page.DescriptorKey) NodeAccessException(com.enonic.xp.node.NodeAccessException) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) User(com.enonic.xp.security.User) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) PropertyTree(com.enonic.xp.data.PropertyTree) Instant(java.time.Instant) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) OneTimeCalendar(com.enonic.xp.scheduler.OneTimeCalendar) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

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