|
6 | 6 | import javax.servlet.http.HttpServletResponse; |
7 | 7 |
|
8 | 8 | import org.springframework.http.HttpStatus; |
| 9 | +import org.springframework.security.web.firewall.RequestRejectedException; |
9 | 10 | import org.springframework.stereotype.Controller; |
| 11 | +import org.springframework.web.bind.annotation.RequestAttribute; |
10 | 12 | import org.springframework.web.bind.annotation.RequestMapping; |
11 | 13 | import org.springframework.web.bind.annotation.ResponseStatus; |
12 | 14 | import org.springframework.web.servlet.ModelAndView; |
@@ -65,4 +67,19 @@ public ModelAndView handlefrozen(HttpServletRequest request){ |
65 | 67 | return new ModelAndView("error/frozen","error","exception" ); |
66 | 68 | } |
67 | 69 |
|
| 70 | + @RequestMapping(value = "/request-rejected") |
| 71 | + @ResponseStatus(HttpStatus.BAD_REQUEST) |
| 72 | + public ModelAndView handleRequestRejected( |
| 73 | + @RequestAttribute("javax.servlet.error.exception") RequestRejectedException ex, |
| 74 | + @RequestAttribute("javax.servlet.error.request_uri") String uri, HttpServletRequest request) { |
| 75 | + |
| 76 | + String msg = ex.getMessage(); |
| 77 | + |
| 78 | + logger.error(String.format("Request with URI [%s] rejected. %s", uri, msg)); |
| 79 | + |
| 80 | + request.getSession().setAttribute("lastErrorCode", 403); |
| 81 | + request.getSession().setAttribute("lastErrorTime", new Date()); |
| 82 | + request.getSession().setAttribute("lastErrorURL", request.getAttribute("javax.servlet.error.request_uri")); |
| 83 | + return new ModelAndView("error/403","error", 403); |
| 84 | + } |
68 | 85 | } |
0 commit comments