|
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;
|
@@ -157,6 +158,8 @@ public class FilterChainProxy extends GenericFilterBean {
|
157 | 158 |
|
158 | 159 | private RequestRejectedHandler requestRejectedHandler = new HttpStatusRequestRejectedHandler();
|
159 | 160 |
|
| 161 | + private ThrowableAnalyzer throwableAnalyzer = new ThrowableAnalyzer(); |
| 162 | + |
160 | 163 | public FilterChainProxy() {
|
161 | 164 | }
|
162 | 165 |
|
@@ -185,8 +188,15 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
|
185 | 188 | request.setAttribute(FILTER_APPLIED, Boolean.TRUE);
|
186 | 189 | doFilterInternal(request, response, chain);
|
187 | 190 | }
|
188 |
| - catch (RequestRejectedException ex) { |
189 |
| - this.requestRejectedHandler.handle((HttpServletRequest) request, (HttpServletResponse) response, ex); |
| 191 | + catch (Exception ex) { |
| 192 | + Throwable[] causeChain = this.throwableAnalyzer.determineCauseChain(ex); |
| 193 | + Throwable requestRejectedException = this.throwableAnalyzer |
| 194 | + .getFirstThrowableOfType(RequestRejectedException.class, causeChain); |
| 195 | + if (!(requestRejectedException instanceof RequestRejectedException)) { |
| 196 | + throw ex; |
| 197 | + } |
| 198 | + this.requestRejectedHandler.handle((HttpServletRequest) request, (HttpServletResponse) response, |
| 199 | + (RequestRejectedException) requestRejectedException); |
190 | 200 | }
|
191 | 201 | finally {
|
192 | 202 | this.securityContextHolderStrategy.clearContext();
|
|
0 commit comments