Skip to content

Commit 75f25bf

Browse files
committed
Polish multiple RequestRejectedHandlers support
Issue gh-10603
1 parent 4ea57f3 commit 75f25bf

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/builders/WebSecurity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

config/src/test/java/org/springframework/security/config/annotation/web/builders/WebSecurityTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
package org.springframework.security.config.annotation.web.builders;
1818

19-
import javax.servlet.http.HttpServletResponse;
19+
import java.io.IOException;
20+
2021
import javax.servlet.ServletException;
22+
import javax.servlet.http.HttpServletResponse;
2123

2224
import org.junit.jupiter.api.AfterEach;
2325
import org.junit.jupiter.api.BeforeEach;
@@ -42,8 +44,6 @@
4244
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
4345
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
4446

45-
import java.io.IOException;
46-
4747
import static org.assertj.core.api.Assertions.assertThat;
4848

4949
/**

web/src/main/java/org/springframework/security/web/firewall/CompositeRequestRejectedHandler.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616

1717
package org.springframework.security.web.firewall;
1818

19+
import java.io.IOException;
20+
import java.util.Arrays;
21+
import java.util.List;
22+
1923
import javax.servlet.ServletException;
2024
import javax.servlet.http.HttpServletRequest;
2125
import javax.servlet.http.HttpServletResponse;
22-
import org.springframework.util.Assert;
2326

24-
import java.io.IOException;
25-
import java.util.Arrays;
26-
import java.util.List;
27+
import org.springframework.util.Assert;
2728

2829
/**
2930
* A {@link RequestRejectedHandler} that delegates to several other
@@ -49,7 +50,7 @@ public CompositeRequestRejectedHandler(RequestRejectedHandler... requestRejected
4950
@Override
5051
public void handle(HttpServletRequest request, HttpServletResponse response,
5152
RequestRejectedException requestRejectedException) throws IOException, ServletException {
52-
for (RequestRejectedHandler requestRejectedhandler : requestRejectedhandlers) {
53+
for (RequestRejectedHandler requestRejectedhandler : this.requestRejectedhandlers) {
5354
requestRejectedhandler.handle(request, response, requestRejectedException);
5455
}
5556
}

web/src/test/java/org/springframework/security/web/firewall/CompositeRequestRejectedHandlerTests.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import javax.servlet.http.HttpServletRequest;
2020
import javax.servlet.http.HttpServletResponse;
21+
2122
import org.junit.jupiter.api.Test;
2223

2324
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -28,9 +29,9 @@ public class CompositeRequestRejectedHandlerTests {
2829
@Test
2930
void compositeRequestRejectedHandlerRethrowsTheException() {
3031
RequestRejectedException requestRejectedException = new RequestRejectedException("rejected");
31-
DefaultRequestRejectedHandler sut = new DefaultRequestRejectedHandler();
32-
CompositeRequestRejectedHandler crrh = new CompositeRequestRejectedHandler(sut);
33-
assertThatExceptionOfType(RequestRejectedException.class).isThrownBy(() -> crrh
32+
CompositeRequestRejectedHandler handler = new CompositeRequestRejectedHandler(
33+
new DefaultRequestRejectedHandler());
34+
assertThatExceptionOfType(RequestRejectedException.class).isThrownBy(() -> handler
3435
.handle(mock(HttpServletRequest.class), mock(HttpServletResponse.class), requestRejectedException))
3536
.withMessage("rejected");
3637
}

0 commit comments

Comments
 (0)