I am trying to implement Oauth2 in my existing application.Initially I have added spring security and then tried to add oauth2, After adding configuration I am able to gener
Please change the code like below in ResourceServer
:
Have a look at this line:
http.anonymous().disable()
.requestMatchers().antMatchers("/patients/**","/patient/**")
Since "/patient/"**, is not added as part of request matcher, the request is actually was handled by other configuration
package project.configuration;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler;
@Configuration
@EnableResourceServer
public class ResourceServer extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.anonymous().disable()
.requestMatchers().antMatchers("/patients/**","/patient/**").and().
authorizeRequests().antMatchers("*/patient/**").hasRole("USER")
.and().exceptionHandling().accessDeniedHandler(new OAuth2AccessDeniedHandler());
}
}