manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1610669 - in /manifoldcf/trunk: ./ connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/ connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/
Date Tue, 15 Jul 2014 12:12:42 GMT
Author: kwright
Date: Tue Jul 15 12:12:42 2014
New Revision: 1610669

URL: http://svn.apache.org/r1610669
Log:
Fix for CONNECTORS-991.

Modified:
    manifoldcf/trunk/CHANGES.txt
    manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraAuthorityConnector.java
    manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraSession.java
    manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraRepositoryConnector.java
    manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraSession.java

Modified: manifoldcf/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/CHANGES.txt?rev=1610669&r1=1610668&r2=1610669&view=diff
==============================================================================
--- manifoldcf/trunk/CHANGES.txt (original)
+++ manifoldcf/trunk/CHANGES.txt Tue Jul 15 12:12:42 2014
@@ -3,6 +3,10 @@ $Id$
 
 ======================= 1.7-dev =====================
 
+CONNECTORS-991: Make Jira connector perform pre-emptive basic auth
+since Jira supports guest users.
+(Daniel Aschauer, Karl Wright)
+
 CONNECTORS-988: Performance improvements for split pipeline crawls.
 (Karl Wright)
 

Modified: manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraAuthorityConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraAuthorityConnector.java?rev=1610669&r1=1610668&r2=1610669&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraAuthorityConnector.java
(original)
+++ manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraAuthorityConnector.java
Tue Jul 15 12:12:42 2014
@@ -214,9 +214,44 @@ public class JiraAuthorityConnector exte
         Logging.authorityConnectors.debug("JIRA: Clientsecret = '" + clientsecret + "'");
       }
 
-      String jiraurl = jiraprotocol + "://" + jirahost + (StringUtils.isEmpty(jiraport)?"":":"+jiraport)
+ jirapath;
-      session = new JiraSession(clientid, clientsecret, jiraurl,
-        jiraproxyhost, jiraproxyport, jiraproxydomain, jiraproxyusername, jiraproxypassword);
+      int portInt;
+      if (jiraport != null && jiraport.length() > 0)
+      {
+        try
+        {
+          portInt = Integer.parseInt(jiraport);
+        }
+        catch (NumberFormatException e)
+        {
+          throw new ManifoldCFException("Bad number: "+e.getMessage(),e);
+        }
+      }
+      else
+      {
+        if (jiraprotocol.toLowerCase(Locale.ROOT).equals("http"))
+          portInt = 80;
+        else
+          portInt = 443;
+      }
+
+      int proxyPortInt;
+      if (jiraproxyport != null && jiraproxyport.length() > 0)
+      {
+        try
+        {
+          proxyPortInt = Integer.parseInt(jiraproxyport);
+        }
+        catch (NumberFormatException e)
+        {
+          throw new ManifoldCFException("Bad number: "+e.getMessage(),e);
+        }
+      }
+      else
+        proxyPortInt = 8080;
+
+      session = new JiraSession(clientid, clientsecret,
+        jiraprotocol, jirahost, portInt, jirapath,
+        jiraproxyhost, proxyPortInt, jiraproxydomain, jiraproxyusername, jiraproxypassword);
 
     }
     lastSessionFetch = System.currentTimeMillis();

Modified: manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraSession.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraSession.java?rev=1610669&r1=1610668&r2=1610669&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraSession.java
(original)
+++ manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/jira/JiraSession.java
Tue Jul 15 12:12:42 2014
@@ -64,6 +64,10 @@ import org.apache.http.client.HttpReques
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
 import org.apache.http.entity.ContentType;
+import org.apache.http.client.AuthCache;
+import org.apache.http.impl.client.BasicAuthCache;
+import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.client.protocol.HttpClientContext;
 
 import org.apache.http.ParseException;
 
