Remove deprecated RequestMatcher methods from Java Configuration
Closes gh-11939
This commit is contained in:
@@ -89,90 +89,6 @@ public abstract class AbstractRequestMatcherRegistry<C> {
|
||||
return configurer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a {@link List} of
|
||||
* {@link org.springframework.security.web.util.matcher.AntPathRequestMatcher}
|
||||
* instances.
|
||||
* @param method the {@link HttpMethod} to use for any {@link HttpMethod}.
|
||||
* @return the object that is chained after creating the {@link RequestMatcher}
|
||||
* @deprecated use {@link #requestMatchers(HttpMethod)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public C antMatchers(HttpMethod method) {
|
||||
return antMatchers(method, "/**");
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a {@link List} of
|
||||
* {@link org.springframework.security.web.util.matcher.AntPathRequestMatcher}
|
||||
* instances.
|
||||
* @param method the {@link HttpMethod} to use or {@code null} for any
|
||||
* {@link HttpMethod}.
|
||||
* @param antPatterns the ant patterns to create. If {@code null} or empty, then
|
||||
* matches on nothing.
|
||||
* @return the object that is chained after creating the {@link RequestMatcher}
|
||||
* @deprecated use {@link #requestMatchers(HttpMethod, String...)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public C antMatchers(HttpMethod method, String... antPatterns) {
|
||||
Assert.state(!this.anyRequestConfigured, "Can't configure antMatchers after anyRequest");
|
||||
return chainRequestMatchers(RequestMatchers.antMatchers(method, antPatterns));
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a {@link List} of
|
||||
* {@link org.springframework.security.web.util.matcher.AntPathRequestMatcher}
|
||||
* instances that do not care which {@link HttpMethod} is used.
|
||||
* @param antPatterns the ant patterns to create
|
||||
* {@link org.springframework.security.web.util.matcher.AntPathRequestMatcher} from
|
||||
* @return the object that is chained after creating the {@link RequestMatcher}
|
||||
* @deprecated use {@link #requestMatchers(String...)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public C antMatchers(String... antPatterns) {
|
||||
Assert.state(!this.anyRequestConfigured, "Can't configure antMatchers after anyRequest");
|
||||
return chainRequestMatchers(RequestMatchers.antMatchers(antPatterns));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Maps an {@link MvcRequestMatcher} that does not care which {@link HttpMethod} is
|
||||
* used. This matcher will use the same rules that Spring MVC uses for matching. For
|
||||
* example, often times a mapping of the path "/path" will match on "/path", "/path/",
|
||||
* "/path.html", etc.
|
||||
* </p>
|
||||
* <p>
|
||||
* If the current request will not be processed by Spring MVC, a reasonable default
|
||||
* using the pattern as a ant pattern will be used.
|
||||
* </p>
|
||||
* @param mvcPatterns the patterns to match on. The rules for matching are defined by
|
||||
* Spring MVC
|
||||
* @return the object that is chained after creating the {@link RequestMatcher}.
|
||||
* @deprecated use {@link #requestMatchers(String...)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract C mvcMatchers(String... mvcPatterns);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Maps an {@link MvcRequestMatcher} that also specifies a specific {@link HttpMethod}
|
||||
* to match on. This matcher will use the same rules that Spring MVC uses for
|
||||
* matching. For example, often times a mapping of the path "/path" will match on
|
||||
* "/path", "/path/", "/path.html", etc.
|
||||
* </p>
|
||||
* <p>
|
||||
* If the current request will not be processed by Spring MVC, a reasonable default
|
||||
* using the pattern as a ant pattern will be used.
|
||||
* </p>
|
||||
* @param method the HTTP method to match on
|
||||
* @param mvcPatterns the patterns to match on. The rules for matching are defined by
|
||||
* Spring MVC
|
||||
* @return the object that is chained after creating the {@link RequestMatcher}.
|
||||
* @deprecated use {@link #requestMatchers(HttpMethod, String...)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract C mvcMatchers(HttpMethod method, String... mvcPatterns);
|
||||
|
||||
/**
|
||||
* Creates {@link MvcRequestMatcher} instances for the method and patterns passed in
|
||||
* @param method the HTTP method to use or null if any should be used
|
||||
@@ -201,40 +117,6 @@ public abstract class AbstractRequestMatcherRegistry<C> {
|
||||
return matchers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a {@link List} of
|
||||
* {@link org.springframework.security.web.util.matcher.RegexRequestMatcher}
|
||||
* instances.
|
||||
* @param method the {@link HttpMethod} to use or {@code null} for any
|
||||
* {@link HttpMethod}.
|
||||
* @param regexPatterns the regular expressions to create
|
||||
* {@link org.springframework.security.web.util.matcher.RegexRequestMatcher} from
|
||||
* @return the object that is chained after creating the {@link RequestMatcher}
|
||||
* @deprecated use {@link #requestMatchers(RequestMatcher...)} with a
|
||||
* {@link RegexRequestMatcher} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public C regexMatchers(HttpMethod method, String... regexPatterns) {
|
||||
Assert.state(!this.anyRequestConfigured, "Can't configure regexMatchers after anyRequest");
|
||||
return chainRequestMatchers(RequestMatchers.regexMatchers(method, regexPatterns));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link List} of
|
||||
* {@link org.springframework.security.web.util.matcher.RegexRequestMatcher} instances
|
||||
* that do not specify an {@link HttpMethod}.
|
||||
* @param regexPatterns the regular expressions to create
|
||||
* {@link org.springframework.security.web.util.matcher.RegexRequestMatcher} from
|
||||
* @return the object that is chained after creating the {@link RequestMatcher}
|
||||
* @deprecated use {@link #requestMatchers(RequestMatcher...)} with a
|
||||
* {@link RegexRequestMatcher} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public C regexMatchers(String... regexPatterns) {
|
||||
Assert.state(!this.anyRequestConfigured, "Can't configure regexMatchers after anyRequest");
|
||||
return chainRequestMatchers(RequestMatchers.regexMatchers(regexPatterns));
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a {@link List} of
|
||||
* {@link org.springframework.security.web.util.matcher.DispatcherTypeRequestMatcher}
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.OrderComparator;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.config.Customizer;
|
||||
@@ -89,7 +88,6 @@ import org.springframework.security.web.session.HttpSessionEventPublisher;
|
||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.OrRequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.RegexRequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -587,7 +585,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http.authorizeRequests().antMatchers("/**").hasRole("USER").and().formLogin()
|
||||
* http.authorizeRequests().requestMatchers("/**").hasRole("USER").and().formLogin()
|
||||
* .permitAll().and()
|
||||
* // Example portMapper() configuration
|
||||
* .portMapper().http(9090).mapsTo(9443).http(80).mapsTo(443);
|
||||
@@ -688,7 +686,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http.authorizeRequests().antMatchers("/**").hasRole("USER").and()
|
||||
* http.authorizeRequests().requestMatchers("/**").hasRole("USER").and()
|
||||
* // Example jee() configuration
|
||||
* .jee().mappableRoles("USER", "ADMIN");
|
||||
* return http.build();
|
||||
@@ -763,7 +761,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .jee((jee) ->
|
||||
* jee
|
||||
@@ -840,7 +838,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http.authorizeRequests().antMatchers("/**").hasRole("USER").and()
|
||||
* http.authorizeRequests().requestMatchers("/**").hasRole("USER").and()
|
||||
* // Example x509() configuration
|
||||
* .x509();
|
||||
* return http.build();
|
||||
@@ -873,7 +871,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .x509(withDefaults());
|
||||
* return http.build();
|
||||
@@ -907,7 +905,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http.authorizeRequests().antMatchers("/**").hasRole("USER").and().formLogin()
|
||||
* http.authorizeRequests().requestMatchers("/**").hasRole("USER").and().formLogin()
|
||||
* .permitAll().and()
|
||||
* // Example Remember Me Configuration
|
||||
* .rememberMe();
|
||||
@@ -952,7 +950,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .formLogin(withDefaults())
|
||||
* .rememberMe(withDefaults());
|
||||
@@ -998,7 +996,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http.authorizeRequests().antMatchers("/**").hasRole("USER").and().formLogin();
|
||||
* http.authorizeRequests().requestMatchers("/**").hasRole("USER").and().formLogin();
|
||||
* return http.build();
|
||||
* }
|
||||
*
|
||||
@@ -1030,8 +1028,8 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http.authorizeRequests().antMatchers("/admin/**").hasRole("ADMIN")
|
||||
* .antMatchers("/**").hasRole("USER").and().formLogin();
|
||||
* http.authorizeRequests().requestMatchers("/admin/**").hasRole("ADMIN")
|
||||
* .requestMatchers("/**").hasRole("USER").and().formLogin();
|
||||
* return http.build();
|
||||
* }
|
||||
*
|
||||
@@ -1063,7 +1061,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http.authorizeRequests().antMatchers("/**").hasRole("USER").antMatchers("/admin/**")
|
||||
* http.authorizeRequests().requestMatchers("/**").hasRole("USER").requestMatchers("/admin/**")
|
||||
* .hasRole("ADMIN")
|
||||
* return http.build();
|
||||
* }
|
||||
@@ -1072,7 +1070,6 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* @return the {@link ExpressionUrlAuthorizationConfigurer} for further customizations
|
||||
* @throws Exception
|
||||
* @deprecated Use {@link #authorizeHttpRequests()} instead
|
||||
* @see #requestMatcher(RequestMatcher)
|
||||
*/
|
||||
@Deprecated
|
||||
public ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry authorizeRequests()
|
||||
@@ -1101,7 +1098,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .formLogin(withDefaults());
|
||||
* return http.build();
|
||||
@@ -1138,8 +1135,8 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/admin/**").hasRole("ADMIN")
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/admin/**").hasRole("ADMIN")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .formLogin(withDefaults());
|
||||
* return http.build();
|
||||
@@ -1176,8 +1173,8 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .antMatchers("/admin/**").hasRole("ADMIN")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/admin/**").hasRole("ADMIN")
|
||||
* );
|
||||
* return http.build();
|
||||
* }
|
||||
@@ -1188,7 +1185,6 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* @return the {@link HttpSecurity} for further customizations
|
||||
* @throws Exception
|
||||
* @deprecated Use {@link #authorizeHttpRequests} instead
|
||||
* @see #requestMatcher(RequestMatcher)
|
||||
*/
|
||||
@Deprecated
|
||||
public HttpSecurity authorizeRequests(
|
||||
@@ -1219,7 +1215,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http
|
||||
* .authorizeHttpRequests()
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* .and()
|
||||
* .formLogin();
|
||||
* return http.build();
|
||||
@@ -1255,8 +1251,8 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http
|
||||
* .authorizeHttpRequests()
|
||||
* .antMatchers("/admin").hasRole("ADMIN")
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/admin").hasRole("ADMIN")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* .and()
|
||||
* .formLogin();
|
||||
* return http.build();
|
||||
@@ -1292,8 +1288,8 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http
|
||||
* .authorizeHttpRequests()
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .antMatchers("/admin/**").hasRole("ADMIN")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/admin/**").hasRole("ADMIN")
|
||||
* .and()
|
||||
* .formLogin();
|
||||
* return http.build();
|
||||
@@ -1303,7 +1299,6 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* @return the {@link HttpSecurity} for further customizations
|
||||
* @throws Exception
|
||||
* @since 5.6
|
||||
* @see #requestMatcher(RequestMatcher)
|
||||
*/
|
||||
public AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry authorizeHttpRequests()
|
||||
throws Exception {
|
||||
@@ -1331,7 +1326,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeHttpRequests((authorizeHttpRequests) ->
|
||||
* authorizeHttpRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .formLogin(withDefaults());
|
||||
* return http.build();
|
||||
@@ -1368,8 +1363,8 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeHttpRequests((authorizeHttpRequests) ->
|
||||
* authorizeHttpRequests
|
||||
* .antMatchers("/admin/**").hasRole("ADMIN")
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/admin/**").hasRole("ADMIN")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .formLogin(withDefaults());
|
||||
* return http.build();
|
||||
@@ -1406,8 +1401,8 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeHttpRequests((authorizeHttpRequests) ->
|
||||
* authorizeHttpRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .antMatchers("/admin/**").hasRole("ADMIN")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/admin/**").hasRole("ADMIN")
|
||||
* );
|
||||
* return http.build();
|
||||
* }
|
||||
@@ -1418,7 +1413,6 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* @return the {@link HttpSecurity} for further customizations
|
||||
* @throws Exception
|
||||
* @since 5.5
|
||||
* @see #requestMatcher(RequestMatcher)
|
||||
*/
|
||||
public HttpSecurity authorizeHttpRequests(
|
||||
Customizer<AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry> authorizeHttpRequestsCustomizer)
|
||||
@@ -1463,7 +1457,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .requestCache((requestCache) ->
|
||||
* requestCache.disable()
|
||||
@@ -1512,7 +1506,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* // sample exception handling customization
|
||||
* .exceptionHandling((exceptionHandling) ->
|
||||
@@ -1695,7 +1689,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http.authorizeRequests().antMatchers("/**").hasRole("USER").and().formLogin()
|
||||
* http.authorizeRequests().requestMatchers("/**").hasRole("USER").and().formLogin()
|
||||
* .and()
|
||||
* // sample logout customization
|
||||
* .logout().deleteCookies("remove").invalidateHttpSession(false)
|
||||
@@ -1744,7 +1738,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .formLogin(withDefaults())
|
||||
* // sample logout customization
|
||||
@@ -1799,7 +1793,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http
|
||||
* .authorizeRequests()
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* .and()
|
||||
* .formLogin()
|
||||
* .and()
|
||||
@@ -1833,7 +1827,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http
|
||||
* .authorizeRequests()
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* .and()
|
||||
* .formLogin()
|
||||
* .and()
|
||||
@@ -1882,7 +1876,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .formLogin(withDefaults())
|
||||
* // sample anonymous customization
|
||||
@@ -1919,7 +1913,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .formLogin(withDefaults())
|
||||
* // sample anonymous customization
|
||||
@@ -1969,7 +1963,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http.authorizeRequests().antMatchers("/**").hasRole("USER").and().formLogin();
|
||||
* http.authorizeRequests().requestMatchers("/**").hasRole("USER").and().formLogin();
|
||||
* return http.build();
|
||||
* }
|
||||
*
|
||||
@@ -1994,7 +1988,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http.authorizeRequests().antMatchers("/**").hasRole("USER").and().formLogin()
|
||||
* http.authorizeRequests().requestMatchers("/**").hasRole("USER").and().formLogin()
|
||||
* .usernameParameter("username") // default is username
|
||||
* .passwordParameter("password") // default is password
|
||||
* .loginPage("/authentication/login") // default is /login with an HTTP get
|
||||
@@ -2046,7 +2040,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .formLogin(withDefaults());
|
||||
* return http.build();
|
||||
@@ -2076,7 +2070,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .formLogin((formLogin) ->
|
||||
* formLogin
|
||||
@@ -2773,7 +2767,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http.authorizeRequests().antMatchers("/**").hasRole("USER").and().formLogin()
|
||||
* http.authorizeRequests().requestMatchers("/**").hasRole("USER").and().formLogin()
|
||||
* .and().requiresChannel().anyRequest().requiresSecure();
|
||||
* return http.build();
|
||||
* }
|
||||
@@ -2819,7 +2813,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .formLogin(withDefaults())
|
||||
* .requiresChannel((requiresChannel) ->
|
||||
@@ -2869,7 +2863,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http.authorizeRequests().antMatchers("/**").hasRole("USER").and().httpBasic();
|
||||
* http.authorizeRequests().requestMatchers("/**").hasRole("USER").and().httpBasic();
|
||||
* return http.build();
|
||||
* }
|
||||
*
|
||||
@@ -2910,7 +2904,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .httpBasic(withDefaults());
|
||||
* return http.build();
|
||||
@@ -2955,7 +2949,7 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
* http
|
||||
* .authorizeRequests(authorizeRequests ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .requestMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .passwordManagement(passwordManagement ->
|
||||
* passwordManagement
|
||||
@@ -3087,291 +3081,6 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
return addFilterAtOffsetOf(filter, 0, atFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows specifying which {@link HttpServletRequest} instances this
|
||||
* {@link HttpSecurity} will be invoked on. This method allows for easily invoking the
|
||||
* {@link HttpSecurity} for multiple different {@link RequestMatcher} instances. If
|
||||
* only a single {@link RequestMatcher} is necessary consider using
|
||||
* {@link #mvcMatcher(String)}, {@link #antMatcher(String)},
|
||||
* {@link #regexMatcher(String)}, or {@link #requestMatcher(RequestMatcher)}.
|
||||
*
|
||||
* <p>
|
||||
* Invoking {@link #requestMatchers()} will not override previous invocations of
|
||||
* {@link #mvcMatcher(String)}}, {@link #requestMatchers()},
|
||||
* {@link #antMatcher(String)}, {@link #regexMatcher(String)}, and
|
||||
* {@link #requestMatcher(RequestMatcher)}.
|
||||
* </p>
|
||||
*
|
||||
* <h3>Example Configurations</h3>
|
||||
*
|
||||
* The following configuration enables the {@link HttpSecurity} for URLs that begin
|
||||
* with "/api/" or "/oauth/".
|
||||
*
|
||||
* <pre>
|
||||
* @Configuration
|
||||
* @EnableWebSecurity
|
||||
* public class RequestMatchersSecurityConfig {
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http
|
||||
* .requestMatchers()
|
||||
* .antMatchers("/api/**", "/oauth/**")
|
||||
* .and()
|
||||
* .authorizeRequests()
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .and()
|
||||
* .httpBasic();
|
||||
* return http.build();
|
||||
* }
|
||||
*
|
||||
* @Bean
|
||||
* public UserDetailsService userDetailsService() {
|
||||
* UserDetails user = User.withDefaultPasswordEncoder()
|
||||
* .username("user")
|
||||
* .password("password")
|
||||
* .roles("USER")
|
||||
* .build();
|
||||
* return new InMemoryUserDetailsManager(user);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* The configuration below is the same as the previous configuration.
|
||||
*
|
||||
* <pre>
|
||||
* @Configuration
|
||||
* @EnableWebSecurity
|
||||
* public class RequestMatchersSecurityConfig {
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http
|
||||
* .requestMatchers()
|
||||
* .antMatchers("/api/**")
|
||||
* .antMatchers("/oauth/**")
|
||||
* .and()
|
||||
* .authorizeRequests()
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .and()
|
||||
* .httpBasic();
|
||||
* return http.build();
|
||||
* }
|
||||
*
|
||||
* @Bean
|
||||
* public UserDetailsService userDetailsService() {
|
||||
* UserDetails user = User.withDefaultPasswordEncoder()
|
||||
* .username("user")
|
||||
* .password("password")
|
||||
* .roles("USER")
|
||||
* .build();
|
||||
* return new InMemoryUserDetailsManager(user);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* The configuration below is also the same as the above configuration.
|
||||
*
|
||||
* <pre>
|
||||
* @Configuration
|
||||
* @EnableWebSecurity
|
||||
* public class RequestMatchersSecurityConfig {
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http
|
||||
* .requestMatchers()
|
||||
* .antMatchers("/api/**")
|
||||
* .and()
|
||||
* .requestMatchers()
|
||||
* .antMatchers("/oauth/**")
|
||||
* .and()
|
||||
* .authorizeRequests()
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* .and()
|
||||
* .httpBasic();
|
||||
* return http.build();
|
||||
* }
|
||||
*
|
||||
* @Bean
|
||||
* public UserDetailsService userDetailsService() {
|
||||
* UserDetails user = User.withDefaultPasswordEncoder()
|
||||
* .username("user")
|
||||
* .password("password")
|
||||
* .roles("USER")
|
||||
* .build();
|
||||
* return new InMemoryUserDetailsManager(user);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
* @return the {@link RequestMatcherConfigurer} for further customizations
|
||||
* @deprecated use {@link #securityMatchers()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public RequestMatcherConfigurer requestMatchers() {
|
||||
return this.requestMatcherConfigurer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows specifying which {@link HttpServletRequest} instances this
|
||||
* {@link HttpSecurity} will be invoked on. This method allows for easily invoking the
|
||||
* {@link HttpSecurity} for multiple different {@link RequestMatcher} instances. If
|
||||
* only a single {@link RequestMatcher} is necessary consider using
|
||||
* {@link #mvcMatcher(String)}, {@link #antMatcher(String)},
|
||||
* {@link #regexMatcher(String)}, or {@link #requestMatcher(RequestMatcher)}.
|
||||
*
|
||||
* <p>
|
||||
* Invoking {@link #requestMatchers()} will not override previous invocations of
|
||||
* {@link #mvcMatcher(String)}}, {@link #requestMatchers()},
|
||||
* {@link #antMatcher(String)}, {@link #regexMatcher(String)}, and
|
||||
* {@link #requestMatcher(RequestMatcher)}.
|
||||
* </p>
|
||||
*
|
||||
* <h3>Example Configurations</h3>
|
||||
*
|
||||
* The following configuration enables the {@link HttpSecurity} for URLs that begin
|
||||
* with "/api/" or "/oauth/".
|
||||
*
|
||||
* <pre>
|
||||
* @Configuration
|
||||
* @EnableWebSecurity
|
||||
* public class RequestMatchersSecurityConfig {
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http
|
||||
* .requestMatchers((requestMatchers) ->
|
||||
* requestMatchers
|
||||
* .antMatchers("/api/**", "/oauth/**")
|
||||
* )
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .httpBasic(withDefaults());
|
||||
* return http.build();
|
||||
* }
|
||||
*
|
||||
* @Bean
|
||||
* public UserDetailsService userDetailsService() {
|
||||
* UserDetails user = User.withDefaultPasswordEncoder()
|
||||
* .username("user")
|
||||
* .password("password")
|
||||
* .roles("USER")
|
||||
* .build();
|
||||
* return new InMemoryUserDetailsManager(user);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* The configuration below is the same as the previous configuration.
|
||||
*
|
||||
* <pre>
|
||||
* @Configuration
|
||||
* @EnableWebSecurity
|
||||
* public class RequestMatchersSecurityConfig {
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http
|
||||
* .requestMatchers((requestMatchers) ->
|
||||
* requestMatchers
|
||||
* .antMatchers("/api/**")
|
||||
* .antMatchers("/oauth/**")
|
||||
* )
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .httpBasic(withDefaults());
|
||||
* return http.build();
|
||||
* }
|
||||
*
|
||||
* @Bean
|
||||
* public UserDetailsService userDetailsService() {
|
||||
* UserDetails user = User.withDefaultPasswordEncoder()
|
||||
* .username("user")
|
||||
* .password("password")
|
||||
* .roles("USER")
|
||||
* .build();
|
||||
* return new InMemoryUserDetailsManager(user);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* The configuration below is also the same as the above configuration.
|
||||
*
|
||||
* <pre>
|
||||
* @Configuration
|
||||
* @EnableWebSecurity
|
||||
* public class RequestMatchersSecurityConfig {
|
||||
*
|
||||
* @Bean
|
||||
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
* http
|
||||
* .requestMatchers((requestMatchers) ->
|
||||
* requestMatchers
|
||||
* .antMatchers("/api/**")
|
||||
* )
|
||||
* .requestMatchers((requestMatchers) ->
|
||||
* requestMatchers
|
||||
* .antMatchers("/oauth/**")
|
||||
* )
|
||||
* .authorizeRequests((authorizeRequests) ->
|
||||
* authorizeRequests
|
||||
* .antMatchers("/**").hasRole("USER")
|
||||
* )
|
||||
* .httpBasic(withDefaults());
|
||||
* return http.build();
|
||||
* }
|
||||
*
|
||||
* @Bean
|
||||
* public UserDetailsService userDetailsService() {
|
||||
* UserDetails user = User.withDefaultPasswordEncoder()
|
||||
* .username("user")
|
||||
* .password("password")
|
||||
* .roles("USER")
|
||||
* .build();
|
||||
* return new InMemoryUserDetailsManager(user);
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
* @param requestMatcherCustomizer the {@link Customizer} to provide more options for
|
||||
* the {@link RequestMatcherConfigurer}
|
||||
* @return the {@link HttpSecurity} for further customizations
|
||||
* @deprecated use {@link #securityMatchers(Customizer)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public HttpSecurity requestMatchers(Customizer<RequestMatcherConfigurer> requestMatcherCustomizer) {
|
||||
requestMatcherCustomizer.customize(this.requestMatcherConfigurer);
|
||||
return HttpSecurity.this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows configuring the {@link HttpSecurity} to only be invoked when matching the
|
||||
* provided {@link RequestMatcher}. If more advanced configuration is necessary,
|
||||
* consider using {@link #requestMatchers()}.
|
||||
*
|
||||
* <p>
|
||||
* Invoking {@link #requestMatcher(RequestMatcher)} will override previous invocations
|
||||
* of {@link #requestMatchers()}, {@link #mvcMatcher(String)},
|
||||
* {@link #antMatcher(String)}, {@link #regexMatcher(String)}, and
|
||||
* {@link #requestMatcher(RequestMatcher)}.
|
||||
* </p>
|
||||
* @param requestMatcher the {@link RequestMatcher} to use (i.e. new
|
||||
* AntPathRequestMatcher("/admin/**","GET") )
|
||||
* @return the {@link HttpSecurity} for further customizations
|
||||
* @deprecated use {@link #securityMatcher(RequestMatcher)} instead
|
||||
* @see #requestMatchers()
|
||||
* @see #antMatcher(String)
|
||||
* @see #regexMatcher(String)
|
||||
*/
|
||||
@Deprecated
|
||||
public HttpSecurity requestMatcher(RequestMatcher requestMatcher) {
|
||||
this.requestMatcher = requestMatcher;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows specifying which {@link HttpServletRequest} instances this
|
||||
* {@link HttpSecurity} will be invoked on. This method allows for easily invoking the
|
||||
@@ -3624,10 +3333,9 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* <p>
|
||||
* Invoking {@link #securityMatcher(RequestMatcher)} will override previous
|
||||
* invocations of {@link #requestMatchers()}, {@link #mvcMatcher(String)},
|
||||
* {@link #antMatcher(String)}, {@link #regexMatcher(String)},
|
||||
* {@link #requestMatcher(RequestMatcher)}, {@link #securityMatchers(Customizer)},
|
||||
* {@link #securityMatchers()} and {@link #securityMatcher(String...)}
|
||||
* invocations of {@link #securityMatcher(RequestMatcher)},
|
||||
* {@link #securityMatcher(String...)}, {@link #securityMatchers(Customizer)} and
|
||||
* {@link #securityMatchers()}
|
||||
* </p>
|
||||
* @param requestMatcher the {@link RequestMatcher} to use (i.e. new
|
||||
* AntPathRequestMatcher("/admin/**","GET") )
|
||||
@@ -3648,9 +3356,9 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
*
|
||||
* <p>
|
||||
* Invoking {@link #securityMatcher(String...)} will override previous invocations of
|
||||
* {@link #mvcMatcher(String)}}, {@link #requestMatchers()},
|
||||
* {@link #antMatcher(String)}, {@link #regexMatcher(String)}, and
|
||||
* {@link #requestMatcher(RequestMatcher)}.
|
||||
* {@link #securityMatcher(String...)} (String)}},
|
||||
* {@link #securityMatcher(RequestMatcher)} ()}, {@link #securityMatchers(Customizer)}
|
||||
* (String)} and {@link #securityMatchers()} (String)}.
|
||||
* </p>
|
||||
* @param patterns the pattern to match on (i.e. "/admin/**")
|
||||
* @return the {@link HttpSecurity} for further customizations
|
||||
@@ -3692,72 +3400,6 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
return matchers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows configuring the {@link HttpSecurity} to only be invoked when matching the
|
||||
* provided ant pattern. If more advanced configuration is necessary, consider using
|
||||
* {@link #requestMatchers()} or {@link #requestMatcher(RequestMatcher)}.
|
||||
*
|
||||
* <p>
|
||||
* Invoking {@link #antMatcher(String)} will override previous invocations of
|
||||
* {@link #mvcMatcher(String)}}, {@link #requestMatchers()},
|
||||
* {@link #antMatcher(String)}, {@link #regexMatcher(String)}, and
|
||||
* {@link #requestMatcher(RequestMatcher)}.
|
||||
* </p>
|
||||
* @param antPattern the Ant Pattern to match on (i.e. "/admin/**")
|
||||
* @return the {@link HttpSecurity} for further customizations
|
||||
* @deprecated use {@link #securityMatcher(String...)} instead
|
||||
* @see AntPathRequestMatcher
|
||||
*/
|
||||
@Deprecated
|
||||
public HttpSecurity antMatcher(String antPattern) {
|
||||
return requestMatcher(new AntPathRequestMatcher(antPattern));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows configuring the {@link HttpSecurity} to only be invoked when matching the
|
||||
* provided Spring MVC pattern. If more advanced configuration is necessary, consider
|
||||
* using {@link #requestMatchers()} or {@link #requestMatcher(RequestMatcher)}.
|
||||
*
|
||||
* <p>
|
||||
* Invoking {@link #mvcMatcher(String)} will override previous invocations of
|
||||
* {@link #mvcMatcher(String)}}, {@link #requestMatchers()},
|
||||
* {@link #antMatcher(String)}, {@link #regexMatcher(String)}, and
|
||||
* {@link #requestMatcher(RequestMatcher)}.
|
||||
* </p>
|
||||
* @param mvcPattern the Spring MVC Pattern to match on (i.e. "/admin/**")
|
||||
* @return the {@link HttpSecurity} for further customizations
|
||||
* @deprecated use {@link #securityMatcher(String...)} instead
|
||||
* @see MvcRequestMatcher
|
||||
*/
|
||||
@Deprecated
|
||||
public HttpSecurity mvcMatcher(String mvcPattern) {
|
||||
HandlerMappingIntrospector introspector = new HandlerMappingIntrospector();
|
||||
introspector.setApplicationContext(getContext());
|
||||
introspector.afterPropertiesSet();
|
||||
return requestMatcher(new MvcRequestMatcher(introspector, mvcPattern));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows configuring the {@link HttpSecurity} to only be invoked when matching the
|
||||
* provided regex pattern. If more advanced configuration is necessary, consider using
|
||||
* {@link #requestMatchers()} or {@link #requestMatcher(RequestMatcher)}.
|
||||
*
|
||||
* <p>
|
||||
* Invoking {@link #regexMatcher(String)} will override previous invocations of
|
||||
* {@link #mvcMatcher(String)}}, {@link #requestMatchers()},
|
||||
* {@link #antMatcher(String)}, {@link #regexMatcher(String)}, and
|
||||
* {@link #requestMatcher(RequestMatcher)}.
|
||||
* </p>
|
||||
* @param pattern the Regular Expression to match on (i.e. "/admin/.+")
|
||||
* @return the {@link HttpSecurity} for further customizations
|
||||
* @deprecated use {@link #securityMatcher(RequestMatcher)} with a
|
||||
* {@link RegexRequestMatcher} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public HttpSecurity regexMatcher(String pattern) {
|
||||
return requestMatcher(new RegexRequestMatcher(pattern, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* If the {@link SecurityConfigurer} has already been specified get the original,
|
||||
* otherwise apply the new {@link SecurityConfigurerAdapter}.
|
||||
@@ -3776,40 +3418,6 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
return apply(configurer);
|
||||
}
|
||||
|
||||
/**
|
||||
* An extension to {@link RequestMatcherConfigurer} that allows optionally configuring
|
||||
* the servlet path.
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
public final class MvcMatchersRequestMatcherConfigurer extends RequestMatcherConfigurer {
|
||||
|
||||
private final List<MvcRequestMatcher> mvcMatchers;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
* @param context the {@link ApplicationContext} to use
|
||||
* @param mvcMatchers the {@link MvcRequestMatcher} instances to set the servlet
|
||||
* path on if {@link #servletPath(String)} is set.
|
||||
* @param allMatchers the {@link RequestMatcher} instances to continue the
|
||||
* configuration
|
||||
*/
|
||||
private MvcMatchersRequestMatcherConfigurer(ApplicationContext context, List<MvcRequestMatcher> mvcMatchers,
|
||||
List<RequestMatcher> allMatchers) {
|
||||
super(context);
|
||||
this.mvcMatchers = new ArrayList<>(mvcMatchers);
|
||||
this.matchers = allMatchers;
|
||||
}
|
||||
|
||||
public RequestMatcherConfigurer servletPath(String servletPath) {
|
||||
for (MvcRequestMatcher matcher : this.mvcMatchers) {
|
||||
matcher.setServletPath(servletPath);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows mapping HTTP requests that this {@link HttpSecurity} will be used for
|
||||
*
|
||||
@@ -3824,26 +3432,6 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder<Defaul
|
||||
setApplicationContext(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(HttpMethod, String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersRequestMatcherConfigurer mvcMatchers(HttpMethod method, String... mvcPatterns) {
|
||||
List<MvcRequestMatcher> mvcMatchers = createMvcMatchers(method, mvcPatterns);
|
||||
setMatchers(mvcMatchers);
|
||||
return new MvcMatchersRequestMatcherConfigurer(getContext(), mvcMatchers, this.matchers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersRequestMatcherConfigurer mvcMatchers(String... patterns) {
|
||||
return mvcMatchers(null, patterns);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RequestMatcherConfigurer chainRequestMatchers(List<RequestMatcher> requestMatchers) {
|
||||
setMatchers(requestMatchers);
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.access.PermissionEvaluator;
|
||||
import org.springframework.security.access.expression.SecurityExpressionHandler;
|
||||
import org.springframework.security.access.hierarchicalroles.RoleHierarchy;
|
||||
@@ -58,7 +57,6 @@ import org.springframework.security.web.debug.DebugFilter;
|
||||
import org.springframework.security.web.firewall.HttpFirewall;
|
||||
import org.springframework.security.web.firewall.RequestRejectedHandler;
|
||||
import org.springframework.security.web.firewall.StrictHttpFirewall;
|
||||
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.RequestMatcherEntry;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -375,32 +373,6 @@ public final class WebSecurity extends AbstractConfiguredSecurityBuilder<Filter,
|
||||
this.servletContext = servletContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link IgnoredRequestConfigurer} that allows optionally configuring the
|
||||
* {@link MvcRequestMatcher#setMethod(HttpMethod)}
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @deprecated use {@link MvcRequestMatcher.Builder} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public final class MvcMatchersIgnoredRequestConfigurer extends IgnoredRequestConfigurer {
|
||||
|
||||
private final List<MvcRequestMatcher> mvcMatchers;
|
||||
|
||||
private MvcMatchersIgnoredRequestConfigurer(ApplicationContext context, List<MvcRequestMatcher> mvcMatchers) {
|
||||
super(context);
|
||||
this.mvcMatchers = mvcMatchers;
|
||||
}
|
||||
|
||||
public IgnoredRequestConfigurer servletPath(String servletPath) {
|
||||
for (MvcRequestMatcher matcher : this.mvcMatchers) {
|
||||
matcher.setServletPath(servletPath);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows registering {@link RequestMatcher} instances that should be ignored by
|
||||
* Spring Security.
|
||||
@@ -414,26 +386,6 @@ public final class WebSecurity extends AbstractConfiguredSecurityBuilder<Filter,
|
||||
setApplicationContext(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(HttpMethod, String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersIgnoredRequestConfigurer mvcMatchers(HttpMethod method, String... mvcPatterns) {
|
||||
List<MvcRequestMatcher> mvcMatchers = createMvcMatchers(method, mvcPatterns);
|
||||
WebSecurity.this.ignoredRequests.addAll(mvcMatchers);
|
||||
return new MvcMatchersIgnoredRequestConfigurer(getApplicationContext(), mvcMatchers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersIgnoredRequestConfigurer mvcMatchers(String... mvcPatterns) {
|
||||
return mvcMatchers(null, mvcPatterns);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IgnoredRequestConfigurer chainRequestMatchers(List<RequestMatcher> requestMatchers) {
|
||||
WebSecurity.this.ignoredRequests.addAll(requestMatchers);
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||
* <pre>
|
||||
* @Bean
|
||||
* public WebSecurityCustomizer ignoringCustomizer() {
|
||||
* return (web) -> web.ignoring().antMatchers("/ignore1", "/ignore2");
|
||||
* return (web) -> web.ignoring().requestMatchers("/ignore1", "/ignore2");
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.List;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.authorization.AuthenticatedAuthorizationManager;
|
||||
import org.springframework.security.authorization.AuthorityAuthorizationManager;
|
||||
import org.springframework.security.authorization.AuthorizationDecision;
|
||||
@@ -34,7 +33,6 @@ import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
|
||||
import org.springframework.security.web.access.intercept.AuthorizationFilter;
|
||||
import org.springframework.security.web.access.intercept.RequestAuthorizationContext;
|
||||
import org.springframework.security.web.access.intercept.RequestMatcherDelegatingAuthorizationManager;
|
||||
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.RequestMatcherEntry;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -146,24 +144,6 @@ public final class AuthorizeHttpRequestsConfigurer<H extends HttpSecurityBuilder
|
||||
return postProcess(this.managerBuilder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersAuthorizedUrl mvcMatchers(String... mvcPatterns) {
|
||||
return mvcMatchers(null, mvcPatterns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(HttpMethod, String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersAuthorizedUrl mvcMatchers(HttpMethod method, String... mvcPatterns) {
|
||||
return new MvcMatchersAuthorizedUrl(createMvcMatchers(method, mvcPatterns));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthorizedUrl chainRequestMatchers(List<RequestMatcher> requestMatchers) {
|
||||
this.unmappedMatchers = requestMatchers;
|
||||
@@ -205,35 +185,6 @@ public final class AuthorizeHttpRequestsConfigurer<H extends HttpSecurityBuilder
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link AuthorizeHttpRequestsConfigurer.AuthorizedUrl} that allows optionally
|
||||
* configuring the {@link MvcRequestMatcher#setServletPath(String)}.
|
||||
*
|
||||
* @author Evgeniy Cheban
|
||||
* @deprecated use {@link MvcRequestMatcher.Builder} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public final class MvcMatchersAuthorizedUrl extends AuthorizedUrl {
|
||||
|
||||
private MvcMatchersAuthorizedUrl(List<MvcRequestMatcher> matchers) {
|
||||
super(matchers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures <code>servletPath</code> to {@link MvcRequestMatcher}s.
|
||||
* @param servletPath the servlet path
|
||||
* @return the {@link MvcMatchersAuthorizedUrl} for further customizations
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public MvcMatchersAuthorizedUrl servletPath(String servletPath) {
|
||||
for (MvcRequestMatcher matcher : (List<MvcRequestMatcher>) getMatchers()) {
|
||||
matcher.setServletPath(servletPath);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An object that allows configuring the {@link AuthorizationManager} for
|
||||
* {@link RequestMatcher}s.
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.access.ConfigAttribute;
|
||||
import org.springframework.security.access.SecurityConfig;
|
||||
import org.springframework.security.config.annotation.ObjectPostProcessor;
|
||||
@@ -41,7 +40,6 @@ import org.springframework.security.web.access.channel.RetryWithHttpEntryPoint;
|
||||
import org.springframework.security.web.access.channel.RetryWithHttpsEntryPoint;
|
||||
import org.springframework.security.web.access.channel.SecureChannelProcessor;
|
||||
import org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource;
|
||||
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||
|
||||
/**
|
||||
@@ -155,25 +153,6 @@ public final class ChannelSecurityConfigurer<H extends HttpSecurityBuilder<H>>
|
||||
setApplicationContext(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(HttpMethod, String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersRequiresChannelUrl mvcMatchers(HttpMethod method, String... mvcPatterns) {
|
||||
List<MvcRequestMatcher> mvcMatchers = createMvcMatchers(method, mvcPatterns);
|
||||
return new MvcMatchersRequiresChannelUrl(mvcMatchers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersRequiresChannelUrl mvcMatchers(String... patterns) {
|
||||
return mvcMatchers(null, patterns);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RequiresChannelUrl chainRequestMatchersInternal(List<RequestMatcher> requestMatchers) {
|
||||
return new RequiresChannelUrl(requestMatchers);
|
||||
@@ -222,21 +201,6 @@ public final class ChannelSecurityConfigurer<H extends HttpSecurityBuilder<H>>
|
||||
|
||||
}
|
||||
|
||||
public final class MvcMatchersRequiresChannelUrl extends RequiresChannelUrl {
|
||||
|
||||
private MvcMatchersRequiresChannelUrl(List<MvcRequestMatcher> matchers) {
|
||||
super(matchers);
|
||||
}
|
||||
|
||||
public RequiresChannelUrl servletPath(String servletPath) {
|
||||
for (RequestMatcher matcher : this.requestMatchers) {
|
||||
((MvcRequestMatcher) matcher).setServletPath(servletPath);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class RequiresChannelUrl {
|
||||
|
||||
protected List<? extends RequestMatcher> requestMatchers;
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.List;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.config.annotation.web.AbstractRequestMatcherRegistry;
|
||||
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
|
||||
@@ -40,7 +39,6 @@ import org.springframework.security.web.csrf.CsrfTokenRequestHandler;
|
||||
import org.springframework.security.web.csrf.HttpSessionCsrfTokenRepository;
|
||||
import org.springframework.security.web.csrf.LazyCsrfTokenRepository;
|
||||
import org.springframework.security.web.csrf.MissingCsrfTokenException;
|
||||
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
|
||||
import org.springframework.security.web.session.InvalidSessionAccessDeniedHandler;
|
||||
import org.springframework.security.web.session.InvalidSessionStrategy;
|
||||
import org.springframework.security.web.util.matcher.AndRequestMatcher;
|
||||
@@ -139,37 +137,6 @@ public final class CsrfConfigurer<H extends HttpSecurityBuilder<H>>
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Allows specifying {@link HttpServletRequest} that should not use CSRF Protection
|
||||
* even if they match the {@link #requireCsrfProtectionMatcher(RequestMatcher)}.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* For example, the following configuration will ensure CSRF protection ignores:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>Any GET, HEAD, TRACE, OPTIONS (this is the default)</li>
|
||||
* <li>We also explicitly state to ignore any request that starts with "/sockjs/"</li>
|
||||
* </ul>
|
||||
*
|
||||
* <pre>
|
||||
* http
|
||||
* .csrf()
|
||||
* .ignoringAntMatchers("/sockjs/**")
|
||||
* .and()
|
||||
* ...
|
||||
* </pre>
|
||||
*
|
||||
* @since 4.0
|
||||
* @deprecated use {@link #ignoringRequestMatchers(RequestMatcher...)} with an
|
||||
* {@link org.springframework.security.web.util.matcher.AntPathRequestMatcher} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public CsrfConfigurer<H> ignoringAntMatchers(String... antPatterns) {
|
||||
return new IgnoreCsrfProtectionRegistry(this.context).antMatchers(antPatterns).and();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Allows specifying {@link HttpServletRequest}s that should not use CSRF Protection
|
||||
@@ -378,26 +345,6 @@ public final class CsrfConfigurer<H extends HttpSecurityBuilder<H>>
|
||||
setApplicationContext(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(HttpMethod, String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersIgnoreCsrfProtectionRegistry mvcMatchers(HttpMethod method, String... mvcPatterns) {
|
||||
List<MvcRequestMatcher> mvcMatchers = createMvcMatchers(method, mvcPatterns);
|
||||
CsrfConfigurer.this.ignoredCsrfProtectionMatchers.addAll(mvcMatchers);
|
||||
return new MvcMatchersIgnoreCsrfProtectionRegistry(getApplicationContext(), mvcMatchers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersIgnoreCsrfProtectionRegistry mvcMatchers(String... mvcPatterns) {
|
||||
return mvcMatchers(null, mvcPatterns);
|
||||
}
|
||||
|
||||
CsrfConfigurer<H> and() {
|
||||
return CsrfConfigurer.this;
|
||||
}
|
||||
@@ -410,29 +357,4 @@ public final class CsrfConfigurer<H extends HttpSecurityBuilder<H>>
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link IgnoreCsrfProtectionRegistry} that allows optionally configuring the
|
||||
* {@link MvcRequestMatcher#setMethod(HttpMethod)}
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
private final class MvcMatchersIgnoreCsrfProtectionRegistry extends IgnoreCsrfProtectionRegistry {
|
||||
|
||||
private final List<MvcRequestMatcher> mvcMatchers;
|
||||
|
||||
private MvcMatchersIgnoreCsrfProtectionRegistry(ApplicationContext context,
|
||||
List<MvcRequestMatcher> mvcMatchers) {
|
||||
super(context);
|
||||
this.mvcMatchers = mvcMatchers;
|
||||
}
|
||||
|
||||
IgnoreCsrfProtectionRegistry servletPath(String servletPath) {
|
||||
for (MvcRequestMatcher matcher : this.mvcMatchers) {
|
||||
matcher.setServletPath(servletPath);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.access.AccessDecisionVoter;
|
||||
import org.springframework.security.access.ConfigAttribute;
|
||||
import org.springframework.security.access.PermissionEvaluator;
|
||||
@@ -38,7 +37,6 @@ import org.springframework.security.web.FilterInvocation;
|
||||
import org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler;
|
||||
import org.springframework.security.web.access.expression.ExpressionBasedFilterInvocationSecurityMetadataSource;
|
||||
import org.springframework.security.web.access.expression.WebExpressionVoter;
|
||||
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -222,24 +220,6 @@ public final class ExpressionUrlAuthorizationConfigurer<H extends HttpSecurityBu
|
||||
setApplicationContext(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(HttpMethod, String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersAuthorizedUrl mvcMatchers(HttpMethod method, String... mvcPatterns) {
|
||||
return new MvcMatchersAuthorizedUrl(createMvcMatchers(method, mvcPatterns));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersAuthorizedUrl mvcMatchers(String... patterns) {
|
||||
return mvcMatchers(null, patterns);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AuthorizedUrl chainRequestMatchersInternal(List<RequestMatcher> requestMatchers) {
|
||||
return new AuthorizedUrl(requestMatchers);
|
||||
@@ -275,31 +255,6 @@ public final class ExpressionUrlAuthorizationConfigurer<H extends HttpSecurityBu
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link AuthorizedUrl} that allows optionally configuring the
|
||||
* {@link MvcRequestMatcher#setMethod(HttpMethod)}
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
public final class MvcMatchersAuthorizedUrl extends AuthorizedUrl {
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
* @param requestMatchers the {@link RequestMatcher} instances to map
|
||||
*/
|
||||
private MvcMatchersAuthorizedUrl(List<MvcRequestMatcher> requestMatchers) {
|
||||
super(requestMatchers);
|
||||
}
|
||||
|
||||
public AuthorizedUrl servletPath(String servletPath) {
|
||||
for (MvcRequestMatcher matcher : (List<MvcRequestMatcher>) getMatchers()) {
|
||||
matcher.setServletPath(servletPath);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class AuthorizedUrl {
|
||||
|
||||
private List<? extends RequestMatcher> requestMatchers;
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.springframework.security.config.annotation.ObjectPostProcessor;
|
||||
import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
|
||||
import org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource;
|
||||
import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
|
||||
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -51,8 +50,8 @@ import org.springframework.util.Assert;
|
||||
* <pre>
|
||||
* protected void configure(HttpSecurity http) throws Exception {
|
||||
* http.apply(new UrlAuthorizationConfigurer<HttpSecurity>()).getRegistry()
|
||||
* .antMatchers("/users**", "/sessions/**").hasRole("USER")
|
||||
* .antMatchers("/signup").hasRole("ANONYMOUS").anyRequest().hasRole("USER");
|
||||
* .requestMatchers("/users**", "/sessions/**").hasRole("USER")
|
||||
* .requestMatchers("/signup").hasRole("ANONYMOUS").anyRequest().hasRole("USER");
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
@@ -202,22 +201,24 @@ public final class UrlAuthorizationConfigurer<H extends HttpSecurityBuilder<H>>
|
||||
setApplicationContext(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(HttpMethod, String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersAuthorizedUrl mvcMatchers(HttpMethod method, String... mvcPatterns) {
|
||||
return new MvcMatchersAuthorizedUrl(createMvcMatchers(method, mvcPatterns));
|
||||
public AuthorizedUrl requestMatchers(String... patterns) {
|
||||
return super.requestMatchers(patterns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #requestMatchers(String...)} instead
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public MvcMatchersAuthorizedUrl mvcMatchers(String... patterns) {
|
||||
return mvcMatchers(null, patterns);
|
||||
public AuthorizedUrl requestMatchers(HttpMethod method, String... patterns) {
|
||||
return super.requestMatchers(method, patterns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthorizedUrl requestMatchers(HttpMethod method) {
|
||||
return super.requestMatchers(method);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthorizedUrl requestMatchers(RequestMatcher... requestMatchers) {
|
||||
return super.requestMatchers(requestMatchers);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -242,32 +243,6 @@ public final class UrlAuthorizationConfigurer<H extends HttpSecurityBuilder<H>>
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@link AuthorizedUrl} that allows optionally configuring the
|
||||
* {@link MvcRequestMatcher#setMethod(HttpMethod)}
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
public final class MvcMatchersAuthorizedUrl extends AuthorizedUrl {
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
* @param requestMatchers the {@link RequestMatcher} instances to map
|
||||
*/
|
||||
private MvcMatchersAuthorizedUrl(List<MvcRequestMatcher> requestMatchers) {
|
||||
super(requestMatchers);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public AuthorizedUrl servletPath(String servletPath) {
|
||||
for (MvcRequestMatcher matcher : (List<MvcRequestMatcher>) getMatchers()) {
|
||||
matcher.setServletPath(servletPath);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps the specified {@link RequestMatcher} instances to {@link ConfigAttribute}
|
||||
* instances.
|
||||
|
||||
@@ -26,9 +26,11 @@ import org.springframework.security.config.annotation.web.configurers.AuthorizeH
|
||||
import org.springframework.security.core.Authentication
|
||||
import org.springframework.security.web.access.intercept.AuthorizationFilter
|
||||
import org.springframework.security.web.access.intercept.RequestAuthorizationContext
|
||||
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher
|
||||
import org.springframework.security.web.util.matcher.AnyRequestMatcher
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher
|
||||
import org.springframework.util.ClassUtils
|
||||
import org.springframework.web.servlet.handler.HandlerMappingIntrospector
|
||||
import java.util.function.Supplier
|
||||
|
||||
/**
|
||||
@@ -43,6 +45,7 @@ class AuthorizeHttpRequestsDsl : AbstractRequestMatcherDsl() {
|
||||
|
||||
private val authorizationRules = mutableListOf<AuthorizationManagerRule>()
|
||||
|
||||
private val HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME = "mvcHandlerMappingIntrospector"
|
||||
private val HANDLER_MAPPING_INTROSPECTOR = "org.springframework.web.servlet.handler.HandlerMappingIntrospector"
|
||||
private val MVC_PRESENT = ClassUtils.isPresent(
|
||||
HANDLER_MAPPING_INTROSPECTOR,
|
||||
@@ -244,10 +247,15 @@ class AuthorizeHttpRequestsDsl : AbstractRequestMatcherDsl() {
|
||||
is MatcherAuthorizationManagerRule -> requests.requestMatchers(rule.matcher).access(rule.rule)
|
||||
is PatternAuthorizationManagerRule -> {
|
||||
when (rule.patternType) {
|
||||
PatternType.ANT -> requests.antMatchers(rule.httpMethod, rule.pattern).access(rule.rule)
|
||||
PatternType.MVC -> requests.mvcMatchers(rule.httpMethod, rule.pattern)
|
||||
.apply { if (rule.servletPath != null) servletPath(rule.servletPath) }
|
||||
.access(rule.rule)
|
||||
PatternType.ANT -> requests.requestMatchers(rule.httpMethod, rule.pattern).access(rule.rule)
|
||||
PatternType.MVC -> {
|
||||
val introspector = requests.applicationContext.getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, HandlerMappingIntrospector::class.java)
|
||||
val mvcMatcher = MvcRequestMatcher.Builder(introspector)
|
||||
.servletPath(rule.servletPath)
|
||||
.pattern(rule.pattern)
|
||||
mvcMatcher.setMethod(rule.httpMethod)
|
||||
requests.requestMatchers(mvcMatcher).access(rule.rule)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,11 @@ package org.springframework.security.config.annotation.web
|
||||
import org.springframework.http.HttpMethod
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
||||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer
|
||||
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher
|
||||
import org.springframework.security.web.util.matcher.AnyRequestMatcher
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher
|
||||
import org.springframework.util.ClassUtils
|
||||
import org.springframework.web.servlet.handler.HandlerMappingIntrospector
|
||||
|
||||
/**
|
||||
* A Kotlin DSL to configure [HttpSecurity] request authorization using idiomatic Kotlin code.
|
||||
@@ -32,6 +34,7 @@ import org.springframework.util.ClassUtils
|
||||
class AuthorizeRequestsDsl : AbstractRequestMatcherDsl() {
|
||||
private val authorizationRules = mutableListOf<AuthorizationRule>()
|
||||
|
||||
private val HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME = "mvcHandlerMappingIntrospector"
|
||||
private val HANDLER_MAPPING_INTROSPECTOR = "org.springframework.web.servlet.handler.HandlerMappingIntrospector"
|
||||
private val MVC_PRESENT = ClassUtils.isPresent(
|
||||
HANDLER_MAPPING_INTROSPECTOR,
|
||||
@@ -224,10 +227,15 @@ class AuthorizeRequestsDsl : AbstractRequestMatcherDsl() {
|
||||
is MatcherAuthorizationRule -> requests.requestMatchers(rule.matcher).access(rule.rule)
|
||||
is PatternAuthorizationRule -> {
|
||||
when (rule.patternType) {
|
||||
PatternType.ANT -> requests.antMatchers(rule.httpMethod, rule.pattern).access(rule.rule)
|
||||
PatternType.MVC -> requests.mvcMatchers(rule.httpMethod, rule.pattern)
|
||||
.apply { if(rule.servletPath != null) servletPath(rule.servletPath) }
|
||||
.access(rule.rule)
|
||||
PatternType.ANT -> requests.requestMatchers(rule.httpMethod, rule.pattern).access(rule.rule)
|
||||
PatternType.MVC -> {
|
||||
val introspector = requests.applicationContext.getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, HandlerMappingIntrospector::class.java)
|
||||
val mvcMatcher = MvcRequestMatcher.Builder(introspector)
|
||||
.servletPath(rule.servletPath)
|
||||
.pattern(rule.pattern)
|
||||
mvcMatcher.setMethod(rule.httpMethod)
|
||||
requests.requestMatchers(mvcMatcher).access(rule.rule)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.springframework.security.config.annotation.web
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
||||
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer
|
||||
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy
|
||||
import org.springframework.security.web.csrf.CsrfTokenRepository
|
||||
import org.springframework.security.web.csrf.CsrfTokenRequestHandler
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
|
||||
/**
|
||||
* A Kotlin DSL to configure [HttpSecurity] CSRF protection
|
||||
@@ -42,23 +42,10 @@ class CsrfDsl {
|
||||
var sessionAuthenticationStrategy: SessionAuthenticationStrategy? = null
|
||||
var csrfTokenRequestHandler: CsrfTokenRequestHandler? = null
|
||||
|
||||
private var ignoringAntMatchers: Array<out String>? = null
|
||||
private var ignoringRequestMatchers: Array<out RequestMatcher>? = null
|
||||
private var ignoringRequestMatchersPatterns: Array<out String>? = null
|
||||
private var disabled = false
|
||||
|
||||
/**
|
||||
* Allows specifying [HttpServletRequest]s that should not use CSRF Protection
|
||||
* even if they match the [requireCsrfProtectionMatcher].
|
||||
*
|
||||
* @param antMatchers the ANT pattern matchers that should not use CSRF
|
||||
* protection
|
||||
*/
|
||||
@Deprecated("Use ignoringRequestMatchers instead")
|
||||
fun ignoringAntMatchers(vararg antMatchers: String) {
|
||||
ignoringAntMatchers = antMatchers
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows specifying [HttpServletRequest]s that should not use CSRF Protection
|
||||
* even if they match the [requireCsrfProtectionMatcher].
|
||||
@@ -93,7 +80,6 @@ class CsrfDsl {
|
||||
requireCsrfProtectionMatcher?.also { csrf.requireCsrfProtectionMatcher(requireCsrfProtectionMatcher) }
|
||||
sessionAuthenticationStrategy?.also { csrf.sessionAuthenticationStrategy(sessionAuthenticationStrategy) }
|
||||
csrfTokenRequestHandler?.also { csrf.csrfTokenRequestHandler(csrfTokenRequestHandler) }
|
||||
ignoringAntMatchers?.also { csrf.ignoringAntMatchers(*ignoringAntMatchers!!) }
|
||||
ignoringRequestMatchers?.also { csrf.ignoringRequestMatchers(*ignoringRequestMatchers!!) }
|
||||
ignoringRequestMatchersPatterns?.also { csrf.ignoringRequestMatchers(*ignoringRequestMatchersPatterns!!) }
|
||||
if (disabled) {
|
||||
|
||||
@@ -137,18 +137,8 @@ class HttpSecurityDsl(private val http: HttpSecurity, private val init: HttpSecu
|
||||
* configuration should be invoked.
|
||||
*/
|
||||
fun securityMatcher(vararg pattern: String) {
|
||||
val mvcPresent = ClassUtils.isPresent(
|
||||
HANDLER_MAPPING_INTROSPECTOR,
|
||||
AuthorizeRequestsDsl::class.java.classLoader) ||
|
||||
ClassUtils.isPresent(
|
||||
HANDLER_MAPPING_INTROSPECTOR,
|
||||
AuthorizeHttpRequestsDsl::class.java.classLoader)
|
||||
this.http.requestMatchers {
|
||||
if (mvcPresent) {
|
||||
it.mvcMatchers(*pattern)
|
||||
} else {
|
||||
it.antMatchers(*pattern)
|
||||
}
|
||||
this.http.securityMatchers {
|
||||
it.requestMatchers(*pattern)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +170,7 @@ class HttpSecurityDsl(private val http: HttpSecurity, private val init: HttpSecu
|
||||
* this configuration should be invoked.
|
||||
*/
|
||||
fun securityMatcher(vararg requestMatcher: RequestMatcher) {
|
||||
this.http.requestMatchers {
|
||||
this.http.securityMatchers {
|
||||
it.requestMatchers(*requestMatcher)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,11 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
||||
import org.springframework.security.config.annotation.web.configurers.ChannelSecurityConfigurer
|
||||
import org.springframework.security.web.access.channel.ChannelDecisionManagerImpl
|
||||
import org.springframework.security.web.access.channel.ChannelProcessor
|
||||
import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher
|
||||
import org.springframework.security.web.util.matcher.AnyRequestMatcher
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher
|
||||
import org.springframework.util.ClassUtils
|
||||
import org.springframework.web.servlet.handler.HandlerMappingIntrospector
|
||||
|
||||
/**
|
||||
* A Kotlin DSL to configure [HttpSecurity] channel security using idiomatic
|
||||
@@ -36,6 +38,7 @@ import org.springframework.util.ClassUtils
|
||||
class RequiresChannelDsl : AbstractRequestMatcherDsl() {
|
||||
private val channelSecurityRules = mutableListOf<AuthorizationRule>()
|
||||
|
||||
private val HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME = "mvcHandlerMappingIntrospector"
|
||||
private val HANDLER_MAPPING_INTROSPECTOR = "org.springframework.web.servlet.handler.HandlerMappingIntrospector"
|
||||
private val MVC_PRESENT = ClassUtils.isPresent(
|
||||
HANDLER_MAPPING_INTROSPECTOR,
|
||||
@@ -119,11 +122,14 @@ class RequiresChannelDsl : AbstractRequestMatcherDsl() {
|
||||
is MatcherAuthorizationRule -> channelSecurity.requestMatchers(rule.matcher).requires(rule.rule)
|
||||
is PatternAuthorizationRule -> {
|
||||
when (rule.patternType) {
|
||||
PatternType.ANT -> channelSecurity.antMatchers(rule.pattern).requires(rule.rule)
|
||||
PatternType.ANT -> channelSecurity.requestMatchers(rule.pattern).requires(rule.rule)
|
||||
PatternType.MVC -> {
|
||||
val mvcMatchersRequiresChannel = channelSecurity.mvcMatchers(rule.pattern)
|
||||
rule.servletPath?.also { mvcMatchersRequiresChannel.servletPath(rule.servletPath) }
|
||||
mvcMatchersRequiresChannel.requires(rule.rule)
|
||||
val introspector = channelSecurity.applicationContext.getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, HandlerMappingIntrospector::class.java)
|
||||
val mvcMatcher = MvcRequestMatcher.Builder(introspector)
|
||||
.servletPath(rule.servletPath)
|
||||
.pattern(rule.pattern)
|
||||
mvcMatcher.setMethod(rule.httpMethod)
|
||||
channelSecurity.requestMatchers(mvcMatcher).requires(rule.rule)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user