How to intercept a RequestRejectedException in Spring?

后端 未结 7 1093
傲寒
傲寒 2020-12-14 01:06

I am seeing a ton of RequestRejectedException entries in my Tomcat log (sample pasted below). These started appearing in my log file after a minor vers

7条回答
  •  渐次进展
    2020-12-14 01:41

    For Spring security versions 5.4 and above, you could simply create a bean of the type RequestRejectedHandler that will be injected in the Spring security filter chain

    import org.springframework.security.web.firewall.RequestRejectedHandler;
    import org.springframework.security.web.firewall.HttpStatusRequestRejectedHandler;
    
    @Bean
    RequestRejectedHandler requestRejectedHandler() {
       // sends an error response with a configurable status code (default is 400 BAD_REQUEST)
       // we can pass a different value in the constructor
       return new HttpStatusRequestRejectedHandler();
    }
    

提交回复
热议问题