Skip to content

Commit df9cf6b

Browse files
committed
Make ErrorPageSecurityFilter compatible with Servlet 3.1
Ensure that all default methods are implemented so that the filter is compatible with Servlet 3.1 environments. Fixes gh-29558
1 parent fe43d52 commit df9cf6b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/filter/ErrorPageSecurityFilter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ private WebInvocationPrivilegeEvaluator getPrivilegeEvaluatorBean() {
114114
}
115115
}
116116

117+
@Override
118+
public void destroy() {
119+
}
120+
117121
/**
118122
* {@link WebInvocationPrivilegeEvaluator} that always allows access.
119123
*/

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/filter/ErrorPageSecurityFilterTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
package org.springframework.boot.web.servlet.filter;
1818

19+
import java.lang.reflect.Method;
20+
1921
import javax.servlet.DispatcherType;
22+
import javax.servlet.Filter;
2023
import javax.servlet.FilterChain;
2124
import javax.servlet.RequestDispatcher;
2225

@@ -32,6 +35,7 @@
3235
import org.springframework.security.core.context.SecurityContext;
3336
import org.springframework.security.core.context.SecurityContextHolder;
3437
import org.springframework.security.web.access.WebInvocationPrivilegeEvaluator;
38+
import org.springframework.util.ReflectionUtils;
3539

3640
import static org.assertj.core.api.Assertions.assertThat;
3741
import static org.mockito.ArgumentMatchers.any;
@@ -145,4 +149,18 @@ void whenThereIsAContextPathAndServletIsMappedToWildcardPathCorrectPathIsPassedT
145149
verify(this.privilegeEvaluator).isAllowed(eq("/dispatcher/path/error"), any());
146150
}
147151

152+
@Test
153+
void filterIsCompatibleWithServlet31() {
154+
Method[] methods = Filter.class.getDeclaredMethods();
155+
for (Method method : methods) {
156+
if (method.isDefault()) {
157+
Method securityFilterMethod = ReflectionUtils.findMethod(ErrorPageSecurityFilter.class,
158+
method.getName(), method.getParameterTypes());
159+
assertThat(securityFilterMethod).isNotNull();
160+
assertThat(securityFilterMethod.getDeclaringClass()).as(method.getName())
161+
.isEqualTo(ErrorPageSecurityFilter.class);
162+
}
163+
}
164+
}
165+
148166
}

0 commit comments

Comments
 (0)