Return HTTP Error 401 Code & Skip Filter Chains

后端 未结 4 806
孤街浪徒
孤街浪徒 2020-12-09 15:49

Using a custom Spring Security filter, I\'d like to return an HTTP 401 error code if the HTTP Header doesn\'t contain a particular key-value pair.

Example:



        
4条回答
  •  醉酒成梦
    2020-12-09 16:00

    From the API docs for the doFilter method, you can:

    • Either invoke the next entity in the chain using the FilterChain object (chain.doFilter()),
    • or not pass on the request/response pair to the next entity in the filter chain to block the request processing

    so setting the response status code and returning immediately without invoking chain.doFilter is the best option for what you want to achieve here.

提交回复
热议问题