|
@@ -19,11 +19,15 @@ package org.springframework.security.web;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.apache.commons.logging.LogFactory;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
+import org.springframework.security.web.firewall.DefaultRequestRejectedHandler;
|
|
import org.springframework.security.web.firewall.FirewalledRequest;
|
|
import org.springframework.security.web.firewall.FirewalledRequest;
|
|
import org.springframework.security.web.firewall.HttpFirewall;
|
|
import org.springframework.security.web.firewall.HttpFirewall;
|
|
|
|
+import org.springframework.security.web.firewall.RequestRejectedException;
|
|
|
|
+import org.springframework.security.web.firewall.RequestRejectedHandler;
|
|
import org.springframework.security.web.firewall.StrictHttpFirewall;
|
|
import org.springframework.security.web.firewall.StrictHttpFirewall;
|
|
import org.springframework.security.web.util.matcher.RequestMatcher;
|
|
import org.springframework.security.web.util.matcher.RequestMatcher;
|
|
import org.springframework.security.web.util.UrlUtils;
|
|
import org.springframework.security.web.util.UrlUtils;
|
|
|
|
+import org.springframework.util.Assert;
|
|
import org.springframework.web.filter.DelegatingFilterProxy;
|
|
import org.springframework.web.filter.DelegatingFilterProxy;
|
|
import org.springframework.web.filter.GenericFilterBean;
|
|
import org.springframework.web.filter.GenericFilterBean;
|
|
|
|
|
|
@@ -149,6 +153,8 @@ public class FilterChainProxy extends GenericFilterBean {
|
|
|
|
|
|
private HttpFirewall firewall = new StrictHttpFirewall();
|
|
private HttpFirewall firewall = new StrictHttpFirewall();
|
|
|
|
|
|
|
|
+ private RequestRejectedHandler requestRejectedHandler = new DefaultRequestRejectedHandler();
|
|
|
|
+
|
|
// ~ Methods
|
|
// ~ Methods
|
|
// ========================================================================================================
|
|
// ========================================================================================================
|
|
|
|
|
|
@@ -176,6 +182,8 @@ public class FilterChainProxy extends GenericFilterBean {
|
|
try {
|
|
try {
|
|
request.setAttribute(FILTER_APPLIED, Boolean.TRUE);
|
|
request.setAttribute(FILTER_APPLIED, Boolean.TRUE);
|
|
doFilterInternal(request, response, chain);
|
|
doFilterInternal(request, response, chain);
|
|
|
|
+ } catch (RequestRejectedException e) {
|
|
|
|
+ requestRejectedHandler.handle((HttpServletRequest) request, (HttpServletResponse) response, e);
|
|
}
|
|
}
|
|
finally {
|
|
finally {
|
|
SecurityContextHolder.clearContext();
|
|
SecurityContextHolder.clearContext();
|
|
@@ -272,6 +280,17 @@ public class FilterChainProxy extends GenericFilterBean {
|
|
this.firewall = firewall;
|
|
this.firewall = firewall;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Sets the {@link RequestRejectedHandler} to be used for requests rejected by the firewall.
|
|
|
|
+ *
|
|
|
|
+ * @since 5.2
|
|
|
|
+ * @param requestRejectedHandler the {@link RequestRejectedHandler}
|
|
|
|
+ */
|
|
|
|
+ public void setRequestRejectedHandler(RequestRejectedHandler requestRejectedHandler) {
|
|
|
|
+ Assert.notNull(requestRejectedHandler, "requestRejectedHandler may not be null");
|
|
|
|
+ this.requestRejectedHandler = requestRejectedHandler;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public String toString() {
|
|
public String toString() {
|
|
StringBuilder sb = new StringBuilder();
|
|
StringBuilder sb = new StringBuilder();
|