spring boot security 安全权限 ---4cookie自动登录
spring boot security 安全权限 ---4cookie自动登录
·
1、securityConfig配置

注意如果配置:
.authenticationSuccessHandler(successHandler)
则http.formLogin()这配置
.loginProcessingUrl("/platform/loginForm")与.authenticationSuccessHandler(successHandler)重定向不能一致不然会陷入死循环,这个坑会踩了两个小时
2、持久化数据库存储Token
@Bean
public PersistentTokenRepository persistentTokenRepository(){
JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl();
tokenRepository.setDataSource(dataSource);
// 如果token表不存在,使用下面语句可以初始化该表;若存在,请注释掉这条语句,否则会报错。
//tokenRepository.setCreateTableOnStartup(true);
return tokenRepository;
}
数据库CREATE TABLE `persistent_logins` (
`username` varchar(64) NOT NULL,
`series` varchar(64) NOT NULL,
`token` varchar(64) NOT NULL,
`last_used` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`series`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

更多推荐
所有评论(0)