@@ -77,7 +81,8 @@ import org.json.simple.JSONArray;
  */
 public class JiraSession {
 
-  private final String URLbase;
+  private final HttpHost host;
+  private final String path;
   private final String clientId;
   private final String clientSecret;
   
@@ -104,10 +109,12 @@ public class JiraSession {
   /**
    * Constructor. Create a session.
    */
-  public JiraSession(String clientId, String clientSecret, String URLbase,
-    String proxyHost, String proxyPort, String proxyDomain, String proxyUsername, String
proxyPassword)
+  public JiraSession(String clientId, String clientSecret,
+    String protocol, String host, int port, String path,
+    String proxyHost, int proxyPort, String proxyDomain, String proxyUsername, String proxyPassword)
     throws ManifoldCFException {
-    this.URLbase = URLbase;
+    this.host = new HttpHost(host,port,protocol);
+    this.path = path;
     this.clientId = clientId;
     this.clientSecret = clientSecret;
 
@@ -142,21 +149,6 @@ public class JiraSession {
     if (proxyHost != null && proxyHost.length() > 0)
     {
 
-      int proxyPortInt;
-      if (proxyPort != null && proxyPort.length() > 0)
-      {
-        try
-        {
-          proxyPortInt = Integer.parseInt(proxyPort);
-        }
-        catch (NumberFormatException e)
-        {
-          throw new ManifoldCFException("Bad number: "+e.getMessage(),e);
-        }
-      }
-      else
-        proxyPortInt = 8080;
-
       // Configure proxy authentication
       if (proxyUsername != null && proxyUsername.length() > 0)
       {
@@ -166,11 +158,11 @@ public class JiraSession {
           proxyDomain = "";
 
         credentialsProvider.setCredentials(
-          new AuthScope(proxyHost, proxyPortInt),
+          new AuthScope(proxyHost, proxyPort),
           new NTCredentials(proxyUsername, proxyPassword, currentHost, proxyDomain));
       }
 
-      HttpHost proxy = new HttpHost(proxyHost, proxyPortInt);
+      HttpHost proxy = new HttpHost(proxyHost, proxyPort);
       requestBuilder.setProxy(proxy);
     }
 
@@ -261,14 +253,25 @@ public class JiraSession {
     return charSet;
   }
 
-  private void getRest(String rightside, JiraJSONResponse response)
+  private void getRest(String rightside, JiraJSONResponse response) 
     throws IOException, ResponseException {
 
-    final HttpRequestBase method = new HttpGet(URLbase + rightside);
+    // Create AuthCache instance
+    AuthCache authCache = new BasicAuthCache();
+    // Generate BASIC scheme object and add it to the local
+    // auth cache
+    BasicScheme basicAuth = new BasicScheme();
+    authCache.put(host, basicAuth);
+
+    // Add AuthCache to the execution context
+    HttpClientContext localContext = HttpClientContext.create();
+    localContext.setAuthCache(authCache);
+
+    final HttpRequestBase method = new HttpGet(host.toURI() + path + rightside);
     method.addHeader("Accept", "application/json");
 
     try {
-      HttpResponse httpResponse = httpClient.execute(method);
+      HttpResponse httpResponse = httpClient.execute(method,localContext);
       int resultCode = httpResponse.getStatusLine().getStatusCode();
       if (resultCode != 200)
         throw new ResponseException("Unexpected result code "+resultCode+": "+convertToString(httpResponse));

Modified: manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraRepositoryConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraRepositoryConnector.java?rev=1610669&r1=1610668&r2=1610669&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraRepositoryConnector.java
(original)
+++ manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraRepositoryConnector.java
Tue Jul 15 12:12:42 2014
@@ -290,9 +290,44 @@ public class JiraRepositoryConnector ext
         Logging.connectors.debug("JIRA: Clientsecret = '" + clientsecret + "'");
       }
 
-      String jiraurl = jiraprotocol + "://" + jirahost + (StringUtils.isEmpty(jiraport)?"":":"+jiraport)
+ jirapath;
-      session = new JiraSession(clientid, clientsecret, jiraurl,
-        jiraproxyhost, jiraproxyport, jiraproxydomain, jiraproxyusername, jiraproxypassword);
+      int portInt;
+      if (jiraport != null && jiraport.length() > 0)
+      {
+        try
+        {
+          portInt = Integer.parseInt(jiraport);
+        }
+        catch (NumberFormatException e)
+        {
+          throw new ManifoldCFException("Bad number: "+e.getMessage(),e);
+        }
+      }
+      else
+      {
+        if (jiraprotocol.toLowerCase(Locale.ROOT).equals("http"))
+          portInt = 80;
+        else
+          portInt = 443;
+      }
+
+      int proxyPortInt;
+      if (jiraproxyport != null && jiraproxyport.length() > 0)
+      {
+        try
+        {
+          proxyPortInt = Integer.parseInt(jiraproxyport);
+        }
+        catch (NumberFormatException e)
+        {
+          throw new ManifoldCFException("Bad number: "+e.getMessage(),e);
+        }
+      }
+      else
+        proxyPortInt = 8080;
+
+      session = new JiraSession(clientid, clientsecret,
+        jiraprotocol, jirahost, portInt, jirapath,
+        jiraproxyhost, proxyPortInt, jiraproxydomain, jiraproxyusername, jiraproxypassword);
 
     }
     lastSessionFetch = System.currentTimeMillis();

Modified: manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraSession.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraSession.java?rev=1610669&r1=1610668&r2=1610669&view=diff
==============================================================================
--- manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraSession.java
(original)
+++ manifoldcf/trunk/connectors/jira/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/jira/JiraSession.java
Tue Jul 15 12:12:42 2014
@@ -62,6 +62,10 @@ import org.apache.http.client.HttpReques
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
 import org.apache.http.entity.ContentType;
+import org.apache.http.client.AuthCache;
+import org.apache.http.impl.client.BasicAuthCache;
+import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.client.protocol.HttpClientContext;
 
 import org.apache.http.ParseException;
 
@@ -75,7 +79,8 @@ import org.json.simple.JSONArray;
  */
 public class JiraSession {
 
-  private final String URLbase;
+  private final HttpHost host;
+  private final String path;
   private final String clientId;
   private final String clientSecret;
   
@@ -102,10 +107,12 @@ public class JiraSession {
   /**
    * Constructor. Create a session.
    */
-  public JiraSession(String clientId, String clientSecret, String URLbase,
-    String proxyHost, String proxyPort, String proxyDomain, String proxyUsername, String
proxyPassword)
+  public JiraSession(String clientId, String clientSecret,
+    String protocol, String host, int port, String path,
+    String proxyHost, int proxyPort, String proxyDomain, String proxyUsername, String proxyPassword)
     throws ManifoldCFException {
-    this.URLbase = URLbase;
+    this.host = new HttpHost(host,port,protocol);
+    this.path = path;
     this.clientId = clientId;
     this.clientSecret = clientSecret;
 
@@ -140,20 +147,6 @@ public class JiraSession {
     if (proxyHost != null && proxyHost.length() > 0)
     {
 
-      int proxyPortInt;
-      if (proxyPort != null && proxyPort.length() > 0)
-      {
-        try
-        {
-          proxyPortInt = Integer.parseInt(proxyPort);
-        }
-        catch (NumberFormatException e)
-        {
-          throw new ManifoldCFException("Bad number: "+e.getMessage(),e);
-        }
-      }
-      else
-        proxyPortInt = 8080;
 
       // Configure proxy authentication
       if (proxyUsername != null && proxyUsername.length() > 0)
@@ -164,11 +157,11 @@ public class JiraSession {
           proxyDomain = "";
 
         credentialsProvider.setCredentials(
-          new AuthScope(proxyHost, proxyPortInt),
+          new AuthScope(proxyHost, proxyPort),
           new NTCredentials(proxyUsername, proxyPassword, currentHost, proxyDomain));
       }
 
-      HttpHost proxy = new HttpHost(proxyHost, proxyPortInt);
+      HttpHost proxy = new HttpHost(proxyHost, proxyPort);
       requestBuilder.setProxy(proxy);
     }
 
@@ -262,11 +255,22 @@ public class JiraSession {
   private void getRest(String rightside, JiraJSONResponse response) 
     throws IOException, ResponseException {
 
-    final HttpRequestBase method = new HttpGet(URLbase + rightside);
+    // Create AuthCache instance
+    AuthCache authCache = new BasicAuthCache();
+    // Generate BASIC scheme object and add it to the local
+    // auth cache
+    BasicScheme basicAuth = new BasicScheme();
+    authCache.put(host, basicAuth);
+
+    // Add AuthCache to the execution context
+    HttpClientContext localContext = HttpClientContext.create();
+    localContext.setAuthCache(authCache);
+
+    final HttpRequestBase method = new HttpGet(host.toURI() + path + rightside);
     method.addHeader("Accept", "application/json");
 
     try {
-      HttpResponse httpResponse = httpClient.execute(method);
+      HttpResponse httpResponse = httpClient.execute(method,localContext);
       int resultCode = httpResponse.getStatusLine().getStatusCode();
       if (resultCode != 200)
         throw new IOException("Unexpected result code "+resultCode+": "+convertToString(httpResponse));



Mime
View raw message