Springboot应用程序正在生成令牌,但没有存储在oauth_access_token表中。在邮递员中生成的令牌是
{
"access_token": "142d60e2-583e-434a-9ae8-9888e6f3d595",
"token_type": "bearer",
"refresh_token": "d5f96a96-0103-4a59-9908-a1ac6384fb51",
"expires_in": 7712,
"scope": "read write"
}
在数据库中,它存储为:
Token_Id| Token| Authentication_Id| User_Name| Client_Id| Authentication| Refresh_Token
c720d0e2630b1b43d00bd1dc83277e23| [B@6edfa9ca| d557e74143287f87984f133c7409755d| admin| spring-security-oauth2-read-write-client| [B@1d2745a2| 05fee5dab25b6a76202a76a74902df1e
它在我的控制台中没有显示任何警告/错误。下面是我的Springboot Security中的代码:
@Configuration
@EnableAuthorizationServer
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Import(ServerSecurityConfig.class)
public class AuthServerOAuth2Config extends AuthorizationServerConfigurerAdapter {
@Autowired
@Qualifier("dataSource")
private DataSource dataSource;
@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private UserDetailsService userDetailsService;
@Autowired
private PasswordEncoder oauthClientPasswordEncoder;
@Bean
public TokenStore tokenStore() {
return new JdbcTokenStore(dataSource);
}
@Bean
public OAuth2AccessDeniedHandler oauthAccessDeniedHandler() {
return new OAuth2AccessDeniedHandler();
}
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) {
oauthServer.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()")
.passwordEncoder(oauthClientPasswordEncoder);
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.jdbc(dataSource);
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
endpoints.tokenStore(tokenStore()).authenticationManager(authenticationManager)
.userDetailsService(userDetailsService);
}
}
@Configuration
@EnableWebSecurity
@Order(1)
@Import(Encoders.class)
public class ServerSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Autowired
private PasswordEncoder userPasswordEncoder;
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(userPasswordEncoder);
}
}
我按照Spring JdbcTokenStore doesn't store/ create tokens. (Failed to fetch token)修改了代码,但仍然无法存储在oauth_access_token表中生成的令牌