[ 
https://issues.apache.org/jira/browse/SOLR-1490?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15754983#comment-15754983
 ] 

Chantal Ackermann edited comment on SOLR-1490 at 12/19/16 12:45 PM:
--------------------------------------------------------------------

It would be nice if the user info from the URL could be used as done in this 
code snippet:

{code:java}
URL url = new URL("http://user:[email protected]/url";);
URLConnection conn = url.openConnection();

String userInfo = url.getUserInfo();
if (userInfo != null) {
    Base64.Encoder encoder = Base64.getEncoder();
    String basicAuth = "Basic " + 
encoder.encodeToString(userInfo.getBytes(UTF_8));
    conn.setRequestProperty("Authorization", basicAuth);
} else {
    throw new RuntimeException("No user info detected!");
}

InputStream is = conn.getInputStream();
{code}
inspired from http://stackoverflow.com/a/13122190/621690

This works for me in a subclass of 
org.apache.solr.handler.dataimport.URLDataSource.

Note that when fetching via HTTPS, a user agent might have to be set explicitly 
(at least, that's the case for me) - either programmatically in the DataSource 
class or via -Dhttp.agent jvm commandline argument.



was (Author: chantal):
It would be nice if the user info from the URL could be used as done in this 
code snippet:

{code:java}
URL url = new URL("http://user:[email protected]/url";);
URLConnection urlConnection = url.openConnection();

if (url.getUserInfo() != null) {
    String basicAuth = "Basic " + new String(new 
Base64().encode(url.getUserInfo().getBytes()));
    urlConnection.setRequestProperty("Authorization", basicAuth);
}

InputStream inputStream = urlConnection.getInputStream();
{code}
taken from http://stackoverflow.com/a/13122190/621690


> URLDataSource should be able to handle HTTP authentication
> ----------------------------------------------------------
>
>                 Key: SOLR-1490
>                 URL: https://issues.apache.org/jira/browse/SOLR-1490
>             Project: Solr
>          Issue Type: Improvement
>          Components: contrib - DataImportHandler
>            Reporter: Adam Foltzer
>            Assignee: Noble Paul
>         Attachments: SOLR-1490.patch
>
>
> Right now, there seems to be no way to provide HTTP authentication 
> (username/password) to the URLDataSource. This makes any password-protected 
> data sources inaccessible for indexing. I would try and add support myself, 
> but with all things security-related, I'm fearful of shooting myself in the 
> foot with systems I don't fully understand. Thanks for your time/feedback!



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to