|
40 | 40 | import org.springframework.security.web.firewall.RequestRejectedException; |
41 | 41 | import org.springframework.security.web.firewall.RequestRejectedHandler; |
42 | 42 | import org.springframework.security.web.firewall.StrictHttpFirewall; |
| 43 | +import org.springframework.security.web.util.ThrowableAnalyzer; |
43 | 44 | import org.springframework.security.web.util.UrlUtils; |
44 | 45 | import org.springframework.security.web.util.matcher.RequestMatcher; |
45 | 46 | import org.springframework.util.Assert; |
@@ -154,6 +155,8 @@ public class FilterChainProxy extends GenericFilterBean { |
154 | 155 |
|
155 | 156 | private RequestRejectedHandler requestRejectedHandler = new DefaultRequestRejectedHandler(); |
156 | 157 |
|
| 158 | + private ThrowableAnalyzer throwableAnalyzer = new ThrowableAnalyzer(); |
| 159 | + |
157 | 160 | public FilterChainProxy() { |
158 | 161 | } |
159 | 162 |
|
@@ -182,8 +185,15 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha |
182 | 185 | request.setAttribute(FILTER_APPLIED, Boolean.TRUE); |
183 | 186 | doFilterInternal(request, response, chain); |
184 | 187 | } |
185 | | - catch (RequestRejectedException ex) { |
186 | | - this.requestRejectedHandler.handle((HttpServletRequest) request, (HttpServletResponse) response, ex); |
| 188 | + catch (Exception ex) { |
| 189 | + Throwable[] causeChain = this.throwableAnalyzer.determineCauseChain(ex); |
| 190 | + Throwable requestRejectedException = this.throwableAnalyzer |
| 191 | + .getFirstThrowableOfType(RequestRejectedException.class, causeChain); |
| 192 | + if (!(requestRejectedException instanceof RequestRejectedException)) { |
| 193 | + throw ex; |
| 194 | + } |
| 195 | + this.requestRejectedHandler.handle((HttpServletRequest) request, (HttpServletResponse) response, |
| 196 | + (RequestRejectedException) requestRejectedException); |
187 | 197 | } |
188 | 198 | finally { |
189 | 199 | SecurityContextHolder.clearContext(); |
|
0 commit comments