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

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

Introduction

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

Prototype

public AuthenticationException getException() 

Source Link

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 ww  w.jav a 2 s .co m
                "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());
    }
}