我必須使用LDAP將用戶驗證到我的系統中,我的問題是我有很多組織,並且我沒有列出用戶組織。LDAP在不知道他的情況下驗證用戶uid
我有這樣的代碼工作迫使知道組織:
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的結構現在允許我搜索用戶的DN,但我會試一試。 – AgamenonD2