Merge pull request #1238 from Alfresco/fix/SEARCH-3022_OptionalSSLProperties

SEARCH-3022 Cherry pick from https://github.com/Alfresco/SearchServic…
This commit is contained in:
Angel Borroy
2021-07-29 14:21:28 +02:00
committed by GitHub
2 changed files with 50 additions and 7 deletions
@@ -91,11 +91,15 @@ public class CoreDescriptorDecorator
try
{
coreProperties.forEach(prop ->
properties.put(prop, ConfigUtil.locateProperty(prop,properties.getProperty(prop)))
);
coreProperties.forEach(prop -> {
String value = ConfigUtil.locateProperty(prop, null);
if (value != null)
{
properties.put(prop, value);
}
});
}
catch(Exception e)
catch (Exception e)
{
log.warn("Unable to locate alfresco host|port|baseUrl|ssl properties", e);
}
@@ -26,14 +26,17 @@
package org.alfresco.solr.config;
import java.io.File;
import java.util.HashMap;
import java.util.Properties;
import org.alfresco.solr.AlfrescoCoreAdminHandler;
import org.alfresco.solr.SolrInformationServer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.CoreDescriptorDecorator;
import org.junit.Test;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
/**
* Tests configuring and setup of Alfresco and Solr properties
@@ -74,5 +77,41 @@ public class ConfigUtilTest {
assertEquals("SOLR_SOLR_PORT",ConfigUtil.convertPropertyNameToEnvironmentParam(SolrInformationServer.SOLR_PORT));
assertEquals("SOLR_SOLR_BASEURL",ConfigUtil.convertPropertyNameToEnvironmentParam(SolrInformationServer.SOLR_BASEURL));
}
/**
* See https://github.com/Alfresco/SearchServices/pull/382
*/
@Test
public void testMissingCoreProperty()
{
HashMap<String, String> coreProps = new HashMap<String, String>();
Properties saved = (Properties) System.getProperties().clone();
System.setProperty("alfresco.secureComms", "https");
for (String key : CoreDescriptorDecorator.SUBSTITUTABLE_PROPERTIES_SECURE)
{
// Intentionally omit store provider settings
if (!key.endsWith("store.provider"))
{
// Set store type as system property
if (key.endsWith("store.type"))
{
System.setProperty(key, "JKS");
}
coreProps.put(key, "irrelevant");
}
}
Properties contProps = new Properties();
File tmp = new File("/tmp");
CoreDescriptor coreDesc = new CoreDescriptor("test", tmp.toPath(), coreProps, contProps, false);
CoreDescriptorDecorator decorator = new CoreDescriptorDecorator(coreDesc);
Properties decProps = decorator.getProperties();
// Verify store types are in system property
assertEquals("JKS", ConfigUtil.locateProperty("alfresco.encryption.ssl.keystore.type", null));
assertEquals("JKS", ConfigUtil.locateProperty("alfresco.encryption.ssl.truststore.type", null));
// Verify store types in CoreDescriptor came from system property
assertEquals("JKS", decProps.get("alfresco.encryption.ssl.keystore.type"));
assertEquals("JKS", decProps.get("alfresco.encryption.ssl.truststore.type"));
System.setProperties(saved);
}
}