Apache Solr open-source search software
SOLR-15575: Propagate request level basic auth creds from the top-level request to internally used async requests (#246)
Timothy Potterdd655f700f25
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex b2b26a2393d..0d17ea4900e 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -404,6 +404,9 @@ Bug Fixes* SOLR-14506: Fix NPE in COLSTATUS for collections using implicit routing. (Austin Weidler, ab)+* SOLR-15575: Propagate request level basic auth creds from the top-level async CollectionAdminRequest to internally+ used async requests, such as async status checking (Timothy Potter)+Other Changes---------------------* SOLR-15566: Clarify ref guide documentation about SQL queries with `SELECT *` requiring a `LIMIT` clause (Timothy Potter)diff --git a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.javaindex cca61991152..d460669835f 100644--- a/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java+++ b/solr/core/src/test/org/apache/solr/cloud/TestPullReplicaWithAuth.java@@ -89,7 +89,7 @@ public class TestPullReplicaWithAuth extends SolrCloudTestCase {public void testPKIAuthWorksForPullReplication() throws Exception {int numPullReplicas = 2;withBasicAuth(CollectionAdminRequest.createCollection(collectionName, "conf", 1, 1, 0, numPullReplicas))- .process(cluster.getSolrClient());+ .processAndWait(cluster.getSolrClient(), 10);waitForState("Expected collection to be created with 1 shard and " + (numPullReplicas + 1) + " replicas",collectionName, clusterShape(1, numPullReplicas + 1));DocCollection docCollection =diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.javaindex d37cdcfe57b..9edfcb98c73 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CollectionAdminRequest.java@@ -126,6 +126,19 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>return SolrRequestType.ADMIN.toString();}+ /**+ * Take the request specific basic auth creds on this admin request and propagate them to a related request if does+ * not already have credentials set, such as a CollectionAdminRequest.RequestStatus when doing async requests.+ */+ protected <T extends CollectionAdminRequest<? extends CollectionAdminResponse>> T propagateBasicAuthCreds(T req) {+ String user = getBasicAuthUser();+ String pass = getBasicAuthPassword();+ if (user != null && pass != null && req.getBasicAuthUser() == null) {+ req.setBasicAuthCredentials(user, pass);+ }+ return req;+ }+/*** Base class for asynchronous collection admin requests*/@@ -207,7 +220,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>public RequestStatusState processAndWait(String asyncId, SolrClient client, long timeoutSeconds)throws IOException, SolrServerException, InterruptedException {processAsync(asyncId, client);- return requestStatus(asyncId).waitFor(client, timeoutSeconds);+ return propagateBasicAuthCreds(requestStatus(asyncId)).waitFor(client, timeoutSeconds);}@Override@@ -1617,7 +1630,7 @@ public abstract class CollectionAdminRequest<T extends CollectionAdminResponse>while (System.nanoTime() < finishTime) {state = this.process(client).getRequestStatus();if (state == RequestStatusState.COMPLETED || state == RequestStatusState.FAILED) {- deleteAsyncId(requestId).process(client);+ propagateBasicAuthCreds(deleteAsyncId(requestId)).process(client);return state;}TimeUnit.SECONDS.sleep(1);