Example usage for org.springframework.security.authentication.event AbstractAuthenticationFailureEvent getAuthentication

List of usage examples for org.springframework.security.authentication.event AbstractAuthenticationFailureEvent getAuthentication

Introduction

In this page you can find the example usage for org.springframework.security.authentication.event AbstractAuthenticationFailureEvent getAuthentication.

Prototype

public Authentication getAuthentication() 

Source Link

Document

Getters for the Authentication request that caused the event.

Usage

From source file:com.devnexus.ting.core.applicationlistener.SecurityEventListener.java

@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {

    if (event instanceof AuthenticationSuccessEvent) {

        final AuthenticationSuccessEvent successEvent = (AuthenticationSuccessEvent) event;
        LOGGER.info("Successful Authentication of User: " + successEvent.getAuthentication().getName());
        successEvent.getAuthentication();

        final User user = (User) successEvent.getAuthentication().getPrincipal();
        userService.trackUserLogin(user);

    } else if (event instanceof InteractiveAuthenticationSuccessEvent) {

        final InteractiveAuthenticationSuccessEvent successEvent = (InteractiveAuthenticationSuccessEvent) event;
        LOGGER.info(//from   w  w  w  .j  a va2  s . c  om
                "Successful Interactive Authentication of User: " + successEvent.getAuthentication().getName());

    } else if (event instanceof AbstractAuthenticationFailureEvent) {

        final AbstractAuthenticationFailureEvent failureEvent = (AbstractAuthenticationFailureEvent) event;
        LOGGER.warn("Authentication Failure for User '" + failureEvent.getAuthentication().getPrincipal() + "' "
                + failureEvent.getException().getMessage(), failureEvent.getException());

    } else {

        /*
         * Since we really don't care about other events, we log it for
         *  now, but because of that we don't throw an explicit exception.
         */
        LOGGER.error("Unhandled AuthenticationEvent (" + event.getClass().getName() + ") for user '"
                + event.getAuthentication().getPrincipal() + "':" + event.toString());
    }
}

From source file:org.web4thejob.security.AuthenticationFailureListener.java

@Override
public void onApplicationEvent(AbstractAuthenticationFailureEvent event) {

    if (event instanceof AuthenticationFailureCredentialsExpiredEvent) {

        ContextUtil.getBean(CredentialsExpiredErrorHandler.class)
                .setExpiredUserName((String) event.getAuthentication().getPrincipal());
    }/*from   w  w  w.  ja  va2s.  c o m*/

}