How can I use Java Beans to create...
Articles and Tips: qna
01 Mar 2001
Q.
How can I use Java Beans to create NDS Directory objects?
A.
Novell's Java Beans provide an easy interface to manipulate NDS objects from within a servlet. Using the "NWDir" bean, objects can be created and configured.
The following code samples create a container and a user within that container:
import com.novell.beans.NWDir.*; import com.novell.beans.util.*; import java.io.*; import java.util.*; .. NWDir dirBean; NWEntry parentContainerEntry; NWEntry newContainerEntry; NWEntry newUserEntry; .. // //Authenticate to the tree as Admin: // dirBean = new NWDir(); try { if (dirBean.authenticate("admin" +"." +"novell", "YOUR_TREE") == false) { throw new Exception(); } } catch(Exception e) { out.println("Not Authenticated"); } // //Create a new container under a parent container: // try { dirBean.setFullName("NDS:\\\\YOUR_TREE\\parentContainer"); parentContainerEntry = dirBean.getEntry(); newContainerName = "NewContainer"; newContainerEntry = dirBean.createEntry("Organizational Unit", newContainerName); newContainerEntry.setFieldValue("Description", "A New Container"); entries = parentContainerEntry.getEntries(); entries.addElement(newContainerEntry); } catch (Exception e) { System.out.println(e.getMessage()); } ... // //Create a new user in the new container: // try { dirBean.setFullName("NDS:\\\\YOUR_TREE\\parentContainer\\"); newContainerEntry = dirBean.getEntry(); newUserName = "NewUser"; newUserEntry = dirBean.createEntry("User", newUserName); newUserEntry.setFieldValue("Surname", newUserName); entries = newContainerEntry.getEntries(); entries.addElement(newUserEntry); newUserEntry = entries.getElement(newUserName); newUserEntry.setPassword(newUserPassword); } catch (Exception e) { System.out.println(e.getMessage()); }
For more information, refer to the "NDS Developer's Guide" and to the "NDS101" example online at http://developer.novell.com/support. (Thanks to Tim Slaton of Novell, Inc.)
* Originally published in Novell AppNotes
Disclaimer
The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.