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

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

Introduction

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

Prototype

public void setExceptionMappings(Map<?, ?> failureUrlMap) 

Source Link

Document

Sets the map of exception types (by name) to URLs.

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