Hi Ravion,

(Note: I'm not sure what Solr version you're using.  My answer below
assumes Solr 7 APIs.  These APIs don't change often, but you might
find them under slightly different names in your version of Solr.)

SolrJ provides 2 ways (that I know of) to provide basic auth credentials.

The first (and IMO simplest) way is to use the setBasicAuthCredentials
method on each individual SolrRequest.  You can see what this looks
like in the example below:

final SolrClient client = new
SolrQuery req = new SolrQuery("*:*");
req.setBasicAuthCredentials("yourUsername", "yourPassword);

SolrJ also has a PreemptiveBasicAuthClientBuilderFactory, which reads
the username/password from Java system properties, and is used to
configure the HttpClient that SolrJ creates internally for sending
requests.  I find this second method a little more complex, and it
looks like you're providing your own HttpClient anyways, so for both
those reasons I'd recommend sticking with the first approach (at least
while you're getting things up and running).

Hope that helps.



On Thu, Aug 9, 2018 at 5:47 PM ☼ R Nair <ravishankar.n...@gmail.com> wrote:
> Dear all,
> I have tried my best to do it - searched all Google. But I an=m
> unsuccessful. Kindly help.
> We have a solo environment. Its secured with userid and password.
> I used
> CloudSolrClient.Builder(solrURLs).withHttpClient(mycloseablehttpclient)
> method to access it. The url is of the form http:/userid:password@/
> passionbytes.com/solr. I set defaultCollectionName later.
> In mycloseablehttpclient, I set Basic Authentication with
> CredentialProvider and gave url, port, userid and password.
> I have changed HTTPCLIENT to 4.4.1 version, even tried 4.5.3.
> Still, I get the JSON response from server, saying the URL did not return
> the state information from SOLR. It says HTTP 401 , Authentication Required.
> This is fourth day on this problem. Any help is appreciated. I have done
> whatever is available through documentation and/or Google.
> Best,
> Ravion

Reply via email to