When do we use antMatcher() vs antMatchers()?
For example:
http
.antMatcher("/high_level_url_A/**")
.authorizeRequests()
.antMatchers("/high_level_url_A/sub_level_1").hasRole('USER')
.antMatchers("/high_level_url_A/sub_level_2").hasRole('USER2')
.somethingElse()
.anyRequest().authenticated()
.and()
.antMatcher("/high_level_url_B/**")
.authorizeRequests()
.antMatchers("/high_level_url_B/sub_level_1").permitAll()
.antMatchers("/high_level_url_B/sub_level_2").hasRole('USER3')
.somethingElse()
.anyRequest().authenticated()
.and()
...
What I expect here is,
- Any request matches to
/high_level_url_A/**should be authenticated +/high_level_url_A/sub_level_1only for USER and/high_level_url_A/sub_level_2only for USER2 - Any request matches to
/high_level_url_B/**should be authenticated +/high_level_url_B/sub_level_1for public access and/high_level_url_A/sub_level_2only for USER3. - Any other pattern I don't care - But should be public ?
I have seen latest examples do not include antMatcher() these days. Why is that? Is antMatcher() no longer required?
You need
antMatcherfor multipleHttpSecurity, see Spring Security Reference:In your case you need no
antMatcher, because you have only one configuration. Your modified code: