turboFei commented on code in PR #4009:
URL: https://github.com/apache/amoro/pull/4009#discussion_r2653749828


##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/LoginController.java:
##########
@@ -49,10 +50,11 @@ public void login(Context ctx) {
     Map<String, String> bodyParams = ctx.bodyAsClass(Map.class);
     String user = bodyParams.get("user");
     String pwd = bodyParams.get("password");
-    if (adminUser.equals(user) && (adminPassword.equals(pwd))) {
-      ctx.sessionAttribute("user", new SessionInfo(adminUser, 
System.currentTimeMillis() + ""));
-      ctx.json(OkResponse.of("success"));

Review Comment:
   Seems this part of logic is missed after 
`dashboardServer.getLoginAuthProvider().authenticate(credential);`



##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/LoginController.java:
##########
@@ -49,10 +50,11 @@ public void login(Context ctx) {
     Map<String, String> bodyParams = ctx.bodyAsClass(Map.class);
     String user = bodyParams.get("user");
     String pwd = bodyParams.get("password");

Review Comment:
   check the user and pwd non empty 



##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/LoginController.java:
##########
@@ -49,10 +50,11 @@ public void login(Context ctx) {
     Map<String, String> bodyParams = ctx.bodyAsClass(Map.class);
     String user = bodyParams.get("user");
     String pwd = bodyParams.get("password");
-    if (adminUser.equals(user) && (adminPassword.equals(pwd))) {
-      ctx.sessionAttribute("user", new SessionInfo(adminUser, 
System.currentTimeMillis() + ""));
-      ctx.json(OkResponse.of("success"));
-    } else {
+    DefaultPasswordCredential credential = new DefaultPasswordCredential(user, 
pwd);
+    try {
+      dashboardServer.getLoginAuthProvider().authenticate(credential);
+    } catch (Exception e) {
+      LOG.error("authenticate user {} failed", user, e);
       throw new RuntimeException("invalid user " + user + " or password!");

Review Comment:
   return the cause message as well



##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/DashboardServer.java:
##########
@@ -92,6 +92,8 @@ public class DashboardServer {
 
   private final PasswdAuthenticationProvider basicAuthProvider;
   private final TokenAuthenticationProvider jwtAuthProvider;
+
+  private final PasswdAuthenticationProvider loginAuthProvider;

Review Comment:
   how about moving the loginAuthProvider into LoginController?



##########
amoro-ams/src/main/java/org/apache/amoro/server/authentication/LdapPasswdAuthenticationProvider.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.authentication.BasicPrincipal;
+import org.apache.amoro.authentication.PasswdAuthenticationProvider;
+import org.apache.amoro.authentication.PasswordCredential;
+import org.apache.amoro.config.Configurations;
+import org.apache.amoro.exception.SignatureCheckException;
+import org.apache.amoro.server.AmoroManagementConf;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.InitialDirContext;
+
+import java.text.MessageFormat;
+import java.util.Hashtable;
+
+public class LdapPasswdAuthenticationProvider implements 
PasswdAuthenticationProvider {
+  public static final Logger LOG = 
LoggerFactory.getLogger(LdapPasswdAuthenticationProvider.class);
+
+  private String ldapUrl;
+  private String ldapUserParttern;
+  private MessageFormat formatter;
+
+  public LdapPasswdAuthenticationProvider(Configurations conf) {
+    this.ldapUrl = 
conf.get(AmoroManagementConf.HTTP_SERVER_LOGIN_AUTH_LDAP_URL);
+    this.ldapUserParttern = 
conf.get(AmoroManagementConf.HTTP_SERVER_LOGIN_AUTH_LDAP_USERPARTTERN);

Review Comment:
   check the ldapUrl and ldapUserParttern non empty 



##########
amoro-ams/src/test/resources/ldap/users.ldif:
##########
@@ -0,0 +1,37 @@
+################################################################################
+#  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.
+################################################################################
+version: 1
+dn: dc=test,dc=com
+objectClass: domain
+objectClass: top
+dc: test
+
+dn: ou=Users,dc=test,dc=com
+objectClass: organizationalUnit
+objectClass: top
+ou: Users
+
+dn: cn=user1,ou=Users,dc=test,dc=com
+objectClass: inetOrgPerson
+objectClass: organizationalPerson
+objectClass: person
+objectClass: top
+cn: user1
+sn: Ldap
+uid: ldaptest1
+userPassword: 12345

Review Comment:
   new line at the end



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