[ISSUE #11887] add some tips for upgrade (#12434)

This commit is contained in:
Plato 2024-07-29 10:34:40 +08:00 committed by GitHub
parent 3e28b586bb
commit 927fbfd110
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,6 +19,8 @@ package com.alibaba.nacos.plugin.auth.impl.jwt;
import com.alibaba.nacos.plugin.auth.exception.AccessException;
import com.alibaba.nacos.plugin.auth.impl.users.NacosUser;
import com.alibaba.nacos.plugin.auth.impl.utils.Base64Decode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
@ -33,11 +35,14 @@ import java.util.concurrent.TimeUnit;
@SuppressWarnings("PMD.UndefineMagicConstantRule")
public class NacosJwtParser {
private static final Logger LOG = LoggerFactory.getLogger(NacosJwtParser.class);
private final NacosSignatureAlgorithm signatureAlgorithm;
private final Key key;
public NacosJwtParser(String base64edKey) {
this.validKey(base64edKey);
byte[] decode = Base64Decode.decode(base64edKey);
int bitLength = decode.length << 3;
if (bitLength < 256) {
@ -59,6 +64,14 @@ public class NacosJwtParser {
this.key = new SecretKeySpec(decode, signatureAlgorithm.getJcaName());
}
private void validKey(String base64edKey) {
int length = base64edKey.toCharArray().length;
if (length % 4 != 0) {
LOG.warn("The secret Key currently in use is not a standard Base64 encoding"
+ " and will no longer be supported in future versions;");
}
}
private String sign(NacosJwtPayload payload) {
return signatureAlgorithm.sign(payload, key);
}