manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1847999 - in /manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch: ElasticSearchConfig.java ElasticSearchConnection.java ElasticSearchConnector.java
Date Sun, 02 Dec 2018 13:40:37 GMT
Author: kwright
Date: Sun Dec  2 13:40:36 2018
New Revision: 1847999

URL: http://svn.apache.org/viewvc?rev=1847999&view=rev
Log:
Hook up SSL for ES connector

Modified:
    manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConfig.java
    manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnection.java
    manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java

Modified: manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConfig.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConfig.java?rev=1847999&r1=1847998&r2=1847999&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConfig.java
(original)
+++ manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConfig.java
Sun Dec  2 13:40:36 2018
@@ -215,6 +215,17 @@ public class ElasticSearchConfig extends
     return get(ParameterEnum.PASSWORD);
   }
 
+  final public IKeystoreManager getSSLKeystore()
+    throws ManifoldCFException
+  {
+    final String packedKeystore = get(ParameterEnum.SERVERKEYSTORE);
+    if (packedKeystore == null || packedKeystore.length() == 0)
+    {
+      return null;
+    }
+    return KeystoreManagerFactory.make("", packedKeystore);
+  }
+  
   final public String getIndexName()
   {
     return get(ParameterEnum.INDEXNAME);

Modified: manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnection.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnection.java?rev=1847999&r1=1847998&r2=1847999&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnection.java
(original)
+++ manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnection.java
Sun Dec  2 13:40:36 2018
@@ -67,43 +67,32 @@ import org.apache.manifoldcf.crawler.sys
 
 public class ElasticSearchConnection
 {
-  protected ElasticSearchConfig config;
   
-  private HttpClient client;
-  
-  private String serverLocation;
-
-  private String indexName;
-
-  private String userName;
-
-  private String userPassword;
-
-  private String resultDescription;
-
-  private String callUrlSnippet;
-
-  private String response;
-
-  private String resultCode;
-
-  protected final static String jsonException = "\"error\"";
-
   public enum Result
   {
     OK, ERROR, UNKNOWN;
   }
 
-  private Result result;
+  protected final ElasticSearchConfig config;
+  
+  private final HttpClient client;
+  private final String serverLocation;
+  private final String indexName;
+  private final String userName;
+  private final String userPassword;
   
+  private String resultDescription = "";
+  private String callUrlSnippet = null;
+  private String response = null;
+  private String resultCode = null;
+  private Result result = Result.UNKNOWN;
+  
+  protected final static String jsonException = "\"error\"";
+
   protected ElasticSearchConnection(ElasticSearchConfig config, HttpClient client)
   {
     this.config = config;
     this.client = client;
-    result = Result.UNKNOWN;
-    response = null;
-    resultDescription = "";
-    callUrlSnippet = null;
     serverLocation = config.getServerLocation();
     indexName = config.getIndexName();
     userName = config.getUserName();
@@ -129,7 +118,7 @@ public class ElasticSearchConnection
     if (!serverLocation.endsWith("/"))
       url.append('/');
 
-      Logging.connectors.debug("Url: " + url);
+    Logging.connectors.debug("Url: " + url);
 
     if(!checkConnection)
       url.append(URLEncoder.encode(indexName)).append("/");

Modified: manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java?rev=1847999&r1=1847998&r2=1847999&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java
(original)
+++ manifoldcf/trunk/connectors/elasticsearch/connector/src/main/java/org/apache/manifoldcf/agents/output/elasticsearch/ElasticSearchConnector.java
Sun Dec  2 13:40:36 2018
@@ -39,6 +39,14 @@ import org.apache.http.client.config.Req
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.config.SocketConfig;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainConnectionSocketFactory;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.auth.AuthScope;
 //import org.apache.http.client.HttpRequestRetryHandler;
 //import org.apache.http.protocol.HttpContext;
 
@@ -61,6 +69,9 @@ import org.apache.manifoldcf.core.interf
 import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
 //import org.apache.manifoldcf.core.interfaces.SpecificationNode;
 import org.apache.manifoldcf.core.interfaces.VersionContext;
+import org.apache.manifoldcf.connectorcommon.interfaces.IKeystoreManager;
+import org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory;
+
 
 /**
  * This is the "output connector" for elasticsearch.
@@ -114,8 +125,35 @@ public class ElasticSearchConnector exte
       int socketTimeout = 900000;
       int connectionTimeout = 60000;
       
+      // Load configuration from parameters
+      final ElasticSearchConfig config = new ElasticSearchConfig(params);
+      final IKeystoreManager keystoreManager = config.getSSLKeystore();
+      final String userName = config.getUserName();
+      final String password = config.getPassword();
+
+      final Credentials credentials;
+      if (userName != null && userName.length() > 0)
+        credentials = new UsernamePasswordCredentials(userName, password);
+      else
+        credentials = null;
+      
+      // Set up ingest ssl if indicated
+      SSLConnectionSocketFactory myFactory = null;
+      if (keystoreManager != null)
+      {
+        myFactory = new SSLConnectionSocketFactory(new InterruptibleSocketFactory(keystoreManager.getSecureSocketFactory(),
connectionTimeout),
+          NoopHostnameVerifier.INSTANCE);
+      }
+      else
+      {
+        myFactory = SSLConnectionSocketFactory.getSocketFactory();
+      }
+
       // Set up connection manager
-      PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager();
+      PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create()
+        .register("http", PlainConnectionSocketFactory.getSocketFactory())
+        .register("https", myFactory)
+        .build());
       poolingConnectionManager.setDefaultMaxPerRoute(1);
       poolingConnectionManager.setValidateAfterInactivity(2000);
       poolingConnectionManager.setDefaultSocketConfig(SocketConfig.custom()
@@ -125,7 +163,11 @@ public class ElasticSearchConnector exte
       connectionManager = poolingConnectionManager;
 
       CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
-
+      if (credentials != null)
+      {
+        credentialsProvider.setCredentials(AuthScope.ANY, credentials);
+      }
+      
       RequestConfig.Builder requestBuilder = RequestConfig.custom()
           .setCircularRedirectsAllowed(true)
           .setSocketTimeout(socketTimeout)



Mime
View raw message