Java eclipse - Activity 目录、属性修改#2

标签 java eclipse attributes active-directory

首先感谢 Sotirios Delimanolis 帮助我解决了我的第一个问题(第一部分是访问 Activity 目录)。

所以现在我的代码是:

        DirContext ctx = null;

        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://"+serverAddress+":389");

        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, DOMAIN+username);
        env.put(Context.SECURITY_CREDENTIALS, password);

        try {


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

            Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
            matchAttrs.put(new BasicAttribute("mail", "XXXXXX@XXXX.com"));
            matchAttrs.put(new BasicAttribute("cn"));

            // Search for objects that have those matching attributes
            NamingEnumeration<SearchResult> answer = ctx.search("ou=People", matchAttrs);

            while (answer.hasMore()) {
                SearchResult sr = (SearchResult)answer.next();
                System.out.println(">>>" + sr.getName());
            }

我有错误: 无法绑定(bind)到 LDAP/获取帐户信息:javax.naming.NamingException: [LDAP: 错误代码 1 - 000020D6: SvcErr: DSID-03100754,问题 5012 (DIR_ERROR),数据 0 ;剩余名称 'ou=People'

我在 http://docs.oracle.com/javase/jndi/tutorial/basics/directory/basicsearch.html 中找到了这段代码(如下) :

// Specify the attributes to match
// Ask for objects that has a surname ("sn") attribute with 
// the value "Geisel" and the "mail" attribute
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
matchAttrs.put(new BasicAttribute("sn", "Geisel"));
matchAttrs.put(new BasicAttribute("mail"));

// Search for objects that have those matching attributes
NamingEnumeration answer = ctx.search("ou=People", matchAttrs);
 You can then print the results as follows. 
while (answer.hasMore()) {
    SearchResult sr = (SearchResult)answer.next();
    System.out.println(">>>" + sr.getName());
    printAttrs(sr.getAttributes());
}

所以我想知道他的目标上下文“ou=People”是否特定于每个 Activity 目录,或者对于“ou”和“People”始终相同:http://www.kouti.com/tables/userattributes.htm

非常感谢!

最佳答案

Active Directory 是一个 LDAP 服务器。还有其他 LDAP 服务器(我想到的是 OpenLDAP)。其中每一个都有自己的或相似的对象类和属性,它们构成了您的目录模式。您可以在this Microsoft link下查看对于所有 Active Directory 对象类和属性。

在您的示例中,snmail 和 ,ou 是不同的属性名称,分别代表surnamemail组织单位。这些属性是名称/值对,因此 ou=People 表示具有值为 People组织单位 属性的对象。

您使用的搜索功能:

ctx.search("ou=People", matchAttrs)

正在 ou=People 的上下文中查找与您传递的属性相匹配的属性。

参数 ou=People 并不特定于每个 Active Directory。 People 只是他们决定使用的名称。我的目录使用Users,另一个可能使用Accounts。然而,ou 通常是用于唯一标识对象的属性。

我读过并可以推荐的一个很好的资源是 Building Java Enterprise Applications Volume I - Architecture 。该链接包含 pdf 版本。其中有一节介绍如何使用 LDAP 对应用程序用户进行身份验证,但还解释了很多有关 LDAP 服务器条目组织的内容,我认为您会发现这些内容很有用。

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

相关文章:

java - 如何在 Android 上使用 3 级数据从 Firebase 数据库中选择数据?

java - JUnit 测试未在 Eclipse 中运行

java - 找不到处理执行default-proguard的市场条目

ruby-on-rails - 为模型创建状态属性

python - 在每个对象调用后更改属性

c# - Java 等效于 AttributeUsage C#

java - 将 jpa bean 绑定(bind)到可取消表单的正确方法是什么?

Java - 两个并排的网格

java - Google Play 拒绝了适用于全屏正确 DHU 型号的 Android Auto 应用程序

c++ - Mac 上的 Eclipse dyld : Library not loaded: Image not found