From f69fb1a39b5ec646d907986b4579e1d4c945517b Mon Sep 17 00:00:00 2001 From: Maciej Kucharek Date: Tue, 21 Apr 2020 21:32:12 +0200 Subject: [PATCH] Set ES username and password only if they're not blank (#1806) This is important for AWS-hosted ES, as it does not accept HTTP requests with Basic authentication (even if the username/passwords are blank). Skipping those settings in case they're blank solves the issue. Co-authored-by: Maciej Kucharek --- .../elastic/ElasticsearchHibernatePropertiesBuilder.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/elastic/ElasticsearchHibernatePropertiesBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/elastic/ElasticsearchHibernatePropertiesBuilder.java index 4195fafa609..3435d733f61 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/elastic/ElasticsearchHibernatePropertiesBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/elastic/ElasticsearchHibernatePropertiesBuilder.java @@ -20,6 +20,7 @@ package ca.uhn.fhir.jpa.search.elastic; * #L% */ +import org.apache.commons.lang3.StringUtils; import org.hibernate.search.cfg.Environment; import org.hibernate.search.elasticsearch.cfg.ElasticsearchEnvironment; import org.hibernate.search.elasticsearch.cfg.ElasticsearchIndexStatus; @@ -63,8 +64,12 @@ public class ElasticsearchHibernatePropertiesBuilder { theProperties.put("hibernate.search." + ElasticsearchEnvironment.ANALYSIS_DEFINITION_PROVIDER, ElasticsearchMappingProvider.class.getName()); theProperties.put("hibernate.search.default.elasticsearch.host", myRestUrl); - theProperties.put("hibernate.search.default.elasticsearch.username", myUsername); - theProperties.put("hibernate.search.default.elasticsearch.password", myPassword); + if (StringUtils.isNotBlank(myUsername)) { + theProperties.put("hibernate.search.default.elasticsearch.username", myUsername); + } + if (StringUtils.isNotBlank(myPassword)) { + theProperties.put("hibernate.search.default.elasticsearch.password", myPassword); + } theProperties.put("hibernate.search.default." + ElasticsearchEnvironment.INDEX_SCHEMA_MANAGEMENT_STRATEGY, myIndexSchemaManagementStrategy.getExternalName()); theProperties.put("hibernate.search.default." + ElasticsearchEnvironment.INDEX_MANAGEMENT_WAIT_TIMEOUT, Long.toString(myIndexManagementWaitTimeoutMillis));