captainzmc commented on a change in pull request #236: [LIVY-678] Thrift ldap 
authentication, based on ldapurl, basedn, domain
URL: https://github.com/apache/incubator-livy/pull/236#discussion_r334236191
 
 

 ##########
 File path: 
thriftserver/server/src/main/scala/org/apache/livy/thriftserver/auth/ldap/LdapUtils.scala
 ##########
 @@ -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.livy.thriftserver.auth.ldap
+
+import org.apache.livy.{LivyConf, Logging}
+
+/**
+ * Static utility methods related to LDAP authentication module.
+ */
+object LdapUtils extends Logging {
+
+  /**
+   * Extracts username from user DN.
+   * <br>
+   * <b>Examples:</b>
+   * <pre>
+   * LdapUtils.extractUserName("UserName")                        = "UserName"
+   * LdapUtils.extractUserName("usern...@mycorp.com")             = "UserName"
+   * LdapUtils.extractUserName("cn=UserName,dc=mycompany,dc=com") = "UserName"
+   * </pre>
+   */
+  def extractUserName(userDn: String): String = {
+    var userName = userDn
+
+    if (!isDn(userDn) && !hasDomain(userDn)) {
+      userName = userDn
+    } else {
+      val domainIdx = indexOfDomainMatch(userDn)
+      if (domainIdx > 0) {
+        userName = userDn.substring(0, domainIdx)
+      } else if (userDn.contains("=")) {
+        userName = userDn.substring(userDn.indexOf("=") + 1, 
userDn.indexOf(","))
+      }
+    }
+    userName
+  }
+
+  /**
+   * Get the index separating the user name from domain name (the user's name 
up
+   * to the first '/' or '@'). Index of domain match or -1 if not found
+   */
+  def indexOfDomainMatch(userName: String): Int = {
+    var endIdx = -1
 
 Review comment:
   endIdx then needs to be assigned, so we need var here
   endIdx = Math.min(idx, idx2)
   endIdx = Math.max(idx, idx2)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to