Spring Security Remember-Me
Posted 阮胜的个人博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Security Remember-Me相关的知识,希望对你有一定的参考价值。
引入POM
<dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>5.0.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>5.0.3.RELEASE</version> </dependency>
html:
<input type="checkbox" name="remember-me" checked value="true">
配置:
@Autowired private DataSource dataSource;
@Autowired private UserDetailService userDetailsService; @Override protected void configure(HttpSecurity http) throws Exception { http.rememberMe() .tokenRepository(persistentTokenRepository()) .userDetailsService(userDetailsService) //token "记住我"功能的token过期时间(秒) .tokenValiditySeconds(3600); }
@Bean public PersistentTokenRepository persistentTokenRepository() { JdbcTokenRepositoryImpl jdbcTokenRepository = new JdbcTokenRepositoryImpl();
//第一次启动的时候需要手动创建Remember-Me的数据库表
//jdbcTokenRepository.setCreateTableOnStartup(true);
jdbcTokenRepository.setDataSource(dataSource);
return jdbcTokenRepository;
}
以上是关于Spring Security Remember-Me的主要内容,如果未能解决你的问题,请参考以下文章
spring security remember me实现自动登录
Spring Security(12)——Remember-Me功能