Java 类org.springframework.boot.actuate.audit.AuditEvent 实例源码

项目:qualitoast    文件:CustomAuditEventRepositoryIntTest.java   
@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());
}
项目:spring-io    文件:CustomAuditEventRepositoryIntTest.java   
@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()));
}
项目:patient-portal    文件:CustomAuditEventRepositoryIntTest.java   
@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()));
}
项目:codemotion-2017-taller-de-jhipster    文件:CustomAuditEventRepositoryIntTest.java   
@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());
}
项目:jhipster-microservices-example    文件:CustomAuditEventRepositoryIntTest.java   
@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");
}
项目:onboarding-service    文件:AuditApplicationEventLogger.java   
@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()
    );

}
项目:TorgCRM-Server    文件:CustomAuditEventRepositoryIntTest.java   
@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()));
}
项目:TorgCRM-Server    文件:CustomAuditEventRepositoryIntTest.java   
@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());
}
项目:qualitoast    文件:CustomAuditEventRepositoryIntTest.java   
@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()));
}
项目:sentry    文件:AuditResource.java   
/**
 * 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);
}
项目:spring-io    文件:CustomAuditEventRepositoryIntTest.java   
@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");
}
项目:spring-io    文件:CustomAuditEventRepositoryIntTest.java   
@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()));
}
项目:TorgCRM-Server    文件:AuditResource.java   
/**
 * 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);
}
项目:xm-uaa    文件:CustomAuditEventRepository.java   
@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);
    }
}
项目:codemotion-2017-taller-de-jhipster    文件:AuditResource.java   
/**
 * 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);
}
项目:codemotion-2017-taller-de-jhipster    文件:CustomAuditEventRepositoryIntTest.java   
@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);
}
项目:spring-io    文件:CustomAuditEventRepository.java   
@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);
}
项目:Microservices-with-JHipster-and-Spring-Boot    文件:AuditEventConverter.java   
/**
 * 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;
}
项目:Microservices-with-JHipster-and-Spring-Boot    文件:CustomAuditEventRepository.java   
@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);
}
项目:qualitoast    文件:AuditResource.java   
/**
 * 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);
}
项目:sentry    文件:AuditEventConverter.java   
/**
 * 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;
}
项目:xm-uaa    文件:CustomAuditEventRepositoryIntTest.java   
@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);
}
项目:speakTogether    文件:AuditResource.java   
/**
 * 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);
}
项目:jhipster-microservices-example    文件:AuditResource.java   
/**
 * 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);
}
项目:jhipster-microservices-example    文件:CustomAuditEventRepository.java   
@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);
}
项目:devoxxus-jhipster-microservices-demo    文件:AuditResource.java   
/**
 * 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);
}
项目:klask-io    文件:AuditResource.java   
/**
 * 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));
}
项目:spring-io    文件:CustomAuditEventRepositoryIntTest.java   
@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");
}
项目:qualitoast    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void testAddEventWithNullData() {
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", null);
    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("test-key")).isEqualTo("null");
}
项目:jhipster-microservices-example    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void testFindAfter() {
    persistenceAuditEventRepository.save(testUserEvent);
    persistenceAuditEventRepository.save(testOldUserEvent);

    List<AuditEvent> events =
        customAuditEventRepository.find(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()));
}
项目:qualitoast    文件:CustomAuditEventRepository.java   
@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());
        Map<String, String> eventData = auditEventConverter.convertDataToStrings(event.getData());
        persistentAuditEvent.setData(truncate(eventData));
        persistenceAuditEventRepository.save(persistentAuditEvent);
    }
}
项目:jhipster-microservices-example    文件:CustomAuditEventRepositoryIntTest.java   
@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");
}
项目:onboarding-service    文件:AuditLog.java   
public static AuditLog fromAuditEvent(AuditEvent auditEvent) {
    return AuditLog.builder()
            .timestamp(auditEvent.getTimestamp().toInstant())
            .principal(auditEvent.getPrincipal())
            .type(auditEvent.getType())
            .data(auditEvent.getData())
            .build();
}
项目:jhipster-microservices-example    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void addAuditEvent() {
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", "test-value");
    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");
    assertThat(persistentAuditEvent.getData().get("test-key")).isEqualTo("test-value");
    assertThat(persistentAuditEvent.getAuditEventDate()).isEqualTo(event.getTimestamp().toInstant());
}
项目:codemotion-2017-taller-de-jhipster    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void addAuditEventWithAuthorizationFailureType() {
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", "test-value");
    AuditEvent event = new AuditEvent("test-user", "AUTHORIZATION_FAILURE", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(0);
}
项目:shoucang    文件:AuditEventConverter.java   
/**
 * 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;
}
项目:devoxxus-jhipster-microservices-demo    文件:AuditEventConverter.java   
/**
 * 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;
}
项目:MTC_Labrat    文件:AuditResource.java   
/**
 * 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
 */

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

    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);
}
项目:spring-io    文件:CustomAuditEventRepositoryIntTest.java   
@Test
public void testFindByPrincipalNotNullAndAfterIsNull() {
    persistenceAuditEventRepository.save(testUserEvent);
    persistenceAuditEventRepository.save(testOtherUserEvent);

    List<AuditEvent> events = customAuditEventRepository.find("test-user", null);
    assertThat(events).hasSize(1);
    assertThat(events.get(0).getPrincipal()).isEqualTo("test-user");
}
项目:qualitoast    文件:AuditResource.java   
/**
 * 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
 */
@GetMapping(params = {"fromDate", "toDate"})
public ResponseEntity<List<AuditEvent>> getByDates(
    @RequestParam(value = "fromDate") LocalDate fromDate,
    @RequestParam(value = "toDate") LocalDate toDate,
    Pageable pageable) {

    Page<AuditEvent> page = auditEventService.findByDates(
        fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant(),
        toDate.atStartOfDay(ZoneId.systemDefault()).plusDays(1).toInstant(),
        pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}