Search in sources :

Example 1 with ICachedDirectoryServices

use of com.iplanet.am.sdk.common.ICachedDirectoryServices in project OpenAM by OpenRock.

the class EntryEventListener method entryChanged.

/**
     * This method will be invoked by the <code>EventService</code> if the
     * events for which this listener registered has been triggered. Since this
     * listener is interested in modifications/deletions/renaming of normal
     * directory entires, it identifies the distinguished names affected by this
     * event and sends a notification to the <code>AMObjectImpl</code> by
     * calling the appropriate method.
     * 
     * @param dsEvent
     *            <code>DSEvent</code> object generated by the
     *            <code>EventService</code>.
     */
public void entryChanged(DSEvent dsEvent) {
    // Get the "dn" responsible for the event
    DN dn = DN.valueOf(dsEvent.getID());
    String normalizedDN = dn.toString().toLowerCase();
    if (debug.messageEnabled()) {
        debug.message("EntryEventListener.entryChanged(): DSEvent " + "generated for: " + dn);
    }
    // Check if the event was caused by changes/deletions to cos entries
    // (cosdefinitions & costemplates) and figure out the affected dn
    // subtree. Parse the dn in case of cos related events to find out the
    // affected subtree of dns Examples of costemplate dn:
    // "cn="cn=RoleThree,o=hp.com,o=vortex.com",cn=nsCalUser,
    // o=hp.com,o=vortex.com"
    // affectDNs will be all those which suffix match
    // "o=hp.com,o=vortex.com"
    // Examples of cosdefintion dn:
    // "cn=nsCalUser,o=hp.com,o=vortex.com";
    // affectDNs => "o=hp.com,o=vortex.com"
    boolean cosType = true;
    String affectDNs = "";
    Set attrNames = Collections.EMPTY_SET;
    String serviceName = null;
    String objClasses = dsEvent.getClassName();
    if (objClasses.indexOf("cosClassicDefinition") != -1) {
        // COS
        // definition
        affectDNs = dn.parent().toString().toLowerCase();
        // Get the serviceName this applies to, and get the attribute
        // names of this service which impact the DNs.
        serviceName = LDAPUtils.rdnValueFromDn(dn);
        attrNames = getDynamicAttributeNames(serviceName);
        if (debug.messageEnabled()) {
            debug.message("EntryEventListener.entryChanged() " + "Cos Definition changed for service: " + serviceName + "Dynamic Attributes: " + attrNames);
        }
    } else if (objClasses.indexOf("costemplate") != -1) {
        // COS template
        affectDNs = dn.parent().parent().toString().toLowerCase();
        serviceName = LDAPUtils.rdnValueFromDn(dn.parent());
        attrNames = getDynamicAttributeNames(serviceName);
        if (debug.messageEnabled()) {
            debug.message("EntryEventListener." + "entryChanged()" + "Cos template changed for service: " + serviceName + "Dynamic Attributes: " + attrNames);
        }
    } else {
        // Not cos related - only a single dn affected
        cosType = false;
        affectDNs = normalizedDN;
    }
    if (debug.messageEnabled()) {
        debug.message("EntryEventListener.entryChanged(): Affected dn: " + affectDNs + " cosType: " + cosType);
    }
    IDirectoryServices dsServices = DirectoryServicesFactory.getInstance();
    // Call the listeners
    synchronized (listeners) {
        Set keys = listeners.keySet();
        for (Iterator items = keys.iterator(); items.hasNext(); ) {
            AMObjectListener listener = (AMObjectListener) items.next();
            Map configMap = (Map) listeners.get(listener);
            if (cosType) {
                // removed for user entries as well the affected template
                if (DirectoryServicesFactory.isCachingEnabled()) {
                    ((ICachedDirectoryServices) dsServices).dirtyCache(affectDNs, dsEvent.getEventType(), true, false, attrNames);
                    ((ICachedDirectoryServices) dsServices).dirtyCache(normalizedDN, dsEvent.getEventType(), false, false, Collections.EMPTY_SET);
                }
                listener.objectsChanged(affectDNs, dsEvent.getEventType(), attrNames, configMap);
                // first call removes the attributes. now remove
                // the template.
                listener.objectChanged(normalizedDN, dsEvent.getEventType(), configMap);
            } else {
                if (DirectoryServicesFactory.isCachingEnabled()) {
                    ((ICachedDirectoryServices) dsServices).dirtyCache(affectDNs, dsEvent.getEventType(), false, false, Collections.EMPTY_SET);
                }
                listener.objectChanged(affectDNs, dsEvent.getEventType(), configMap);
            }
        }
    }
}
Also used : IDirectoryServices(com.iplanet.am.sdk.common.IDirectoryServices) Set(java.util.Set) AMObjectListener(com.iplanet.am.sdk.AMObjectListener) Iterator(java.util.Iterator) DN(org.forgerock.opendj.ldap.DN) ICachedDirectoryServices(com.iplanet.am.sdk.common.ICachedDirectoryServices) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ICachedDirectoryServices

use of com.iplanet.am.sdk.common.ICachedDirectoryServices in project OpenAM by OpenRock.

