Hashtable<String, String> hash = new Hashtable<String, String>();
//使用的Drive名稱
hash.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory");
//連線的位置
hash.put(Context.PROVIDER_URL, "ldap://XXX.XXX.XXX.XXX:389");
//認證的方式使用 simple
hash.put(Context.SECURITY_AUTHENTICATION, "simple");
//認證的戶名
hash.put(Context.SECURITY_PRINCIPAL, "域名\\帳號");
//認證的密碼
hash.put(Context.SECURITY_CREDENTIALS, userPassword);

InitialLdapContext usrCtx = null;
try{
    usrCtx = new InitialLdapContext(hash, null);

}catch(AuthenticationException ex){

/**
* error Code 說明 :
* 525 : 用戶沒有找到
* 52e : 證號不正確
* 530 : 此時間不允許登入(not permitted to logon at this time)
* 532 : 密碼期滿
* 533 : 帳號不可用
* 701 : 帳戶期滿
* 773 : 用戶必須重設密碼
*/

}catch (NamingException e) {

}

//代表登入成功

if(usrCtx != null){

try {
    usrCtx.close();
} catch (NamingException e) {
                   
}

//代表登入成功,不需要再做其它工作。

}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 werwolf 的頭像
    werwolf

    等待著真實的自由

    werwolf 發表在 痞客邦 留言(0) 人氣()