This is an automated email from the ASF dual-hosted git repository.
gerlowskija pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new cae9f7c16f4 SOLR-17515: Always init Http2SolrClient authStore (#2802)
cae9f7c16f4 is described below
commit cae9f7c16f4a4fe20544dee5886cae2989a897c8
Author: Jason Gerlowski <[email protected]>
AuthorDate: Tue Oct 29 11:15:22 2024 -0700
SOLR-17515: Always init Http2SolrClient authStore (#2802)
Prior to this commit, Http2SolrClient only initialized its
'authenticationStore' instance var when creating a fresh Jetty
HttpClient. This causes NPE's later on when client code (e.g.
PreemptiveBasicAuthClientBuilderFactory) would attempt to access the
object.
This commit fixes this by making sure that 'authenticationStore' is
initialized when using an existing Jetty client (typically by reusing
the AuthenticationStore already used by the client).
---
.../src/test/org/apache/solr/cloud/RecoveryZkTestWithAuth.java | 10 ++++++++++
.../org/apache/solr/client/solrj/impl/Http2SolrClient.java | 10 ++++++++++
2 files changed, 20 insertions(+)
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 1609f34bdf2..7edaa4090a2 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;
@@ -60,6 +61,15 @@ 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", 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 36f8bfcf9b2..cf8415ee64c 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
@@ -137,6 +137,8 @@ public class Http2SolrClient extends HttpSolrClientBase {
if (this.executor == null) {
this.executor = builder.executor;
}
+
+ initAuthStoreFromExistingClient(httpClient);
this.closeClient = false;
} else {
this.httpClient = createHttpClient(builder);
@@ -152,6 +154,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);