Search in sources :

Example 51 with PrincipalKey

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

the class IssueDataSerializer method toUpdateNodeData.

public PropertyTree toUpdateNodeData(final Issue editedIssue) {
    final PropertyTree propertyTree = new PropertyTree();
    final PropertySet issueAsData = propertyTree.getRoot();
    issueAsData.ifNotNull().addEnum(TYPE, editedIssue.getIssueType());
    issueAsData.ifNotNull().addLong(INDEX, editedIssue.getIndex());
    issueAsData.ifNotNull().addString(TITLE, editedIssue.getTitle());
    issueAsData.ifNotNull().addInstant(CREATED_TIME, editedIssue.getCreatedTime());
    issueAsData.ifNotNull().addInstant(MODIFIED_TIME, editedIssue.getModifiedTime());
    issueAsData.ifNotNull().addString(CREATOR, editedIssue.getCreator().toString());
    issueAsData.ifNotNull().addString(MODIFIER, editedIssue.getModifier().toString());
    issueAsData.ifNotNull().addString(STATUS, editedIssue.getStatus().toString());
    issueAsData.addString(DESCRIPTION, editedIssue.getDescription());
    issueAsData.addStrings(APPROVERS, editedIssue.getApproverIds().stream().map(PrincipalKey::toString).collect(Collectors.toList()));
    if (editedIssue.getPublishRequest() != null) {
        addPublishRequest(issueAsData, editedIssue.getPublishRequest());
    }
    if (editedIssue instanceof PublishRequestIssue) {
        publishRequestIssueSerializer.toUpdateNodeData((PublishRequestIssue) editedIssue, issueAsData);
    }
    return propertyTree;
}
Also used : PublishRequestIssue(com.enonic.xp.issue.PublishRequestIssue) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 52 with PrincipalKey

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

the class AccessControlListStoreDocumentFactory method create.

static List<IndexItem> create(final AccessControlList accessControlList) {
    final List<IndexItem> aclStoreDocumentItems = new ArrayList<>();
    for (final AccessControlEntry entry : accessControlList) {
        final Iterable<Permission> allowedPermissions = entry.getAllowedPermissions();
        final PrincipalKey principalKey = entry.getPrincipal();
        for (final Permission permission : allowedPermissions) {
            aclStoreDocumentItems.add(new IndexItemString(getPathForPermission(permission), principalKey.toString()));
        }
    }
    return aclStoreDocumentItems;
}
Also used : IndexItemString(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItemString) ArrayList(java.util.ArrayList) Permission(com.enonic.xp.security.acl.Permission) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) PrincipalKey(com.enonic.xp.security.PrincipalKey) IndexItem(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItem)

Example 53 with PrincipalKey

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

the class ScheduleAuditLogSupportImpl method log.

private void log(final String type, final PropertyTree data, final AuditLogUris uris, final Context rootContext) {
    final PrincipalKey userPrincipalKey = rootContext.getAuthInfo().getUser() != null ? rootContext.getAuthInfo().getUser().getKey() : PrincipalKey.ofAnonymous();
    final LogAuditLogParams logParams = LogAuditLogParams.create().type(type).source(SOURCE_CORE_CONTENT).data(data).objectUris(uris).user(userPrincipalKey).build();
    runAsAuditLog(() -> auditLogService.log(logParams), rootContext);
}
Also used : LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Example 54 with PrincipalKey

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

the class SchedulerServiceImplTest method create.

@Test
void create() throws Exception {
    final ScheduledJobName name = ScheduledJobName.from("test");
    final DescriptorKey descriptor = DescriptorKey.from(ApplicationKey.from("com.enonic.app.features"), "landing");
    final CronCalendar calendar = calendarService.cron("* * * * *", TimeZone.getDefault());
    final PropertyTree config = new PropertyTree();
    config.addString("string", "value");
    final PrincipalKey user = PrincipalKey.from("user:system:user");
    final CreateScheduledJobParams params = CreateScheduledJobParams.create().name(name).descriptor(descriptor).calendar(calendar).config(config).description("description").enabled(true).user(user).build();
    final Instant now = Instant.now();
    Thread.sleep(100);
    final ScheduledJob scheduledJob = adminContext().callWith(() -> schedulerService.create(params));
    assertEquals(name, scheduledJob.getName());
    assertEquals(descriptor, scheduledJob.getDescriptor());
    assertEquals(calendar.getCronValue(), ((CronCalendar) scheduledJob.getCalendar()).getCronValue());
    assertEquals(calendar.getTimeZone(), ((CronCalendar) scheduledJob.getCalendar()).getTimeZone());
    assertEquals(config, scheduledJob.getConfig());
    assertEquals("description", scheduledJob.getDescription());
    assertEquals(user, scheduledJob.getUser());
    assertEquals("user:system:repo-test-user", scheduledJob.getModifier().toString());
    assertEquals("user:system:repo-test-user", scheduledJob.getCreator().toString());
    assertTrue(now.isBefore(scheduledJob.getCreatedTime()));
    assertTrue(now.isBefore(scheduledJob.getModifiedTime()));
    assertTrue(scheduledJob.isEnabled());
}
Also used : CreateScheduledJobParams(com.enonic.xp.scheduler.CreateScheduledJobParams) CronCalendar(com.enonic.xp.scheduler.CronCalendar) ScheduledJobName(com.enonic.xp.scheduler.ScheduledJobName) PropertyTree(com.enonic.xp.data.PropertyTree) Instant(java.time.Instant) ScheduledJob(com.enonic.xp.scheduler.ScheduledJob) DescriptorKey(com.enonic.xp.page.DescriptorKey) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 55 with PrincipalKey

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

the class ProjectServiceImplTest method create_with_role_members.

@Test
void create_with_role_members() {
    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()).addOwner(user2.getKey()).build());
        final Set<PrincipalKey> members = securityService.getRelationships(PrincipalKey.ofRole("cms.project.test-project.owner")).stream().map(PrincipalRelationship::getTo).collect(Collectors.toSet());
        assertTrue(members.contains(user1.getKey()));
        assertTrue(members.contains(user2.getKey()));
    });
}
Also used : User(com.enonic.xp.security.User) RepositoryId(com.enonic.xp.repository.RepositoryId) PrincipalKey(com.enonic.xp.security.PrincipalKey) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Aggregations

PrincipalKey (com.enonic.xp.security.PrincipalKey)84 Test (org.junit.jupiter.api.Test)47 PropertyTree (com.enonic.xp.data.PropertyTree)22 User (com.enonic.xp.security.User)18 AbstractElasticsearchIntegrationTest (com.enonic.xp.repo.impl.elasticsearch.AbstractElasticsearchIntegrationTest)15 CreateUserParams (com.enonic.xp.security.CreateUserParams)14 PrincipalKeys (com.enonic.xp.security.PrincipalKeys)14 Instant (java.time.Instant)12 Node (com.enonic.xp.node.Node)10 DescriptorKey (com.enonic.xp.page.DescriptorKey)10 Context (com.enonic.xp.context.Context)9 IdProviderKey (com.enonic.xp.security.IdProviderKey)9 PrincipalRelationship (com.enonic.xp.security.PrincipalRelationship)9 CreateGroupParams (com.enonic.xp.security.CreateGroupParams)8 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)8 NodeId (com.enonic.xp.node.NodeId)7 NodeQuery (com.enonic.xp.node.NodeQuery)7 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)7 Group (com.enonic.xp.security.Group)6 AccessControlList (com.enonic.xp.security.acl.AccessControlList)6