This is an automated email from the ASF dual-hosted git repository.
gerlowskija pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 700d2f22910 SOLR-17515: Always init Http2SolrClient authStore (#2802)
700d2f22910 is described below
commit 700d2f2291030c0eade9b20004fdd428e633b7c1
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 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);