Skip to content
Snippets Groups Projects
Commit 3202951f authored by OZGCloud's avatar OZGCloud
Browse files

OZG-3322 load cert file only if exists

parent f0e46858
Branches
No related tags found
No related merge requests found
package de.itvsh.kop.user; package de.itvsh.kop.user;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.KeyStoreException; import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
...@@ -13,6 +16,7 @@ import javax.enterprise.event.Observes; ...@@ -13,6 +16,7 @@ import javax.enterprise.event.Observes;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.eclipse.microprofile.config.inject.ConfigProperty; import org.eclipse.microprofile.config.inject.ConfigProperty;
import de.itvsh.kop.common.errorhandling.TechnicalException;
import io.quarkus.runtime.StartupEvent; import io.quarkus.runtime.StartupEvent;
@ApplicationScoped @ApplicationScoped
...@@ -22,9 +26,21 @@ class MongodbCertificateLoader { ...@@ -22,9 +26,21 @@ class MongodbCertificateLoader {
String mongoDbCaCert; String mongoDbCaCert;
void onStart(@Observes StartupEvent ev) throws KeyStoreException, CertificateException, IOException, NoSuchAlgorithmException { void onStart(@Observes StartupEvent ev) throws KeyStoreException, CertificateException, IOException, NoSuchAlgorithmException {
if(Files.exists(Paths.get(mongoDbCaCert))) {
System.out.println("loading cert..."); System.out.println("loading cert...");
KeyStore keystore = KeyStore.getInstance("pkcs12"); KeyStore keystore = KeyStore.getInstance("pkcs12");
keystore.load(IOUtils.toInputStream(mongoDbCaCert, Charset.defaultCharset()), null); keystore.load(loadCaCrt(), null);
System.out.println("cert loaded"); System.out.println("cert loaded");
} else {
System.out.println("cert file does not exists");
}
}
InputStream loadCaCrt() {
try {
return Files.newInputStream(Paths.get(mongoDbCaCert));
} catch (IOException e) {
throw new TechnicalException("Error loading caCert", e);
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment