anchor.diff:  }
   ----
   
  +.Kotlin
  +[source,kotlin,role="secondary"]
  +----
  +@Bean
  +fun authenticationEventPublisher
  +        (applicationEventPublisher: ApplicationEventPublisher?): AuthenticationEventPublisher {
  +    return DefaultAuthenticationEventPublisher(applicationEventPublisher)
  +}
  +----
  +====
  +
   Then, you can use Spring's `@EventListener` support:
   
  -[source,java]
  +====
  +.Java
  +[source,java,role="primary"]
   ----
   @Component
   public class AuthenticationEvents {
  
positive.code: To listen for these events, you must first publish an `AuthenticationEventPublisher`.
  Spring Security's `DefaultAuthenticationEventPublisher` will probably do fine:
  
  [source,java]
  ----
  @Bean
  public AuthenticationEventPublisher authenticationEventPublisher
  
negative.code:     return authenticationEventPublisher;
  }
  ----
  
  .Kotlin
  [source,kotlin,role="secondary"]
  ----
  @Bean
  fun authenticationEventPublisher
          (applicationEventPublisher: ApplicationEventPublisher?): AuthenticationEventPublisher {
      val authenticationEventPublisher = DefaultAuthenticationEventPublisher(applicationEventPublisher)
      authenticationEventPublisher.setDefaultAuthenticationFailureEvent(GenericAuthenticationFailureEvent::class.java)
      return authenticationEventPublisher
  }
  ----
  ====
  