the class ACIEventListener method entryChanged.

/**
     * This method will be invoked by the <code>EventService</code> if the
     * events for which this listener registered has been triggered. Since this
     * listener is interested in modifications with respect to ACI's it
     * identifies the DN's affected by this event and sends a notification to
     * the <code>AMObjectImpl</code> by calling the appropriate method.
     * Usually all the DN's whose have a suffix of this DN of this event will
     * get affected
     * <p>
     * 
     * @param dsEvent
     *            <code>DSEvent</code> object generated by the
     *            <code>EventService</code>.
     */
public void entryChanged(DSEvent dsEvent) {
    if (debug.messageEnabled()) {
        debug.message("ACIEventListener.entryChanged() DSEvent for dn: " + dsEvent.getID());
    }
    // Should not get cos related aci changes events here. But check anyway.
    String objClasses = dsEvent.getClassName();
    if ((objClasses.indexOf("cosClassicDefinition") != -1) || (objClasses.indexOf("costemplate") != -1)) {
        // Ignore Event.COS entries should'nt contain ACI's
        return;
    }
    String affectedDNs = LDAPUtils.formatToRFC(dsEvent.getID());
    IDirectoryServices dsServices = DirectoryServicesFactory.getInstance();
    if (DirectoryServicesFactory.isCachingEnabled()) {
        ((ICachedDirectoryServices) dsServices).dirtyCache(affectedDNs, dsEvent.getEventType(), false, true, Collections.EMPTY_SET);
    }
    // Call Listeners
    synchronized (listeners) {
        Set keys = listeners.keySet();
        for (Iterator items = keys.iterator(); items.hasNext(); ) {
            AMObjectListener listener = (AMObjectListener) items.next();
            if (dsEvent.getEventType() == DSEvent.OBJECT_CHANGED) {
                listener.permissionsChanged(dsEvent.getID(), (Map) listeners.get(listener));
            } else {
                listener.objectChanged(affectedDNs, dsEvent.getEventType(), (Map) listeners.get(listener));
            }
        }
    }
}
Also used : IDirectoryServices(com.iplanet.am.sdk.common.IDirectoryServices) Set(java.util.Set) AMObjectListener(com.iplanet.am.sdk.AMObjectListener) Iterator(java.util.Iterator) ICachedDirectoryServices(com.iplanet.am.sdk.common.ICachedDirectoryServices)

Example 3 with ICachedDirectoryServices

use of com.iplanet.am.sdk.common.ICachedDirectoryServices in project OpenAM by OpenRock.

the class EventListener method sendNotification.

/**
     * Sends notifications to listeners added via <code>addListener</code>.
     * The parameter <code>nItem</code> is an XML document having a single
     * notification event, using the following DTD.
     * <p>
     * 
     * <pre>
     *       &lt;!-- EventNotification element specifes the change notification
     *       which contains AttributeValuePairs. The attributes defined
     *       are &quot;method&quot;, &quot;entityName&quot;, &quot;
     *       eventType&quot; and &quot;attrNames&quot;. --&gt;
     *       &lt;!ELEMENT EventNotification ( AttributeValuePairs )* &gt;
     *  
     *       &lt;!-- AttributeValuePair element contains attribute name and 
     *       values --&gt;
     *       &lt;!ELEMENT AttributeValuPair ( Attribute, Value*) &gt;
     *  
     *       &lt;!-- Attribute contains the attribute names, and the allowed 
     *       names are &quot;method&quot;, &quot;entityName&quot;, 
     *       &quot;eventType&quot; and &quot;attrNames&quot; --&gt;
     *       &lt;!ELEMENT Attribute EMPTY&gt;
     *       &lt;!ATTRLIST Attribute
     *       name ( method | entityName | eventType | attrNames ) 
     *       &quot;method&quot;
     *       &gt;
     *  
     *       &lt;!-- Value element specifies the values for the attributes 
     *       --&gt; &lt;!ELEMENT Value (#PCDATA) &gt;
     * </pre>
     * 
     * @param nItem
     *            notification event as a xml document
     * 
     */
