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

The following examples show how to use org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent. 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
Source File: GlobalSecurityConfig.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@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
Source File: AuthenticationFailureEvenHandler.java    From smaker with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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
Source File: LoginFailureListener.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
@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
Source File: AuthenticationListener.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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
Source File: AuthenticationLoggerListener.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Source File: AuthenticationFailureEventListener.java    From oauth2-resource with MIT License 4 votes vote down vote up
@Override
public void onApplicationEvent(AbstractAuthenticationFailureEvent event) {
    log.info("User Oauth2 login Failed, " + event.getException().getMessage());
}
 
Example #7
Source File: AuthenticationFailureListener.java    From gravitee-management-rest-api with Apache License 2.0 4 votes vote down vote up
@Override
public void onApplicationEvent(AbstractAuthenticationFailureEvent e) {
  GraviteeAuthenticationDetails auth = (GraviteeAuthenticationDetails)  e.getAuthentication().getDetails();
  LOGGER.warn("Authentication failed event for: " + e.getAuthentication().getPrincipal() + " - IP: " + auth.getRemoteAddress());
}