当前位置:网站首页>JWT主动校验Token是否过期
JWT主动校验Token是否过期
2022-08-04 17:18:00 【InfoQ】
JWT 组成

JWT 校验原理

主动校验是否过期
/**
* 验证令牌是否过期
*/
public boolean isExpiration(String token) {
try {
Claims claims = parseToken(token);
String userKey = getTokenKey(claims.get(Constants.LOGIN_USER_KEY).toString());
LoginUser loginUser = redisCache.getCacheObject(userKey);
long expireTime = loginUser.getExpireTime();
long currentTime = System.currentTimeMillis();
if (expireTime - currentTime <= 0)
{
return true;
}
} catch (Exception e) {
return true;
}
return false;
}
/**
* 从令牌中获取数据声明
*
* @param token 令牌
* @return 数据声明
*/
private Claims parseToken(String token)
{
return Jwts.parser()
.setSigningKey(secret)
.parseClaimsJws(token)
.getBody();
}
边栏推荐
猜你喜欢
随机推荐
软件基础的理论
WEB 渗透之SSTI 模板注入
mmdetection/mmdetection3d多机多卡训练
R语言计算时间序列数据的逐次差分(successive differences):使用diff函数计算时间序列数据的逐次差分值
arm交叉编译
LeetCode Question of the Day - 1403. Minimum Subsequence in Non-Increasing Order
What does the product system of a digital financial enterprise look like?
化学制品制造业数智化供应链管理系统:打造智慧供应体系,赋能企业产效提升
php如何查询字符串以什么开头
Copycat CNN: Stealing Knowledge by Persuading Confession with Random Non-Labeled Data阅读心得
Understand Chisel language. 32. Chisel advanced hardware generator (1) - parameterization in Chisel
el-date-picker 设置时间范围
全球电子产品需求萎靡:三星越南工厂大幅压缩产能,减少工人工作日
要有遥不可及的梦想,也要有脚踏实地的本事
御神楽的学习记录之基于FPGA的AHT10温湿度数据采集
【 Gazebo introductory tutorial] speak the second model library into robot modeling and visualization (editor) model
RecyclerView 缓存与复用机制
Liunx删除乱码文件
机器学习(十九):梯度提升回归(GBR)
88.(cesium之家)cesium聚合图









