Search in sources :

Example 1 with EntryChangeNotificationResponseControl

use of org.forgerock.opendj.ldap.controls.EntryChangeNotificationResponseControl in project OpenAM by OpenRock.

the class IndexChangeHandler method handleEntry.

@Override
public boolean handleEntry(SearchResultEntry entry) {
    EntryChangeNotificationResponseControl control = null;
    try {
        // Retrieve details of the policy change.
        control = entry.getControl(EntryChangeNotificationResponseControl.DECODER, new DecodeOptions());
    } catch (DecodeException dE) {
        DEBUG.error("Error occurred attempting to read policy rule change.", dE);
        // Notify observers of the exception and proceed no further.
        observable.notifyObservers(ErrorEventType.SEARCH_FAILURE.createEvent());
        return true;
    }
    // Extract the realm from the DN to be passed as part of the event.
    String dn = entry.getName().toString();
    String orgName = dn.substring(dn.indexOf(SERVICE_DECLARATION) + SERVICE_DECLARATION.length());
    String realm = dnMapper.orgNameToRealmName(orgName);
    // Retrieve all sunxmlKeyValue attributes.
    Attribute attributes = entry.getAttribute(AttributeDescription.valueOf("sunxmlKeyValue"));
    for (ByteString attrValue : attributes) {
        String attStrValue = attrValue.toString();
        if (attStrValue.startsWith(INDEX_PATH_ATT)) {
            // Extract the path index out of the attribute value.
            String pathIndex = attStrValue.substring(INDEX_PATH_ATT.length() + 1);
            switch(control.getChangeType()) {
                case MODIFY:
                // this will result in the old index remaining.
                case ADD:
                    observable.notifyObservers(ModificationEventType.ADD.createEvent(pathIndex, realm));
                    break;
                case DELETE:
                    observable.notifyObservers(ModificationEventType.DELETE.createEvent(pathIndex, realm));
                    break;
            }
        }
    }
    return true;
}
Also used : Attribute(org.forgerock.opendj.ldap.Attribute) ByteString(org.forgerock.opendj.ldap.ByteString) EntryChangeNotificationResponseControl(org.forgerock.opendj.ldap.controls.EntryChangeNotificationResponseControl) ByteString(org.forgerock.opendj.ldap.ByteString) DecodeException(org.forgerock.opendj.ldap.DecodeException) DecodeOptions(org.forgerock.opendj.ldap.DecodeOptions)

Aggregations

Attribute (org.forgerock.opendj.ldap.Attribute)1 ByteString (org.forgerock.opendj.ldap.ByteString)1 DecodeException (org.forgerock.opendj.ldap.DecodeException)1 DecodeOptions (org.forgerock.opendj.ldap.DecodeOptions)1 EntryChangeNotificationResponseControl (org.forgerock.opendj.ldap.controls.EntryChangeNotificationResponseControl)1