Merge pull request #1365 from Alfresco/fix/MNT-22391_httpclient_upgrade_20x

MNT-22391 httpclient upgrade to 4.5.13
This commit is contained in:
Vítor Moreira
2022-03-02 11:10:02 +00:00
committed by GitHub
10 changed files with 24 additions and 145 deletions
+6
View File
@@ -46,6 +46,7 @@
<dependency.restlet.version>2.3.12</dependency.restlet.version>
<dependency.jdom2.version>2.0.6.1</dependency.jdom2.version>
<dependency.spring.version>5.3.7</dependency.spring.version>
<dependency.httpclient.version>4.5.13</dependency.httpclient.version>
</properties>
<dependencyManagement>
<dependencies>
@@ -120,6 +121,11 @@
<version>${dependency.jdom2.version}</version>
</dependency>
<!-- spring framework is defined in "search-services" and "insight-engine" because "e2e-test" uses different versions -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${dependency.httpclient.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
+4
View File
@@ -207,6 +207,10 @@
<artifactId>avatica-core</artifactId>
<version>1.13.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
@@ -45,7 +45,6 @@ import org.alfresco.solr.tracker.TrackerRegistry;
import org.alfresco.solr.utils.Utils;
import org.alfresco.util.Pair;
import org.alfresco.util.shard.ExplicitShardingPolicy;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.io.FileUtils;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CoreAdminParams;
@@ -314,7 +313,6 @@ public class AlfrescoCoreAdminHandler extends CoreAdminHandler
AlfrescoSolrDataModel.getInstance().close();
SOLRAPIClientFactory.close();
MultiThreadedHttpConnectionManager.shutdownAll();
coreNames().forEach(trackerRegistry::removeTrackersForCore);
informationServers.clear();
@@ -46,6 +46,11 @@
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
@@ -60,8 +60,7 @@ import org.alfresco.util.ISO8601DateFormat;
import org.alfresco.util.Pair;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.net.URLCodec;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.util.DateUtil;
import org.apache.http.HttpStatus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -75,6 +74,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@@ -112,6 +112,8 @@ public class SOLRAPIClient
private static final String CHECKSUM_HEADER = "XAlfresco-modelChecksum";
private static final SimpleDateFormat httpHeaderDateFormat = new SimpleDateFormat("EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z", Locale.US);
private AlfrescoHttpClient repositoryHttpClient;
private SOLRDeserializer deserializer;
private DictionaryService dictionaryService;
@@ -1030,7 +1032,7 @@ public class SOLRAPIClient
Map<String, String> headers = new HashMap<>();
if(modifiedSince != null)
{
headers.put("If-Modified-Since", String.valueOf(DateUtil.formatDate(new Date(modifiedSince))));
headers.put("If-Modified-Since", httpHeaderDateFormat.format(new Date(modifiedSince)));
}
if (compression)
{
@@ -38,7 +38,6 @@ import org.alfresco.httpclient.HttpClientFactory;
import org.alfresco.httpclient.HttpClientFactory.SecureCommsType;
import org.alfresco.repo.dictionary.NamespaceDAO;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.apache.commons.httpclient.params.DefaultHttpParams;
/**
* This factory encapsulates the creation of a SOLRAPIClient and the management of that resource.
@@ -263,13 +262,6 @@ public class SOLRAPIClientFactory
setMaxTotalConnections(maxTotalConnections);
setMaxHostConnections(maxHostConnections);
setSocketTimeout(socketTimeout);
init();
}
@Override
public void init()
{
DefaultHttpParams.setHttpParamsFactory(new NonBlockingHttpParamsFactory());
}
}
@@ -32,7 +32,6 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -46,7 +45,7 @@ import org.alfresco.httpclient.Response;
import org.alfresco.repo.dictionary.NamespaceDAO;
import org.alfresco.repo.index.shard.ShardState;
import org.alfresco.service.namespace.QName;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.http.HttpStatus;
import org.json.JSONException;
// TODO error handling, including dealing with a repository that is not responsive (ConnectException in sendRemoteRequest)
@@ -26,16 +26,13 @@
package org.alfresco.solr.client;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.AlgorithmParameters;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -48,11 +45,8 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.alfresco.encryption.DefaultEncryptionUtils;
import org.alfresco.encryption.KeyProvider;
import org.alfresco.encryption.KeyResourceLoader;
import org.alfresco.encryption.KeyStoreParameters;
import org.alfresco.encryption.MACUtils.MACInput;
import org.alfresco.encryption.ssl.SSLEncryptionParameters;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.httpclient.AlfrescoHttpClient;
@@ -76,13 +70,9 @@ import org.alfresco.repo.tenant.SingleTServiceImpl;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.DynamicallySizedThreadPoolExecutor;
import org.alfresco.util.Pair;
import org.alfresco.util.TraceableThreadFactory;
import org.alfresco.util.cache.DefaultAsynchronouslyRefreshedCacheRegistry;
import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
@@ -103,10 +93,6 @@ public class SOLRAPIClientTest extends TestCase
private SOLRAPIClient client;
private SOLRAPIClient invalidKeyClient;
private SOLRAPIClient tamperWithClient;
private DictionaryDAOImpl dictionaryDAO;
private CMISStrictDictionaryService cmisDictionaryService;
@@ -567,118 +553,4 @@ public class SOLRAPIClientTest extends TestCase
assertTrue(diffs.size() > 0);
}
// public void testMAC() throws IOException, JSONException
// {
// // dodyClient has a secret key that is not the same as the repository's. This
// // should fail with a 401
// try
// {
// Transactions transactions = invalidKeyClient.getTransactions(1298288417234l, null, null, null, 5);
// }
// catch (AuthenticationException e)
// {
// assertEquals("Should have caught unathorised request", e.getMethod().getStatusCode(), HttpStatus.SC_UNAUTHORIZED);
// }
//
// try
// {
// tamperWithEncryptionService.setOverrideTimestamp(true);
// Transactions transactions = tamperWithClient.getTransactions(1298288417234l, null, null, null, 5);
// }
// catch (AuthenticationException e)
// {
// assertEquals("Should have caught unathorised request", e.getMethod().getStatusCode(), HttpStatus.SC_UNAUTHORIZED);
// }
// finally
// {
// tamperWithEncryptionService.setOverrideTimestamp(false);
// }
//
// try
// {
// tamperWithEncryptionService.setOverrideMAC(true);
// Transactions transactions = tamperWithClient.getTransactions(1298288417234l, null, null, null, 5);
// }
// catch (AuthenticationException e)
// {
// assertEquals("Should have caught unathorised request", e.getMethod().getStatusCode(), HttpStatus.SC_UNAUTHORIZED);
// }
// finally
// {
// tamperWithEncryptionService.setOverrideMAC(false);
// }
// }
private void outputTextContent(SOLRAPIClient.GetTextContentResponse response) throws IOException
{
InputStream in = response.getContent();
if (in != null)
{
logger.debug("Text content:");
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null)
{
logger.debug(line);
}
}
}
/**
* Overrides request encryption to create dodgy MAC and timestamp on requests
*/
private static class TestEncryptionUtils extends DefaultEncryptionUtils
{
private boolean overrideMAC = false;
private boolean overrideTimestamp = false;
public void setOverrideMAC(boolean overrideMAC)
{
this.overrideMAC = overrideMAC;
}
public void setOverrideTimestamp(boolean overrideTimestamp)
{
this.overrideTimestamp = overrideTimestamp;
}
@Override
public void setRequestAuthentication(HttpMethod method, byte[] message) throws IOException
{
if (method instanceof PostMethod)
{
// encrypt body
Pair<byte[], AlgorithmParameters> encrypted = encryptor.encrypt(KeyProvider.ALIAS_SOLR, null, message);
setRequestAlgorithmParameters(method, encrypted.getSecond());
((PostMethod) method).setRequestEntity(new ByteArrayRequestEntity(encrypted.getFirst(), "application/octet-stream"));
}
long requestTimestamp = System.currentTimeMillis();
// add MAC header
byte[] mac = macUtils.generateMAC(KeyProvider.ALIAS_SOLR, new MACInput(message, requestTimestamp, getLocalIPAddress()));
if (logger.isDebugEnabled())
{
logger.debug("Setting MAC " + mac + " on HTTP request " + method.getPath());
logger.debug("Setting timestamp " + requestTimestamp + " on HTTP request " + method.getPath());
}
if (overrideMAC)
{
mac[0] += (byte) 1;
}
setRequestMac(method, mac);
if (overrideTimestamp)
{
requestTimestamp += 60000;
}
// prevent replays
setRequestTimestamp(method, requestTimestamp);
}
}
}
+1
View File
@@ -175,6 +175,7 @@
<delete file="${project.build.directory}/solr-${solr.version}/server/solr-webapp/webapp/WEB-INF/lib/avatica-core-1.9.0.jar" />
<delete file="${project.build.directory}/solr-${solr.version}/server/solr-webapp/webapp/WEB-INF/lib/org.restlet-2.3.0.jar" />
<delete file="${project.build.directory}/solr-${solr.version}/server/solr-webapp/webapp/WEB-INF/lib/org.restlet.ext.servlet-2.3.0.jar" />
<delete file="${project.build.directory}/solr-${solr.version}/server/solr-webapp/webapp/WEB-INF/lib/httpclient-4.4.1.jar" />
<delete file="${project.build.directory}/solr-${solr.version}/server/solr-webapp/webapp/libs/jquery-2.1.3.min.js" />
<delete file="${project.build.directory}/solr-${solr.version}/server/solr-webapp/webapp/js/lib/jquery-1.7.2.min.js" />
</target>
@@ -35,7 +35,7 @@ json-20210307.jar https://github.com/stleary/JSON-java
xml-resolver-1.2.jar https://github.com/FasterXML/jackson
neethi-3.1.1.jar http://ws.apache.org/commons/neethi/
commons-dbcp-1.4.jar http://jakarta.apache.org/commons/
commons-logging-1.1.3.jar http://jakarta.apache.org/commons/
commons-logging-1.2.jar http://jakarta.apache.org/commons/
commons-lang3-3.11.jar http://jakarta.apache.org/commons/
commons-pool-1.5.4.jar http://jakarta.apache.org/commons/
commons-compress-1.21.jar https://commons.apache.org/proper/commons-compress/
@@ -192,7 +192,7 @@ gmetric4j-1.0.7.jar
guava-14.0.1.jar
hppc-0.7.1.jar
htrace-core-3.2.0-incubating.jar
httpclient-4.4.1.jar
httpclient-4.5.13.jar
httpcore-4.4.1.jar
httpmime-4.4.1.jar
icu4j-56.1.jar