title: Spring Security: AuthenticationFailureCredentialsExpiredEvent not fired
body: <p>I am using spring.security.version = 3.1.0.RELEASE. The problem I am having is that for some reason AuthenticationFailureCredentialsExpiredEvent is not fired.</p>
  
  <p>While debugging the code I found that AbstractUserDetailsAuthenticationProvider do display in the console that "User account credentials have expired". But I am still baffling as to why the event in concern is not triggered.</p>
  
  <p>Here is my code: </p>
  
  <pre><code>class JpaUserDetails implements UserDetails {
  ...
  ...
     @Override
     public boolean isCredentialsNonExpired() {
         if (some logic) {
             return true;
         }
         else {
             return false;
         }
     }
  }
  </code></pre>
  
  <p>I do see AbstractUserDetailsAuthenticationProvider displaying in the console "User account credentials have expired" from the following lines of spring code:</p>
  
  <pre><code>public abstract class AbstractUserDetailsAuthenticationProvider implements AuthenticationProvider, InitilizeBean, MessageSourceAware {
  ...
  ...
      private class DefaultPostAuthenticationChecks implements UserDetailsChecker {
          public void check(UserDetails user) {
              if(!user.isCredentialsNonExpired()) {
                  logger.debug("User account credentials have expired");
                  throw new CredentialsExpiredException(message.getMessage(
                            "AbstractUserDetailsAuthenticationProvider.credentialsExpired",
                            "User credentials have expired"), user);
              }
          }
      }
  }
  </code></pre>
  
  <p>The issue is that when the user credentials have expired, I am expecting the Spring to generate the event AuthenticationFailureCredentialsExpiredEvent which I am handling in the following way:</p>
  
  <pre><code>class SecurityEventDispatcher implements ApplicationListener&lt;ApplicationEvent&gt; {
      final List&lt;SecurityEventListener&gt; listeners = new ArrayList&lt;SecurityEventListener&gt;();
  
      public void registerListener(SecurityEventListener listener) {
          this.listener.add(listener);
      }
  
      public void onApplicationEvent(ApplicationEvent event) {
          for (SecurityEventListener listener : this.listeners) {
              if(listener.canHandle(event)) {
                  listener.handle(event);
              }
          }
      }
  }
  </code></pre>
  
  <p>This is how I am handling the login failure event:</p>
  
  <pre><code>public class LoginFailedEvent extends SecurityEventListener {
  
      @Override
      public boolean canHandle(Object event) {
          if(event instanceof AbstractAuthenticationFailureEvent) {
              return true;
          }
          else {
              return false;
          }
      }
  
      @Override
      public void handle(Object event) {
          if (event instanceof AuthenticationFailureBadCredentialsEvent) {
              // do something
          }
  
          if (event instanceof AuthenticationFailureCredentialsExpiredEvent) {
              // do something
          }
      }
  }
  </code></pre>
  
  <p>The issue as I mentioned before is that AuthenticationFailureCredentialsExpiredEvent is never fired. I have tested the AuthenticationFailureBadCredentialsEvent which works fine.</p>
  
  <p>This is what I get in event for bad credentials: (which is working fine)</p>
  
  <blockquote>
    <p>org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent </p>
  </blockquote>
  
  <p>This is what I get in event for expired password:</p>
  
  <blockquote>
    <p>ServletRequestHandledEvent: url=[/app/loginFailure] with failureCause = null</p>
  </blockquote>
  
  <p>Does anyone have any idea what could be wrong? Any help will be highly appreciated.</p>