mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-30 23:26:41 +08:00
【update】修改jjwt支持jdk11
This commit is contained in:
parent
83718c61cd
commit
9cf335c1cd
14
pom.xml
14
pom.xml
@ -24,7 +24,7 @@
|
||||
<fastjson.version>1.2.76</fastjson.version>
|
||||
<poi.version>4.1.2</poi.version>
|
||||
<velocity.version>1.7</velocity.version>
|
||||
<jwt.version>0.9.1</jwt.version>
|
||||
<jwt.version>0.11.2</jwt.version>
|
||||
<mybatis-plus.version>3.4.3</mybatis-plus.version>
|
||||
<hutool.version>5.6.5</hutool.version>
|
||||
<feign.version>2.2.6.RELEASE</feign.version>
|
||||
@ -83,7 +83,17 @@
|
||||
<!-- Token生成与解析-->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
<version>${jwt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>${jwt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>${jwt.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
@ -91,8 +91,8 @@ spring:
|
||||
token:
|
||||
# 令牌自定义标识
|
||||
header: Authorization
|
||||
# 令牌密钥
|
||||
secret: abcdefghijklmnopqrstuvwxyz
|
||||
# 令牌密钥 HMAC-SHA sha256
|
||||
secret: ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890==========
|
||||
# 令牌有效期(默认30分钟)
|
||||
expireTime: 30
|
||||
|
||||
|
@ -74,7 +74,15 @@
|
||||
<!--Token生成与解析-->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt</artifactId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- redis 缓存操作 -->
|
||||
|
@ -14,10 +14,13 @@ import com.ruoyi.framework.config.properties.TokenProperties;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.jsonwebtoken.io.Decoders;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.security.Key;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -145,10 +148,9 @@ public class TokenService {
|
||||
* @return 令牌
|
||||
*/
|
||||
private String createToken(Map<String, Object> claims) {
|
||||
String token = Jwts.builder()
|
||||
.setClaims(claims)
|
||||
.signWith(SignatureAlgorithm.HS512, tokenProperties.getSecret()).compact();
|
||||
return token;
|
||||
byte[] keyBytes = Decoders.BASE64.decode(tokenProperties.getSecret());
|
||||
Key key = Keys.hmacShaKeyFor(keyBytes);
|
||||
return Jwts.builder().setClaims(claims).signWith(key).compact();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,10 +160,7 @@ public class TokenService {
|
||||
* @return 数据声明
|
||||
*/
|
||||
private Claims parseToken(String token) {
|
||||
return Jwts.parser()
|
||||
.setSigningKey(tokenProperties.getSecret())
|
||||
.parseClaimsJws(token)
|
||||
.getBody();
|
||||
return Jwts.parserBuilder().setSigningKey(tokenProperties.getSecret()).build().parseClaimsJws(token).getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user