You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2014/11/17 16:48:42 UTC

svn commit: r1640174 - in /manifoldcf/branches/CONNECTORS-1104/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf: authorities/authorities/sharepoint/SharePointAuthority.java crawler/connectors/sharepoint/SharePointRepository.java

Author: kwright
Date: Mon Nov 17 15:48:42 2014
New Revision: 1640174

URL: http://svn.apache.org/r1640174
Log:
Hook up proxy definition to code

Modified:
    manifoldcf/branches/CONNECTORS-1104/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java
    manifoldcf/branches/CONNECTORS-1104/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java

Modified: manifoldcf/branches/CONNECTORS-1104/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1104/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java?rev=1640174&r1=1640173&r2=1640174&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1104/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java (original)
+++ manifoldcf/branches/CONNECTORS-1104/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java Mon Nov 17 15:48:42 2014
@@ -56,6 +56,7 @@ import org.apache.http.impl.client.Defau
 import org.apache.http.util.EntityUtils;
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.HttpHost;
 
 
 /** This is the native SharePoint implementation of the IAuthorityConnector interface.
@@ -90,6 +91,12 @@ public class SharePointAuthority extends
   private String encodedServerLocation = null;
   private String keystoreData = null;
   
+  private String proxyHost = null;
+  private String proxyPortString = null;
+  private String proxyUsername = null;
+  private String proxyPassword = null;
+  private String proxyDomain = null;
+  
   private String cacheLRUsize = null;
   private String cacheLifetime = null;
   
@@ -205,6 +212,12 @@ public class SharePointAuthority extends
       ntlmDomain = null;
     }
     
+    proxyHost = params.getParameter(SharePointConfig.PARAM_PROXYHOST);
+    proxyPortString = params.getParameter(SharePointConfig.PARAM_PROXYPORT);
+    proxyUsername = params.getParameter(SharePointConfig.PARAM_PROXYUSER);
+    proxyPassword = params.getParameter(SharePointConfig.PARAM_PROXYPASSWORD);
+    proxyDomain = params.getParameter(SharePointConfig.PARAM_PROXYDOMAIN);
+
     keystoreData = params.getParameter(SharePointConfig.PARAM_SERVERKEYSTORE);
 
   }
@@ -289,6 +302,12 @@ public class SharePointAuthority extends
     encodedServerLocation = null;
     serverPort = -1;
 
+    proxyHost = null;
+    proxyPortString = null;
+    proxyUsername = null;
+    proxyPassword = null;
+    proxyDomain = null;
+    
     keystoreData = null;
     keystoreManager = null;
 
@@ -741,6 +760,19 @@ public class SharePointAuthority extends
         throw new ManifoldCFException(e.getMessage(),e);
       }
       
+      int proxyPort = 8080;
+      if (proxyPortString != null && proxyPortString.length() > 0)
+      {
+        try
+        {
+          proxyPort = Integer.parseInt(proxyPortString);
+        }
+        catch (NumberFormatException e)
+        {
+          throw new ManifoldCFException(e.getMessage(),e);
+        }
+      }
+
       serverUrl = serverProtocol + "://" + serverName;
       if (serverProtocol.equals("https"))
       {
@@ -786,6 +818,28 @@ public class SharePointAuthority extends
           .setConnectTimeout(connectionTimeout)
           .setConnectionRequestTimeout(socketTimeout);
 
+      // If there's a proxy, set that too.
+      if (proxyHost != null && proxyHost.length() > 0)
+      {
+
+        // Configure proxy authentication
+        if (proxyUsername != null && proxyUsername.length() > 0)
+        {
+          if (proxyPassword == null)
+            proxyPassword = "";
+          if (proxyDomain == null)
+            proxyDomain = "";
+
+          credentialsProvider.setCredentials(
+            new AuthScope(proxyHost, proxyPort),
+            new NTCredentials(proxyUsername, proxyPassword, currentHost, proxyDomain));
+        }
+
+        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
+
+        requestBuilder.setProxy(proxy);
+      }
+
       HttpClientBuilder builder = HttpClients.custom()
         .setConnectionManager(connectionManager)
         .setMaxConnTotal(1)

Modified: manifoldcf/branches/CONNECTORS-1104/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1104/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java?rev=1640174&r1=1640173&r2=1640174&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1104/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java (original)
+++ manifoldcf/branches/CONNECTORS-1104/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java Mon Nov 17 15:48:42 2014
@@ -66,6 +66,7 @@ import org.apache.http.impl.client.Defau
 import org.apache.http.util.EntityUtils;
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.HttpHost;
 
 /** This is the "repository connector" for Microsoft SharePoint.
 * Document identifiers for this connector come in three forms:
@@ -216,6 +217,24 @@ public class SharePointRepository extend
         ntlmDomain = null;
       }
 
+      String proxyHost = params.getParameter(SharePointConfig.PARAM_PROXYHOST);
+      String proxyPortString = params.getParameter(SharePointConfig.PARAM_PROXYPORT);
+      int proxyPort = 8080;
+      if (proxyPortString != null && proxyPortString.length() > 0)
+      {
+        try
+        {
+          proxyPort = Integer.parseInt(proxyPortString);
+        }
+        catch (NumberFormatException e)
+        {
+          throw new ManifoldCFException(e.getMessage(),e);
+        }
+      }
+      String proxyUsername = params.getParameter(SharePointConfig.PARAM_PROXYUSER);
+      String proxyPassword = params.getParameter(SharePointConfig.PARAM_PROXYPASSWORD);
+      String proxyDomain = params.getParameter(SharePointConfig.PARAM_PROXYDOMAIN);
+      
       serverUrl = serverProtocol + "://" + serverName;
       if (serverProtocol.equals("https"))
       {
@@ -262,6 +281,28 @@ public class SharePointRepository extend
           .setConnectTimeout(connectionTimeout)
           .setConnectionRequestTimeout(socketTimeout);
 
+      // If there's a proxy, set that too.
+      if (proxyHost != null && proxyHost.length() > 0)
+      {
+
+        // Configure proxy authentication
+        if (proxyUsername != null && proxyUsername.length() > 0)
+        {
+          if (proxyPassword == null)
+            proxyPassword = "";
+          if (proxyDomain == null)
+            proxyDomain = "";
+
+          credentialsProvider.setCredentials(
+            new AuthScope(proxyHost, proxyPort),
+            new NTCredentials(proxyUsername, proxyPassword, currentHost, proxyDomain));
+        }
+
+        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
+
+        requestBuilder.setProxy(proxy);
+      }
+
       HttpClientBuilder builder = HttpClients.custom()
         .setConnectionManager(connectionManager)
         .setMaxConnTotal(1)