public static String extractUserName(String userDn) {
    if (!isDn(userDn) && !hasDomain(userDn)) {
      return userDn;
    }

    int domainIdx = ServiceUtils.indexOfDomainMatch(userDn);
    if (domainIdx > 0) {
      return userDn.substring(0, domainIdx);
    }

    if (userDn.contains("=")) {
      return userDn.substring(userDn.indexOf("=") + 1, userDn.indexOf(","));
    }
    return userDn;
  }
Extracts username from user DN.
<br>
<b>Examples:</b>
<pre>
LdapUtils.extractUserName("UserName")                        = "UserName"
LdapUtils.extractUserName("UserName@mycorp.com")             = "UserName"
LdapUtils.extractUserName("cn=UserName,dc=mycompany,dc=com") = "UserName"
</pre>
@param userDn
@return
standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/ldap/LdapUtils.java