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