栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将自定义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
    提到在引导几乎可以肯定是一个错字,我无法找到源代码串的任何地方对任何春。


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/635604.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号