java - LDAP 在不知道用户 ou 的情况下验证用户 uid

标签 java ldap

我必须使用 LDAP 对用户进行身份验证进入我的系统,我的问题是我有很多组织,但没有列表用户组织。

我有这个代码,迫使一个知情的组织工作:

ldap.validate("uid=" + this.email + ",ou="+ThisIsTheOrImForcing+",ou=users,dc=myDC,dc=com,dc=br", this.password);  

我的验证方法:

public boolean validate(String principal, String password){
    // Set up the environment for creating the initial context
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
    //env.put(Context.PROVIDER_URL, "ldap://IP:PORT/DC=opus");
    //env.put(Context.PROVIDER_URL, "ldap://IP:PORT/dc=mydc,dc=com,dc=br");
    env.put(Context.PROVIDER_URL, "ldap://IP:PORT/dc=mydc,dc=com,dc=br");

    //Authenticate as S. User and password
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL,principal );
    env.put(Context.SECURITY_CREDENTIALS, password);

    try{
        // Create the initial context
        DirContext ctx = new InitialDirContext(env);
        return true;
    } catch( AuthenticationException ae ) {
        return false;
    } catch( NamingException ne ) {
        return false;
    }
}

我有 var ThisIsTheOrImForcing,如何在不知道用户组织的情况下对用户进行身份验证,我必须先搜索它,如何?

最佳答案

LDAP 中的简单绑定(bind)要求您提供用户的 DN,因此您需要了解码织。

你有两种方法来处理它:

  • 在目录中搜索具有属性 uid = this.email 的用户,检索其 DN,并使用找到的 DN 进行身份验证以验证用户

  • 使用其他方式进行身份验证,例如SASL机制:See this for more information 。您还必须查找支持哪种机制的目录配置

关于java - LDAP 在不知道用户 ou 的情况下验证用户 uid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44288237/

相关文章:

java - WinForms 中有哪些轻量级/重量级组件?

java - 如何在android中实时统计按键次数

java - Java-如何使我的代码使用更少的内存?

java - Mockito When...Then Return - 返回被忽略?

Apache 2.4 和 LDAP

java - 在 session 中存储/检索 InitialLdapContext 时获取连接重置异常

php - 实现 LDAP 合规性

java.exe CPU 使用率高

c - ldap_init 和 ldap_set_option 问题

asp.net - 使用 LDAP 时无法与服务器建立安全连接