Skip to content
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

Add PathPatternRequestMatcher #16499

Closed
wants to merge 10 commits into from
Closed

Conversation

jzheaux
Copy link
Contributor

@jzheaux jzheaux commented Jan 29, 2025

This PR adds PathPatternRequestMatcher, a request matcher that doesn't require HandlerMappingIntrospector.

Also, it adds a servlet-aware builder for specifying the servlet path (using this request matcher) in a way that looks similar to Kotlin and XML:

import static org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher.servletPath;

@Bean
SecurityFilterChain appEndpoints(HttpSecurity http) {
	http
		.authorizeHttpRequests((authorize) -> authorize
			.requestMatchers(servletPath("/spring-mvc").matcher("/admin/**")).hasAuthority("admin")
			.requestMatchers(servletPath("/spring-mvc").matcher("/my/controller/**")).hasAuthority("controller")
			.anyRequest().authenticated()
		);

	return http.build();
}

Future tickets like #16509 are taking a look at a first-class way to represent the servlet inside the authorization DSL. This builder is still helpful since there are many other places in the Java DSL where request matchers are provided that may need the servlet path specified.

@jzheaux jzheaux added this to the 6.5.0-M2 milestone Jan 29, 2025
@jzheaux jzheaux self-assigned this Jan 29, 2025
@jzheaux jzheaux force-pushed the gh-16429 branch 2 times, most recently from bdd1cf1 to 12f1cf2 Compare January 29, 2025 21:29
@jzheaux jzheaux force-pushed the gh-16429 branch 2 times, most recently from bca1d7f to a22f87d Compare February 7, 2025 01:01
@jzheaux jzheaux marked this pull request as ready for review February 7, 2025 18:08
@jzheaux jzheaux added in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement labels Feb 7, 2025
Copy link
Member

@rwinch rwinch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all of your work on this @jzheaux! I've provided feedback below:

@jzheaux jzheaux modified the milestones: 6.5.0-M2, 6.5.x Feb 18, 2025
This static factory simplifes the creation of RequestMatchers
that specify the servlet path and other request elements

Closes spring-projectsgh-16430
- Refined documentation
- Applied method naming feedback
Copy link
Member

@rwinch rwinch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all your work on this! I've provided (optional) feedback. Feel free to merge once you are comfortable.

@jzheaux
Copy link
Contributor Author

jzheaux commented Feb 21, 2025

This was merged manually in 588220a and 7d301f8

@jzheaux jzheaux closed this Feb 21, 2025
@jzheaux jzheaux removed this from the 6.5.x milestone Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants