vic
vic

Reputation: 2816

How to put a URL with a regular expression in Spring Java based configuration

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?

Upvotes: 1

Views: 1772

Answers (1)

Jakub Kubrynski
Jakub Kubrynski

Reputation: 14149

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");
    }
}

Upvotes: 2

Related Questions