Example usage for org.springframework.security.authentication.event AbstractAuthenticationEvent getClass

List of usage examples for org.springframework.security.authentication.event AbstractAuthenticationEvent getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

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(//  ww  w .  j  a  v  a  2  s  . c  o 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());
    }
}

From source file:org.springframework.security.authentication.event.LoggerListener.java

public void onApplicationEvent(AbstractAuthenticationEvent event) {
    if (!logInteractiveAuthenticationSuccessEvents && event instanceof InteractiveAuthenticationSuccessEvent) {
        return;//  w w  w.  java  2s . c  o m
    }

    if (logger.isWarnEnabled()) {
        final StringBuilder builder = new StringBuilder();
        builder.append("Authentication event ");
        builder.append(ClassUtils.getShortName(event.getClass()));
        builder.append(": ");
        builder.append(event.getAuthentication().getName());
        builder.append("; details: ");
        builder.append(event.getAuthentication().getDetails());

        if (event instanceof AbstractAuthenticationFailureEvent) {
            builder.append("; exception: ");
            builder.append(((AbstractAuthenticationFailureEvent) event).getException().getMessage());
        }

        logger.warn(builder.toString());
    }
}