我有一个存储多个值的 LDAP 属性 即,用户详细信息(如名字、姓氏、电子邮件地址)存储在具有键值对的一个属性中。
例如,属性名称='Testuser'。此“Testuser”属性为以下多个值:firstname=test、lastname=testing email=testing@xxx.com 像这样。
现在我想使用java代码单独修改名字值。 (我搜索了许多可以使用 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: Profile.Contact.Email=asde@xxx.com
value: Profile.Contact.LastName=lastname
现在我想单独修改 propertycollection 属性中的“Profile.Contact.FirstName=David”值。
非常感谢您的帮助。
谢谢!
最佳答案
创建一个javax.naming.directory.BasicAttribute怎么样? ,添加所有必要的属性。
然后,按照此处的简短教程进行操作:Oracle tutorial
请向我提供一个简短的代码片段,以便我们了解您的苦恼。
关于java - LDAP 中多值属性中的单值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18492698/