Search in sources :

Example 1 with NotificationSet

use of com.iplanet.services.comm.share.NotificationSet in project OpenAM by OpenRock.

the class PLLNotificationServlet method handleNotification.

/*
     * This method is used by doPost method. It gets the corresponding notification handler and passes the Notification
     * objects to it for processing.
     *
     * @param notificationXML The XML String for the NotificationSet object.
     */
private void handleNotification(String notificationXML) throws ServletException {
    NotificationSet notificationSet = NotificationSet.parseXML(notificationXML);
    Vector<Notification> notifications = notificationSet.getNotifications();
    if (!notifications.isEmpty()) {
        // Each notification in this set shall have the same service id
        String serviceID = notificationSet.getServiceID();
        NotificationHandler notificationHandler = PLLClient.getNotificationHandler(serviceID);
        if (notificationHandler == null) {
            throw new ServletException(PLLBundle.getString("noNotificationHandler") + serviceID);
        }
        notificationHandler.process(notifications);
    }
}
Also used : NotificationSet(com.iplanet.services.comm.share.NotificationSet) ServletException(javax.servlet.ServletException) Notification(com.iplanet.services.comm.share.Notification)

Example 2 with NotificationSet

use of com.iplanet.services.comm.share.NotificationSet in project OpenAM by OpenRock.

the class PolicyListenerRequest method policyChanged.

/**
     * Handles policy change event.
     *
     * @param evt the policy event regarding the policy change.
     */
public void policyChanged(PolicyEvent evt) {
    debug.message("PolicyListenerRequest.policyChanged()");
    if (evt == null) {
        debug.error("PolicyListenerRequest.policyChanged(PolicyEvent): " + "invalid policy event");
        return;
    }
    // get the policy change type from the event
    String changeType = null;
    int type = evt.getChangeType();
    if (type == PolicyEvent.POLICY_ADDED) {
        changeType = PolicyChangeNotification.ADDED;
    } else if (type == PolicyEvent.POLICY_REMOVED) {
        changeType = PolicyChangeNotification.DELETED;
    } else {
        changeType = PolicyChangeNotification.MODIFIED;
    }
    // get the resource names from the event
    Set resourceNames = evt.getResourceNames();
    if (debug.messageEnabled()) {
        debug.message("PolicyListenerRequest.policyChanged(PolicyEvent): " + "resource names from the policy event : " + resourceNames.toString());
    }
    PolicyService ps = new PolicyService();
    PolicyNotification pn = new PolicyNotification();
    PolicyChangeNotification pcn = new PolicyChangeNotification();
    /*
         * sets the service name and resource names which are affected
         *  by this policy change notification.
         */
    pcn.setResourceNames(resourceNames);
    pcn.setPolicyChangeType(changeType);
    pcn.setServiceName(serviceName);
    pn.setNotificationType(PolicyNotification.POLICY_CHANGE_TYPE);
    pn.setPolicyChangeNotification(pcn);
    ps.setMethodID(PolicyService.POLICY_NOTIFICATION_ID);
    ps.setPolicyNotification(pn);
    /*
         * create a Notification object based on the policy change
         * notification.
         */
    Notification notification = new Notification(ps.toXMLString());
    NotificationSet set = new NotificationSet(PolicyService.POLICY_SERVICE);
    // add the notification to the notification set to be sent to the client
    set.addNotification(notification);
    if (debug.messageEnabled()) {
        debug.message("PolicyListenerRequest.policyChanged(PolicyEvent): " + "the notification set sent is : " + set.toXMLString());
    }
    try {
        // sends the notification to the client
        PLLServer.send(new URL(notificationURL), set);
        if (debug.messageEnabled()) {
            debug.message("PolicyListenerRequest.policyChanged(PolicyEvent): " + "the policy change notification has been sent to " + notificationURL);
        }
    } catch (SendNotificationException e) {
        debug.error("PolicyListenerRequest.policyChanged(): " + "PLLServer.send() failed", e);
    } catch (MalformedURLException e) {
        debug.error("PolicyListenerRequest.policyChanged(): " + "PLLServer.send() failed", e);
    }
}
Also used : NotificationSet(com.iplanet.services.comm.share.NotificationSet) MalformedURLException(java.net.MalformedURLException) NotificationSet(com.iplanet.services.comm.share.NotificationSet) Set(java.util.Set) SendNotificationException(com.iplanet.services.comm.server.SendNotificationException) Notification(com.iplanet.services.comm.share.Notification) URL(java.net.URL)

