【问题标题】:single value in multivalued attribute in LDAPLDAP中多值属性中的单个值
【发布时间】:2013-08-28 15:52:35
【问题描述】:

我有一个存储多个值的 LDAP 属性 即,用户详细信息(如名字、姓氏、电子邮件地址)存储在具有键值对的一个属性中。

例如,属性名称='Testuser'。此“Testuser”属性为以下多个值:firstname=test, lastname=testing email=testing@xxx.com 像这样。

现在我想使用 java 代码单独修改名字的值。 (我搜索了很多网站,我可以使用 ModificationItem 找到单个属性更改)

这是我的代码 sn-p:

DirContext ctx = new InitialDirContext(env);
                  SearchControls ctls = new SearchControls();
                ctls.setReturningObjFlag(true);
                ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
                                String filter;
                filter = "(&(objectClass=myobjectclass)(apn=" + userName + "))";

                                 NamingEnumeration answer = ctx.search("o=mydomain", filter, ctls);



while (answer.hasMore()) {
    SearchResult sr = (SearchResult)answer.next();
        Attributes attrs = sr.getAttributes();
        String givenName = " ";
try {
                for (NamingEnumeration e = attrs.getAll(); e.hasMore();) {

                    Attribute attr = (Attribute) e.next();

                    System.out.println("Attribute name: " + attr.getID());



                    for (NamingEnumeration n = attr.getAll(); n.hasMore(); System.out

                            .println("value: " + n.next()));
}} catch (Exception err) {
givenName = " ";
}
  }

我得到以下输出:

Attribute name: apn
value: testuser
Attribute name: appropertycollection
value: Profile.Contact.ZipCode=46784157
value: Profile.Contact.State=7
value: Profile.Contact.MobileNum=4564545455
value: Profile.Contact.Password=12345
value: Profile.Contact.FirstName=David
value: Profile.Contact.Address=TestAddress456
value: Profile.Contact.Email=asde@xxx.com
value: Profile.Contact.LastName=lastname

现在我想单独修改属性集合属性中的“Profile.Contact.FirstName=David”值。

非常感谢您的帮助。

谢谢!

【问题讨论】:

    标签: java ldap


    【解决方案1】:

    创建一个javax.naming.directory.BasicAttribute 怎么样,添加所有必要的属性。

    然后,按照此处的简短教程进行操作:Oracle tutorial

    请给我一个简短的代码 sn-p,以便我们看到你在苦恼什么。

    【讨论】:

      猜你喜欢
      • 2020-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-10
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多