當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。