From 1acaced80b2eb8ace290ce12fcefffed5e4b359f Mon Sep 17 00:00:00 2001 From: Nick Shanin Date: Sun, 4 Oct 2026 10:42:16 +0000 Subject: [PATCH 1/5] SOLR-18368: fix the ref-guide example still using the removed withInternalClientBuilder alias, and pin the removal with a test (the removal itself landed upstream in #4782) --- .../pages/basic-authentication-plugin.adoc | 6 ++--- ...udHttp2SolrClientMultiConstructorTest.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc b/solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc index b3cce8cfd39a..a4ddc45fcade 100644 --- a/solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc +++ b/solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc @@ -368,13 +368,13 @@ var client = new HttpJettySolrClient.Builder(solrUrl) QueryResponse rsp = req.process(client); ---- -CloudSolrClient's Builder 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: +CloudSolrClient's Builder supports receiving an HTTP SolrClient builder for creating its internal client, so to set the credentials at the client level you could use a code like: [source,java] ---- -var httpClientBuilder = HttpJettySolrClient.Builder().withBasicAuthCredentials(userName, password); +var httpClientBuilder = new HttpJettySolrClient.Builder().withBasicAuthCredentials(userName, password); var client = new CloudSolrClient.Builder(zkHostList, chroot) - .withInternalClientBuilder(httpClientBuilder).build(); + .withHttpClientBuilder(httpClientBuilder).build(); QueryResponse rsp = req.process(client); ---- diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientMultiConstructorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientMultiConstructorTest.java index 83d9e55701a8..8088ce8541c2 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientMultiConstructorTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientMultiConstructorTest.java @@ -17,6 +17,7 @@ package org.apache.solr.client.solrj.impl; import java.io.IOException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashSet; @@ -87,4 +88,25 @@ public void testBadChroot() { new CloudSolrClient.Builder(new CloudSolrClient.CloudSolrClientConnection(true, zkHosts, "foo")) .build(); } + + /** SOLR-18368: the 9.10-deprecated alias is gone; callers use {@code withHttpClientBuilder}. */ + @Test + public void testWithInternalClientBuilderRemoved() { + boolean foundDeprecatedName = false; + boolean foundReplacement = false; + for (Method method : CloudSolrClient.Builder.class.getDeclaredMethods()) { + if ("withInternalClientBuilder".equals(method.getName())) { + foundDeprecatedName = true; + } + if ("withHttpClientBuilder".equals(method.getName())) { + foundReplacement = true; + } + } + assertFalse( + "SOLR-18368: CloudSolrClient.Builder.withInternalClientBuilder was removed; use withHttpClientBuilder", + foundDeprecatedName); + assertTrue( + "CloudSolrClient.Builder.withHttpClientBuilder must remain as the replacement", + foundReplacement); + } } From a7ec9a1b65c05b2e359e9a186fc2938fe7b7ca7d Mon Sep 17 00:00:00 2001 From: Nick Shanin Date: Mon, 5 Oct 2026 08:27:20 +0000 Subject: [PATCH 2/5] SOLR-18368: drop the reflection test pinning the withInternalClientBuilder removal, keep the docs fix only The test asserted by reflection that CloudSolrClient.Builder no longer declares withInternalClientBuilder. The method is already gone on main (the removal landed upstream in #4782), so the test passed before the change and could never fail: any caller of the removed method fails to compile anyway. The branch is now the ref-guide example fix alone. --- ...udHttp2SolrClientMultiConstructorTest.java | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientMultiConstructorTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientMultiConstructorTest.java index 8088ce8541c2..83d9e55701a8 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientMultiConstructorTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientMultiConstructorTest.java @@ -17,7 +17,6 @@ package org.apache.solr.client.solrj.impl; import java.io.IOException; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashSet; @@ -88,25 +87,4 @@ public void testBadChroot() { new CloudSolrClient.Builder(new CloudSolrClient.CloudSolrClientConnection(true, zkHosts, "foo")) .build(); } - - /** SOLR-18368: the 9.10-deprecated alias is gone; callers use {@code withHttpClientBuilder}. */ - @Test - public void testWithInternalClientBuilderRemoved() { - boolean foundDeprecatedName = false; - boolean foundReplacement = false; - for (Method method : CloudSolrClient.Builder.class.getDeclaredMethods()) { - if ("withInternalClientBuilder".equals(method.getName())) { - foundDeprecatedName = true; - } - if ("withHttpClientBuilder".equals(method.getName())) { - foundReplacement = true; - } - } - assertFalse( - "SOLR-18368: CloudSolrClient.Builder.withInternalClientBuilder was removed; use withHttpClientBuilder", - foundDeprecatedName); - assertTrue( - "CloudSolrClient.Builder.withHttpClientBuilder must remain as the replacement", - foundReplacement); - } } From 15dd2aa74b08044cb919a079e7c87044923e9934 Mon Sep 17 00:00:00 2001 From: Nick Shanin Date: Fri, 16 Oct 2026 07:44:29 +0000 Subject: [PATCH 3/5] SOLR-18368: name HttpSolrClient.BuilderBase in the basic-auth prose sentence --- .../deployment-guide/pages/basic-authentication-plugin.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc b/solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc index a4ddc45fcade..05ac287cfa78 100644 --- a/solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc +++ b/solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc @@ -368,7 +368,7 @@ var client = new HttpJettySolrClient.Builder(solrUrl) QueryResponse rsp = req.process(client); ---- -CloudSolrClient's Builder supports receiving an HTTP SolrClient builder for creating its internal client, so to set the credentials at the client level you could use a code like: +CloudSolrClient's Builder supports receiving an `HttpSolrClient.BuilderBase` instance for creating its internal client, so to set the credentials at the client level you could use a code like: [source,java] ---- From 1291474fcad113a742e67d693de0c1577b382887 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Tue, 20 Oct 2026 20:32:15 -0400 Subject: [PATCH 4/5] Test the per-client basic-auth SolrJ examples, include them in the doc Both code blocks in the 'Per-Client Credentials' section were hand-typed and had silently gone stale (the bug this branch's prior commits fix). Add BasicAuthenticationRefGuideExamplesTest, which exercises both snippets against a real cluster secured with BasicAuthPlugin, and switch the page to include::[] the tagged snippets instead of duplicating the code, so a future rename breaks the build instead of the docs. --- ...sicAuthenticationRefGuideExamplesTest.java | 124 ++++++++++++++++++ .../pages/basic-authentication-plugin.adoc | 13 +- 2 files changed, 128 insertions(+), 9 deletions(-) create mode 100644 solr/solr-ref-guide/modules/deployment-guide/examples/BasicAuthenticationRefGuideExamplesTest.java diff --git a/solr/solr-ref-guide/modules/deployment-guide/examples/BasicAuthenticationRefGuideExamplesTest.java b/solr/solr-ref-guide/modules/deployment-guide/examples/BasicAuthenticationRefGuideExamplesTest.java new file mode 100644 index 000000000000..150a47cdd42f --- /dev/null +++ b/solr/solr-ref-guide/modules/deployment-guide/examples/BasicAuthenticationRefGuideExamplesTest.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.solr.client.ref_guide_examples; + +import java.util.List; +import java.util.Optional; +import org.apache.solr.client.solrj.impl.CloudSolrClient; +import org.apache.solr.client.solrj.jetty.HttpJettySolrClient; +import org.apache.solr.client.solrj.request.CollectionAdminRequest; +import org.apache.solr.client.solrj.request.QueryRequest; +import org.apache.solr.client.solrj.request.SolrQuery; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.cloud.SolrCloudAuthTestCase; +import org.apache.solr.util.ExternalPaths; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Example SolrJ usage with Basic Authentication. + * + *

Snippets surrounded by "tag" and "end" comments are extracted and used in the Solr Reference + * Guide. + */ +public class BasicAuthenticationRefGuideExamplesTest extends SolrCloudAuthTestCase { + + private static final String COLLECTION = "techproducts"; + private static final String USER_NAME = "solr"; + private static final String PASSWORD = "SolrRocks"; + + private static final String SECURITY_JSON = + "{\n" + + " \"authentication\":{\n" + + " \"blockUnknown\": true,\n" + + " \"class\":\"solr.BasicAuthPlugin\",\n" + + " \"credentials\":{\"solr\":\"JeRyxP8A3dVWhFgFbf/Eg2RXmuoU8BE5gbNQyxmGAJQ= 6zkmjMjkMKyJX6/f0VarEWQujju5BzxZXub6WOrEKCw=\"}\n" + + " },\n" + + " \"authorization\":{\n" + + " \"class\":\"solr.RuleBasedAuthorizationPlugin\",\n" + + " \"permissions\":[\n" + + " {\"name\":\"security-edit\", \"role\":\"admin\"},\n" + + " {\"name\":\"collection-admin-edit\", \"role\":\"admin\"},\n" + + " {\"name\":\"core-admin-edit\", \"role\":\"admin\"}\n" + + " ],\n" + + " \"user-role\":{\"solr\":\"admin\"}\n" + + " }\n" + + "}"; + + @BeforeClass + public static void setupCluster() throws Exception { + configureCluster(1) + .addConfig("conf", ExternalPaths.DEFAULT_CONFIGSET) + .withSecurityJson(SECURITY_JSON) + .configure(); + + CollectionAdminRequest.createCollection(COLLECTION, "conf", 1, 1) + .setBasicAuthCredentials(USER_NAME, PASSWORD) + .process(cluster.getSolrClient()); + cluster.waitForActiveCollection(COLLECTION, 1, 1); + } + + @AfterClass + public static void tearDownCluster() throws Exception { + shutdownCluster(); + } + + @Test + public void perClientHttpJettySolrClientExample() throws Exception { + final String userName = USER_NAME; + final String password = PASSWORD; + final String solrUrl = cluster.getJettySolrRunner(0).getBaseUrl().toString() + "/" + COLLECTION; + QueryRequest req = new QueryRequest(new SolrQuery("*:*")); + + // tag::solrj-basicauth-per-client-httpjettysolrclient[] + var client = + new HttpJettySolrClient.Builder(solrUrl) + .withBasicAuthCredentials(userName, password) + .build(); + QueryResponse rsp = req.process(client); + // end::solrj-basicauth-per-client-httpjettysolrclient[] + + assertEquals(0, rsp.getStatus()); + client.close(); + } + + @Test + public void perClientCloudSolrClientExample() throws Exception { + final String userName = USER_NAME; + final String password = PASSWORD; + final List zkHostList = List.of(cluster.getZkServer().getZkAddress()); + final Optional chroot = Optional.empty(); + final SolrQuery query = new SolrQuery("*:*"); + query.set("collection", COLLECTION); + QueryRequest req = new QueryRequest(query); + + // tag::solrj-basicauth-per-client-cloudsolrclient[] + var httpClientBuilder = + new HttpJettySolrClient.Builder().withBasicAuthCredentials(userName, password); + var client = + new CloudSolrClient.Builder(zkHostList, chroot) + .withHttpClientBuilder(httpClientBuilder) + .build(); + QueryResponse rsp = req.process(client); + // end::solrj-basicauth-per-client-cloudsolrclient[] + + assertEquals(0, rsp.getStatus()); + client.close(); + } +} diff --git a/solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc b/solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc index 05ac287cfa78..4948de597345 100644 --- a/solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc +++ b/solr/solr-ref-guide/modules/deployment-guide/pages/basic-authentication-plugin.adoc @@ -361,21 +361,16 @@ This will ensure all requests issued with this particular client get the Basic A NOTE: The examples below use `HttpJettySolrClient`, which requires the `solr-solrj-jetty` maven dependency. -[source,java] +[source,java,indent=0] ---- -var client = new HttpJettySolrClient.Builder(solrUrl) - .withBasicAuthCredentials(userName, password).build(); -QueryResponse rsp = req.process(client); +include::example$BasicAuthenticationRefGuideExamplesTest.java[tag=solrj-basicauth-per-client-httpjettysolrclient] ---- CloudSolrClient's Builder supports receiving an `HttpSolrClient.BuilderBase` instance for creating its internal client, so to set the credentials at the client level you could use a code like: -[source,java] +[source,java,indent=0] ---- -var httpClientBuilder = new HttpJettySolrClient.Builder().withBasicAuthCredentials(userName, password); -var client = new CloudSolrClient.Builder(zkHostList, chroot) - .withHttpClientBuilder(httpClientBuilder).build(); -QueryResponse rsp = req.process(client); +include::example$BasicAuthenticationRefGuideExamplesTest.java[tag=solrj-basicauth-per-client-cloudsolrclient] ---- === Global (JVM) Basic Auth Credentials From 79f6624c62a24afc08bf06d31e13c8dfb17efd18 Mon Sep 17 00:00:00 2001 From: Eric Pugh Date: Wed, 21 Oct 2026 13:30:45 -0400 Subject: [PATCH 5/5] Make SECURITY_JSON a text block Readable JSON instead of a string-concatenation chain; no quote escaping needed. No other test defines a shared constant for this - BasicAuthOnSingleNodeTest, AuthWithShardHandlerFactoryOverrideTest, and TestQueryingOnDownCollection each independently define their own STD_CONF with a different (but equivalent) credential hash. --- ...sicAuthenticationRefGuideExamplesTest.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/solr/solr-ref-guide/modules/deployment-guide/examples/BasicAuthenticationRefGuideExamplesTest.java b/solr/solr-ref-guide/modules/deployment-guide/examples/BasicAuthenticationRefGuideExamplesTest.java index 150a47cdd42f..e2c6c9fd5665 100644 --- a/solr/solr-ref-guide/modules/deployment-guide/examples/BasicAuthenticationRefGuideExamplesTest.java +++ b/solr/solr-ref-guide/modules/deployment-guide/examples/BasicAuthenticationRefGuideExamplesTest.java @@ -44,22 +44,23 @@ public class BasicAuthenticationRefGuideExamplesTest extends SolrCloudAuthTestCa private static final String PASSWORD = "SolrRocks"; private static final String SECURITY_JSON = - "{\n" - + " \"authentication\":{\n" - + " \"blockUnknown\": true,\n" - + " \"class\":\"solr.BasicAuthPlugin\",\n" - + " \"credentials\":{\"solr\":\"JeRyxP8A3dVWhFgFbf/Eg2RXmuoU8BE5gbNQyxmGAJQ= 6zkmjMjkMKyJX6/f0VarEWQujju5BzxZXub6WOrEKCw=\"}\n" - + " },\n" - + " \"authorization\":{\n" - + " \"class\":\"solr.RuleBasedAuthorizationPlugin\",\n" - + " \"permissions\":[\n" - + " {\"name\":\"security-edit\", \"role\":\"admin\"},\n" - + " {\"name\":\"collection-admin-edit\", \"role\":\"admin\"},\n" - + " {\"name\":\"core-admin-edit\", \"role\":\"admin\"}\n" - + " ],\n" - + " \"user-role\":{\"solr\":\"admin\"}\n" - + " }\n" - + "}"; + """ + { + "authentication":{ + "blockUnknown": true, + "class":"solr.BasicAuthPlugin", + "credentials":{"solr":"JeRyxP8A3dVWhFgFbf/Eg2RXmuoU8BE5gbNQyxmGAJQ= 6zkmjMjkMKyJX6/f0VarEWQujju5BzxZXub6WOrEKCw="} + }, + "authorization":{ + "class":"solr.RuleBasedAuthorizationPlugin", + "permissions":[ + {"name":"security-edit", "role":"admin"}, + {"name":"collection-admin-edit", "role":"admin"}, + {"name":"core-admin-edit", "role":"admin"} + ], + "user-role":{"solr":"admin"} + } + }"""; @BeforeClass public static void setupCluster() throws Exception {