Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring security: @EnableResourceServer vs oauth2ResourceServer()

What is the difference between using @EnableResourceServer and using HttpSecurity.oauth2ResourceServer()? Why should I use one or the other?

like image 376
adrhc Avatar asked Jan 02 '23 05:01

adrhc


1 Answers

@EnableResourceServer is an annotation from the Spring Security OAuth project that is being replaced by new OAuth features in Spring Security 5. In essence, it loads ResourceServerConfiguration, which extends WebSecurityConfigurerAdapter and configures it, creating a filter chain that gives your application resource server functionality. Check out the docs or its source code for more info.

http.oauth2ResourceServer() is in the current Spring Security 5 reference and is the way to go. It creates a BearerTokenAuthenticationFilter that intercepts requests, extracts any Bearer Tokens and attempts to authenticate. For more details, check out the source code for the filter or for the configurer that creates the filter.

like image 103
NatFar Avatar answered May 19 '23 10:05

NatFar