之前就有發現一段很簡單的語法
可以透過JAVA跟AD主機做網域帳號認證
我就寫得一個很簡單的javaBean來做ad帳號驗證的動作
============================================
package com.checkad;
import java.lang.*;
import java.util.Hashtable ;
import javax.naming.*;
import javax.naming.directory.* ;
import javax.naming.ldap.*;
import javax.naming.spi.*;
public class ADCheck {
//環境設定
private Hashtable env = null;
//目錄
DirContext ctx = null;
//是否能login
private boolean bLogind = false;
private String strID;
private String strPass;
public ADCheck(){
}
private boolean chkAuth(){
try{
ctx = new InitialDirContext(env);
this.bLogind = true;
}
catch(javax.naming.AuthenticationException authe) {
System.out.println(authe);
this.bLogind = false;
}
catch(Exception e) {
System.out.println(e);
} finally{
try{
ctx.close();
}catch(Exception Ignore){}
}
return bLogind;
}//end checkAuth
private void connad()
{
env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://xxx.xxx.xxx.xxx");
env.put(Context.SECURITY_AUTHENTICATION,"Simple");
env.put(Context.SECURITY_PRINCIPAL,strID+"@xxx.com.tw");
env.put(Context.SECURITY_CREDENTIALS , strPass );
}
public void setName ( String name )
{
this.strID = name;
}
public void setPass ( String pass )
{
this.strPass = pass;
}
public boolean getLoginAuth() {
this.connad();
this.chkAuth();
return this.bLogind;
}
}
===========================================
剛又發現一些教學感覺還不錯
LDAP的簡單應用 http://mxdxm.javaeye.com/blog/728256
LDAP的特定錯誤 http://mxdxm.javaeye.com/blog/728251
留言列表