Example 3 with NotificationSet

use of com.iplanet.services.comm.share.NotificationSet in project OpenAM by OpenRock.

the class AgentsRepo method sendNotificationSet.

// If notification URLs are present, send notifications to clients/agents.
private void sendNotificationSet(int type, IdType agentIdTypeforNotificationSet, String agentNameforNotificationSet) {
    try {
        // If notification enabled is set to true ,send notifications.
        Set<String> nSet = new HashSet<String>(2);
        nSet.add(notificationURLenabled);
        SSOToken adminToken = AccessController.doPrivileged(AdminTokenAction.getInstance());
        Map<String, Set<String>> ansMap = getAttributes(adminToken, agentIdTypeforNotificationSet, agentNameforNotificationSet, nSet);
        Set<String> neSet = ansMap.get(notificationURLenabled);
        if (neSet != null && !neSet.isEmpty() && neSet.iterator().next().equalsIgnoreCase("true")) {
            switch(type) {
                case MODIFIED:
                    if (agentIdTypeforNotificationSet == null) {
                        break;
                    }
                    String modItem;
                    Set<String> aNameSet = new HashSet<String>(2);
                    if (debug.messageEnabled()) {
                        debug.message("AgentsRepo.sendNotificationSet(): agentIdTypeforNotificationSet " + agentIdTypeforNotificationSet);
                        debug.message("AgentsRepo.sendNotificationSet(): agentNameforNotificationSet " + agentNameforNotificationSet);
                    }
                    // notifications to all its members.
                    if (agentIdTypeforNotificationSet.equals(IdType.AGENTGROUP)) {
                        Set<String> members = getMembers(adminToken, agentIdTypeforNotificationSet, agentNameforNotificationSet, IdType.AGENTONLY);
                        for (String agent : members) {
                            aNameSet.add(agent);
                            //An agent group has been updated, so now we need to notify the internal cache for the
                            //group members so they return the changed inherited values as well.
                            repoListener.objectChanged(agent, IdType.AGENT, type, repoListener.getConfigMap());
                            repoListener.objectChanged(agent, IdType.AGENTONLY, type, repoListener.getConfigMap());
                        }
                    } else {
                        aNameSet.add(agentNameforNotificationSet);
                    }
                    if (debug.messageEnabled()) {
                        debug.message("AgentsRepo.sendNotificationSet(): aNameSet " + aNameSet);
                    }
                    if (!aNameSet.isEmpty()) {
                        for (String agentName : aNameSet) {
                            agentIdTypeforNotificationSet = IdType.AGENTONLY;
                            // To be consistent and for easy web agent
                            // parsing,the notification set should start with
                            // "AgentConfigChangeNotification"
                            StringBuilder xmlsb = new StringBuilder(1000);
                            xmlsb.append("<").append(AGENT_NOTIFICATION).append(" ").append(AGENT_ID).append("=\"").append(agentName).append("\"").append(" ").append(AGENT_IDTYPE).append("=\"").append(agentIdTypeforNotificationSet.getName()).append("\"/>");
                            modItem = xmlsb.toString();
                            if (debug.messageEnabled()) {
                                debug.message("AgentsRepo.sendNotificationSet(): modItem " + modItem);
                            }
                            // If notification URLs are present,send
                            // notifications
                            nSet = new HashSet<String>(2);
                            nSet.add(notificationURLname);
                            String nval;
                            ansMap = getAttributes(adminToken, agentIdTypeforNotificationSet, agentName, nSet);
                            Set<String> nvalSet = ansMap.get(notificationURLname);
                            if (nvalSet != null && !nvalSet.isEmpty()) {
                                nval = nvalSet.iterator().next();
                                try {
                                    URL url = new URL(nval);
                                    // Construct NotificationSet to be sent to
                                    // Agents.
                                    Notification notification = new Notification(modItem);
                                    NotificationSet ns = new NotificationSet(AGENT_CONFIG_SERVICE);
                                    ns.addNotification(notification);
                                    try {
                                        PLLServer.send(url, ns);
                                        if (debug.messageEnabled()) {
                                            debug.message("AgentsRepo:sendNotificationSet Sent Notification to URL: " + url + " Data: " + ns);
                                        }
                                    } catch (SendNotificationException ne) {
                                        if (debug.warningEnabled()) {
                                            debug.warning("AgentsRepo.sendNotificationSet: failed sending notification" + " to: " + url + " " + ne.getMessage());
                                        }
                                    }
                                } catch (MalformedURLException e) {
                                    if (debug.warningEnabled()) {
                                        debug.warning("AgentsRepo.sendNotificationSet:(): invalid URL: " + e.getMessage());
                                    }
                                }
                            }
                        }
                    }
            }
        }
    } catch (IdRepoException idpe) {
        debug.error("AgentsRepo.sendNotificationSet(): Unable to send notification due to " + idpe);
    } catch (SSOException ssoe) {
        if (debug.warningEnabled()) {
            debug.warning("AgentsRepo.sendNotificationSet(): Unable to send notification due to " + ssoe.getMessage());
        }
    }
}
Also used : NotificationSet(com.iplanet.services.comm.share.NotificationSet) MalformedURLException(java.net.MalformedURLException) SSOToken(com.iplanet.sso.SSOToken) NotificationSet(com.iplanet.services.comm.share.NotificationSet) Set(java.util.Set) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) SendNotificationException(com.iplanet.services.comm.server.SendNotificationException) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) URL(java.net.URL) Notification(com.iplanet.services.comm.share.Notification) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet)

