我使用Spring安全性和oauth2,但我有一个问题,我没有找到任何答案,在项目的许多例子中你有2次配置(HttpSecurity http) .
例如https://github.com/spring-projects/spring-security-oauth/blob/master/samples/oauth2/sparklr/src/main/java/org/springframework/security/oauth/examples/sparklr/config/SecurityConfiguration.java
并且
https://github.com/spring-projects/spring-security-oauth/blob/master/samples/oauth2/sparklr/src/main/java/org/springframework/security/oauth/examples/sparklr/config/OAuth2ServerConfig.java
所以我的问题为什么要在WebSecurityConfigurerAdapter或ResourceServerConfigurerAdapter中配置和配置http安全性?
ResourceServerConfigurerAdapter配置用于不同的 endpoints (请参阅antMatchers),而不是WebSecurityConfigurerAdapter .
这两个适配器之间的区别在于,ResourceServerConfigurerAdapter使用特殊的过滤器来检查请求中的承载令牌,以通过OAuth2对请求进行身份验证 .
WebSecurityConfigurerAdapter用于通过会话对用户进行身份验证(在给定示例的情况下,使用表单登录) .
1 回答
ResourceServerConfigurerAdapter配置用于不同的 endpoints (请参阅antMatchers),而不是WebSecurityConfigurerAdapter .
这两个适配器之间的区别在于,ResourceServerConfigurerAdapter使用特殊的过滤器来检查请求中的承载令牌,以通过OAuth2对请求进行身份验证 .
WebSecurityConfigurerAdapter用于通过会话对用户进行身份验证(在给定示例的情况下,使用表单登录) .