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>
|
||||
<velocity.version>2.3</velocity.version>
|
||||
<fastjson.version>1.2.79</fastjson.version>
|
||||
<jjwt.version>0.9.1</jjwt.version>
|
||||
<minio.version>8.2.2</minio.version>
|
||||
<poi.version>4.1.2</poi.version>
|
||||
<common-pool.version>2.10.0</common-pool.version>
|
||||
|
|
@ -198,13 +197,6 @@
|
|||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JWT -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<version>${jjwt.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 线程传递值 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
|
|
|
|||
|
|
@ -81,12 +81,6 @@
|
|||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Jwt -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Jaxb -->
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
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.TokenConstants;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Jwt工具类
|
||||
|
|
@ -25,7 +27,8 @@ public class JwtUtils
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -35,9 +38,10 @@ public class JwtUtils
|
|||
* @param token 令牌
|
||||
* @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)
|
||||
{
|
||||
Claims claims = parseToken(token);
|
||||
JSONObject claims = parseToken(token);
|
||||
return getValue(claims, SecurityConstants.USER_KEY);
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +62,7 @@ public class JwtUtils
|
|||
* @param claims 身份信息
|
||||
* @return 用户ID
|
||||
*/
|
||||
public static String getUserKey(Claims claims)
|
||||
public static String getUserKey(JSONObject claims)
|
||||
{
|
||||
return getValue(claims, SecurityConstants.USER_KEY);
|
||||
}
|
||||
|
|
@ -71,7 +75,7 @@ public class JwtUtils
|
|||
*/
|
||||
public static String getUserId(String token)
|
||||
{
|
||||
Claims claims = parseToken(token);
|
||||
JSONObject claims = parseToken(token);
|
||||
return getValue(claims, SecurityConstants.DETAILS_USER_ID);
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +85,7 @@ public class JwtUtils
|
|||
* @param claims 身份信息
|
||||
* @return 用户ID
|
||||
*/
|
||||
public static String getUserId(Claims claims)
|
||||
public static String getUserId(JSONObject claims)
|
||||
{
|
||||
return getValue(claims, SecurityConstants.DETAILS_USER_ID);
|
||||
}
|
||||
|
|
@ -94,7 +98,7 @@ public class JwtUtils
|
|||
*/
|
||||
public static String getUserName(String token)
|
||||
{
|
||||
Claims claims = parseToken(token);
|
||||
JSONObject claims = parseToken(token);
|
||||
return getValue(claims, SecurityConstants.DETAILS_USERNAME);
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +108,7 @@ public class JwtUtils
|
|||
* @param claims 身份信息
|
||||
* @return 用户名
|
||||
*/
|
||||
public static String getUserName(Claims claims)
|
||||
public static String getUserName(JSONObject claims)
|
||||
{
|
||||
return getValue(claims, SecurityConstants.DETAILS_USERNAME);
|
||||
}
|
||||
|
|
@ -116,7 +120,7 @@ public class JwtUtils
|
|||
* @param key 键
|
||||
* @return 值
|
||||
*/
|
||||
public static String getValue(Claims claims, String key)
|
||||
public static String getValue(JSONObject claims, String key)
|
||||
{
|
||||
return Convert.toStr(claims.get(key), "");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.gateway.filter;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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.redis.service.RedisService;
|
||||
import com.ruoyi.gateway.config.properties.IgnoreWhiteProperties;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
|
|
@ -56,7 +56,7 @@ public class AuthFilter implements GlobalFilter, Ordered
|
|||
{
|
||||
return unauthorizedResponse(exchange, "令牌不能为空");
|
||||
}
|
||||
Claims claims = JwtUtils.parseToken(token);
|
||||
JSONObject claims = JwtUtils.parseToken(token);
|
||||
if (claims == null)
|
||||
{
|
||||
return unauthorizedResponse(exchange, "令牌已过期或验证不正确!");
|
||||
|
|
|
|||
Loading…
Reference in New Issue