spring security采用基于持久化 token 的方法实现的remember me功能
2017-03-23 16:51
573 查看
采用该方法相较于简单加密方式安全一些。具体的原理见 http://wiki.jikexueyuan.com/project/spring-security/remember-me.html
一、建立存储token的表persistent_logins
因为我们采用的是JdbcTokenRepositoryImpl,所以表名以及字段采用的都是官方文档中的。
二、修改SecurityConfig配置
三、即可进行测试了
观察数据库,可以发现当使用remember me方式登录以后,token值会被修改
一、建立存储token的表persistent_logins
CREATE TABLE persistent_logins ( username varchar(64) not null, series varchar(64) not null, token varchar(64) not null, last_used timestamp not null, PRIMARY KEY (series) );
因为我们采用的是JdbcTokenRepositoryImpl,所以表名以及字段采用的都是官方文档中的。
二、修改SecurityConfig配置
.and() .rememberMe().tokenRepository(persistentTokenRepository()) .tokenValiditySeconds(1209600);
@Resource private DataSource dataSource;
//如果采用持久化 token 的方法则需要指定保存token的方法 @Bean public PersistentTokenRepository persistentTokenRepository() { JdbcTokenRepositoryImpl db = new JdbcTokenRepositoryImpl(); db.setDataSource(dataSource); return db; }
三、即可进行测试了
观察数据库,可以发现当使用remember me方式登录以后,token值会被修改
相关文章推荐
- spring security采用基于简单加密 token 的方法实现的remember me功能
- jQuery基于排序功能实现上移、下移的方法
- spring security 3.1中基于数据库自定义验证授权功能实现
- 基于Laravel5.4实现多字段登录功能方法示例
- 基于thinkPHP3.2实现微信接入及查询token值的方法
- 在使用 Spring Security 的 Remember Me 记住密码功能时遇到的问题和解决方法
- PHP+Mysql基于事务处理实现转账功能的方法
- essential c++ 基于第二章的内容采用面向过程的方法实现猜字游戏的基本实现代码
- Android开发之图片旋转功能实现方法【基于Matrix】
- 利用php-cli和任务计划实现刷新token功能的方法
- php基于ob_start(ob_gzhandler)实现网页压缩功能的方法
- spring security 3.1中基于数据库自定义验证授权功能实现
- nodejs基于WS模块实现WebSocket聊天功能的方法
- jQuery基于扩展简单实现倒计时功能的方法
- jQuery基于xml格式数据实现模糊查询及分页功能的方法
- php基于ob_start(ob_gzhandler)实现网页压缩功能的方法
- spring security起步五:Remember Me功能实现
- C#基于纯数学方法递归实现货币数字转换中文功能详解
- 微信小程序基于本地缓存实现点赞功能的方法
- Spring Security 中实现 Remember Me 记住密码功能