Java Code Examples for org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent

The following examples show how to use org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@EventListener
public void loginFailureListener(AbstractAuthenticationFailureEvent event) {
    if (event.getSource() instanceof AbstractAuthenticationToken) {
        AbstractAuthenticationToken token = (AbstractAuthenticationToken) event.getSource();
        Object details = token.getDetails();
        if (details instanceof WebAuthenticationDetails) {
            LOG.info("Login failed from [{}]", ((WebAuthenticationDetails) details).getRemoteAddress());
        }
    }
}
 
Example 2
/**
 * Handle an application event.
 *
 * @param event the event to respond to
 */
@Override
public void onApplicationEvent(AbstractAuthenticationFailureEvent event) {
	AuthenticationException authenticationException = event.getException();
	Authentication authentication = (Authentication) event.getSource();

	handle(authenticationException, authentication);
}
 
Example 3
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof AbstractAuthenticationFailureEvent) {
        if (event.getSource() instanceof AbstractAuthenticationToken) {
            AbstractAuthenticationToken token = (AbstractAuthenticationToken) event.getSource();
            Object details = token.getDetails();
            if (details instanceof WebAuthenticationDetails) {
                LOG.info("Login failed from [" + ((WebAuthenticationDetails) details).getRemoteAddress() + "]");
            }
        }
    }

}
 
Example 4
@EventListener
public void handleAuthenticationFailure( AbstractAuthenticationFailureEvent event )
{
    Authentication auth = event.getAuthentication();

    if ( TwoFactorWebAuthenticationDetails.class.isAssignableFrom( auth.getDetails().getClass() ) )
    {
        TwoFactorWebAuthenticationDetails authDetails =
            ( TwoFactorWebAuthenticationDetails ) auth.getDetails();

        log.info( String.format( "Login attempt failed for remote IP: %s", authDetails.getIp() ) );
    }

    securityService.registerFailedLogin( auth.getName() );
}
 
Example 5
public void onApplicationEvent( AbstractAuthenticationEvent event )
{
    if ( log.isWarnEnabled() )
    {
        final StringBuilder builder = new StringBuilder();
        builder.append( "Authentication event " );
        builder.append( ClassUtils.getShortName( event.getClass() ) );
        builder.append( ": " );
        builder.append( event.getAuthentication().getName() );

        Object details = event.getAuthentication().getDetails();

        if ( ForwardedIpAwareWebAuthenticationDetails.class.isAssignableFrom( details.getClass() ) )
        {
            ForwardedIpAwareWebAuthenticationDetails authDetails = (ForwardedIpAwareWebAuthenticationDetails) details;
            String ip = authDetails.getIp();

            builder.append( "; ip: " );
            builder.append( ip );

            String sessionId = authDetails.getSessionId();
            if ( sessionId != null )
            {
                HashCode hash = Hashing.sha256().newHasher().putString( sessionId, Charsets.UTF_8 ).hash();
                builder.append( " sessionId: " );
                builder.append( hash.toString() );
            }

        }

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

        log.warn( builder.toString() );
    }
}
 
Example 6
@Override
public void onApplicationEvent(AbstractAuthenticationFailureEvent event) {
    log.info("User Oauth2 login Failed, " + event.getException().getMessage());
}
 
Example 7
@Override
public void onApplicationEvent(AbstractAuthenticationFailureEvent e) {
  GraviteeAuthenticationDetails auth = (GraviteeAuthenticationDetails)  e.getAuthentication().getDetails();
  LOGGER.warn("Authentication failed event for: " + e.getAuthentication().getPrincipal() + " - IP: " + auth.getRemoteAddress());
}