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:     }
  }
  ----
  
  While similar to `AuthenticationSuccessHandler` and `AuthenticationFailureHandler`, these are nice in that they can be used independently from the servlet API.
  
  
negative.code: }
  ----
  
  .Kotlin
  [source,kotlin,role="secondary"]
  ----
  @Bean
  fun authenticationEventPublisher
          (applicationEventPublisher: ApplicationEventPublisher?): AuthenticationEventPublisher {
      val mapping: Map<Class<out AuthenticationException>, Class<out AbstractAuthenticationFailureEvent>> =
              mapOf(Pair(FooException::class.java, FooEvent::class.java))
      val authenticationEventPublisher = DefaultAuthenticationEventPublisher(applicationEventPublisher)
      authenticationEventPublisher.setAdditionalExceptionMappings(mapping)
      return authenticationEventPublisher
  }
  ----
  ====
  
  === Default Event
  
  And, you can supply a catch-all event to fire in the case of any `AuthenticationException`:
  
  ====
  .Java
  [source,java,role="primary"]
  ----
  @Bean
  public AuthenticationEventPublisher authenticationEventPublisher
  