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 <maciej@oraoncology.com>
This commit is contained in:
Maciej Kucharek 2020-04-21 21:32:12 +02:00 committed by GitHub
parent 1f848dde82
commit f69fb1a39b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -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));