0
我正在嘗試與AD聯繫。我試圖用這個代碼來連接,但它似乎並沒有連接。我很抱歉不能比這更具體,但這只是我所知道的。什麼都沒發生。我已經刪除了我認爲是這個類的非必要部分,在那裏處理結果,因爲在這一點上根本沒有任何結果需要處理。我在Netbeans中沒有遇到任何錯誤,但是..當我嘗試連接時沒有任何反應。Java:連接到Active Directory(AD)?
發生了什麼事?我究竟做錯了什麼?
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.*;
import java.util.Hashtable;
import java.util.*;
public class AD {
public static void main(String[] args) {
String userName = "xx"; //AD username
String password = "xx"; //AD password
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://192.168.1.102:389/dc=agileworks,dc=com"); //AD Server URL - dc lader til at være "domain content"
//env.put(Context.SECURITY_AUTHENTICATION, "simple"); //virker ikke nødvendig
//env.put(Context.SECURITY_PRINCIPAL, new String("agileworks" + "\\" + userName));
env.put(Context.SECURITY_PRINCIPAL, "agileworks" + "\\" + userName); //måske er tabelnavn\\ ikke nødvendig?
env.put(Context.SECURITY_CREDENTIALS, password); //password
DirContext ctx = null; //initialisering
NamingEnumeration results = null; //initialisering
}
}
參考http://stackoverflow.com/questions/389746/ldap-java-library – Egor 2011-12-16 20:08:18