static void sendNotification(String nItem) {
    if (debug.messageEnabled()) {
        debug.message("EventListener::sendNotification: " + "Received notification.");
    }
    // Construct the XML document
    StringBuilder sb = new StringBuilder(nItem.length() + 50);
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append(nItem);
    try {
        Map attrs = CreateServiceConfig.getAttributeValuePairs(SMSSchema.getXMLDocument(sb.toString(), false).getDocumentElement());
        if (debug.messageEnabled()) {
            debug.message("EventListener::sendNotification " + "Decoded Event: " + attrs);
        }
        // Get method name
        String method = getAttributeValue(attrs, METHOD);
        if (method == null) {
            handleError("invalid method name: " + attrs.get(METHOD));
        }
        // Get entity name
        String entityName = getAttributeValue(attrs, ENTITY_NAME);
        if (entityName == null) {
            handleError("invalid entity Name: " + attrs.get(ENTITY_NAME));
        }
        String entryDN = LDAPUtils.formatToRFC(entityName);
        IDirectoryServices dsServices = RemoteServicesFactory.getInstance();
        // Switch based on method
        if (method.equalsIgnoreCase(OBJECT_CHANGED)) {
            int eventType = getEventType((Set) attrs.get(EVENT_TYPE));
            if (RemoteServicesFactory.isCachingEnabled()) {
                ((ICachedDirectoryServices) dsServices).dirtyCache(entryDN, eventType, false, false, Collections.EMPTY_SET);
            }
            synchronized (listeners) {
                for (Iterator items = listeners.iterator(); items.hasNext(); ) {
                    AMObjectListener listener = (AMObjectListener) items.next();
                    listener.objectChanged(entityName, eventType, null);
                }
            }
        } else if (method.equalsIgnoreCase(OBJECTS_CHANGED)) {
            int eventType = getEventType((Set) attrs.get(EVENT_TYPE));
            Set attributes = (Set) attrs.get(attrs.get(ATTR_NAMES));
            if (RemoteServicesFactory.isCachingEnabled()) {
                ((ICachedDirectoryServices) dsServices).dirtyCache(entryDN, eventType, true, false, attributes);
            }
            // Call objectsChanged method on the listeners
            synchronized (listeners) {
                for (Iterator items = listeners.iterator(); items.hasNext(); ) {
                    AMObjectListener listener = (AMObjectListener) items.next();
                    listener.objectsChanged(entityName, eventType, attributes, null);
                }
            }
        } else if (method.equalsIgnoreCase(PERMISSIONS_CHANGED)) {
            if (RemoteServicesFactory.isCachingEnabled()) {
                ((ICachedDirectoryServices) dsServices).dirtyCache(entryDN, AMEvent.OBJECT_CHANGED, false, true, Collections.EMPTY_SET);
            }
            // Call permissionChanged method on the listeners
            synchronized (listeners) {
                for (Iterator items = listeners.iterator(); items.hasNext(); ) {
                    AMObjectListener listener = (AMObjectListener) items.next();
                    listener.permissionsChanged(entityName, null);
                }
            }
        } else if (method.equalsIgnoreCase(ALL_OBJECTS_CHANGED)) {
            if (RemoteServicesFactory.isCachingEnabled()) {
                ((ICachedDirectoryServices) dsServices).clearCache();
            }
            // Call allObjectsChanged method on listeners
            synchronized (listeners) {
                for (Iterator items = listeners.iterator(); items.hasNext(); ) {
                    AMObjectListener listener = (AMObjectListener) items.next();
                    listener.allObjectsChanged();
                }
            }
        } else {
            // Invalid method name
            handleError("invalid method name: " + method);
        }
        if (debug.messageEnabled()) {
            debug.message("EventListener::sendNotification: Sent " + "notification.");
        }
    } catch (Exception e) {
        if (debug.warningEnabled()) {
            debug.warning("EventListener::sendNotification: Unable to send" + " notification: " + nItem, e);
        }
    }
}
Also used : IDirectoryServices(com.iplanet.am.sdk.common.IDirectoryServices) HashSet(java.util.HashSet) Set(java.util.Set) AMObjectListener(com.iplanet.am.sdk.AMObjectListener) Iterator(java.util.Iterator) ICachedDirectoryServices(com.iplanet.am.sdk.common.ICachedDirectoryServices) Map(java.util.Map) AMEventManagerException(com.iplanet.am.sdk.AMEventManagerException) SSOException(com.iplanet.sso.SSOException)

Example 4 with ICachedDirectoryServices

use of com.iplanet.am.sdk.common.ICachedDirectoryServices in project OpenAM by OpenRock.

the class EntryEventListener method allEntriesChanged.

public void allEntriesChanged() {
    debug.error("EntryEventListener: Received all entries changed event" + "from event service");
    IDirectoryServices dsServices = DirectoryServicesFactory.getInstance();
    if (DirectoryServicesFactory.isCachingEnabled()) {
        ((ICachedDirectoryServices) dsServices).clearCache();
    }
    // Call the listeners
    synchronized (listeners) {
        Set keys = listeners.keySet();
        for (Iterator items = keys.iterator(); items.hasNext(); ) {
            AMObjectListener listener = (AMObjectListener) items.next();
            listener.allObjectsChanged();
        }
    }
}
Also used : IDirectoryServices(com.iplanet.am.sdk.common.IDirectoryServices) Set(java.util.Set) AMObjectListener(com.iplanet.am.sdk.AMObjectListener) Iterator(java.util.Iterator) ICachedDirectoryServices(com.iplanet.am.sdk.common.ICachedDirectoryServices)

Aggregations

AMObjectListener (com.iplanet.am.sdk.AMObjectListener)4 ICachedDirectoryServices (com.iplanet.am.sdk.common.ICachedDirectoryServices)4 IDirectoryServices (com.iplanet.am.sdk.common.IDirectoryServices)4 Iterator (java.util.Iterator)4 Set (java.util.Set)4 Map (java.util.Map)2 AMEventManagerException (com.iplanet.am.sdk.AMEventManagerException)1 SSOException (com.iplanet.sso.SSOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 DN (org.forgerock.opendj.ldap.DN)1