klion26 commented on code in PR #3905:
URL: https://github.com/apache/amoro/pull/3905#discussion_r2510192001


##########
amoro-ams/src/main/java/org/apache/amoro/server/authentication/HttpAuthenticationFactory.java:
##########
@@ -40,4 +57,28 @@ private static <T> T createAuthenticationProvider(
       throw new IllegalStateException(className + " must extend of " + 
expected.getName());
     }
   }
+
+  public static TokenCredential getBearerTokenCredential(
+      Context context, String proxyClientIpHeader) {
+    return new DefaultTokenCredential(
+        getBearerToken(context), getCredentialExtraInfo(context, 
proxyClientIpHeader));
+  }
+
+  private static String getBearerToken(Context context) {
+    String authorization = context.header(Header.AUTHORIZATION);
+    if (authorization != null) {

Review Comment:
   Do we need to add some comments for this



##########
amoro-common/src/main/java/org/apache/amoro/spi/authentication/TokenCredential.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.amoro.spi.authentication;
+
+import java.util.Map;
+
+public interface TokenCredential {
+  String CLIENT_IP_KEY = "clientIp";

Review Comment:
   Can this constant be static?



##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/DashboardServer.java:
##########
@@ -90,6 +92,8 @@ public class DashboardServer {
   private final ApiTokenController apiTokenController;
 
   private final PasswdAuthenticationProvider basicAuthProvider;
+  private final TokenAuthenticationProvider bearerAuthProvider;
+  private final String proxyClientIpHeader;

Review Comment:
   Do we need to inject the `proxyClientIp` into `basicAuthProvider` ?



##########
amoro-ams/src/test/java/org/apache/amoro/server/authentication/UserDefinedTokenAuthenticationProviderImpl.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.amoro.server.authentication;
+
+import org.apache.amoro.exception.SignatureCheckException;
+import org.apache.amoro.spi.authentication.BasicPrincipal;
+import org.apache.amoro.spi.authentication.TokenAuthenticationProvider;
+import org.apache.amoro.spi.authentication.TokenCredential;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.security.Principal;
+
+public class UserDefinedTokenAuthenticationProviderImpl implements 
TokenAuthenticationProvider {
+  private static final Logger LOG =
+      
LoggerFactory.getLogger(UserDefinedTokenAuthenticationProviderImpl.class);
+  public static final String VALID_TOKEN = "token";
+
+  @Override
+  public Principal authenticate(TokenCredential credential) throws 
SignatureCheckException {
+    String clientIp = 
credential.extraInfo().get(TokenCredential.CLIENT_IP_KEY);
+    if (VALID_TOKEN.equals(credential.token())) {
+      LOG.info("Success log in of token: {} with clientIp: {}", 
credential.token(), clientIp);

Review Comment:
   Seems the `credential.token()` here is always be `token`?



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