Example 4 with NotificationSet

use of com.iplanet.services.comm.share.NotificationSet in project OpenAM by OpenRock.

the class DirectoryManagerImpl method processEntryChanged.

// Implementation to process entry changed events
protected static void processEntryChanged(String method, String name, int type, Set attrNames) {
    debug.message("DirectoryManagerImpl.processEntryChaged method " + "processing");
    initializeCacheSize();
    // Construct the XML document for the event change
    StringBuilder sb = new StringBuilder(100);
    sb.append("<EventNotification><AttributeValuePair>").append("<Attribute name=\"method\" /><Value>").append(method).append("</Value></AttributeValuePair>").append("<AttributeValuePair><Attribute name=\"entityName\" />").append("<Value>").append(name).append("</Value></AttributeValuePair>");
    if (method.equalsIgnoreCase("objectChanged") || method.equalsIgnoreCase("objectsChanged")) {
        sb.append("<AttributeValuePair><Attribute name=\"eventType\" />").append("<Value>").append(type).append("</Value></AttributeValuePair>");
        if (method.equalsIgnoreCase("objectsChanged")) {
            sb.append("<AttributeValuePair><Attribute ").append("name=\"attrNames\"/>");
            for (Iterator items = attrNames.iterator(); items.hasNext(); ) {
                String attr = (String) items.next();
                sb.append("<Value>").append(attr).append("</Value>");
            }
            sb.append("</AttributeValuePair>");
        }
    }
    sb.append("</EventNotification>");
    if (cacheSize > 0) {
        Set<String> modDNs = getCachedValues(cache);
        // Add to cache
        modDNs.add(sb.toString());
        if (debug.messageEnabled()) {
            debug.message("DirectoryManagerImpl::processing entry change: " + sb.toString());
        }
    }
    if (debug.messageEnabled()) {
        debug.message("DirectoryManagerImpl = notificationURLS" + notificationURLs.values());
    }
    // If notification URLs are present, send notifications
    NotificationSet ns = null;
    synchronized (notificationURLs) {
        for (Map.Entry<String, URL> entry : notificationURLs.entrySet()) {
            String id = entry.getKey();
            URL url = entry.getValue();
            // Construct NotificationSet
            if (ns == null) {
                Notification notification = new Notification(sb.toString());
                ns = new NotificationSet(com.iplanet.am.sdk.remote.RemoteServicesImpl.SDK_SERVICE);
                ns.addNotification(notification);
            }
            try {
                PLLServer.send(url, ns);
                if (debug.messageEnabled()) {
                    debug.message("DirectorManagerImpl:sentNotification " + "URL: " + url + " Data: " + ns);
                }
            } catch (SendNotificationException ne) {
                if (debug.warningEnabled()) {
                    debug.warning("DirectoryManagerImpl: failed sending " + "notification to: " + url + "\nRemoving " + "URL from notification list.", ne);
                }
                // Remove the URL from Notification List
                notificationURLs.remove(id);
            }
        }
    }
}
Also used : NotificationSet(com.iplanet.services.comm.share.NotificationSet) SendNotificationException(com.iplanet.services.comm.server.SendNotificationException) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) URL(java.net.URL) Notification(com.iplanet.services.comm.share.Notification)

Example 5 with NotificationSet

use of com.iplanet.services.comm.share.NotificationSet in project OpenAM by OpenRock.

