使用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行开始更改了以下内容,则可能对您有用:
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.parentAuthenticationManager(authenticationManager)
.userDetailsService(userDetailsService);
}
您当然也需要@Autowired Users userDetailsService;
在WebSecurityConfigurerAdapter
我想提及的其他事项: