admin 管理员组文章数量: 887021
2024年1月17日发(作者:html5网站开发教学视频)
//当前的签名的秘钥 private String secret = "cdd"; //token的有效时间
约25min private Long expiration = 1296000L; public String getUsernameFromToken(String token) { String username; try { final Claims claims = getClaimsFromToken(token); username = ject(); } catch (Exception e) { username = null; } return username; } public Date getCreatDateFromToken(String token) { Date created; try { final Claims claims = getClaimsFromToken(token); created = new Date((Long) (CLAIM_KEY_CREATED)); } catch (Exception e) { created = null; } return created; } //得到token的有效期 private Date getExpirationDateFromToken(String token) { Date expiration; try { final Claims claims = getClaimsFromToken(token); expiration = iration(); } catch (Exception e) { expiration = null; } return expiration; } public String getAudienceFromToken(String token) { String audience; try { final Claims claims = getClaimsFromToken(token); audience = (String) (CLAIM_KEY_AUDIENCE); } catch (Exception e) { audience = null; } return audience; } private Claims getClaimsFromToken(String token) { Claims claims; try { claims = () .setSigningKey(secret) .parseClaimsJws(token) .getBody(); } catch (Exception e) { claims = null; } return claims; } //设置过期时间 private Date generateExpeirationDate() { return new Date(tTimeMillis() + expiration * 1000);
} private Boolean isTokenExpired(String token) { final Date expiration = getExpirationDateFromToken(token); return (new Date()); } private Boolean isCreatedAfterTenMinutes(Date created) { int minutes = (int) ((tTimeMillis() - e()) / (1000 * 60)); if (minutes >= 10) { return true; } return false; } private String generateAudience(Device device) { String audience = AUDIENCE_UNKNOWN; if (al()) { audience = AUDIENCE_WEB; } else if (et()) { audience = AUDIENCE_TABLET; } else if (le()) { audience = AUDIENCE_MOBILE; } return audience; } private Boolean ignoreTokenExpiration(String token) { String audience = getAudienceFromToken(token); return (AUDIENCE_(audience) || AUDIENCE_(audience)); } String generateToken(Map
版权声明:本文标题:Springsecurity集成jwt+redis实现验证码登录注册 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1705496397h487212.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论