Allow Configure RequestRjectedHandler in XML

Issue gh-5007
This commit is contained in:
Rob Winch
2020-05-01 10:50:45 -05:00
parent 0483b3e042
commit 4a9fa0337a
3 changed files with 93 additions and 2 deletions

View File

@@ -94,6 +94,8 @@ import org.springframework.security.web.context.request.async.WebAsyncManagerInt
import org.springframework.security.web.csrf.CsrfFilter;
import org.springframework.security.web.firewall.FirewalledRequest;
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.header.HeaderWriterFilter;
import org.springframework.security.web.savedrequest.RequestCache;
import org.springframework.security.web.savedrequest.RequestCacheAwareFilter;
@@ -754,6 +756,21 @@ public class MiscHttpConfigTests {
verify(firewall).getFirewalledResponse(any(HttpServletResponse.class));
}
@Test
public void getWhenUsingCustomRequestRejectedHandlerThenRequestRejectedHandlerIsInvoked() throws Exception {
this.spring.configLocations(xml("RequestRejectedHandler")).autowire();
HttpServletResponse response = new MockHttpServletResponse();
RequestRejectedException rejected = new RequestRejectedException("failed");
HttpFirewall firewall = this.spring.getContext().getBean(HttpFirewall.class);
RequestRejectedHandler requestRejectedHandler = this.spring.getContext().getBean(RequestRejectedHandler.class);
when(firewall.getFirewalledRequest(any(HttpServletRequest.class))).thenThrow(rejected);
this.mvc.perform(get("/unprotected"));
verify(requestRejectedHandler).handle(any(), any(), any());
}
@Test
public void getWhenUsingCustomAccessDecisionManagerThenAuthorizesAccordingly() throws Exception {
this.spring.configLocations(xml("CustomAccessDecisionManager")).autowire();