In a Spring Security XML configuration file, I have something like
<security:intercept-url pattern="\A/categories/\d+/items/admin\Z" access="ROLE_USER" />
How to handle the regular expression if I convert the above into a Java based configuration?
You have to use regexMatchers
method on HttpSecurity
:
public class SpringSecurity extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.regexMatchers("\A/categories/\d+/items/admin\").hasRole("USER");
}
}