Skip to content

Remove Deprecated Usages of RemoteJWKSet #16296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 132 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
1be13b4
Remove Deprecated Usages of RemoteJWKSet
kwondh5217 Dec 17, 2024
bab5f35
Remove Deprecated Usages of RemoteJWKSet
kwondh5217 Dec 18, 2024
662f7dd
Remove Deprecated Usages of RemoteJWKSet
kwondh5217 Dec 18, 2024
43a07a7
Remove Deprecated Usages of RemoteJWKSet
kwondh5217 Dec 18, 2024
bf4ed14
Remove Deprecated Usages of RemoteJWKSet
kwondh5217 Dec 18, 2024
22949c0
Add Serializable Compatilibity to Saml 2.0 Exceptions
jzheaux Dec 17, 2024
09c583a
Add Serializable Compatibility to Web Authentication Exceptions
jzheaux Dec 17, 2024
a3170d1
Use relative URLs in /login redirects
Pistolnik Mar 10, 2024
831ac13
Add setFavorRelativeUris
jzheaux Dec 18, 2024
d683eae
Added a constant for DPOP in OAuth2AccessToken.TokenType
ThomasKasene Nov 13, 2024
a858a9b
Polish gh-16087
sjohnr Dec 18, 2024
975170e
Make TokenType constructor public
sjohnr Dec 18, 2024
6ec991b
Address SessionLimitStrategy
Dec 5, 2024
eb46d89
Polish SessionLimit
jzheaux Dec 18, 2024
a7f7493
Bump org.hibernate.orm:hibernate-core from 6.6.3.Final to 6.6.4.Final
dependabot[bot] Dec 19, 2024
5cbf1d4
Bump ch.qos.logback:logback-classic from 1.5.12 to 1.5.13
dependabot[bot] Dec 19, 2024
cbcad6e
Set Saml2RelyingPartyInitiatedLogoutSuccessHandler#logoutRequestRepos…
sawprogramming Nov 14, 2024
e1a4717
Test Setting logoutRequestRepository
jzheaux Dec 19, 2024
29a9341
Polish SecurityFilterChain Validation
franticticktick Dec 17, 2024
1a497a6
Add Support Same Request Matchers Checking
franticticktick Dec 17, 2024
4b4fcc8
Add Alerting About Deprecated Authorize Config
franticticktick Dec 19, 2024
848c31e
Add Filter Chain Validation Test
jzheaux Dec 19, 2024
53b81be
Support Meta-Annotation Parameters on Parameter Annotations
github-actions[bot] Dec 9, 2024
2e20fff
Bump ch.qos.logback:logback-classic from 1.5.13 to 1.5.14
dependabot[bot] Dec 20, 2024
e3c4c8a
Bump org.jetbrains.kotlinx:kotlinx-coroutines-bom from 1.9.0 to 1.10.0
dependabot[bot] Dec 20, 2024
5eb8de6
Bump org.assertj:assertj-core from 3.26.3 to 3.27.0
dependabot[bot] Dec 20, 2024
795f1e2
Remove Unused loggers
franticticktick Dec 20, 2024
32c416d
Add Support JdbcUserCredentialRepository
franticticktick Dec 13, 2024
fb17c5f
Add Support JdbcPublicKeyCredentialUserEntityRepository
franticticktick Dec 13, 2024
9a332dc
Bump io.mockk:mockk from 1.13.13 to 1.13.14
dependabot[bot] Dec 23, 2024
a185671
Bump ch.qos.logback:logback-classic from 1.5.14 to 1.5.15
dependabot[bot] Dec 23, 2024
311863d
Bump org.jetbrains.kotlinx:kotlinx-coroutines-bom from 1.10.0 to 1.10.1
dependabot[bot] Dec 23, 2024
0ae77e1
Bump com.webauthn4j:webauthn4j-core
dependabot[bot] Jan 2, 2025
6b25e3e
Bump org.assertj:assertj-core from 3.27.0 to 3.27.1
dependabot[bot] Jan 2, 2025
00ca29d
Bump org.mockito:mockito-bom from 5.14.2 to 5.15.2
dependabot[bot] Jan 3, 2025
6b809c1
Bump ch.qos.logback:logback-classic from 1.5.15 to 1.5.16
dependabot[bot] Jan 6, 2025
f029f38
CLA -> DCO
rwinch Jan 6, 2025
47383a5
Bump org.assertj:assertj-core from 3.27.1 to 3.27.2
dependabot[bot] Jan 6, 2025
7cc4be8
Fix missing space in documentation
wndyd0131 Dec 31, 2024
4037493
Polish use getBeanProvider instead of getBeanNamesForType
kse-music Jan 6, 2025
5c5603d
Change deprecated FilterSecurityInterceptor to AuthorizationFilter wi…
Dec 30, 2024
785e632
Remove obsolete typo in OAuth 2.0 Client page
ngocnhan-tran1996 Dec 29, 2024
fc3221d
Fix incorrect rendering of SpEL expression example tabs
Meehdi Dec 25, 2024
6685f38
Fix logout code snippet for Kotlin: Corrected deleteCookies syntax
intotherealworld Dec 25, 2024
58df1bb
method-security: fix invalid Kotlin syntax
simaotwx Jan 8, 2025
7a08d9d
Polish remove unused code
kse-music Dec 27, 2024
500ade9
Avoid unnecessary instantiation of HttpSecurity when a SecurityFilter…
kse-music Jan 8, 2025
1377f5f
CustomBeanPostProcessor -> CountHttpSecurityBeanPostProcessor
rwinch Jan 9, 2025
fcdfeb4
Add Support OAuth2AuthorizationRequestResolver As Bean
franticticktick Jan 8, 2025
46a4186
Bump io.mockk:mockk from 1.13.14 to 1.13.16
dependabot[bot] Jan 13, 2025
ee2254b
Bump org.htmlunit:htmlunit from 4.7.0 to 4.8.0
dependabot[bot] Jan 13, 2025
1e25387
Fix Kotlin webAuthn {}
franticticktick Jan 11, 2025
ded6f8c
Add Support disableDefaultRegistrationPage to WebAuthnDsl
franticticktick Jan 11, 2025
c0b624a
Fixed a grammatical mistake in the docs.
MuhammadNFadhil Dec 8, 2024
a5713cb
Fixed grammatical mistakes in the docs.
MuhammadNFadhil Dec 8, 2024
8e10305
Improved sentence phrasing in the docs.
MuhammadNFadhil Dec 10, 2024
2e0389b
Update release-scheduler.yml
sjohnr Jan 13, 2025
3128666
Fix for JdbcOneTimeTokenService cleanupExpiredTokens failing with Pos…
making Dec 25, 2024
3130dca
Add support fullyAuthenticated to Kotlin DSL
franticticktick Dec 5, 2024
46e5326
Bump io.micrometer:micrometer-observation from 1.14.2 to 1.14.3
dependabot[bot] Jan 14, 2025
49a1568
Add Serializable to Csrf Components
jzheaux Jan 14, 2025
3a6761c
Formatting
jzheaux Jan 14, 2025
4f2741f
Don't Support Serialization of Jackson Modules
jzheaux Jan 15, 2025
46f2487
Don't Support Serialization for Jackson (De)serializers
jzheaux Jan 15, 2025
0dce2a8
Support Serialization in Exceptions
jzheaux Jan 15, 2025
d7f6b71
Bump org-bouncycastle from 1.79 to 1.80
dependabot[bot] Jan 15, 2025
a117b2f
Bump io.projectreactor:reactor-bom from 2023.0.13 to 2023.0.14
dependabot[bot] Jan 15, 2025
ecba158
Fix missing GChat notifications with workaround
sjohnr Jan 15, 2025
cfb19ab
Polish requestMatchers Logic
jzheaux Jan 10, 2025
d1b841e
Polish Using Request ServletContext
jzheaux Jan 10, 2025
5ae3dd8
Move Servlet Mocks to Web
jzheaux Jan 15, 2025
39881a8
Fix MVC Documentation for Kotlin
jzheaux Jan 16, 2025
78baeb9
Add support customizing redirect URI
Apr 17, 2024
8a315b1
Fix broken link
ngocnhan-tran1996 Jan 14, 2025
4fe1bbb
Use spring.security prefix instead of security.security
kse-music Jan 16, 2025
a8184a6
Add Breaking Change Section for 6.5
jzheaux Jan 16, 2025
013649d
Fixed typo in WebAuthnDsl
franticticktick Jan 14, 2025
863b0e8
Suggest replacing size() == 0 with isEmpty() for collection check
2-say Jan 16, 2025
aca3b64
Fix broken link to MockMvc documentation
harcomaase Jan 14, 2025
30a64a5
Encode Introspection clientId and clientSecret
ngocnhan-tran1996 Dec 19, 2024
f6a9d0d
Update OpaqueTokenIntrospector Documentation
jzheaux Jan 16, 2025
314b276
Bump org.springframework:spring-framework-bom from 6.2.1 to 6.2.2
dependabot[bot] Jan 17, 2025
461d4e6
Document OpaqueTokenIntrospector Migration
jzheaux Jan 17, 2025
1fb2e45
Case insenstive
rwinch Jan 17, 2025
8a67d79
webauthn: ensure allowCredentials[].id is an ArrayBuffer
Kehrlann Jan 17, 2025
88ce236
Support Serialization in Test Classes
jzheaux Jan 17, 2025
b6259c3
Mark Serialization Support for Events
jzheaux Jan 17, 2025
183acab
Fix checkstyleNohttp OutOfMemoryError
rwinch Jan 17, 2025
f17d009
Add ClientRegistration.clientSettings.requireProofKey to Enable PKCE
kse-music Jan 9, 2025
b4608a9
DefaultServerOAuth2AuthorizationRequestResolver requireProofKey support
rwinch Jan 17, 2025
bfc3bf0
Ensure that ClientSettings cannot be null
rwinch Jan 17, 2025
e8a53fd
ClientSettings equals, hashCode, toString
rwinch Jan 17, 2025
25afd2e
Add AuthorizationGrantType.toString()
rwinch Jan 17, 2025
c3c6828
PKCE cannot be true and AuthorizationGrantType != AUTHORIZATION_CODE
rwinch Jan 17, 2025
4524fda
Ensure missing ClientRegistration.clientSettings JSON node works
rwinch Jan 17, 2025
879e218
Move ClientSettings to ClientRegistration
rwinch Jan 17, 2025
d867231
Document requireProofKey
rwinch Jan 17, 2025
e543ae6
Set HttpMessageConverter by DSL
kse-music Jan 12, 2025
94d92ac
Fix WebAuthnConfigurer Javadoc
rwinch Jan 18, 2025
6d53184
webauthnWhenConfiguredMessageConverter uses mock
rwinch Jan 18, 2025
7702681
Set PublicKeyCredentialCreationOptionsRepository by DSL or Bean
kse-music Jan 12, 2025
6f870a1
Fix whitespace
rwinch Jan 18, 2025
b0cce01
Add WebAuthenticationDsl.creationOptionsRepository
rwinch Jan 18, 2025
81dd0c4
Document PublicKeyCredentialCreationOptionsRepository
rwinch Jan 18, 2025
2ac8c75
Add HttpMessageConverter WebAuthnDsl Support
rwinch Jan 18, 2025
583f2b1
Document custom HttpMessageConverter support for WebAuthn
rwinch Jan 18, 2025
ace8331
Document JDBC Persistence for WebAuthn
rwinch Jan 18, 2025
ae7bd9b
Bump org.hibernate.orm:hibernate-core from 6.6.4.Final to 6.6.5.Final
dependabot[bot] Jan 20, 2025
d5f0846
Bump org.springframework.data:spring-data-bom from 2024.1.1 to 2024.1.2
dependabot[bot] Jan 20, 2025
2d0f71c
Bump org.assertj:assertj-core from 3.27.2 to 3.27.3
dependabot[bot] Jan 20, 2025
13ca284
Release 6.5.0-M1
github-actions[bot] Jan 20, 2025
c03b2c3
Next development version
github-actions[bot] Jan 20, 2025
6484e3c
Bump org.seleniumhq.selenium:selenium-java from 4.27.0 to 4.28.0
dependabot[bot] Jan 21, 2025
31656f6
Add GenerateOneTimeTokenFilterTests
franticticktick Dec 22, 2024
5d96921
Add TestBytes
rwinch Jan 21, 2025
1fddf4f
Implement Serial
ngocnhan-tran1996 Jan 18, 2025
b010f84
Add serializeAndDeserializeAreEqual
rwinch Jan 22, 2025
8751eb7
fix flakey test in WebAuthnWebDriverTests
Kehrlann Jan 21, 2025
9589251
Fix GenerateOneTimeTokenWebFilter double publish of chain.filter(...)
Kehrlann Jan 21, 2025
8a51ef5
Remove debug test
rwinch Jan 22, 2025
154edbf
Add Support GenerateOneTimeTokenRequestResolver
franticticktick Jan 22, 2025
cc90735
Bump io.freefair.gradle:aspectj-plugin from 8.11 to 8.12
dependabot[bot] Jan 23, 2025
82a285a
Bump org.htmlunit:htmlunit from 4.8.0 to 4.9.0
dependabot[bot] Jan 23, 2025
bdaff37
Support Serialization for SecurityConfig
jzheaux Jan 23, 2025
068a102
Don't Support Serialzation of Deprecated Access Classes
jzheaux Jan 23, 2025
6e14699
Serialization Support of Core Components
jzheaux Jan 23, 2025
d02776b
Support Serialization for LDAP Components
jzheaux Jan 23, 2025
dfd0511
Bump com.github.ben-manes:gradle-versions-plugin from 0.51.0 to 0.52.0
dependabot[bot] Jan 24, 2025
5a6e72a
Bump org.seleniumhq.selenium:selenium-java from 4.28.0 to 4.28.1
dependabot[bot] Jan 24, 2025
e7d7795
S101 Depends On Assemble
jzheaux Jan 24, 2025
ed5cccc
Ensure s101 Runs After Assemble
jzheaux Jan 24, 2025
f5a669e
Remove Deprecated Usages of RemoteJWKSet
kwondh5217 Feb 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .github/dco.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require:
members: false
4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
env:
STRUCTURE101_LICENSEID: ${{ secrets.STRUCTURE101_LICENSEID }}
run: |
./gradlew check s101 -Ps101.licenseId="$STRUCTURE101_LICENSEID" --stacktrace
./gradlew assemble && ./gradlew s101 -Ps101.licenseId="$STRUCTURE101_LICENSEID" --stacktrace
deploy-artifacts:
name: Deploy Artifacts
needs: [ build, test, check-samples, check-tangles ]
Expand Down Expand Up @@ -116,7 +116,7 @@ jobs:
send-notification:
name: Send Notification
needs: [ perform-release ]
if: ${{ failure() || cancelled() }}
if: ${{ !success() }}
runs-on: ubuntu-latest
steps:
- name: Send Notification
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-scheduler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
# List of active maintenance branches.
branch: [ main, 6.4.x, 6.3.x, 6.2.x, 5.8.x ]
branch: [ main, 6.4.x, 6.3.x ]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ Please do your best to follow these steps.
Don't worry if you don't get them all correct the first time, we will help you.

