From 563d7bee9571bc805f120f0baf0e5a7b1330ac7b Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Fri, 14 Jan 2022 15:19:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20token=E8=B6=85=E6=97=B6=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/dataease/auth/util/JWTUtils.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/io/dataease/auth/util/JWTUtils.java b/backend/src/main/java/io/dataease/auth/util/JWTUtils.java index 9e27662bf1..28072efd05 100644 --- a/backend/src/main/java/io/dataease/auth/util/JWTUtils.java +++ b/backend/src/main/java/io/dataease/auth/util/JWTUtils.java @@ -17,16 +17,13 @@ import org.springframework.core.env.Environment; import java.util.Date; - public class JWTUtils { - // token过期时间1min (过期会自动刷新续命 目的是避免一直都是同一个token ) private static final long EXPIRE_TIME = 1 * 60 * 1000; // 登录间隔时间10min 超过这个时间强制重新登录 private static long Login_Interval; - /** * 校验token是否正确 * @@ -82,7 +79,8 @@ public class JWTUtils { public static boolean loginExpire(String token) { if (Login_Interval == 0) { // 默认超时时间是8h - int minute = CommonBeanFactory.getBean(Environment.class).getProperty("dataease.login_timeout", Integer.class, 8 * 60); + Long minute = CommonBeanFactory.getBean(Environment.class).getProperty("dataease.login_timeout", Long.class, + 8 * 60L); // 分钟换算成毫秒 Login_Interval = minute * 1000 * 60; } @@ -128,19 +126,19 @@ public class JWTUtils { public static String signLink(String resourceId, Long userId, String secret) { Algorithm algorithm = Algorithm.HMAC256(secret); - if(userId == null){ + if (userId == null) { return JWT.create().withClaim("resourceId", resourceId).sign(algorithm); - }else { + } else { return JWT.create().withClaim("resourceId", resourceId).withClaim("userId", userId).sign(algorithm); } } - public static boolean verifyLink(String token, String resourceId, Long userId, String secret) { + public static boolean verifyLink(String token, String resourceId, Long userId, String secret) { Algorithm algorithm = Algorithm.HMAC256(secret); JWTVerifier verifier; - if(userId == null){ + if (userId == null) { verifier = JWT.require(algorithm).withClaim("resourceId", resourceId).build(); - }else { + } else { verifier = JWT.require(algorithm).withClaim("resourceId", resourceId).withClaim("userId", userId).build(); }