Skip to content

Remove RequestVariablesExtractor in favor of RequestMatcher#matcher #17320

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* 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.
Expand All @@ -23,7 +23,6 @@

import org.springframework.http.HttpMethod;
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.security.web.util.matcher.RequestVariablesExtractor;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
Expand All @@ -49,7 +48,7 @@
* @deprecated Please use {@link PathPatternRequestMatcher} instead
*/
@Deprecated(forRemoval = true)
public class MvcRequestMatcher implements RequestMatcher, RequestVariablesExtractor {
public class MvcRequestMatcher implements RequestMatcher {

private final DefaultMatcher defaultMatcher = new DefaultMatcher();

Expand Down Expand Up @@ -79,12 +78,6 @@ public boolean matches(HttpServletRequest request) {
return matchResult != null;
}

@Override
@Deprecated
public Map<String, String> extractUriTemplateVariables(HttpServletRequest request) {
return matcher(request).getVariables();
}

@Override
public MatchResult matcher(HttpServletRequest request) {
if (notMatchMethodOrServletPath(request)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
* @deprecated please use {@link PathPatternRequestMatcher} instead
*/
@Deprecated(forRemoval = true)
public final class AntPathRequestMatcher implements RequestMatcher, RequestVariablesExtractor {
public final class AntPathRequestMatcher implements RequestMatcher {

private static final String MATCH_ALL = "/**";

Expand Down Expand Up @@ -194,12 +194,6 @@ public boolean matches(HttpServletRequest request) {
return this.matcher.matches(url);
}

@Override
@Deprecated
public Map<String, String> extractUriTemplateVariables(HttpServletRequest request) {
return matcher(request).getVariables();
}

@Override
public MatchResult matcher(HttpServletRequest request) {
if (!matches(request)) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-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.
Expand All @@ -16,8 +16,6 @@

package org.springframework.security.web.servlet.util.matcher;

import java.util.Collections;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -71,39 +69,6 @@ public void setup() {
this.matcher = new MvcRequestMatcher(this.introspector, "/path");
}

@Test
public void extractUriTemplateVariablesSuccess() throws Exception {
this.matcher = new MvcRequestMatcher(this.introspector, "/{p}");
given(this.introspector.getMatchableHandlerMapping(this.request)).willReturn(null);
assertThat(this.matcher.extractUriTemplateVariables(this.request)).containsEntry("p", "path");
assertThat(this.matcher.matcher(this.request).getVariables()).containsEntry("p", "path");
}

@Test
public void extractUriTemplateVariablesFail() throws Exception {
given(this.result.extractUriTemplateVariables()).willReturn(Collections.<String, String>emptyMap());
given(this.introspector.getMatchableHandlerMapping(this.request)).willReturn(this.mapping);
given(this.mapping.match(eq(this.request), this.pattern.capture())).willReturn(this.result);
assertThat(this.matcher.extractUriTemplateVariables(this.request)).isEmpty();
assertThat(this.matcher.matcher(this.request).getVariables()).isEmpty();
}

@Test
public void extractUriTemplateVariablesDefaultSuccess() throws Exception {
this.matcher = new MvcRequestMatcher(this.introspector, "/{p}");
given(this.introspector.getMatchableHandlerMapping(this.request)).willReturn(null);
assertThat(this.matcher.extractUriTemplateVariables(this.request)).containsEntry("p", "path");
assertThat(this.matcher.matcher(this.request).getVariables()).containsEntry("p", "path");
}

@Test
public void extractUriTemplateVariablesDefaultFail() throws Exception {
this.matcher = new MvcRequestMatcher(this.introspector, "/nomatch/{p}");
given(this.introspector.getMatchableHandlerMapping(this.request)).willReturn(null);
assertThat(this.matcher.extractUriTemplateVariables(this.request)).isEmpty();
assertThat(this.matcher.matcher(this.request).getVariables()).isEmpty();
}

@Test
public void matchesServletPathTrue() throws Exception {
given(this.introspector.getMatchableHandlerMapping(this.request)).willReturn(this.mapping);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* 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.
Expand Down