Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
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;
Expand All @@ -32,12 +34,15 @@
*/
@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) {
Expand All @@ -58,6 +63,14 @@ public NacosJwtParser(String base64edKey) {
}
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);
Expand Down
Loading