-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EDGCOMMON-79. Add truststore options to configure Web Clients
- Loading branch information
1 parent
bd00a1e
commit 2925d35
Showing
10 changed files
with
288 additions
and
83 deletions.
There are no files selected for viewing
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
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
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
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
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
55 changes: 55 additions & 0 deletions
55
src/main/java/org/folio/edge/core/utils/OkapiClientFactoryInitializer.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,55 @@ | ||
package org.folio.edge.core.utils; | ||
|
||
import static org.folio.edge.core.Constants.SYS_OKAPI_URL; | ||
import static org.folio.edge.core.Constants.SYS_REQUEST_TIMEOUT_MS; | ||
import static org.folio.edge.core.Constants.SYS_WEB_CLIENT_KEY_ALIAS; | ||
import static org.folio.edge.core.Constants.SYS_WEB_CLIENT_KEY_ALIAS_PASSWORD; | ||
import static org.folio.edge.core.Constants.SYS_WEB_CLIENT_SSL_ENABLED; | ||
import static org.folio.edge.core.Constants.SYS_WEB_CLIENT_TRUSTSTORE_PASSWORD; | ||
import static org.folio.edge.core.Constants.SYS_WEB_CLIENT_TRUSTSTORE_PATH; | ||
import static org.folio.edge.core.Constants.SYS_WEB_CLIENT_TRUSTSTORE_PROVIDER; | ||
import static org.folio.edge.core.Constants.SYS_WEB_CLIENT_TRUSTSTORE_TYPE; | ||
|
||
import io.vertx.core.Vertx; | ||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.core.net.KeyStoreOptions; | ||
import io.vertx.core.net.TrustOptions; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class OkapiClientFactoryInitializer { | ||
private static final Logger logger = LogManager.getLogger(OkapiClientFactoryInitializer.class); | ||
|
||
private OkapiClientFactoryInitializer() { | ||
} | ||
|
||
public static OkapiClientFactory createInstance(Vertx vertx, JsonObject config) { | ||
String okapiUrl = config.getString(SYS_OKAPI_URL); | ||
Integer requestTimeout = config.getInteger(SYS_REQUEST_TIMEOUT_MS); | ||
boolean isSslEnabled = config.getBoolean(SYS_WEB_CLIENT_SSL_ENABLED); | ||
if (isSslEnabled) { | ||
logger.info("Creating OkapiClientFactory with Enhance HTTP Endpoint Security and TLS mode enabled"); | ||
String truststoreType = config.getString(SYS_WEB_CLIENT_TRUSTSTORE_TYPE); | ||
String truststoreProvider = config.getString(SYS_WEB_CLIENT_TRUSTSTORE_PROVIDER); | ||
String truststorePath = config.getString(SYS_WEB_CLIENT_TRUSTSTORE_PATH); | ||
String truststorePassword = config.getString(SYS_WEB_CLIENT_TRUSTSTORE_PASSWORD); | ||
String keyAlias = config.getString(SYS_WEB_CLIENT_KEY_ALIAS); | ||
String keyAliasPassword = config.getString(SYS_WEB_CLIENT_KEY_ALIAS_PASSWORD); | ||
if (truststoreType != null && truststorePath != null && truststorePassword != null) { | ||
logger.info("Web client truststore options for type: {} are set, configuring Web Client with them", truststoreType); | ||
TrustOptions trustOptions = new KeyStoreOptions() | ||
.setType(truststoreType) | ||
.setProvider(truststoreProvider) | ||
.setPath(truststorePath) | ||
.setPassword(truststorePassword) | ||
.setAlias(keyAlias) | ||
.setAliasPassword(keyAliasPassword); | ||
return new OkapiClientFactory(vertx, okapiUrl, requestTimeout, trustOptions); | ||
} else { | ||
return new OkapiClientFactory(vertx, okapiUrl, requestTimeout, null); | ||
} | ||
} else { | ||
return new OkapiClientFactory(vertx, okapiUrl, requestTimeout); | ||
} | ||
} | ||
} |
Oops, something went wrong.