Skip to content

Commit

Permalink
Add temp jks file checker
Browse files Browse the repository at this point in the history
  • Loading branch information
MikkoKauhanen committed Dec 4, 2024
1 parent 2724c1f commit 4b857cd
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package fi.csc.processor.producer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.io.FileInputStream;
import java.security.KeyStore;
import java.util.Enumeration;

@Component
public class JksFileChecker implements CommandLineRunner {

private static final Logger LOG = LoggerFactory.getLogger(JksFileChecker.class.getSimpleName());


@Override
public void run(String... args) throws Exception {
String trustStorePath = System.getProperty("javax.net.ssl.trustStore");
String trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");

if (trustStorePath == null || trustStorePassword == null) {
LOG.error("TrustStore properties are not set!");
return;
}

try (FileInputStream trustStoreStream = new FileInputStream(trustStorePath)) {
KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(trustStoreStream, trustStorePassword.toCharArray());

LOG.info("JKS file loaded successfully!");
LOG.info("Aliases in the JKS:");

Enumeration<String> aliases = trustStore.aliases();
while (aliases.hasMoreElements()) {
System.out.println(" - " + aliases.nextElement());
}
} catch (Exception e) {
LOG.error("Failed to load JKS file: " + e.getMessage());
e.printStackTrace();
}
}
}

0 comments on commit 4b857cd

Please sign in to comment.