View RSS Feed

JNDI

Modifying JNDI Directory Entries

Rate this Entry
by , 07-07-2012 at 04:19 PM (571 Views)
Directory entry’s attribute values modification usually involves the usage of modifyAttributes() of DirContext. This method’s one variant would take the modification type, directory name entry and also anAttribute object which hold modified Attributes object. Other variant would be taking name as well as javax.naming.directory.

E.g, let us assume that phone number “303 454 3365” is required to be removed from attribute telephonenumber of entry of a user and to be replaced with some other number. In given code 2 BasicAttributes objects are created which are OldNumber and NewNumber. They are used in calls, to modifyAttributes():

Java Code:
DirContext user ... ;     // Created somewhere else in the program

BasicAttribute newAttr = new BasicAttribute();
newAttr.add("telephonenumber", "520 765 4321");
BasicAttributes newNumber = new BasicAttributes();
newNumber.put(newAttr);

BasicAttributes oldNumber = 
  new BasicAttributes("telephonenumber", "303 444 6633");

user.modifyAttributes("", DirContext.REMOVE_ATTRIBUTE, oldNumber);
user.modifyAttributes("", DirContext.ADD_ATTRIBUTE, newNumber);
In given code two techniques have been used for creation of objects BasicAttributes. A newBasicAttribute is first of all created for a newNumber and an attribute “telephonenumber” is being added. After this a new object BasicAttributes is created and theBasicAttribute is put into it. Convenience constructor is being used with oldBumber of the BasicAttribute so that same task could be accomplished in just 1 line of code.

Submit "Modifying JNDI Directory Entries" to Facebook Submit "Modifying JNDI Directory Entries" to Digg Submit "Modifying JNDI Directory Entries" to del.icio.us Submit "Modifying JNDI Directory Entries" to StumbleUpon Submit "Modifying JNDI Directory Entries" to Google

Categories
Tutorial

Comments