2013-08-28 51 views
0

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

例如,属性name ='Testuser'。这个'Testuser'属性如下多值:firstname = test,lastname = testing [email protected]像这样。

现在我想用java代码单独修改firstname值。 (找遍了很多网站在那里我能找到使用ModificationItem单一属性的变化)

这里我的代码片段:

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: [email protected] 
value: Profile.Contact.LastName=lastname 

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

帮助真的很感激。

谢谢!

回答