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