Reputation: 472
I have extended WebSecurityConfigurerAdapter
to configure custom authentication and authorization. I have introduced a new API say, "/v1/api". My requirement is as follows,
How would my configuration look like?
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/v1/api**").hasAuthority("ROLE_API");
The above code achieves the 1 purpose, how do I block person with this role to hit any other API?
Upvotes: 0
Views: 144
Reputation: 21923
You can use the following Java Configuration.
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/v1/api**").hasAuthority("ROLE_API")
.and().authorizeRequests()
.antMatchers("/**").not().hasAuthority("ROLE_API");
Upvotes: 1