未验证 提交 12987a72 编写于 作者: sinat_25235033's avatar sinat_25235033 提交者: GitHub

support config your custom jwt secret need (#167)

上级 4e54fb20
package com.usthe.sureness.util;
import com.usthe.sureness.processor.exception.ExtSurenessException;
import io.jsonwebtoken.*;
import io.jsonwebtoken.security.*;
import io.jsonwebtoken.security.SignatureException;
......@@ -37,6 +38,8 @@ public class JsonWebTokenUtil {
/** Encryption and decryption signature **/
private static Key secretKey;
private static boolean isUsedDefault = true;
static {
byte[] secretKeyBytes = DatatypeConverter.parseBase64Binary(DEFAULT_SECRET_KEY);
secretKey = Keys.hmacShaKeyFor(secretKeyBytes);
......@@ -200,6 +203,9 @@ public class JsonWebTokenUtil {
public static String issueJwtAll(String id, String subject, String issuer, Long period,
String audience, String payload, Long notBefore,
Map<String, Object> headerMap, Map<String, Object> customClaimMap){
if (isUsedDefault) {
throw new ExtSurenessException("Please config your custom jwt secret. JsonWebTokenUtil.setDefaultSecretKey | sureness.jwt.secret");
}
long currentTimeMillis = System.currentTimeMillis();
JwtBuilder jwtBuilder = Jwts.builder();
if (id != null) {
......@@ -295,5 +301,6 @@ public class JsonWebTokenUtil {
public static void setDefaultSecretKey(String secretNowKeyValue) {
byte[] secretKeyBytes = DatatypeConverter.parseBase64Binary(secretNowKeyValue);
secretKey = Keys.hmacShaKeyFor(secretKeyBytes);
isUsedDefault = false;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册