mysql设置token有效期_记住我 token保存到数据库
记住我 token保存到数据库
这里使用jpa+mysql
org.springframework.boot
spring-boot-starter-data-jpa
mysql
mysql-connector-java
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/fly-demo?serverTimezone=UTC&useUnicode=yes&characterEncoding=UTF-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
设置配置rememberme
import javax.sql.DataSource;
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthenticationSuccessHandler flyAuthenticationSuccessHandler;
@Autowired
private AuthenticationFailureHandler flyAuthenticationFailureHandler;
@Autowired
private SecurityProperties securityProperties;
@Autowired
private PasswordEncoder passwordEncoder;
@Bean
public PasswordEncoder setPasswordEncoder() {
return new BCryptPasswordEncoder();
}
@Autowired
private DataSource dataSource;
@Bean
public PersistentTokenRepository persistentTokenRepository(){
JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl();
// tokenRepository.setCreateTableOnStartup(true);
tokenRepository.setDataSource(dataSource);
return tokenRepository;
}
@Override
protected void configure(HttpSecurity http) throws Exception {
ValidateCodeFilter codeFilter = new ValidateCodeFilter(flyAuthenticationFailureHandler);
http
.addFilterBefore(codeFilter, UsernamePasswordAuthenticationFilter.class)
.formLogin()
.loginPage("/authentication/request")
.loginProcessingUrl("/authentication/form")
.successHandler(flyAuthenticationSuccessHandler)
.failureHandler(flyAuthenticationFailureHandler)
.and()
.rememberMe()
.tokenRepository(persistentTokenRepository())
.tokenValiditySeconds(securityProperties.getBrowser().getRememberMe())
.userDetailsService(userDetails())
.and()
.authorizeRequests()
.antMatchers("/authentication/request",
securityProperties.getBrowser().getLoginPage(),
"/captcha")
.permitAll()
.anyRequest().authenticated()
.and().csrf().disable();
}
@Bean
public UserDetailsService userDetails(){
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
manager.createUser(User.withUsername("user").password(passwordEncoder.encode("123")).roles("USER").build());
return manager;
}
}
mysql设置token有效期_记住我 token保存到数据库相关推荐
- 小程序token有效期_微信小程序token过期时间后重新获取-微信小程序过期恢复步骤-微信小程序怎么找...
1. 首先先封装个公用的jsclassConfig{constructor(){}}Config.restUrl'https://wx.knowdao.com';export{Config};2. 再 ...
- python token过期_请求时token过期自动刷新token
1.在开发过程中,我们都会接触到token,token的作用是什么呢?主要的作用就是为了安全,用户登陆时,服务器会随机生成一个有时效性的token,用户的每一次请求都需要携带上token,证明其请求的 ...
- java app token 失效_请求时token过期自动刷新token操作
1.在开发过程中,我们都会接触到token,token的作用是什么呢?主要的作用就是为了安全,用户登陆时,服务器会随机生成一个有时效性的token,用户的每一次请求都需要携带上token,证明其请求的 ...
- mysql 游戏服务器设计_游戏服务器之基于文件数据库和mysql数据库的db服务器设计...
设计上: (1)文件数据库是用于处理游戏逻辑业务请求. (2)mysql数据库是用于处理运营后台查询请求. (3)备份业务是用于定时备份文件数据库文件. 本文目录: 1.角色数据更新请求 2.mysq ...
- mysql设置自动递增_《MySQL数据库》约束条件和自增长序列
一.约束(constraint) 约束就是在表上强制执行的一种校验规则,当执行DML操作时,数据必须符合这些规则,如果不符合,将无法执行. 约束的全称:约束条件,也称之为完整性约束条件.可以保证表中数 ...
- mac mysql 设置短命令_短小强大的8个命令,分分钟帮你提高工作效率!
作为一名合格的Linux系统管理员,每天接触使用最多的莫过于Linux 命令了.很多人喜欢Linux,因为Linux 命令短小但却功能强大.在工作中经常使用的命令有很多,对于那些你未使用过的呢? 今天 ...
- mysql设置success信息_【原创】MySQL Cluster安装部署(Success)
参考:http://www.cnblogs.com/zhoulf/archive/2013/01/30/2883207.html 安装要求 安装环境:centos6.3(X64) 软件名称 :mysq ...
- mysql编码丢了_记住:永远不要在 MySQL 中使用 UTF-8
最近我遇到了一个 bug,我试着通过 Rails 在以"utf8"编码的 MariaDB 中保存一个 UTF-8 字符串,然后出现了一个离奇的错误: Incorrect strin ...
- mysql 设置默认值_为什么 Flink 无法实时写入 MySQL?
作者:孙金城 摘要:本文为 Flink 生产环境应用中的疑问剖析,Flink 无法实时写入 MySQL 是初学者常见问题之一,由社区同学罗鹏程提出,Apache Flink PMC 孙金城(金竹)老师 ...
最新文章
- android 获取应用的当前版本号获取当前android系统的版本号
- java接口示例_【基础篇】java-接口及其示例
- 清华大学计算机图形学课程
- mysql设置作业_MySQL-作业1
- postman 请求参数为数组及JsonObject
- 将一个5X5的矩阵中最大的元素放在中心, 4个角分别放4个最小的元素(顺序为从左到右,从上到下,从小到大存放)其余数字从小到大
- centos 等保三级_等保测评三级整改-身份鉴别
- Cocos2d-JS特效
- mysql join联接_MySQL_join连接
- mysql如何设置host_如何快速修改MySQL用户的host属性
- (使用python+adb)能实现王者荣耀自动刷金币?
- halcon算子翻译——cooc_feature_image
- Element UI组件介绍
- 【Java基础】重写equals方法详讲
- Pycharm复制代码时括弧前出现空格
- 【解决方案】SkeyeVSS煤矿安全生产监管视频监控系统,夯实煤矿生产安全防线
- 2021下半年中小学教资考试教育知识与能力试题(中学)——主观题
- 2022-2027年中国降糖药行业市场调研及未来发展趋势预测报告
- 新人 天池大数据初涉水
- 淘宝图片空间的图片可以删除吗?