From a08107b0cbfbb877c1f87f232ef91087365b2418 Mon Sep 17 00:00:00 2001 From: remillet Date: Thu, 9 Jun 2016 15:50:13 -0700 Subject: [PATCH] CSPACE-6959: Added support for property value variables. --- .../client/AbstractServiceClientImpl.java | 17 ++++---- .../client/CollectionSpaceClient.java | 2 +- .../services/common/api/Tools.java | 40 +++++++++++++------ .../context/AbstractServiceContextImpl.java | 3 +- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java index bfb78d319..1b1665b7f 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java @@ -39,15 +39,12 @@ import javax.xml.bind.DatatypeConverter; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScope; - import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.jaxb.AbstractCommonList; - import org.jboss.resteasy.client.jaxrs.ResteasyClient; import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor; import org.jboss.resteasy.plugins.providers.RegisterBuiltin; import org.jboss.resteasy.spi.ResteasyProviderFactory; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; // FIXME: Deprecated classes that need to be updated @@ -152,7 +149,7 @@ public abstract class AbstractServiceClientImpl 0) { - for (String key : inProperties.stringPropertyNames()) { - String propertyValue = inProperties.getProperty(key); - String newPropertyValue = Tools.getPasswordFromEnv(propertyValue); - if (newPropertyValue != null) { // non-null result means the property value was the name of an environment variable - inProperties.setProperty(key, newPropertyValue); + if (inProperties.containsKey(filteredKey) == false) { + // Only process the properties once + if (inProperties != null && inProperties.size() > 0) { + for (String key : inProperties.stringPropertyNames()) { + String propertyValue = inProperties.getProperty(key); + String newPropertyValue = Tools.getValueFromEnv(propertyValue); + if (newPropertyValue != null) { // non-null result means the property value was the name of an environment variable + inProperties.setProperty(key, newPropertyValue); + } } + inProperties.setProperty(filteredKey, filteredFlag); // set to indicated we've already process these properties } } @@ -313,20 +329,20 @@ public class Tools { } /** - * Try to find the value of a password variable in the system or JVM environment. This code substitutes only environment variables formed + * Try to find the value of a property variable in the system or JVM environment. This code substitutes only property values formed * like ${cspace.password.mysecret} or ${cspace_password_mysecret_secret}. The corresponding environment variables would * be "cspace.password.mysecret" and "cspace.password.mysecret.secret". * - * Returns null if the passed in propertyValue is not a password variable -i.e., not something of the form {$cspace.password.foo} + * Returns null if the passed in property value is not a property variable -i.e., not something of the form {$cspace.password.foo} * - * Throws an exception if the passed in propertyValue has a valid variable form but the corresponding environment variable is not + * Throws an exception if the passed in property value has a valid variable form but the corresponding environment variable is not * set. * * @param propertyValue * @return * @throws Exception */ - static private String getPasswordFromEnv(String propertyValue) throws Exception { + static public String getValueFromEnv(String propertyValue) throws Exception { String result = null; // // Replace things like ${cspace.password.cow} with values from either the environment diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java index 6e4d9470f..aebe5ccec 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java @@ -715,8 +715,9 @@ public abstract class AbstractServiceContextImpl properties.setProperty(AuthorityClient.AUTH_PROPERTY, remoteClientConfig.getAuth()); properties.setProperty(AuthorityClient.TENANT_ID_PROPERTY, remoteClientConfig.getTenantId()); properties.setProperty(AuthorityClient.TENANT_NAME_PROPERTY, remoteClientConfig.getTenantName()); - + result = getClient(properties); + return result; } -- 2.47.3