Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-15155: Document how to set credentials in CloudHttp2SolrClient (#51)

Tomas Fernandez Lobbe72a99483c93c
diff --git a/solr/solr-ref-guide/src/basic-authentication-plugin.adoc b/solr/solr-ref-guide/src/basic-authentication-plugin.adoc
index 3e0fef1de03..48e6485da04 100644
--- a/solr/solr-ref-guide/src/basic-authentication-plugin.adoc
+++ b/solr/solr-ref-guide/src/basic-authentication-plugin.adoc
@@ -223,6 +223,16 @@ Http2SolrClient client = new Http2SolrClient.Builder(solrUrl)
QueryResponse rsp = req.process(client);
----
+CloudHttp2SolrClient supports receiving an `Http2SolrClient.Builder` instance for creating its internal client, so to set the credentials at the client level you could use a code like:
+
+[source,java]
+----
+Http2SolrClient.Builder http2ClientBuilder = Http2SolrClient.Builder().withBasicAuthCredentials(userName, password);
+CloudHttp2SolrClient client = new CloudHttp2SolrClient.Builder(zkHostList, chroot)
+ .withInternalClientBuilder(http2ClientBuilder).build();
+QueryResponse rsp = req.process(client);
+----
+
=== Global (JVM) Basic Auth Credentials
Alternatively, users can use SolrJ's `PreemptiveBasicAuthClientBuilderFactory` to add basic authentication credentials to _all_ requests automatically.
To enable this feature, users should set the following system property `-Dsolr.httpclient.builder.factory=org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory`.