Fix Sonar Cloud issue - Static initialization of JWTTokenGenerator (#7283)

This commit is contained in:
Suresh Srinivas 2022-09-09 12:13:13 -07:00 committed by GitHub
parent 027f317725
commit 6887a88725
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,29 +23,19 @@ import org.openmetadata.catalog.teams.authn.JWTTokenExpiry;
@Slf4j
public class JWTTokenGenerator {
private static volatile JWTTokenGenerator instance;
private static JWTTokenGenerator instance = new JWTTokenGenerator();
private RSAPrivateKey privateKey;
@Getter private RSAPublicKey publicKey;
private String issuer;
private String kid;
private JWTTokenGenerator() {
if (instance != null) {
throw new RuntimeException("Use getInstance() method to get the single instance of this class");
}
}
private JWTTokenGenerator() {}
public static JWTTokenGenerator getInstance() {
if (instance == null) {
synchronized (JWTTokenGenerator.class) {
if (instance == null) {
instance = new JWTTokenGenerator();
}
}
}
return instance;
}
/** Expected to be initialized only once during application start */
public void init(JWTTokenConfiguration jwtTokenConfiguration) {
try {
if (jwtTokenConfiguration.getRsaprivateKeyFilePath() != null