-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2724c1f
commit 4b857cd
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...alytics/service-etl-processor/src/main/java/fi/csc/processor/producer/JksFileChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |