You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2014/04/05 13:49:07 UTC

svn commit: r1585062 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/CHANGES.txt solr/core/ solr/core/src/java/org/apache/solr/util/SimplePostTool.java solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java

Author: uschindler
Date: Sat Apr  5 11:49:06 2014
New Revision: 1585062

URL: http://svn.apache.org/r1585062
Log:
Merged revision(s) 1585057 from lucene/dev/trunk:
SOLR-5960: Add support for basic authentication in post.jar tool

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SimplePostTool.java
    lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java

Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1585062&r1=1585061&r2=1585062&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Sat Apr  5 11:49:06 2014
@@ -121,6 +121,10 @@ New Features
   and capable of reporting its configuration, via REST API.
   (Tim Potter via Steve Rowe)
 
+* SOLR-5960: Add support for basic authentication in post.jar tool, e.g.:
+  java -Durl="http://username:password@hostname:8983/solr/update" -jar post.jar sample.xml
+  (Sameer Maggon via Uwe Schindler)
+
 Bug Fixes
 ----------------------
 

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SimplePostTool.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SimplePostTool.java?rev=1585062&r1=1585061&r2=1585062&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SimplePostTool.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/util/SimplePostTool.java Sat Apr  5 11:49:06 2014
@@ -50,6 +50,7 @@ import java.util.zip.GZIPInputStream;
 import java.util.zip.Inflater;
 import java.util.zip.InflaterInputStream;
 
+import javax.xml.bind.DatatypeConverter;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.xpath.XPath;
@@ -812,6 +813,10 @@ public class SimplePostTool {
     try {
       if(mockMode) return;
       HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
+      if (url.getUserInfo() != null) {
+        String encoding = DatatypeConverter.printBase64Binary(url.getUserInfo().getBytes(StandardCharsets.US_ASCII));
+        urlc.setRequestProperty("Authorization", "Basic " + encoding);
+      }
       if (HttpURLConnection.HTTP_OK != urlc.getResponseCode()) {
         warn("Solr returned an error #" + urlc.getResponseCode() + 
             " " + urlc.getResponseMessage() + " for url "+url);
@@ -845,7 +850,10 @@ public class SimplePostTool {
         urlc.setUseCaches(false);
         urlc.setAllowUserInteraction(false);
         urlc.setRequestProperty("Content-type", type);
-
+        if (url.getUserInfo() != null) {
+          String encoding = DatatypeConverter.printBase64Binary(url.getUserInfo().getBytes(StandardCharsets.US_ASCII));
+          urlc.setRequestProperty("Authorization", "Basic " + encoding);
+        }
         if (null != length) urlc.setFixedLengthStreamingMode(length);
 
       } catch (IOException e) {

Modified: lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java?rev=1585062&r1=1585061&r2=1585062&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java Sat Apr  5 11:49:06 2014
@@ -21,7 +21,6 @@ import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
@@ -62,7 +61,7 @@ public class SimplePostToolTest extends 
     t_web = SimplePostTool.parseArgsAndInit(args);
 
     System.setProperty("params", "param1=foo&param2=bar");
-    System.setProperty("url", "http://localhost:5150/solr/update");
+    System.setProperty("url", "http://user:password@localhost:5150/solr/update");
     t_test = SimplePostTool.parseArgsAndInit(args);
 
     pf = new MockPageFetcher();
@@ -83,7 +82,7 @@ public class SimplePostToolTest extends 
     assertEquals(1, t_web.recursive);
     assertEquals(10, t_web.delay);
     
-    assertEquals("http://localhost:5150/solr/update?param1=foo&param2=bar",t_test.solrUrl.toExternalForm());
+    assertEquals("http://user:password@localhost:5150/solr/update?param1=foo&param2=bar",t_test.solrUrl.toExternalForm());
   }
   
   @Test