[[sign-cla]]
1. If you have not previously done so, please sign the https://cla.spring.io/sign/spring[Contributor License Agreement].
You will be reminded automatically when you submit the PR.
1. All commits must include a __Signed-off-by__ trailer at the end of each commit message to indicate that the contributor agrees to the Developer Certificate of Origin.
For additional details, please refer to the blog post https://spring.io/blog/2025/01/06/hello-dco-goodbye-cla-simplifying-contributions-to-spring[Hello DCO, Goodbye CLA: Simplifying Contributions to Spring].
[[create-an-issue]]
1. Must you https://github.com/spring-projects/spring-security/issues/new/choose[create an issue] first? No, but it is recommended for features and larger bug fixes. It's easier discuss with the team first to determine the right fix or enhancement.
For typos and straightforward bug fixes, starting with a pull request is encouraged.
Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ nohttp {
source.builtBy(project(':spring-security-config').tasks.withType(RncToXsd))
}

tasks.named('checkstyleNohttp') {
maxHeapSize = '1g'
}

tasks.register('cloneRepository', IncludeRepoTask) {
repository = project.getProperties().get("repositoryName")
ref = project.getProperties().get("ref")
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/s101/S101Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void configure(S101Configure configure) {

private void configure(JavaExec exec) {
exec.setDescription("Runs Structure101 headless analysis, installing and configuring if necessary");
exec.dependsOn("check");
exec.dependsOn("assemble");
Project project = exec.getProject();
S101PluginExtension extension = project.getExtensions().getByType(S101PluginExtension.class);
exec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* @since 4.2
* @see org.springframework.security.jackson2.SecurityJackson2Modules
*/
@SuppressWarnings("serial")
public class CasJackson2Module extends SimpleModule {

public CasJackson2Module() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
Expand Down Expand Up @@ -273,12 +274,14 @@ private AbstractStringAssert<?> assertHasAlertStartingWith(String alertType, Str

/**
* Await until the assertion passes. If the assertion fails, it will display the
* assertion error in stdout.
* assertion error in stdout. WebDriver-related exceptions are ignored, so that
* {@code assertion}s can interact with the page and be retried on error, e.g.
* {@code assertThat(this.driver.findElement(By.Id("some-id")).isNotNull()}.
*/
private void await(Supplier<AbstractAssert<?, ?>> assertion) {
new FluentWait<>(this.driver).withTimeout(Duration.ofSeconds(2))
.pollingEvery(Duration.ofMillis(100))
.ignoring(AssertionError.class)
.ignoring(AssertionError.class, WebDriverException.class)
.until((d) -> {
assertion.get();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.springframework.http.HttpMethod;
import org.springframework.lang.Nullable;
import org.springframework.security.config.ObjectPostProcessor;
import org.springframework.security.config.annotation.web.ServletRegistrationsSupport.RegistrationMapping;
import org.springframework.security.config.annotation.web.configurers.AbstractConfigAttributeRequestMatcherRegistry;
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
Expand Down Expand Up @@ -235,103 +236,31 @@ private boolean anyPathsDontStartWithLeadingSlash(String... patterns) {
}

private RequestMatcher resolve(AntPathRequestMatcher ant, MvcRequestMatcher mvc, ServletContext servletContext) {
Map<String, ? extends ServletRegistration> registrations = mappableServletRegistrations(servletContext);
if (registrations.isEmpty()) {
ServletRegistrationsSupport registrations = new ServletRegistrationsSupport(servletContext);
Collection<RegistrationMapping> mappings = registrations.mappings();
if (mappings.isEmpty()) {
return new DispatcherServletDelegatingRequestMatcher(ant, mvc, new MockMvcRequestMatcher());
}
if (!hasDispatcherServlet(registrations)) {
Collection<RegistrationMapping> dispatcherServletMappings = registrations.dispatcherServletMappings();
if (dispatcherServletMappings.isEmpty()) {
return new DispatcherServletDelegatingRequestMatcher(ant, mvc, new MockMvcRequestMatcher());
}
ServletRegistration dispatcherServlet = requireOneRootDispatcherServlet(registrations);
if (dispatcherServlet != null) {
if (registrations.size() == 1) {
return mvc;
}
return new DispatcherServletDelegatingRequestMatcher(ant, mvc, servletContext);
}
dispatcherServlet = requireOnlyPathMappedDispatcherServlet(registrations);
if (dispatcherServlet != null) {
String mapping = dispatcherServlet.getMappings().iterator().next();
mvc.setServletPath(mapping.substring(0, mapping.length() - 2));
return mvc;
if (dispatcherServletMappings.size() > 1) {
String errorMessage = computeErrorMessage(servletContext.getServletRegistrations().values());
throw new IllegalArgumentException(errorMessage);
}
String errorMessage = computeErrorMessage(registrations.values());
throw new IllegalArgumentException(errorMessage);
}

private Map<String, ? extends ServletRegistration> mappableServletRegistrations(ServletContext servletContext) {
Map<String, ServletRegistration> mappable = new LinkedHashMap<>();
for (Map.Entry<String, ? extends ServletRegistration> entry : servletContext.getServletRegistrations()
.entrySet()) {
if (!entry.getValue().getMappings().isEmpty()) {
mappable.put(entry.getKey(), entry.getValue());
}
}
return mappable;
}

private boolean hasDispatcherServlet(Map<String, ? extends ServletRegistration> registrations) {
if (registrations == null) {
return false;
RegistrationMapping dispatcherServlet = dispatcherServletMappings.iterator().next();
if (mappings.size() > 1 && !dispatcherServlet.isDefault()) {
String errorMessage = computeErrorMessage(servletContext.getServletRegistrations().values());
throw new IllegalArgumentException(errorMessage);
}
for (ServletRegistration registration : registrations.values()) {
if (isDispatcherServlet(registration)) {
return true;
}
}
return false;
}

private ServletRegistration requireOneRootDispatcherServlet(
Map<String, ? extends ServletRegistration> registrations) {
ServletRegistration rootDispatcherServlet = null;
for (ServletRegistration registration : registrations.values()) {
if (!isDispatcherServlet(registration)) {
continue;
}
if (registration.getMappings().size() > 1) {
return null;
}
if (!"/".equals(registration.getMappings().iterator().next())) {
return null;
}
rootDispatcherServlet = registration;
}
return rootDispatcherServlet;
}

private ServletRegistration requireOnlyPathMappedDispatcherServlet(
Map<String, ? extends ServletRegistration> registrations) {
ServletRegistration pathDispatcherServlet = null;
for (ServletRegistration registration : registrations.values()) {
if (!isDispatcherServlet(registration)) {
return null;
}
if (registration.getMappings().size() > 1) {
return null;
}
String mapping = registration.getMappings().iterator().next();
if (!mapping.startsWith("/") || !mapping.endsWith("/*")) {
return null;
}
if (pathDispatcherServlet != null) {
return null;
if (dispatcherServlet.isDefault()) {
if (mappings.size() == 1) {
return mvc;
}
pathDispatcherServlet = registration;
}
return pathDispatcherServlet;
}

private boolean isDispatcherServlet(ServletRegistration registration) {
Class<?> dispatcherServlet = ClassUtils.resolveClassName("org.springframework.web.servlet.DispatcherServlet",
null);
try {
Class<?> clazz = Class.forName(registration.getClassName());
return dispatcherServlet.isAssignableFrom(clazz);
}
catch (ClassNotFoundException ex) {
return false;
return new DispatcherServletDelegatingRequestMatcher(ant, mvc);
}
return mvc;
}

private static String computeErrorMessage(Collection<? extends ServletRegistration> registrations) {
Expand Down Expand Up @@ -518,18 +447,12 @@ public boolean matches(HttpServletRequest request) {

static class DispatcherServletRequestMatcher implements RequestMatcher {

private final ServletContext servletContext;

DispatcherServletRequestMatcher(ServletContext servletContext) {
this.servletContext = servletContext;
}

@Override
public boolean matches(HttpServletRequest request) {
String name = request.getHttpServletMapping().getServletName();
ServletRegistration registration = this.servletContext.getServletRegistration(name);
ServletRegistration registration = request.getServletContext().getServletRegistration(name);
Assert.notNull(registration,
() -> computeErrorMessage(this.servletContext.getServletRegistrations().values()));
() -> computeErrorMessage(request.getServletContext().getServletRegistrations().values()));
try {
Class<?> clazz = Class.forName(registration.getClassName());
return DispatcherServlet.class.isAssignableFrom(clazz);
Expand All @@ -549,10 +472,8 @@ static class DispatcherServletDelegatingRequestMatcher implements RequestMatcher

private final RequestMatcher dispatcherServlet;

DispatcherServletDelegatingRequestMatcher(AntPathRequestMatcher ant, MvcRequestMatcher mvc,
ServletContext servletContext) {
this(ant, mvc, new OrRequestMatcher(new MockMvcRequestMatcher(),
new DispatcherServletRequestMatcher(servletContext)));
DispatcherServletDelegatingRequestMatcher(AntPathRequestMatcher ant, MvcRequestMatcher mvc) {
this(ant, mvc, new OrRequestMatcher(new MockMvcRequestMatcher(), new DispatcherServletRequestMatcher()));
}

DispatcherServletDelegatingRequestMatcher(AntPathRequestMatcher ant, MvcRequestMatcher mvc,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.security.config.annotation.web;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletRegistration;

import org.springframework.util.ClassUtils;

class ServletRegistrationsSupport {

private final Collection<RegistrationMapping> registrations;

ServletRegistrationsSupport(ServletContext servletContext) {
Map<String, ? extends ServletRegistration> registrations = servletContext.getServletRegistrations();
Collection<RegistrationMapping> mappings = new ArrayList<>();
for (Map.Entry<String, ? extends ServletRegistration> entry : registrations.entrySet()) {
if (!entry.getValue().getMappings().isEmpty()) {
for (String mapping : entry.getValue().getMappings()) {
mappings.add(new RegistrationMapping(entry.getValue(), mapping));
}
}
}
this.registrations = mappings;
}

Collection<RegistrationMapping> dispatcherServletMappings() {
Collection<RegistrationMapping> mappings = new ArrayList<>();
for (RegistrationMapping registration : this.registrations) {
if (registration.isDispatcherServlet()) {
mappings.add(registration);
}
}
return mappings;
}

Collection<RegistrationMapping> mappings() {
return this.registrations;
}

record RegistrationMapping(ServletRegistration registration, String mapping) {
boolean isDispatcherServlet() {
Class<?> dispatcherServlet = ClassUtils
.resolveClassName("org.springframework.web.servlet.DispatcherServlet", null);
try {
Class<?> clazz = Class.forName(this.registration.getClassName());
return dispatcherServlet.isAssignableFrom(clazz);
}
catch (ClassNotFoundException ex) {
return false;
}
}

boolean isDefault() {
return "/".equals(this.mapping);
}
}

}
Loading