gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 13:01:06 25 4
gpt4 key购买 nike

我必须使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com