diff --git a/java/src/main/java/com/cybersource/ws/client/MerchantConfig.java b/java/src/main/java/com/cybersource/ws/client/MerchantConfig.java index a1b5bc73..ba2ae18a 100644 --- a/java/src/main/java/com/cybersource/ws/client/MerchantConfig.java +++ b/java/src/main/java/com/cybersource/ws/client/MerchantConfig.java @@ -19,6 +19,7 @@ package com.cybersource.ws.client; import java.io.File; +import java.net.URI; import java.text.MessageFormat; import java.util.Properties; @@ -38,6 +39,7 @@ public class MerchantConfig { private final Properties props; private final String merchantID; + private URI keyUri; private String keysDirectory; private String keyAlias; private String keyPassword; @@ -73,6 +75,10 @@ public String getMerchantID() { return merchantID; } + public URI getKeyUri() { + return keyUri; + } + public String getKeysDirectory() { return keysDirectory; } @@ -231,6 +237,9 @@ public MerchantConfig(Properties _props, String _merchantID) sendToProduction = getBooleanProperty(merchantID, "sendToProduction", false); sendToAkamai = getBooleanProperty(merchantID, "sendToAkamai", false); targetAPIVersion = getProperty(merchantID, "targetAPIVersion"); + if (props.containsKey("keyFileUri")) { + keyUri = (URI) props.get("keyFileUri"); + } keyFilename = getProperty(merchantID, "keyFilename"); serverURL = getProperty(merchantID, "serverURL"); namespaceURI = getProperty(merchantID, "namespaceURI"); diff --git a/java/src/main/java/com/cybersource/ws/client/SignedAndEncryptedMessageHandler.java b/java/src/main/java/com/cybersource/ws/client/SignedAndEncryptedMessageHandler.java index c7b1ed14..453ecd77 100644 --- a/java/src/main/java/com/cybersource/ws/client/SignedAndEncryptedMessageHandler.java +++ b/java/src/main/java/com/cybersource/ws/client/SignedAndEncryptedMessageHandler.java @@ -11,6 +11,7 @@ import java.io.FileInputStream; import java.io.IOException; +import java.net.URI; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; @@ -96,7 +97,19 @@ private static void readAndStoreCertificateAndPrivateKey( } try { - merchantKeyStore.load(new FileInputStream(merchantConfig.getKeyFile()), merchantConfig.getKeyPassword().toCharArray()); + URI keyUri = merchantConfig.getKeyUri(); + if (keyUri != null) { + if ("classpath".equalsIgnoreCase(keyUri.getScheme())) { + merchantKeyStore.load( + SignedAndEncryptedMessageHandler.class.getResourceAsStream(keyUri.getPath()), + merchantConfig.getKeyPassword().toCharArray() + ); + } else { + throw new IllegalArgumentException("Unsupported URI scheme for key file."); + } + } else { + merchantKeyStore.load(new FileInputStream(merchantConfig.getKeyFile()), merchantConfig.getKeyPassword().toCharArray()); + } } catch (IOException e) { logger.log(Logger.LT_EXCEPTION, "Exception while loading KeyStore, '" + merchantConfig.getKeyFilename() + "'"); throw new SignException(e);