我是Spring的新手,并且我正在使用Spring Security开发Spring Boot REST,目前我实现了JWT令牌。 我有一些问题,但似乎找不到答案。 我尝试添加刷新令牌。
起初,我以为我会将其与用户一起存储在数据库中,但是Spring Security会自动执行所有操作,而且我似乎找不到如何在表用户的给定字段中存储它。
因此,继续前进,我决定我将尝试使用Spring Security自动化,并将刷新令牌过期时间设置为10秒以测试它是否过期,但可惜的是它无法按预期方式工作-我可以使用刷新令牌的时间长短 并以此生成新令牌。
所以在这里我有两个问题:
1.如何使刷新令牌在给定时间后过期? 这是我的安全配置
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${security.signing-key}")
private String signingKey;
@Value("${security.encoding-strength}")
private Integer encodingStrength;
@Value("${security.security-realm}")
private String securityRealm;
@Autowired
private UserDetailsService userDetailsService;
@Bean
@Override
protected AuthenticationManager authenticationManager() throws Exception {
return super.authenticationManager();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@Bean
public PasswordEncoder passwordEncoder() {
PasswordEncoder encoder = new BCryptPasswordEncoder(