Copilot commented on code in PR #2894:
URL: https://github.com/apache/tika/pull/2894#discussion_r3440237572


##########
tika-pipes/tika-pipes-plugins/tika-pipes-solr/src/main/java/org/apache/tika/pipes/plugin/solr/SolrClientHelper.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.tika.pipes.plugin.solr;
+
+import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
+
+import org.apache.tika.client.HttpClientFactory;
+import org.apache.tika.exception.TikaConfigException;
+import org.apache.tika.utils.StringUtils;
+
+public final class SolrClientHelper {
+
+    private SolrClientHelper() {}
+
+    /**
+     * Applies authentication and proxy settings to a {@link 
HttpJettySolrClient.Builder}.
+     * When a username is configured, only the basic auth scheme is supported; 
any other scheme
+     * throws {@link TikaConfigException}. When no username is set, auth is 
skipped regardless
+     * of the configured scheme (matching the behaviour of the original 
Http2SolrClient code).
+     * Proxy is only configured when both a non-blank host and a positive port 
are present.
+     */
+    public static void applyAuthAndProxy(HttpJettySolrClient.Builder builder,
+                                         HttpClientFactory factory) throws 
TikaConfigException {
+        if (!StringUtils.isBlank(factory.getUserName())) {
+            if (!"basic".equalsIgnoreCase(factory.getAuthScheme())) {
+                throw new TikaConfigException(
+                        "Only 'basic' auth scheme is supported by 
HttpJettySolrClient; got: '"
+                                + factory.getAuthScheme() + "'");
+            }
+            builder.withBasicAuthCredentials(factory.getUserName(), 
factory.getPassword());
+        }

Review Comment:
   When a username is set but the password is missing/blank, this helper still 
calls withBasicAuthCredentials(user, null). Previously, the direct-URL Solr 
client path validated credentials via HttpClientFactory.build() (and would fail 
fast on incomplete creds). Add an explicit check to reject partial credentials 
so misconfiguration is caught early and consistently.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to