use of com.iplanet.am.sdk.AMObjectListener 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);
}
}
}
}
use of com.iplanet.am.sdk.AMObjectListener 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));
}
}
}
}
use of com.iplanet.am.sdk.AMObjectListener 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>
* <!-- EventNotification element specifes the change notification
* which contains AttributeValuePairs. The attributes defined
* are "method", "entityName", "
* eventType" and "attrNames". -->
* <!ELEMENT EventNotification ( AttributeValuePairs )* >
*
* <!-- AttributeValuePair element contains attribute name and
* values -->
* <!ELEMENT AttributeValuPair ( Attribute, Value*) >
*
* <!-- Attribute contains the attribute names, and the allowed
* names are "method", "entityName",
* "eventType" and "attrNames" -->
* <!ELEMENT Attribute EMPTY>
* <!ATTRLIST Attribute
* name ( method | entityName | eventType | attrNames )
* "method"
* >
*
* <!-- Value element specifies the values for the attributes
* --> <!ELEMENT Value (#PCDATA) >
* </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);
}
}
}
use of com.iplanet.am.sdk.AMObjectListener 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();
}
}
}
Aggregations