From efb9b49d5c264604f3dc79e8fd6e9fc9fa4b9f68 Mon Sep 17 00:00:00 2001 From: chenqi Date: Fri, 5 Jun 2026 09:17:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(security):=20=E6=9B=B4=E6=96=B0JWT?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E7=89=88=E6=9C=AC=E5=B9=B6=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E4=BB=A4=E7=89=8C=E6=9C=8D=E5=8A=A1=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将JWT版本从0.9.1升级到0.12.6 - 拆分jjwt依赖为api、impl和jackson三个独立模块 - 使用Keys.hmacShaKeyFor替换SignatureAlgorithm.HS512进行签名 - 使用UTF-8编码处理密钥字符串 - 重构令牌创建和解析方法以适配新版本API - 添加运行时作用域配置以优化依赖加载 --- openhis-server-new/core-common/pom.xml | 16 +++++++++++--- .../framework/web/service/TokenService.java | 7 +++--- openhis-server-new/pom.xml | 22 ++++++++++++++----- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/openhis-server-new/core-common/pom.xml b/openhis-server-new/core-common/pom.xml index baf4d8166..51ebf5eb1 100755 --- a/openhis-server-new/core-common/pom.xml +++ b/openhis-server-new/core-common/pom.xml @@ -1,4 +1,4 @@ - + @@ -142,7 +142,17 @@ io.jsonwebtoken - jjwt + jjwt-api + + + io.jsonwebtoken + jjwt-impl + runtime + + + io.jsonwebtoken + jjwt-jackson + runtime @@ -189,4 +199,4 @@ - \ No newline at end of file + diff --git a/openhis-server-new/core-framework/src/main/java/com/core/framework/web/service/TokenService.java b/openhis-server-new/core-framework/src/main/java/com/core/framework/web/service/TokenService.java index f2d4ae845..fc6b63321 100755 --- a/openhis-server-new/core-framework/src/main/java/com/core/framework/web/service/TokenService.java +++ b/openhis-server-new/core-framework/src/main/java/com/core/framework/web/service/TokenService.java @@ -12,7 +12,8 @@ import com.core.common.utils.uuid.IdUtils; import eu.bitwalker.useragentutils.UserAgent; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.security.Keys; +import java.nio.charset.StandardCharsets; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -154,7 +155,7 @@ public class TokenService { * @return 令牌 */ private String createToken(Map claims) { - String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact(); + String token = Jwts.builder().claims(claims).signWith(Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8)), Jwts.SIG.HS512).compact(); return token; } @@ -165,7 +166,7 @@ public class TokenService { * @return 数据声明 */ private Claims parseToken(String token) { - return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody(); + return Jwts.parser().verifyWith(Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8))).build().parseSignedClaims(token).getPayload(); } /** diff --git a/openhis-server-new/pom.xml b/openhis-server-new/pom.xml index 66bcdcbf5..273c87eb9 100755 --- a/openhis-server-new/pom.xml +++ b/openhis-server-new/pom.xml @@ -1,4 +1,4 @@ - + @@ -35,7 +35,7 @@ 2.21.0 4.1.2 2.3 - 0.9.1 + 0.12.6 1.18.34 3.5.16 @@ -293,13 +293,25 @@ ${velocity.version} + io.jsonwebtoken - jjwt + jjwt-api ${jwt.version} - + + io.jsonwebtoken + jjwt-impl + ${jwt.version} + runtime + + + io.jsonwebtoken + jjwt-jackson + ${jwt.version} + runtime + pro.fessional @@ -414,4 +426,4 @@ - \ No newline at end of file +