当前位置: 首页>>代码示例>>Java>>正文


Java AuditEvent类代码示例

本文整理汇总了Java中org.springframework.boot.actuate.audit.AuditEvent的典型用法代码示例。如果您正苦于以下问题:Java AuditEvent类的具体用法?Java AuditEvent怎么用?Java AuditEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuditEvent类属于org.springframework.boot.actuate.audit包,在下文中一共展示了AuditEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getByDates

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
/**
 * GET  /audits : get a page of AuditEvents between the fromDate and toDate.
 *
 * @param fromDate the start of the time period of AuditEvents to get
 * @param toDate the end of the time period of AuditEvents to get
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of AuditEvents in body
 * @throws URISyntaxException if there is an error to generate the pagination HTTP headers
 */

@GetMapping(params = {"fromDate", "toDate"})
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<List<AuditEvent>> getByDates(
    @RequestParam(value = "fromDate") LocalDate fromDate,
    @RequestParam(value = "toDate") LocalDate toDate,
    @ApiParam Pageable pageable) throws URISyntaxException {

    Page<AuditEvent> page = auditEventService.findByDates(fromDate.atTime(0, 0), toDate.atTime(23, 59), pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:22,代码来源:AuditResource.java

示例2: addAuditEventTruncateLargeData

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
@Test
public void addAuditEventTruncateLargeData() {
    Map<String, Object> data = new HashMap<>();
    StringBuilder largeData = new StringBuilder();
    for (int i = 0; i < EVENT_DATA_COLUMN_MAX_LENGTH + 10; i++) {
        largeData.append("a");
    }
    data.put("test-key", largeData);
    AuditEvent event = new AuditEvent("test-user", "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(1);
    PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
    assertThat(persistentAuditEvent.getPrincipal()).isEqualTo(event.getPrincipal());
    assertThat(persistentAuditEvent.getAuditEventType()).isEqualTo(event.getType());
    assertThat(persistentAuditEvent.getData()).containsKey("test-key");
    String actualData = persistentAuditEvent.getData().get("test-key");
    assertThat(actualData.length()).isEqualTo(EVENT_DATA_COLUMN_MAX_LENGTH);
    assertThat(actualData).isSubstringOf(largeData);
    assertThat(persistentAuditEvent.getAuditEventDate()).isEqualTo(event.getTimestamp().toInstant());
}
 
开发者ID:pascalgrimaud,项目名称:qualitoast,代码行数:22,代码来源:CustomAuditEventRepositoryIntTest.java

示例3: testFindByPrincipal

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
@Test
public void testFindByPrincipal() {
    persistenceAuditEventRepository.save(testUserEvent);
    persistenceAuditEventRepository.save(testOldUserEvent);
    persistenceAuditEventRepository.save(testOtherUserEvent);

    List<AuditEvent> events = customAuditEventRepository
        .find("test-user", Date.from(testUserEvent.getAuditEventDate().minusSeconds(3600)));
    assertThat(events).hasSize(1);
    AuditEvent event = events.get(0);
    assertThat(event.getPrincipal()).isEqualTo(testUserEvent.getPrincipal());
    assertThat(event.getType()).isEqualTo(testUserEvent.getAuditEventType());
    assertThat(event.getData()).containsKey("test-key");
    assertThat(event.getData().get("test-key").toString()).isEqualTo("test-value");
    assertThat(event.getTimestamp()).isEqualTo(Date.from(testUserEvent.getAuditEventDate()));
}
 
开发者ID:deepu105,项目名称:spring-io,代码行数:17,代码来源:CustomAuditEventRepositoryIntTest.java

示例4: findByPrincipalAndType

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
@Test
public void findByPrincipalAndType() {
    persistenceAuditEventRepository.save(testUserEvent);
    persistenceAuditEventRepository.save(testOldUserEvent);

    testOtherUserEvent.setAuditEventType(testUserEvent.getAuditEventType());
    persistenceAuditEventRepository.save(testOtherUserEvent);

    PersistentAuditEvent testUserOtherTypeEvent = new PersistentAuditEvent();
    testUserOtherTypeEvent.setPrincipal(testUserEvent.getPrincipal());
    testUserOtherTypeEvent.setAuditEventType("test-other-type");
    testUserOtherTypeEvent.setAuditEventDate(testUserEvent.getAuditEventDate());
    persistenceAuditEventRepository.save(testUserOtherTypeEvent);

    List<AuditEvent> events = customAuditEventRepository.find("test-user",
        Date.from(testUserEvent.getAuditEventDate().minusSeconds(3600)), "test-type");
    assertThat(events).hasSize(1);
    AuditEvent event = events.get(0);
    assertThat(event.getPrincipal()).isEqualTo(testUserEvent.getPrincipal());
    assertThat(event.getType()).isEqualTo(testUserEvent.getAuditEventType());
    assertThat(event.getData()).containsKey("test-key");
    assertThat(event.getData().get("test-key").toString()).isEqualTo("test-value");
    assertThat(event.getTimestamp()).isEqualTo(Date.from(testUserEvent.getAuditEventDate()));
}
 
开发者ID:michaelhoffmantech,项目名称:patient-portal,代码行数:25,代码来源:CustomAuditEventRepositoryIntTest.java

示例5: testAddEventWithWebAuthenticationDetails

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
@Test
public void testAddEventWithWebAuthenticationDetails() {
    HttpSession session = new MockHttpSession(null, "test-session-id");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    request.setRemoteAddr("1.2.3.4");
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", details);
    AuditEvent event = new AuditEvent("test-user", "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(1);
    PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
    assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
    assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:18,代码来源:CustomAuditEventRepositoryIntTest.java

示例6: onAuditEvent

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
@EventListener
public void onAuditEvent(AuditApplicationEvent event) {
    AuditEvent auditEvent = event.getAuditEvent();

    if (auditEvent.getType() == AuthenticationAuditListener.AUTHENTICATION_SUCCESS) {
        return;
    }

    log.info("Logging audit application event: timestamp: {}, principal: {}, type: {}, data: {}",
            auditEvent.getTimestamp(),
            auditEvent.getPrincipal(),
            auditEvent.getType(),
            auditEvent.getData()
    );

    auditLogRepository.save(
        AuditLog.builder()
                .type(auditEvent.getType())
                .principal(auditEvent.getPrincipal())
                .timestamp(auditEvent.getTimestamp().toInstant())
                .data(auditEvent.getData())
                .build()
    );

}
 
开发者ID:TulevaEE,项目名称:onboarding-service,代码行数:26,代码来源:AuditApplicationEventLogger.java

示例7: getAll

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
/**
 * GET /audits : get a page of AuditEvents.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of AuditEvents in body
 */
@GetMapping
public ResponseEntity<List<AuditEvent>> getAll(Pageable pageable) {
    Page<AuditEvent> page = auditEventService.findAll(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
开发者ID:torgcrm,项目名称:TorgCRM-Server,代码行数:13,代码来源:AuditResource.java

示例8: add

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void add(AuditEvent event) {
    if (!AUTHORIZATION_FAILURE.equals(event.getType()) &&
        !Constants.ANONYMOUS_USER.equals(event.getPrincipal())) {

        PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent();
        persistentAuditEvent.setPrincipal(event.getPrincipal());
        persistentAuditEvent.setAuditEventType(event.getType());
        persistentAuditEvent.setAuditEventDate(event.getTimestamp().toInstant());
        persistentAuditEvent.setData(auditEventConverter.convertDataToStrings(event.getData()));
        persistenceAuditEventRepository.save(persistentAuditEvent);
    }
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:15,代码来源:CustomAuditEventRepository.java

示例9: getAll

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
/**
 * GET  /audits : get a page of AuditEvents.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of AuditEvents in body
 */
@GetMapping
public ResponseEntity<List<AuditEvent>> getAll(@ApiParam Pageable pageable) {
    Page<AuditEvent> page = auditEventService.findAll(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
开发者ID:asanzdiego,项目名称:codemotion-2017-taller-de-jhipster,代码行数:13,代码来源:AuditResource.java

示例10: addAuditEventWithAnonymousUser

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
@Test
public void addAuditEventWithAnonymousUser() {
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", "test-value");
    AuditEvent event = new AuditEvent(Constants.ANONYMOUS_USER, "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(0);
}
 
开发者ID:asanzdiego,项目名称:codemotion-2017-taller-de-jhipster,代码行数:10,代码来源:CustomAuditEventRepositoryIntTest.java

示例11: find

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
@Override
public List<AuditEvent> find(String principal, Date after) {
    Iterable<PersistentAuditEvent> persistentAuditEvents;
    if (principal == null && after == null) {
        persistentAuditEvents = persistenceAuditEventRepository.findAll();
    } else if (after == null) {
        persistentAuditEvents = persistenceAuditEventRepository.findByPrincipal(principal);
    } else {
        persistentAuditEvents =
            persistenceAuditEventRepository.findByPrincipalAndAuditEventDateAfter(principal, after.toInstant());
    }
    return auditEventConverter.convertToAuditEvent(persistentAuditEvents);
}
 
开发者ID:deepu105,项目名称:spring-io,代码行数:14,代码来源:CustomAuditEventRepository.java

示例12: convertToAuditEvent

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
/**
 * Convert a list of PersistentAuditEvent to a list of AuditEvent
 *
 * @param persistentAuditEvents the list to convert
 * @return the converted list.
 */
public List<AuditEvent> convertToAuditEvent(Iterable<PersistentAuditEvent> persistentAuditEvents) {
    if (persistentAuditEvents == null) {
        return Collections.emptyList();
    }
    List<AuditEvent> auditEvents = new ArrayList<>();
    for (PersistentAuditEvent persistentAuditEvent : persistentAuditEvents) {
        auditEvents.add(convertToAuditEvent(persistentAuditEvent));
    }
    return auditEvents;
}
 
开发者ID:IBM,项目名称:Microservices-with-JHipster-and-Spring-Boot,代码行数:17,代码来源:AuditEventConverter.java

示例13: find

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
@Override
public List<AuditEvent> find(String principal, Date after) {
    Iterable<PersistentAuditEvent> persistentAuditEvents;
    if (principal == null && after == null) {
        persistentAuditEvents = persistenceAuditEventRepository.findAll();
    } else if (after == null) {
        persistentAuditEvents = persistenceAuditEventRepository.findByPrincipal(principal);
    } else {
        persistentAuditEvents =
            persistenceAuditEventRepository.findByPrincipalAndAuditEventDateAfter(principal, LocalDateTime.from(after.toInstant()));
    }
    return auditEventConverter.convertToAuditEvent(persistentAuditEvents);
}
 
开发者ID:IBM,项目名称:Microservices-with-JHipster-and-Spring-Boot,代码行数:14,代码来源:CustomAuditEventRepository.java

示例14: get

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
/**
 * GET  /audits/:id : get an AuditEvent by id.
 *
 * @param id the id of the entity to get
 * @return the ResponseEntity with status 200 (OK) and the AuditEvent in body, or status 404 (Not Found)
 */
@RequestMapping(value = "/{id:.+}",
    method = RequestMethod.GET)
public ResponseEntity<AuditEvent> get(@PathVariable Long id) {
    return auditEventService.find(id)
            .map((entity) -> new ResponseEntity<>(entity, HttpStatus.OK))
            .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
 
开发者ID:klask-io,项目名称:klask-io,代码行数:14,代码来源:AuditResource.java

示例15: testFindByPrincipalIsNullAndAfterIsNull

import org.springframework.boot.actuate.audit.AuditEvent; //导入依赖的package包/类
@Test
public void testFindByPrincipalIsNullAndAfterIsNull() {
    persistenceAuditEventRepository.save(testUserEvent);
    persistenceAuditEventRepository.save(testOtherUserEvent);

    List<AuditEvent> events = customAuditEventRepository.find(null, null);
    assertThat(events).hasSize(2);
    assertThat(events).extracting("principal")
        .containsExactlyInAnyOrder("test-user", "other-test-user");
}
 
开发者ID:deepu105,项目名称:spring-io,代码行数:11,代码来源:CustomAuditEventRepositoryIntTest.java


注:本文中的org.springframework.boot.actuate.audit.AuditEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。