Reputation: 1
I have an LDAP attribute which stores multiple values ie, user details (like firstname, lastname, email address) are stored in one attribute with key value pair.
For example, attribute name='Testuser'. This 'Testuser' attribute as following multi values: firstname=test, lastname=testing [email protected] like this.
Now i want to modify firstname value alone using java code. (I have searched many sites where i could find single attribute change using ModificationItem)
Here my code snippet:
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
Now I want to modify, "Profile.Contact.FirstName=David" value alone which is in a propertycollection Attribute.
Helps are really appreciated.
Thanks!
Upvotes: 0
Views: 2886
Reputation: 773
What about creating a javax.naming.directory.BasicAttribute, add all necessary attributes.
Then, follow the short tutorial here: Oracle tutorial
Please provide me with a short code snippet, so that we see what you agonize over.
Upvotes: 1