How to handle HTTP 403 with Spring Security 3.0.x

前端 未结 5 1405
温柔的废话
温柔的废话 2021-02-04 09:44

I\'m facing a little issue with Spring Security 3.0.x (3.0.2 in particular at the moment). The whole application I\'m working on is working perfectly except when someone who doe

5条回答
  •  轮回少年
    2021-02-04 10:36

    The way to make this work is to define a handler in your entry point:

    public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {
        @Override
        public void commence(HttpServletRequest request, HttpServletResponse response, org.springframework.security.core.AuthenticationException authException) throws IOException, ServletException {
    
            if (authException != null) {
                // you can check for the spefic exception here and redirect like this
                response.sendRedirect("403.html");
            }
        }
    }
    

    You can define this as your entry point by setting this as you entry point in the xml config file:

    
    
      ...
    
    
    

提交回复
热议问题