Spring oauth2 / HttpSecurity http / ResourceServerConfigurer 和 WebSecurityConfigurerAdapter

Spring oauth2 / HttpSecurity http / ResourceServerConfigurer and WebSecurityConfigurerAdapter

我在 oauth2 中使用 Spring 安全性,但我有一个问题,但我没有找到任何答案,在许多项目示例中,您有 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 安全性?

与 WebSecurityConfigurerAdapter 相比,ResourceServerConfigurerAdapter 针对不同的端点(请参阅 antMatchers)进行配置。

这两个适配器之间的区别在于,ResourceServerConfigurerAdapter 使用一个特殊的过滤器来检查请求中的持有者令牌,以通过 OAuth2 对请求进行身份验证。

WebSecurityConfigurerAdapter 用于通过会话对用户进行身份验证(在您给出的示例中是表单登录)。