3

Almost every aspect of Spring Boot's documentation have proven to be treasure troves of copious amounts of information. That is until I get to Chapter 50: Auditing.

I am trying to understand the 2 paragraphs that make up this entire chapter. If I'm reading it correctly, then when I run my Spring Boot app in "production mode" (that is, as a built/packaged uberjar via java -jar path/to/myapp.jar) then every time an access event (auth attempt/success/fail) occurs, that event will get logged/recorded somewhere.

I haven't done any config whatsoever. I run my app in "prod mode" and log in. I expect to see some console/log output indicating the auth event, but I don't see any. I log out, same deal (no console output). I try to log in with a bad username, and again, nothing in the console output.

  • Is Spring Boot recording access events somewhere else, besides console/log output? If so, where and why?
  • Do I need to define any @Beans and register them with some kind of event listener? If so, can someone please provide a succinct code example?

Basically I'm just looking to get Spring Boot's default audit logging pumping events to STDOUT (console). Any ideas?

smeeb
  • 27,777
  • 57
  • 250
  • 447
  • 1
    That will only happen if you have the actuator stuff on the classpath, else nothing happens. Add `spring-boot-starter-actuator` for that. Also the audit evens are send to the console they are stored with in an `AuditEventRepository` the default is an in-memory map based implementation. – M. Deinum Jun 15 '16 at 06:06
  • Thanks @M.Deinum (+1) - **yes** I do have `spring-boot-actuator-starter` on the classpath. Is that a typo in your comment above? Did you mean to say "*Also the audit events are **not** sent to the console...*"? More importantly, if an [in-memory map](http://docs.spring.io/autorepo/docs/spring-boot/1.2.0.M1/api/org/springframework/boot/actuate/audit/InMemoryAuditEventRepository.html) is the default implementation then how do I inject my own, say, `ConsoleLoggingAuditEventRepository`? – smeeb Jun 15 '16 at 08:35
  • ^^^Meaning, how do I configure Spring to use my own custom impl instead of the default (an in-memory map)? – smeeb Jun 15 '16 at 08:45
  • 1
    By just adding a custom implementation of an `AuditEventRepository`. – M. Deinum Jun 15 '16 at 09:53
  • Thank again @M.Deinum (+1) - do I need to annotate my `ConsoleLoggingAuditEventRepository` with anything like `@Component`, etc.? – smeeb Jun 15 '16 at 12:29
  • 1
    Not if you add it as a `@Bean` if you want it discovered then yes . – M. Deinum Jun 15 '16 at 12:32
  • Thanks again @M.Deinum (+1 again) - so in my `@Configuration` I could add it as a `@Bean`, or I could just mark it is as `@Component`...is there a performance (or otherwise) difference between these two options, or is it a "*six in one, half-dozen in the other*"-type situation? Thanks again! – smeeb Jun 15 '16 at 12:42
  • 1
    There isn't, only that when scanning it might add some (nanoseconds) to your startup time, runtime there is no difference. – M. Deinum Jun 15 '16 at 12:44
  • Thanks again (and +1)! If you can put these comments into an answer, I'll happily give you the green check! – smeeb Jun 15 '16 at 12:57

0 Answers0