concept regex matcher in category spring
appears as: regex matchers, regex matcher

This is an excerpt from Manning's book Spring Security in Action.
The two methods that you can use to use regex matchers are:
Back to our regex matchers example (ssia-ch8-ex6), when you need to write a more complex rule, eventually referring more path patterns a multiple path variable values, you could easier write a regex matcher. In listing 8.16, you find the definition for the configuration class, which uses a regex matcher to solve the requirement given for the /video/{country}/{language} path. We also add two users with different authorities to test the implementation.
Listing 8.16 The configuration class using a regex matcher
@Configuration public class ProjectConfig extends WebSecurityConfigurerAdapter { @Bean public UserDetailsService userDetailsService() { var uds = new InMemoryUserDetailsManager(); var u1 = User.withUsername("john") .password("12345") .authorities("read") .build(); var u2 = User.withUsername("jane") .password("12345") .authorities("read", "premium") .build(); uds.createUser(u1); uds.createUser(u2); return uds; } @Bean public PasswordEncoder passwordEncoder() { return NoOpPasswordEncoder.getInstance(); } @Override protected void configure(HttpSecurity http) throws Exception { http.httpBasic(); http.authorizeRequests() #A .regexMatchers(".*/[us|uk|ca]+/[en|fr].*") .authenticated() .anyRequest() .hasAuthority("premium"); #B } }