将自定义UserDetailsS​​ervice添加到Spring Security OAuth2应用

将自定义UserDetailsS​​ervice添加到Spring Security OAuth2应用,第1张

将自定义UserDetailsS​​ervice添加到Spring Security OAuth2应用

使用Spring
Security开发我的oauth服务器时遇到了类似的问题。我的情况略有不同,因为我想添加一个

UserDetailsService
以对刷新令牌进行身份验证,但是我认为我的解决方案也会为您提供帮助。

像您一样,我首先尝试

UserDetailsService
使用指定
AuthorizationServerEndpointsConfigurer
,但这是行不通的。我不确定这是错误还是设计使然,但是
UserDetailsService
需要在中设置
AuthenticationManager
以便各种oauth2类找到它。这为我工作:

@Configuration@EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter {  @Autowired  Users userDetailsService;  @Autowired  public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {    auth.userDetailsService(userDetailsService);  }  @Override  protected void configure(HttpSecurity http) throws Exception {    http.authorizeRequests()    // other stuff to configure your security  }}

我认为,如果您从第73行开始更改了以下内容,则可能对您有用:

@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {    auth.parentAuthenticationManager(authenticationManager)        .userDetailsService(userDetailsService);}

您当然也需要

@Autowired Users userDetailsService;
WebSecurityConfigurerAdapter

我想提及的其他事项:

  1. 这可能是特定于版本的,我在spring-security-oauth2 2.0.12上
  2. 我无法引用任何来源说明其原因,我什至不确定我的解决方案是真正的解决方案还是黑客。
  3. GlobalAuthenticationManagerConfigurer
    提到在引导几乎可以肯定是一个错字,我无法找到源代码串的任何地方对任何春。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5641474.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存