use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.
the class ContentAuditLogSupportImpl 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.audit.LogAuditLogParams in project xp by enonic.
the class ContentAuditLogSupportImplTest method testUpdateContent.
@Test
public void testUpdateContent() throws Exception {
final PropertyTree propertyTree = new PropertyTree();
propertyTree.addString("test-data", "test-data");
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "testUser")).displayName("Test User").modifiedTime(Instant.now()).email("test-user@enonic.com").login("test-user").build();
final UpdateContentParams params = new UpdateContentParams().requireValid(true).contentId(ContentId.from("contentId")).clearAttachments(true).modifier(user.getKey()).editor(edit -> edit.displayName = "New Display Name");
final Content content = Content.create().id(ContentId.from("contentId")).type(ContentTypeName.site()).name("contentName").displayName("displayName").parentPath(ContentPath.ROOT).build();
final AuthenticationInfo authInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN_LOGIN).build();
final Context context = ContextBuilder.create().branch(ContentConstants.BRANCH_DRAFT).repositoryId(RepositoryId.from("test-repository")).authInfo(authInfo).build();
// test
context.runWith(() -> support.update(params, content));
executor.shutdown();
executor.awaitTermination(1, TimeUnit.MINUTES);
// verify and assert
final ArgumentCaptor<LogAuditLogParams> argumentCaptor = ArgumentCaptor.forClass(LogAuditLogParams.class);
Mockito.verify(auditLogService, Mockito.times(1)).log(argumentCaptor.capture());
Assertions.assertEquals(user.getKey(), argumentCaptor.getValue().getUser());
final String modifier = argumentCaptor.getValue().getData().getSet("params").getString("modifier");
Assertions.assertEquals(user.getKey().toString(), modifier);
}
use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.
the class ScheduleAuditLogSupportImplTest method testCreateJob.
@Test
public void testCreateJob() throws Exception {
final PropertyTree config = new PropertyTree();
config.addString("property", "value");
final CronCalendarImpl calendar = CronCalendarImpl.create().value("* * * * *").timeZone(TimeZone.getTimeZone("GMT+5:30")).build();
final DescriptorKey descriptor = DescriptorKey.from("appKey:descriptorName");
final String jobDescription = "Job description";
final PrincipalKey userKey = PrincipalKey.from("user:system:user");
final CreateScheduledJobParams params = CreateScheduledJobParams.create().name(name).descriptor(descriptor).description(jobDescription).calendar(calendar).config(config).user(userKey).enabled(true).build();
final ScheduledJob job = ScheduledJob.create().name(name).calendar(calendar).descriptor(descriptor).description(jobDescription).config(config).enabled(true).user(userKey).creator(PrincipalKey.from("user:system:creator")).modifier(PrincipalKey.from("user:system:creator")).createdTime(Instant.parse("2021-02-25T10:44:33.170079900Z")).modifiedTime(Instant.parse("2021-02-25T10:44:33.170079900Z")).lastRun(Instant.parse("2021-03-25T10:44:33.170079900Z")).lastTaskId(TaskId.from("task-id")).build();
context.runWith(() -> support.create(params, job));
executor.shutdown();
executor.awaitTermination(1, TimeUnit.MINUTES);
final ArgumentCaptor<LogAuditLogParams> argumentCaptor = ArgumentCaptor.forClass(LogAuditLogParams.class);
verify(auditLogService, times(1)).log(argumentCaptor.capture());
assertEquals(user.getKey(), argumentCaptor.getValue().getUser());
assertEquals("system.scheduler:master:job-name", argumentCaptor.getValue().getObjectUris().first().getValue());
assertEquals("com.enonic.xp.core-scheduler", argumentCaptor.getValue().getSource());
assertEquals(userKey.toString(), argumentCaptor.getValue().getData().getSet("result").getString("user"));
assertEquals(job.getCreator().toString(), argumentCaptor.getValue().getData().getSet("result").getString("creator"));
assertEquals(job.getModifier().toString(), argumentCaptor.getValue().getData().getSet("result").getString("modifier"));
assertEquals(job.getCreatedTime(), argumentCaptor.getValue().getData().getSet("result").getInstant("createdTime"));
assertEquals(job.getModifiedTime(), argumentCaptor.getValue().getData().getSet("result").getInstant("modifiedTime"));
assertEquals(name.getValue(), argumentCaptor.getValue().getData().getSet("result").getString("name"));
assertEquals(jobDescription, argumentCaptor.getValue().getData().getSet("result").getString("description"));
assertEquals(descriptor.toString(), argumentCaptor.getValue().getData().getSet("result").getString("descriptor"));
assertEquals(calendar.getType().name(), argumentCaptor.getValue().getData().getSet("result").getSet("calendar").getString("type"));
assertEquals(calendar.getCronValue(), argumentCaptor.getValue().getData().getSet("result").getSet("calendar").getString("value"));
assertEquals(calendar.getTimeZone().getID(), argumentCaptor.getValue().getData().getSet("result").getSet("calendar").getString("timezone"));
assertEquals(true, argumentCaptor.getValue().getData().getSet("result").getBoolean("enabled"));
assertEquals(config.getRoot(), argumentCaptor.getValue().getData().getSet("result").getSet("config"));
assertNull(argumentCaptor.getValue().getData().getSet("result").getInstant("lastRun"));
assertNull(argumentCaptor.getValue().getData().getSet("result").getString("lastTaskId"));
}
use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.
the class ScheduleAuditLogSupportImplTest method testUpdateContent.
@Test
public void testUpdateContent() throws Exception {
final PropertyTree config = new PropertyTree();
config.addString("property", "value");
final CronCalendarImpl calendar = CronCalendarImpl.create().value("* * * * *").timeZone(TimeZone.getTimeZone("GMT+5:30")).build();
final DescriptorKey descriptor = DescriptorKey.from("appKey:descriptorName");
final String jobDescription = "Job description";
final PrincipalKey userKey = PrincipalKey.from("user:system:user");
final OneTimeCalendarImpl oneTimeCalendar = OneTimeCalendarImpl.create().value(Instant.parse("2021-04-25T10:44:33.170079900Z")).build();
final ModifyScheduledJobParams params = ModifyScheduledJobParams.create().name(name).editor(edit -> edit.calendar = oneTimeCalendar).build();
final ScheduledJob job = ScheduledJob.create().name(name).calendar(oneTimeCalendar).descriptor(descriptor).description(jobDescription).config(config).enabled(true).user(userKey).creator(PrincipalKey.from("user:system:creator")).modifier(PrincipalKey.from("user:system:creator")).createdTime(Instant.parse("2021-02-25T10:44:33.170079900Z")).modifiedTime(Instant.parse("2021-02-25T10:44:33.170079900Z")).build();
context.runWith(() -> support.modify(params, job));
executor.shutdown();
executor.awaitTermination(1, TimeUnit.MINUTES);
final ArgumentCaptor<LogAuditLogParams> argumentCaptor = ArgumentCaptor.forClass(LogAuditLogParams.class);
verify(auditLogService, times(1)).log(argumentCaptor.capture());
assertEquals(user.getKey().toString(), argumentCaptor.getValue().getData().getSet("params").getString("modifier"));
assertEquals("2021-04-25T10:44:33.170079900Z", argumentCaptor.getValue().getData().getSet("result").getSet("calendar").getString("value"));
}
use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.
the class ScheduleAuditLogSupportImplTest method testUpdateWithoutCreator.
@Test
public // jobs were produced with an empty `creator` and `createdTime` fields from 7.7.0 to 7.7.2
void testUpdateWithoutCreator() throws Exception {
final PropertyTree config = new PropertyTree();
config.addString("property", "value");
final CronCalendarImpl calendar = CronCalendarImpl.create().value("* * * * *").timeZone(TimeZone.getTimeZone("GMT+5:30")).build();
final DescriptorKey descriptor = DescriptorKey.from("appKey:descriptorName");
final String jobDescription = "Job description";
final PrincipalKey userKey = PrincipalKey.from("user:system:user");
final OneTimeCalendarImpl oneTimeCalendar = OneTimeCalendarImpl.create().value(Instant.parse("2021-04-25T10:44:33.170079900Z")).build();
final ModifyScheduledJobParams params = ModifyScheduledJobParams.create().name(name).editor(edit -> edit.calendar = oneTimeCalendar).build();
final ScheduledJob job = ScheduledJob.create().name(name).calendar(oneTimeCalendar).descriptor(descriptor).description(jobDescription).config(config).enabled(true).user(userKey).modifier(PrincipalKey.from("user:system:creator")).createdTime(Instant.parse("2021-02-25T10:44:33.170079900Z")).modifiedTime(Instant.parse("2021-02-25T10:44:33.170079900Z")).build();
context.runWith(() -> support.modify(params, job));
executor.shutdown();
executor.awaitTermination(1, TimeUnit.MINUTES);
final ArgumentCaptor<LogAuditLogParams> argumentCaptor = ArgumentCaptor.forClass(LogAuditLogParams.class);
verify(auditLogService, times(1)).log(argumentCaptor.capture());
assertNull(argumentCaptor.getValue().getData().getSet("params").getString("creator"));
}
Aggregations