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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

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 quite similar to Kotlin and XML:

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

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

	return http.build();
}

This static factory simplifes the creation of RequestMatchers
that specify the servlet path.

Closes spring-projectsgh-16430
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant