update 使用 hutool-jwt 替换 jjwt
parent
8a25343bfe
commit
b59a0c44b5
8
pom.xml
8
pom.xml
|
|
@ -34,7 +34,6 @@
|
||||||
<commons.fileupload.version>1.4</commons.fileupload.version>
|
<commons.fileupload.version>1.4</commons.fileupload.version>
|
||||||
<velocity.version>2.3</velocity.version>
|
<velocity.version>2.3</velocity.version>
|
||||||
<fastjson.version>1.2.79</fastjson.version>
|
<fastjson.version>1.2.79</fastjson.version>
|
||||||
<jjwt.version>0.9.1</jjwt.version>
|
|
||||||
<minio.version>8.2.2</minio.version>
|
<minio.version>8.2.2</minio.version>
|
||||||
<poi.version>4.1.2</poi.version>
|
<poi.version>4.1.2</poi.version>
|
||||||
<common-pool.version>2.10.0</common-pool.version>
|
<common-pool.version>2.10.0</common-pool.version>
|
||||||
|
|
@ -198,13 +197,6 @@
|
||||||
<version>${fastjson.version}</version>
|
<version>${fastjson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- JWT -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.jsonwebtoken</groupId>
|
|
||||||
<artifactId>jjwt</artifactId>
|
|
||||||
<version>${jjwt.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- 线程传递值 -->
|
<!-- 线程传递值 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
|
|
|
||||||
|
|
@ -81,12 +81,6 @@
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Jwt -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.jsonwebtoken</groupId>
|
|
||||||
<artifactId>jjwt</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Jaxb -->
|
<!-- Jaxb -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.xml.bind</groupId>
|
<groupId>javax.xml.bind</groupId>
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
package com.ruoyi.common.core.utils;
|
package com.ruoyi.common.core.utils;
|
||||||
|
|
||||||
import java.util.Map;
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.jwt.JWTUtil;
|
||||||
|
import cn.hutool.jwt.signers.JWTSigner;
|
||||||
|
import cn.hutool.jwt.signers.JWTSignerUtil;
|
||||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||||
import com.ruoyi.common.core.constant.TokenConstants;
|
import com.ruoyi.common.core.constant.TokenConstants;
|
||||||
import com.ruoyi.common.core.text.Convert;
|
import com.ruoyi.common.core.text.Convert;
|
||||||
import io.jsonwebtoken.Claims;
|
|
||||||
import io.jsonwebtoken.Jwts;
|
import java.util.Map;
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Jwt工具类
|
* Jwt工具类
|
||||||
|
|
@ -25,7 +27,8 @@ public class JwtUtils
|
||||||
*/
|
*/
|
||||||
public static String createToken(Map<String, Object> claims)
|
public static String createToken(Map<String, Object> claims)
|
||||||
{
|
{
|
||||||
String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact();
|
JWTSigner signer = JWTSignerUtil.hs512(secret.getBytes());
|
||||||
|
String token = JWTUtil.createToken(claims, signer);
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,9 +38,10 @@ public class JwtUtils
|
||||||
* @param token 令牌
|
* @param token 令牌
|
||||||
* @return 数据声明
|
* @return 数据声明
|
||||||
*/
|
*/
|
||||||
public static Claims parseToken(String token)
|
public static JSONObject parseToken(String token)
|
||||||
{
|
{
|
||||||
return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
|
JWTSigner signer = JWTSignerUtil.hs512(secret.getBytes());
|
||||||
|
return JWTUtil.parseToken(token).setSigner(signer).getPayload().getClaimsJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -48,7 +52,7 @@ public class JwtUtils
|
||||||
*/
|
*/
|
||||||
public static String getUserKey(String token)
|
public static String getUserKey(String token)
|
||||||
{
|
{
|
||||||
Claims claims = parseToken(token);
|
JSONObject claims = parseToken(token);
|
||||||
return getValue(claims, SecurityConstants.USER_KEY);
|
return getValue(claims, SecurityConstants.USER_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,7 +62,7 @@ public class JwtUtils
|
||||||
* @param claims 身份信息
|
* @param claims 身份信息
|
||||||
* @return 用户ID
|
* @return 用户ID
|
||||||
*/
|
*/
|
||||||
public static String getUserKey(Claims claims)
|
public static String getUserKey(JSONObject claims)
|
||||||
{
|
{
|
||||||
return getValue(claims, SecurityConstants.USER_KEY);
|
return getValue(claims, SecurityConstants.USER_KEY);
|
||||||
}
|
}
|
||||||
|
|
@ -71,7 +75,7 @@ public class JwtUtils
|
||||||
*/
|
*/
|
||||||
public static String getUserId(String token)
|
public static String getUserId(String token)
|
||||||
{
|
{
|
||||||
Claims claims = parseToken(token);
|
JSONObject claims = parseToken(token);
|
||||||
return getValue(claims, SecurityConstants.DETAILS_USER_ID);
|
return getValue(claims, SecurityConstants.DETAILS_USER_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +85,7 @@ public class JwtUtils
|
||||||
* @param claims 身份信息
|
* @param claims 身份信息
|
||||||
* @return 用户ID
|
* @return 用户ID
|
||||||
*/
|
*/
|
||||||
public static String getUserId(Claims claims)
|
public static String getUserId(JSONObject claims)
|
||||||
{
|
{
|
||||||
return getValue(claims, SecurityConstants.DETAILS_USER_ID);
|
return getValue(claims, SecurityConstants.DETAILS_USER_ID);
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +98,7 @@ public class JwtUtils
|
||||||
*/
|
*/
|
||||||
public static String getUserName(String token)
|
public static String getUserName(String token)
|
||||||
{
|
{
|
||||||
Claims claims = parseToken(token);
|
JSONObject claims = parseToken(token);
|
||||||
return getValue(claims, SecurityConstants.DETAILS_USERNAME);
|
return getValue(claims, SecurityConstants.DETAILS_USERNAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,7 +108,7 @@ public class JwtUtils
|
||||||
* @param claims 身份信息
|
* @param claims 身份信息
|
||||||
* @return 用户名
|
* @return 用户名
|
||||||
*/
|
*/
|
||||||
public static String getUserName(Claims claims)
|
public static String getUserName(JSONObject claims)
|
||||||
{
|
{
|
||||||
return getValue(claims, SecurityConstants.DETAILS_USERNAME);
|
return getValue(claims, SecurityConstants.DETAILS_USERNAME);
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +120,7 @@ public class JwtUtils
|
||||||
* @param key 键
|
* @param key 键
|
||||||
* @return 值
|
* @return 值
|
||||||
*/
|
*/
|
||||||
public static String getValue(Claims claims, String key)
|
public static String getValue(JSONObject claims, String key)
|
||||||
{
|
{
|
||||||
return Convert.toStr(claims.get(key), "");
|
return Convert.toStr(claims.get(key), "");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ruoyi.gateway.filter;
|
package com.ruoyi.gateway.filter;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
@ -18,7 +19,6 @@ import com.ruoyi.common.core.utils.ServletUtils;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.common.redis.service.RedisService;
|
import com.ruoyi.common.redis.service.RedisService;
|
||||||
import com.ruoyi.gateway.config.properties.IgnoreWhiteProperties;
|
import com.ruoyi.gateway.config.properties.IgnoreWhiteProperties;
|
||||||
import io.jsonwebtoken.Claims;
|
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -56,7 +56,7 @@ public class AuthFilter implements GlobalFilter, Ordered
|
||||||
{
|
{
|
||||||
return unauthorizedResponse(exchange, "令牌不能为空");
|
return unauthorizedResponse(exchange, "令牌不能为空");
|
||||||
}
|
}
|
||||||
Claims claims = JwtUtils.parseToken(token);
|
JSONObject claims = JwtUtils.parseToken(token);
|
||||||
if (claims == null)
|
if (claims == null)
|
||||||
{
|
{
|
||||||
return unauthorizedResponse(exchange, "令牌已过期或验证不正确!");
|
return unauthorizedResponse(exchange, "令牌已过期或验证不正确!");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue