From 991f319a89fc2d939bfe22117f42fca5cd1b35d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E9=A3=9E=E4=BA=91?= <1941783199@qq.com> Date: Mon, 28 Sep 2020 15:44:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dq-framework-common/dq-framework-common.iml | 164 ++++++++++++++++++ .../com/daqing/framework/util/BasePage.java | 9 + dq-govern-gateway/pom.xml | 23 +-- .../gateway/config/ApiGlobalFilter.java | 3 +- .../financial/gateway/util/JwtUtil.java | 142 +++++++-------- 5 files changed, 246 insertions(+), 95 deletions(-) create mode 100644 dq-framework-common/dq-framework-common.iml create mode 100644 dq-framework-common/src/main/java/com/daqing/framework/util/BasePage.java diff --git a/dq-framework-common/dq-framework-common.iml b/dq-framework-common/dq-framework-common.iml new file mode 100644 index 00000000..f683c485 --- /dev/null +++ b/dq-framework-common/dq-framework-common.iml @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dq-framework-common/src/main/java/com/daqing/framework/util/BasePage.java b/dq-framework-common/src/main/java/com/daqing/framework/util/BasePage.java new file mode 100644 index 00000000..ad2d5da3 --- /dev/null +++ b/dq-framework-common/src/main/java/com/daqing/framework/util/BasePage.java @@ -0,0 +1,9 @@ +package com.daqing.framework.util; + +import lombok.Data; +//分页工具类 +@Data +public class BasePage { + private int page = 0; + private int size = 10; +} diff --git a/dq-govern-gateway/pom.xml b/dq-govern-gateway/pom.xml index f34cda2e..1cbbb367 100644 --- a/dq-govern-gateway/pom.xml +++ b/dq-govern-gateway/pom.xml @@ -20,11 +20,6 @@ - org.springframework.cloud @@ -53,27 +48,11 @@ 1.18.12 - - com.auth0 - java-jwt - 3.3.0 - - org.springframework.boot spring-boot-starter-data-redis - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - + diff --git a/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/config/ApiGlobalFilter.java b/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/config/ApiGlobalFilter.java index 27639e65..53ad45d0 100644 --- a/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/config/ApiGlobalFilter.java +++ b/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/config/ApiGlobalFilter.java @@ -1,7 +1,6 @@ package com.daqing.financial.gateway.config; import com.alibaba.fastjson.JSONObject; -import com.daqing.financial.gateway.util.JwtUtil; import com.daqing.financial.gateway.util.RedisUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; @@ -86,7 +85,7 @@ public class ApiGlobalFilter implements GlobalFilter, Ordered { */ private Long verifyJWT(String token){ String id = RedisUtil.get("dq:token:"+token); - return JwtUtil.verifyToken(token); + return Long.parseLong(id); } @Override diff --git a/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/JwtUtil.java b/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/JwtUtil.java index af0d0001..a59c22dd 100644 --- a/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/JwtUtil.java +++ b/dq-govern-gateway/src/main/java/com/daqing/financial/gateway/util/JwtUtil.java @@ -1,71 +1,71 @@ -package com.daqing.financial.gateway.util; - - -import com.auth0.jwt.JWT; -import com.auth0.jwt.algorithms.Algorithm; -import com.daqing.financial.gateway.SpringContextHolder; - -import java.util.Date; -import java.util.Set; - -/** - * @author zcw - * @version 1.0 - * @date 2019/11/23 11:06 - * @description jwt工具类 - */ -public class JwtUtil { - - private final static Algorithm algorithm = SpringContextHolder.getBean("algorithm", Algorithm.class); - - //private final static OdcProperties properties = SpringContextHolder.getBean("odcProperties", OdcProperties.class); - - /** - * 创建token - * - * @param userId; - * @param timeout; 单位是秒 - */ - public static String createJwtToken(Long userId, long timeout) { - return JWT.create() - .withClaim("member", userId) - .withExpiresAt(new Date(System.currentTimeMillis() + timeout * 1000)) - .sign(algorithm); - } - - /** - * token正确且有效,则返回userId - */ - public static Long verifyToken(String token) { - try { - String noBearerToken = token.replaceFirst("Bearer ", ""); - Long userId = JWT.require(algorithm) - .build() - .verify(noBearerToken) - .getClaim("member") - .asLong(); - if (RedisUtil.get(getRedisKey(userId, noBearerToken)) != null) { - return userId; - } - } catch (Exception e) { - e.printStackTrace(); - return null; - } - return null; - } - - public static String getRedisKey(Long userId, String token) { - return String.format("dq:token:%d:%s", userId, token); - } - - public static void putTokenToRedis(Long userId, String token, long times) { - RedisUtil.setEx(getRedisKey(userId, token), "nothing", times); - } - - public static void removeTokenByUserId(Long userId) { - Set tokenSet = RedisUtil.keys(getRedisKey(userId, "*")); - for (String key : tokenSet) { - RedisUtil.del(key); - } - } -} +//package com.daqing.financial.gateway.util; +// +// +//import com.auth0.jwt.JWT; +//import com.auth0.jwt.algorithms.Algorithm; +//import com.daqing.financial.gateway.SpringContextHolder; +// +//import java.util.Date; +//import java.util.Set; +// +///** +// * @author zcw +// * @version 1.0 +// * @date 2019/11/23 11:06 +// * @description jwt工具类 +// */ +//public class JwtUtil { +// +// private final static Algorithm algorithm = SpringContextHolder.getBean("algorithm", Algorithm.class); +// +// //private final static OdcProperties properties = SpringContextHolder.getBean("odcProperties", OdcProperties.class); +// +// /** +// * 创建token +// * +// * @param userId; +// * @param timeout; 单位是秒 +// */ +// public static String createJwtToken(Long userId, long timeout) { +// return JWT.create() +// .withClaim("member", userId) +// .withExpiresAt(new Date(System.currentTimeMillis() + timeout * 1000)) +// .sign(algorithm); +// } +// +// /** +// * token正确且有效,则返回userId +// */ +// public static Long verifyToken(String token) { +// try { +// String noBearerToken = token.replaceFirst("Bearer ", ""); +// Long userId = JWT.require(algorithm) +// .build() +// .verify(noBearerToken) +// .getClaim("member") +// .asLong(); +// if (RedisUtil.get(getRedisKey(userId, noBearerToken)) != null) { +// return userId; +// } +// } catch (Exception e) { +// e.printStackTrace(); +// return null; +// } +// return null; +// } +// +// public static String getRedisKey(Long userId, String token) { +// return String.format("dq:token:%d:%s", userId, token); +// } +// +// public static void putTokenToRedis(Long userId, String token, long times) { +// RedisUtil.setEx(getRedisKey(userId, token), "nothing", times); +// } +// +// public static void removeTokenByUserId(Long userId) { +// Set tokenSet = RedisUtil.keys(getRedisKey(userId, "*")); +// for (String key : tokenSet) { +// RedisUtil.del(key); +// } +// } +//}