the class IdRepoJAXRPCObjectImpl method processEntryChanged_idrepo.

// Implementation to process entry changed events
protected static void processEntryChanged_idrepo(String method, String name, int type, Set attrNames) {
    if (idRepoDebug.messageEnabled()) {
        idRepoDebug.message("IdRepoJAXRPCObjectImpl.processEntryChaged " + "method processing method: " + method + " name: " + name + " type: " + type + " attrName: " + attrNames);
    }
    initializeCacheSize();
    // Return if cache size is 0 or there are no remote clients
    if (cacheSize == 0 && idRepoNotificationURLs.isEmpty()) {
        if (idRepoDebug.messageEnabled()) {
            idRepoDebug.message("IdRepoJAXRPCObjectImpl." + "processEntryChaged No registered notification URLs: " + idRepoNotificationURLs + " and cache size is: " + cacheSize);
        }
        return;
    }
    // Construct the XML document for the event change
    StringBuilder sb = new StringBuilder(100);
    sb.append("<EventNotification><AttributeValuePair>").append("<Attribute name=\"method\" /><Value>").append(method).append("</Value></AttributeValuePair>").append("<AttributeValuePair><Attribute name=\"entityName\" />").append("<Value>").append(XMLUtils.escapeSpecialCharacters(name)).append("</Value></AttributeValuePair>");
    if (method.equalsIgnoreCase("objectChanged") || method.equalsIgnoreCase("objectsChanged")) {
        sb.append("<AttributeValuePair><Attribute name=\"eventType\" />").append("<Value>").append(type).append("</Value></AttributeValuePair>");
        if (method.equalsIgnoreCase("objectsChanged")) {
            sb.append("<AttributeValuePair><Attribute ").append("name=\"attrNames\"/>");
            for (Iterator items = attrNames.iterator(); items.hasNext(); ) {
                String attr = (String) items.next();
                sb.append("<Value>").append(attr).append("</Value>");
            }
            sb.append("</AttributeValuePair>");
        }
    }
    sb.append("</EventNotification>");
    // Update cache for polling by remote clients
    if (cacheSize > 0) {
        Set<String> modDNs = getCachedValues(idrepoCache);
        // Add to cache
        modDNs.add(sb.toString());
        if (idRepoDebug.messageEnabled()) {
            idRepoDebug.message("IdRepoJAXRPCObjectImpl.processing " + "entry change:" + sb.toString());
        }
    }
    // If notification URLs are present, send notifications
    if (idRepoDebug.messageEnabled()) {
        idRepoDebug.message("IdRepoJAXRPCObjectImpl.processEntryChaged =" + " notificationURLS " + idRepoNotificationURLs.values());
    }
    NotificationSet ns = null;
    synchronized (idRepoNotificationURLs) {
        for (Map.Entry<String, URL> entry : idRepoNotificationURLs.entrySet()) {
            String id = entry.getKey();
            URL url = entry.getValue();
            // Construct NotificationSet
            if (ns == null) {
                Notification notification = new Notification(sb.toString());
                ns = new NotificationSet(IDREPO_SERVICE);
                ns.addNotification(notification);
            }
            try {
                PLLServer.send(url, ns);
                if (idRepoDebug.messageEnabled()) {
                    idRepoDebug.message("IdRepoJAXRPCObjectImpl:" + "sentNotification URL: " + url + " Data: " + ns);
                }
            } catch (SendNotificationException ne) {
                if (idRepoDebug.warningEnabled()) {
                    idRepoDebug.warning("IdRepoJAXRPCObjectImpl: failed " + "sending notification to: " + url + "\nRemoving " + "URL from notification list.", ne);
                }
                // Remove the URL from Notification List
                idRepoNotificationURLs.remove(id);
            }
        }
    }
}
Also used : NotificationSet(com.iplanet.services.comm.share.NotificationSet) SendNotificationException(com.iplanet.services.comm.server.SendNotificationException) Iterator(java.util.Iterator) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) URL(java.net.URL) Notification(com.iplanet.services.comm.share.Notification)

Aggregations

Notification (com.iplanet.services.comm.share.Notification)6 NotificationSet (com.iplanet.services.comm.share.NotificationSet)6 SendNotificationException (com.iplanet.services.comm.server.SendNotificationException)5 URL (java.net.URL)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Set (java.util.Set)3 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)2 MalformedURLException (java.net.MalformedURLException)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)2 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 ServletException (javax.servlet.ServletException)1