X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fsa%2Fsearchdbabstraction%2Felasticsearch%2Fconfig%2FElasticSearchConfig.java;h=f4bc5eff9bdd193147b5315fe6a657c99d27b14c;hb=61110b0508dbc10d1e925c1f3ee637f61689ffac;hp=0d116f85129133f951ecf7d075aff3a8e15921e8;hpb=3f66d5f1ef60c60116589e73ec1207f9574840af;p=aai%2Fsearch-data-service.git diff --git a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfig.java b/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfig.java index 0d116f8..f4bc5ef 100644 --- a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfig.java +++ b/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/config/ElasticSearchConfig.java @@ -24,6 +24,8 @@ import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.Optional; import java.util.Properties; + +import org.apache.commons.lang.StringUtils; import org.eclipse.jetty.util.security.Password; import org.onap.aai.sa.searchdbabstraction.util.SearchDbConstants; @@ -40,6 +42,7 @@ public class ElasticSearchConfig { private String httpPort; private String javaApiPort; private String clusterName; + private String authorizationEnabled; public static final String ES_CLUSTER_NAME = "es.cluster-name"; public static final String ES_IP_ADDRESS = "es.ip-address"; @@ -51,6 +54,7 @@ public class ElasticSearchConfig { public static final String ES_KEY_STORE_ENC = "es.key-store-password"; public static final String ES_AUTH_USER = "es.auth-user"; public static final String ES_AUTH_ENC = "es.auth-password"; + public static final String ES_AUTH_ENABLED = "es.auth.authorization.enabled"; private static final String DEFAULT_URI_SCHEME = "http"; private static final String JAVA_API_PORT_DEFAULT = "9300"; @@ -66,6 +70,7 @@ public class ElasticSearchConfig { setHttpPort(props.getProperty(ES_HTTP_PORT)); setJavaApiPort(JAVA_API_PORT_DEFAULT); initializeAuthValues(props); + setAuthorizationEnabled(props.getProperty(ES_AUTH_ENABLED)); } @@ -161,12 +166,24 @@ public class ElasticSearchConfig { return authValue; } + public String getAuthorizationEnabled() { + return authorizationEnabled; + } + + public void setAuthorizationEnabled(String authorizationEnabled) { + this.authorizationEnabled = authorizationEnabled; + } + + public boolean useAuthorizationUser() { + return getAuthorizationEnabled()== null? true : Boolean.parseBoolean(getAuthorizationEnabled()); + } + @Override public String toString() { return String.format( - "%s://%s:%s (cluster=%s) (API port=%s)%nauth=%s%ntrustStore=%s (passwd %s)%nkeyStore=%s (passwd %s)", + "%s://%s:%s (cluster=%s) (API port=%s)%nauth=%s%ntrustStore=%s (passwd %s)%nkeyStore=%s (passwd %s)%nauthorizationUser=%s", uriScheme, ipAddress, httpPort, clusterName, javaApiPort, useAuth(), trustStore, - trustStorePassword != null, keyStore, keyStorePassword != null); + trustStorePassword != null, keyStore, keyStorePassword != null, useAuthorizationUser()); } private void initializeAuthValues(Properties props) { @@ -191,7 +208,10 @@ public class ElasticSearchConfig { if (passwordValue.isPresent()) { if(passwordValue.get().startsWith("OBF:")){ setTrustStorePassword(Password.deobfuscate(passwordValue.get())); - }else{ + }else if(passwordValue.get().startsWith("ENV:")){ + setTrustStorePassword(System.getProperty(StringUtils.removeStart(passwordValue.get(), "ENV:"))); + } + else{ setTrustStorePassword(passwordValue.get()); } } @@ -205,7 +225,10 @@ public class ElasticSearchConfig { if (passwordValue.isPresent()) { if(passwordValue.get().startsWith("OBF:")){ setKeyStorePassword(Password.deobfuscate(passwordValue.get())); - }else{ + }else if(passwordValue.get().startsWith("ENV:")){ + setKeyStorePassword(System.getProperty(StringUtils.removeStart(passwordValue.get(), "ENV:"))); + } + else{ setKeyStorePassword(passwordValue.get()); } }