Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-17515: Always init Http2SolrClient authStore (#2802)

Jason Gerlowski700d2f229103
diff --git a/solr/core/src/test/org/apache/solr/cloud/RecoveryZkTestWithAuth.java b/solr/core/src/test/org/apache/solr/cloud/RecoveryZkTestWithAuth.java
index 63f66736b83..2cec10d8610 100644
--- a/solr/core/src/test/org/apache/solr/cloud/RecoveryZkTestWithAuth.java
+++ b/solr/core/src/test/org/apache/solr/cloud/RecoveryZkTestWithAuth.java
@@ -27,6 +27,7 @@ import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudLegacySolrClient;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.QueryRequest;
@@ -43,6 +44,15 @@ import org.junit.Test;
public class RecoveryZkTestWithAuth extends SolrCloudTestCase {
@BeforeClass
public static void setupCluster() throws Exception {
+ // Periodically mimic the sysprops set by bin/solr when it knows auth is active (see SOLR-17515
+ // for context)
+ if (rarely()) {
+ System.setProperty(
+ HttpClientUtil.SYS_PROP_HTTP_CLIENT_BUILDER_FACTORY,
+ "org.apache.solr.client.solrj.impl.PreemptiveBasicAuthClientBuilderFactory");
+ System.setProperty("basicauth", SecurityJson.USER_PASS);
+ }
+
cluster =
configureCluster(1)
.addConfig("conf", configset("cloud-minimal"))
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
index c35e11cf491..e3f974e41e3 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
@@ -133,6 +133,8 @@ public class Http2SolrClient extends HttpSolrClientBase {
if (this.executor == null) {
this.executor = builder.executor;
}
+
+ initAuthStoreFromExistingClient(httpClient);
this.closeClient = false;
} else {
this.httpClient = createHttpClient(builder);
@@ -148,6 +150,14 @@ public class Http2SolrClient extends HttpSolrClientBase {
assert ObjectReleaseTracker.track(this);
}
+ private void initAuthStoreFromExistingClient(HttpClient httpClient) {
+ // Since we don't allow users to provide arbitrary Jetty clients, all parameters to this method
+ // must originate from the 'createHttpClient' method, which uses AuthenticationStoreHolder.
+ // Verify this assumption and copy the existing instance to avoid unnecessary wrapping.
+ assert httpClient.getAuthenticationStore() instanceof AuthenticationStoreHolder;
+ this.authenticationStore = (AuthenticationStoreHolder) httpClient.getAuthenticationStore();
+ }
+
@Deprecated(since = "9.7")
public void addListenerFactory(HttpListenerFactory factory) {
this.listenerFactory.add(factory);