Example usage for org.springframework.security.web.authentication ExceptionMappingAuthenticationFailureHandler ExceptionMappingAuthenticationFailureHandler

List of usage examples for org.springframework.security.web.authentication ExceptionMappingAuthenticationFailureHandler ExceptionMappingAuthenticationFailureHandler

Introduction

In this page you can find the example usage for org.springframework.security.web.authentication ExceptionMappingAuthenticationFailureHandler ExceptionMappingAuthenticationFailureHandler.

Prototype

ExceptionMappingAuthenticationFailureHandler

Source Link

Usage

From source file:com.test.config.BackendConsoleConfig.java

@Bean(name = { "defaultAuthenticationFailureHandler", "authenticationFailureHandler" })
protected AuthenticationFailureHandler defaultAuthenticationFailureHandler() {
    Map<String, String> exceptionMappings = new HashMap<>();
    exceptionMappings.put(InternalAuthenticationServiceException.class.getCanonicalName(),
            "/login?error=servererror");
    exceptionMappings.put(BadCredentialsException.class.getCanonicalName(), "/login?error=authfailed");
    exceptionMappings.put(CredentialsExpiredException.class.getCanonicalName(),
            "/login?error=credentialsExpired");
    exceptionMappings.put(LockedException.class.getCanonicalName(), "/login?error=locked");
    exceptionMappings.put(DisabledException.class.getCanonicalName(), "/login?error=disabled");
    exceptionMappings.put(AccessDeniedException.class.getCanonicalName(), "/login?error=denied");

    final ExceptionMappingAuthenticationFailureHandler result = new ExceptionMappingAuthenticationFailureHandler();
    result.setExceptionMappings(exceptionMappings);
    result.setDefaultFailureUrl("/login?error=default");
    return result;
}