Last updated July 06, 2009 13:22, by mariemat
More controls for Netscape LDAP SDK
This project brings implementation for more LDAP controls to developers that work with the Netscape Java LDAP SDK. The LDAP SDK is stable and does not seem to envision any additional control classes.
The list of default controls that are shipped in the LDAP SDK can be found on the official javadoc.
Additional controls that are currently delivered in the More LDAP Controls projects are :
* Pre-Read Control * Post-Read Control * GetEffectiveRights Control * CSN Control
Associated Javadoc is hosted externally.
Example
/**
* Registers all of the response controls for automatic instantiation
* of the control responses
*/
try {
LDAPControl.register(PreReadResponseControl.OID,
PreReadResponseControl.class);
LDAPControl.register(PostReadResponseControl.OID,
PostReadResponseControl.class);
} catch (LDAPException ex) {
...
}
...
LDAPAttribute newAttr = new LDAPAttribute("description", "new description");
newAttr.addValue(getDescription());
LDAPModificationSet mods = new LDAPModificationSet();
mods.add(LDAPModification.REPLACE, newAttr);
// Controls
LDAPConstraints cons = null;
cons = new LDAPConstraints();
LDAPControl[] requestControls = new LDAPControl[2];
requestControls[0] = new PreReadControl(false, "description", "cn");
requestControls[1] = new PostReadControl(false, "description", "cn");
cons.setServerControls(requestControls);
...
try {
conn.modify(myDN, mods, cons);
} catch (LDAPException e) {
...
}
LDAPControl[] controls = connection.getResponseControls();
if (controls != null) {
for (LDAPControl control : controls) {
String oid = control.getID();
if (oid.equals(PreReadResponseControl.OID)) {
LDAPAttributeSet attributeSet = ((PreReadResponseControl) control).getAttributeSet();
LDAPAttribute cnAttr = attributeSet.getAttribute("cn");
System.out.println("PRE " + cnAttr);
LDAPAttribute descAttr = attributeSet.getAttribute("description");
System.out.println("PRE " + descAttr);
} else if (oid.equals(PostReadResponseControl.OID)) {
PostReadResponseControl response = (PostReadResponseControl) control;
LDAPAttributeSet attributeSet = response.getAttributeSet();
LDAPAttribute cnAttr = attributeSet.getAttribute("cn");
System.out.println("POST " + cnAttr);
LDAPAttribute descAttr = attributeSet.getAttribute("description");
System.out.println("POST " + descAttr);
}
}
License
This project is under CDDL license.





