prabhashkr commented on code in PR #21483:
URL: https://github.com/apache/kafka/pull/21483#discussion_r2852895546


##########
clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/secured/HttpRequestFormatterFactory.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.kafka.common.security.oauthbearer.internals.secured;
+
+import org.apache.kafka.common.config.SaslConfigs;
+import 
org.apache.kafka.common.security.oauthbearer.internals.secured.assertion.AssertionSupplierFactory;
+import 
org.apache.kafka.common.security.oauthbearer.internals.secured.assertion.CloseableSupplier;
+import org.apache.kafka.common.utils.Time;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Objects;
+
+import static 
org.apache.kafka.common.config.SaslConfigs.DEFAULT_SASL_OAUTHBEARER_HEADER_URLENCODE;
+import static 
org.apache.kafka.common.config.SaslConfigs.SASL_OAUTHBEARER_ASSERTION_CLAIM_ISS;
+import static 
org.apache.kafka.common.config.SaslConfigs.SASL_OAUTHBEARER_ASSERTION_FILE;
+import static 
org.apache.kafka.common.config.SaslConfigs.SASL_OAUTHBEARER_HEADER_URLENCODE;
+
+/**
+ * Factory class for creating {@link HttpRequestFormatter} instances based on 
the OAuth authentication
+ * method configured.
+ *
+ * <p>
+ * This factory implements a three-tier fallback mechanism: file-based 
assertion (first), locally-generated
+ * assertion (second), or client secret (third/fallback). When multiple 
authentication methods are configured,
+ * the first preference takes precedence and other configurations are ignored 
with a WARN log message.
+ * </p>
+ *
+ * <p>
+ * The factory handles reading configuration values from both the main 
configuration and JAAS options
+ * (for backward compatibility) using {@link ConfigOrJaas}.
+ * </p>
+ */
+public class HttpRequestFormatterFactory {

Review Comment:
   The current interface-based design (`HttpRequestFormatter`) is intentionally 
kept flat. Creating a `ClientCredentialsRequestFormatter` superclass would add 
a layer of
    abstraction without significant code sharing — the two implementations 
(`ClientAssertionRequestFormatter` and `ClientSecretRequestFormatter`) have 
quite different internals (different headers, body parameters, and only one 
implements `Closeable`). The factory already captures the "client credentials" 
concept in its fallback logic. Happy to reconsider if you feel strongly about 
it.



-- 
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