From 72b33cd4bbe7dd279e22369b7e2096a78e216083 Mon Sep 17 00:00:00 2001 From: smallchill Date: Tue, 12 Sep 2023 13:36:26 +0800 Subject: [PATCH] =?UTF-8?q?:tada:=203.7.0.RELEASE=20Token=E5=8A=A0?= =?UTF-8?q?=E5=AF=86=E4=BC=A0=E8=BE=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springblade/gateway/utils/JwtUtil.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/blade-gateway/src/main/java/org/springblade/gateway/utils/JwtUtil.java b/blade-gateway/src/main/java/org/springblade/gateway/utils/JwtUtil.java index e1b0e4e7..70cc2994 100644 --- a/blade-gateway/src/main/java/org/springblade/gateway/utils/JwtUtil.java +++ b/blade-gateway/src/main/java/org/springblade/gateway/utils/JwtUtil.java @@ -55,34 +55,44 @@ public static String getBase64Security() { } /** - * 判断token类型为crypto + * 获取请求传递的token串 * * @param auth token * @return String */ - public static Boolean isCrypto(String auth) { + public static String getToken(String auth) { + if (isBearer(auth) || isCrypto(auth)) { + return auth.substring(AUTH_LENGTH); + } + return null; + } + + /** + * 判断token类型为bearer + * + * @param auth token + * @return String + */ + public static Boolean isBearer(String auth) { if ((auth != null) && (auth.length() > AUTH_LENGTH)) { String headStr = auth.substring(0, 6).toLowerCase(); - return headStr.compareTo(CRYPTO) == 0; + return headStr.compareTo(BEARER) == 0; } return false; } /** - * 获取token串 + * 判断token类型为crypto * * @param auth token * @return String */ - public static String getToken(String auth) { + public static Boolean isCrypto(String auth) { if ((auth != null) && (auth.length() > AUTH_LENGTH)) { String headStr = auth.substring(0, 6).toLowerCase(); - if (headStr.compareTo(BEARER) == 0) { - auth = auth.substring(7); - } - return auth; + return headStr.compareTo(CRYPTO) == 0; } - return null; + return false; } /**