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; } /**