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

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

Introduction

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

Prototype

public void setDefaultFailureUrl(String defaultFailureUrl) 

Source Link

Document

The URL which will be used as the failure destination.

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;
}