Reputation: 260
I need an ant matcher for my spring security config. This matcher should match following urls
Now i had this one .antMatchers("/health").permitAll()
but this rejects /contolller/health
Then i tried .antMatchers("/*/health").permitAll()
but this rejects /health
So any suggestions ?
P.S. i'd like to use antMatchers method, not regexMatchers
Upvotes: 0
Views: 1175
Reputation: 571
.antMatchers("/health")
refers only to the specific ant.
You can add "/**".antMatchers("/controller/**")
to refer to all of its subfolders
You can add "**/" before /health .antMatchers("/**/health")
to match "health" directories that are located anywhere or .antMatchers("/**/health/**")
to match all files in "health" directories that are located anywhere
or else write all the specific subfolders .antMatchers("/health", "/contoller/health")
with comma.
Upvotes: 3
Reputation: 511
You can add multiple .antMatchers()
or you can add multiple endpoints in one antmatcher
If you don't filter your .antmatcher()
using .hasRole()
or .hasAuthority()
, you can just use multiple endpoint in one antmatcher
.antMatchers("/health", "/contolller/health").permitAll()
But, if you have .hasRole()
or .hasAuthority()
you can just add multiple antmatchers
.antMatchers("/health").hasRole("ROLE_ADMIN");
.antMatchers("/contolller/health").hasRole("ROLE_EMPLOYEE")
Upvotes: 2