public void addLdapAuthentication(UserEntity userEntity, String dn, boolean persist) throws AmbariException {
    addAuthentication(userEntity,
        UserAuthenticationType.LDAP,
        StringUtils.lowerCase(dn), // DNs are case-insensitive and are stored internally as the bytes of lowercase characters
            (user, key) -> {
              List<UserAuthenticationEntity> authenticationEntities = user.getAuthenticationEntities();

              // Ensure only one UserAuthenticationEntity exists for LDAP for the user...
              for (UserAuthenticationEntity entity : authenticationEntities) {
                if ((entity.getAuthenticationType() == UserAuthenticationType.LDAP) &&
                    ((key == null) ? (entity.getAuthenticationKey() == null) : key.equalsIgnoreCase(entity.getAuthenticationKey()))) {
                  throw new AmbariException("The authentication type already exists for this user");
                }
              }
            },
        persist);
  }
Adds the ability for a user to authenticate using a remote LDAP server

@param userEntity the user
@param dn         the user's distinguished name
@param persist    true, to persist the created entity; false, to not persist the created entity
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/security/authorization/Users.java