Java eclipse - Activity 目录、属性修改

标签 java eclipse attributes active-directory

我想使用 Java (Eclipse) 获取 Activity 目录的属性。

我找到了这段代码:

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, "?????????") 中放入什么才能有效?

非常感谢。

最佳答案

在您找到的示例中,当您执行以下操作时,就会建立连接:

// Create the initial context
DirContext ctx = new InitialDirContext(env);

为此,您需要设置所有必需的环境属性,例如

SECURITY_CREDENTIALS
SECURITY_PRINCIPAL
SECURITY_AUTHENTICATION
PROVIDER_URL
INITIAL_CONTEXT_FACTORY
(possibly others depending on if you have encryption set in your Active Directory)

Java 将使用上下文工厂来创建该连接。如果您不指定它,java将使用默认值,即com.sun.jndi.ldap.LdapCtxFactory(如果我没记错的话)。

关于Java eclipse - Activity 目录、属性修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14899339/

相关文章:

Java MouseListener图形实现

java - 优化Java客户端HTTPS连接

java - 如何在 SWT TreeItem 之间绘制线条

eclipse - 在不重新加载页面的情况下将 jsp、css、js、html 的更改反射(reflect)到浏览器

java - 在 Eclipse 中添加 API 基线

encoding - 带问号的钻石

java - 子数组最大和

android - Eclipse 无法识别 Android 支持库修订版 9

javascript - 在javascript中获取属性

c++ - 我什么时候使用 "__attribute__((nonnull))"与 "not_null<T*>"?