org.springframework.boot.actuate.audit.AuditEventRepository Java Examples

The following examples show how to use org.springframework.boot.actuate.audit.AuditEventRepository. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomAuditEventRepository.java    From angularjs-springboot-bookstore with MIT License 5 votes vote down vote up
@Bean
public AuditEventRepository auditEventRepository() {
    return new AuditEventRepository() {

        @Inject
        private AuditEventConverter auditEventConverter;

        @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, new LocalDateTime(after));
            }
            return auditEventConverter.convertToAuditEvent(persistentAuditEvents);
        }

        @Override
        @Transactional(propagation = Propagation.REQUIRES_NEW)
        public void add(AuditEvent event) {
            PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent();
            persistentAuditEvent.setPrincipal(event.getPrincipal());
            persistentAuditEvent.setAuditEventType(event.getType());
            persistentAuditEvent.setAuditEventDate(new LocalDateTime(event.getTimestamp()));
            persistentAuditEvent.setData(auditEventConverter.convertDataToStrings(event.getData()));

            persistenceAuditEventRepository.save(persistentAuditEvent);
        }
    };
}
 
Example #2
Source File: ConfigTest.java    From sshd-shell-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean
public AuditEventRepository auditEventRepository() {
    return new InMemoryAuditEventRepository();
}
 
Example #3
Source File: CustomAuditEventRepository.java    From ServiceCutter with Apache License 2.0 4 votes vote down vote up
@Bean
public AuditEventRepository auditEventRepository() {
    return new AuditEventRepository() {

        private static final String AUTHORIZATION_FAILURE = "AUTHORIZATION_FAILURE";

        private static final String ANONYMOUS_USER = "anonymousUser";

        @Inject
        private AuditEventConverter auditEventConverter;

        @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, new LocalDateTime(after));
            }
            return auditEventConverter.convertToAuditEvent(persistentAuditEvents);
        }

        @Override
        @Transactional(propagation = Propagation.REQUIRES_NEW)
        public void add(AuditEvent event) {
            if(!AUTHORIZATION_FAILURE.equals(event.getType()) &&
                !ANONYMOUS_USER.equals(event.getPrincipal().toString())){

                PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent();
                persistentAuditEvent.setPrincipal(event.getPrincipal());
                persistentAuditEvent.setAuditEventType(event.getType());
                persistentAuditEvent.setAuditEventDate(new LocalDateTime(event.getTimestamp()));
                persistentAuditEvent.setData(auditEventConverter.convertDataToStrings(event.getData()));
                persistenceAuditEventRepository.save(persistentAuditEvent);
            }
        }
    };
}
 
Example #4
Source File: CustomAuditEventRepository.java    From expper with GNU General Public License v3.0 4 votes vote down vote up
@Bean
public AuditEventRepository auditEventRepository() {
    return new AuditEventRepository() {

        private static final String AUTHORIZATION_FAILURE = "AUTHORIZATION_FAILURE";

        private static final String ANONYMOUS_USER = "anonymousUser";

        @Inject
        private AuditEventConverter auditEventConverter;

        @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);
        }

        @Override
        @Transactional(propagation = Propagation.REQUIRES_NEW)
        public void add(AuditEvent event) {
            if (!AUTHORIZATION_FAILURE.equals(event.getType()) &&
                !ANONYMOUS_USER.equals(event.getPrincipal().toString())) {

                PersistentAuditEvent persistentAuditEvent = new PersistentAuditEvent();
                persistentAuditEvent.setPrincipal(event.getPrincipal());
                persistentAuditEvent.setAuditEventType(event.getType());
                Instant instant = Instant.ofEpochMilli(event.getTimestamp().getTime());
                persistentAuditEvent.setAuditEventDate(LocalDateTime.ofInstant(instant, ZoneId.systemDefault()));
                persistentAuditEvent.setData(auditEventConverter.convertDataToStrings(event.getData()));
                persistenceAuditEventRepository.save(persistentAuditEvent);
            }
        }
    };
}
 
Example #5
Source File: SpringBootAdminServletApplication.java    From spring-boot-admin with Apache License 2.0 4 votes vote down vote up
@Bean
public AuditEventRepository auditEventRepository() {
	return new InMemoryAuditEventRepository();
}