1)先用hashTable初始化ldap用到的參數。
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,"ldap://192.***.***.***:portNumber(389 is defualt)");
env.put(Context.SECURITY_PRINCIPAL,userID+"yourDomain(@***.com)");//
env.put(Context.SECURITY_CREDENTIALS, pass);
userID 和 pass就是登錄域的賬號。不要用全稱。因為你在上面用到了域名。
2)開始驗證。通過try..catch來判斷用戶的合法性。
try{
LdapContext ctx = new InitialLdapContext(env, null);
System.out.println("Succeess");
} catch (Exception e) {
if (e.getMessage().indexOf("775") > = 0) {
System.out.println("你的賬號被鎖了。");
}else {
System.out.println("Invalid User");
}
}
posted on 2007-08-22 11:58
happytian 閱讀(425)
評論(0) 編輯 收藏