Search in sources :

Example 11 with LogAuditLogParams

use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.

the class AuditLogServiceImplTest_log method log_anonymous.

@Test
public void log_anonymous() {
    final Context context = ContextBuilder.create().repositoryId(AuditLogConstants.AUDIT_LOG_REPO_ID).branch(AuditLogConstants.AUDIT_LOG_BRANCH).authInfo(AuthenticationInfo.create().principals(PrincipalKey.ofAnonymous()).user(User.ANONYMOUS).build()).build();
    assertThrows(NodeAccessException.class, () -> context.runWith(() -> {
        LogAuditLogParams params = LogAuditLogParams.create().type("test").build();
        auditLogService.log(params);
    }));
}
Also used : AuditLogContext(com.enonic.xp.core.impl.audit.AuditLogContext) Context(com.enonic.xp.context.Context) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) Test(org.junit.jupiter.api.Test)

Example 12 with LogAuditLogParams

use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.

the class ContentServiceImplTest_create method audit_data.

@Test
public void audit_data() {
    final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    Mockito.verify(auditLogService, Mockito.timeout(5000).times(1)).log(captor.capture());
    final PropertySet logResultSet = captor.getValue().getData().getSet("result");
    assertEquals(content.getId().toString(), logResultSet.getString("id"));
    assertEquals(content.getPath().toString(), logResultSet.getString("path"));
}
Also used : LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 13 with LogAuditLogParams

use of com.enonic.xp.audit.LogAuditLogParams 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 14 with LogAuditLogParams

use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.

the class AuditLogServiceImplTest_log method get.

@Test
public void get() {
    final LogAuditLogParams params = LogAuditLogParams.create().type("test").build();
    final AuditLog log1 = AuditLogContext.createAdminContext().callWith(() -> auditLogService.log(params));
    final AuditLog log2 = AuditLogContext.createAdminContext().callWith(() -> auditLogService.get(log1.getId()));
    assertEquals(log1, log2);
}
Also used : LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) AuditLog(com.enonic.xp.audit.AuditLog) Test(org.junit.jupiter.api.Test)

Example 15 with LogAuditLogParams

use of com.enonic.xp.audit.LogAuditLogParams in project xp by enonic.

the class ContentServiceImplTest_delete method audit_data.

@Test
public void audit_data() {
    final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
    // Creates a content with children
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Root Content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final CreateContentParams createChild1ContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("Child1 Content").parent(content.getPath()).type(ContentTypeName.folder()).build();
    this.contentService.create(createChild1ContentParams);
    final DeleteContentParams deleteContentParams = DeleteContentParams.create().contentPath(content.getPath()).build();
    this.contentService.deleteWithoutFetch(deleteContentParams);
    Mockito.verify(auditLogService, Mockito.timeout(5000).times(3)).log(captor.capture());
    final PropertySet logResultSet = captor.getValue().getData().getSet("result");
    final Iterable<String> deletedContents = logResultSet.getStrings("deletedContents");
    assertEquals(2, StreamSupport.stream(deletedContents.spliterator(), false).count());
}
Also used : DeleteContentParams(com.enonic.xp.content.DeleteContentParams) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Aggregations

LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)22 Test (org.junit.jupiter.api.Test)20 Content (com.enonic.xp.content.Content)12 PropertyTree (com.enonic.xp.data.PropertyTree)12 PropertySet (com.enonic.xp.data.PropertySet)10 Context (com.enonic.xp.context.Context)8 CreateContentParams (com.enonic.xp.content.CreateContentParams)7 PrincipalKey (com.enonic.xp.security.PrincipalKey)6 User (com.enonic.xp.security.User)5 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)5 AuditLog (com.enonic.xp.audit.AuditLog)3 FindAuditLogResult (com.enonic.xp.audit.FindAuditLogResult)3 ContextBuilder (com.enonic.xp.context.ContextBuilder)3 CronCalendarImpl (com.enonic.xp.impl.scheduler.distributed.CronCalendarImpl)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 CreateScheduledJobParams (com.enonic.xp.scheduler.CreateScheduledJobParams)3 ScheduledJob (com.enonic.xp.scheduler.ScheduledJob)3 IdProviderKey (com.enonic.xp.security.IdProviderKey)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)3