1
我想用Java(Eclipse)在我的活动目录上获取属性。Java eclipse - 活动目录,属性修改
我发现这个代码:
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial");
// Authenticate as S. User and password "mysecret"
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL,
"cn=S. User, ou=NewHires, o=JNDITutorial");
env.put(Context.SECURITY_CREDENTIALS, "mysecret");
// Create the initial context
DirContext ctx = new InitialDirContext(env);
,但我已经开始与此知道是否有必然联系:
String ldapUrl = "ldap://"+serverAddress+":389";
//Prepare the environment with the username and password.
Hashtable env = new Hashtable();
DirContext ctx = null;
env.put(Context.SECURITY_PRINCIPAL, DOMAIN+username);
//env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);
ctx = LdapCtxFactory.getLdapCtxInstance(ldapUrl, env); // To test the connection
那么,怎样才能创建一个InitialDirContext? 我应该为env.put(Context.INITIAL_CONTEXT_FACTORY, "?????????")
放置那个作品?
非常感谢。
为什么不把你发现的代码放在你的代码中:'com.sun.jndi.ldap.LdapCtxFactory'?不要直接调用'getLdapCtxInstance',就像你的例子和'new InitialDirContext(env)' – 2013-02-15 16:59:38