richardantal commented on code in PR #299:
URL: https://github.com/apache/calcite-avatica/pull/299#discussion_r2763065677


##########
core/src/main/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryImpl.java:
##########
@@ -131,6 +131,24 @@ public static AvaticaHttpClientFactoryImpl getInstance() {
       LOG.debug("{} is not capable of kerberos authentication.", authType);
     }
 
+    if (client instanceof BearerAuthenticateable) {
+      if (AuthenticationType.BEARER == authType) {
+        try {
+          BearerTokenProvider tokenProvider =
+                  BearerTokenProviderFactory.getBearerTokenProvider(config);
+          String username = config.avaticaUser();
+          if (null == username) {
+            username = System.getProperty("user.name");
+          }
+          ((BearerAuthenticateable) client).setTokenProvider(username, 
tokenProvider);

Review Comment:
   The userName can not be null when calling setTokenProvider
   We need it later when we get the JWT token:
   `new BearerToken(tokenProvider.obtain(username))`



##########
core/src/main/java/org/apache/calcite/avatica/remote/BearerTokenProvider.java:
##########
@@ -0,0 +1,28 @@
+/*
+ * 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.calcite.avatica.remote;
+
+import org.apache.calcite.avatica.ConnectionConfig;
+
+import java.io.IOException;
+
+public interface BearerTokenProvider {
+
+  void init(ConnectionConfig config) throws IOException;
+
+  String obtain(String username);

Review Comment:
   Sure, I'll do that
   
   It returns the Token used for Authentication.



##########
core/src/main/java/org/apache/calcite/avatica/ConnectionPropertyValue.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.calcite.avatica;
+
+public interface ConnectionPropertyValue {
+  /**
+   * Returns the string value of this property, or null if not specified and
+   * no default.
+   */
+  String getString();
+
+  /**
+   * Returns the string value of this property, or null if not specified and
+   * no default.
+   */
+  String getString(String defaultValue);
+
+  /**
+   * Returns the int value of this property. Throws if not set and no

Review Comment:
   It has been copied from PropEnv, the same applies to all similar functions.
   Should I remove the` trows if not set and no default` part?
   Do you think a comment like this would be better?
   `Returns the long value of this property or the defaultValue.`



##########
core/src/test/java/org/apache/calcite/avatica/remote/BearerTokenProviderFactoryTest.java:
##########
@@ -0,0 +1,149 @@
+/*
+ * 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.calcite.avatica.remote;
+
+import org.apache.calcite.avatica.BuiltInConnectionProperty;
+import org.apache.calcite.avatica.ConnectionConfig;
+import org.apache.calcite.avatica.ConnectionConfigImpl;
+import org.apache.calcite.avatica.ConnectionProperty;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Properties;
+
+import static 
org.apache.calcite.avatica.remote.BearerTokenProviderFactoryTest.TestTokenProvider.*;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class BearerTokenProviderFactoryTest {

Review Comment:
   Can you please be more specific?
   
   In testCustomBearerToken and testConstantBearerToken I test the happy path 
to validate the correct behavior of tokenProvider.obtain.
   There is message property provided if the expected value is different from 
the actual.



##########
core/src/main/java/org/apache/calcite/avatica/ConnectionPropertyValue.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.calcite.avatica;
+
+public interface ConnectionPropertyValue {
+  /**
+   * Returns the string value of this property, or null if not specified and
+   * no default.
+   */
+  String getString();
+
+  /**
+   * Returns the string value of this property, or null if not specified and
+   * no default.
+   */
+  String getString(String defaultValue);

Review Comment:
   I think either getString methods Throw.
   It has been copied from PropEnv which is the implementation of this 
ConnectionPropertyValue interface



##########
core/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java:
##########
@@ -137,7 +137,16 @@ public enum BuiltInConnectionProperty implements 
ConnectionProperty {
    * HTTP Response Timeout (socket timeout) in milliseconds.
    */
   HTTP_RESPONSE_TIMEOUT("http_response_timeout",
-      Type.NUMBER, Timeout.ofMinutes(3).toMilliseconds(), false);
+                        Type.NUMBER, Timeout.ofMinutes(3).toMilliseconds(), 
false),
+
+  /** Bearer token to use to perform Bearer authentication. */
+  BEARER_TOKEN("bearer_token", Type.STRING, null, false),
+
+  /** File containing bearer tokens to use to perform Bearer authentication. */

Review Comment:
   Yes, a path
   With this I would like to add the possibility to add an other implementation 
for BearerTokenProvider In the future.
   Where instead of storing the Token, we can store the token file's location 
and load the token(s) from a file.
   
   



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