Search in sources :

Example 1 with Notification

use of com.iplanet.services.comm.share.Notification 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 2 with Notification

use of com.iplanet.services.comm.share.Notification 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 3 with Notification

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

the class PolicyNotificationHandler method processPLLNotifications.

/**
     * Processes PLL notifications
     * @param notifications PLL notification to be processed
     */
void processPLLNotifications(Vector notifications) {
    for (int i = 0; i < notifications.size(); i++) {
        Notification notification = (Notification) notifications.elementAt(i);
        if (debug.messageEnabled()) {
            debug.message("PolicyNotificationHandler." + "processPLLNotifications():" + "got notification: " + notification.getContent());
        }
        try {
            PolicyService ps = PolicyService.parseXML(notification.getContent());
            PolicyNotification pn = ps.getPolicyNotification();
            if (pn != null) {
                processPolicyNotification(pn);
            }
        } catch (PolicyException pe) {
            debug.error("PolicyNotificationHandler." + "processPLLNotifications():" + "invalid notifcation format", pe);
        }
    }
}
Also used : PolicyNotification(com.sun.identity.policy.remote.PolicyNotification) PolicyException(com.sun.identity.policy.PolicyException) PolicyService(com.sun.identity.policy.remote.PolicyService) Notification(com.iplanet.services.comm.share.Notification) PolicyNotification(com.sun.identity.policy.remote.PolicyNotification)

Example 4 with Notification

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

the class SMSJAXRPCObjectImpl method objectChanged.

// Implementation for SMSObjectListener
public synchronized void objectChanged(String name, int type) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    String cacheIndex = calendarToString(calendar);
    Set modDNs = (Set) cache.get(cacheIndex);
    if (modDNs == null) {
        modDNs = new HashSet();
        cache.put(cacheIndex, modDNs);
        // Maintain cacheIndex
        cacheIndices.addFirst(cacheIndex);
        if (cacheIndices.size() > cacheSize) {
            String index = (String) cacheIndices.removeLast();
            cache.remove(index);
        }
    }
    String modItem = null;
    switch(type) {
        case ADD:
            modItem = "ADD:" + name;
            break;
        case DELETE:
            modItem = "DEL:" + name;
            break;
        default:
            modItem = "MOD:" + name;
    }
    modDNs.add(modItem);
    // If notification URLs are present, send notifications
    synchronized (notificationURLs) {
        for (Map.Entry<String, URL> entry : notificationURLs.entrySet()) {
            String id = entry.getKey();
            URL url = entry.getValue();
            // Construct NotificationSet
            Notification notification = new Notification(modItem);
            NotificationSet ns = new NotificationSet(JAXRPCUtil.SMS_SERVICE);
            ns.addNotification(notification);
            try {
                PLLServer.send(url, ns);
                if (debug.messageEnabled()) {
                    debug.message("SMSJAXRPCObjectImpl:objectChanged sent notification to " + "URL: " + url + " Data: " + ns);
                }
            } catch (SendNotificationException ne) {
                if (debug.warningEnabled()) {
                    debug.warning("SMSJAXRPCObjectImpl:objectChanged 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) HashSet(java.util.HashSet) NotificationSet(com.iplanet.services.comm.share.NotificationSet) Set(java.util.Set) SendNotificationException(com.iplanet.services.comm.server.SendNotificationException) Calendar(java.util.Calendar) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) Date(java.util.Date) URL(java.net.URL) Notification(com.iplanet.services.comm.share.Notification) HashSet(java.util.HashSet)

Example 5 with Notification

use of com.iplanet.services.comm.share.Notification 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)

Aggregations

Notification (com.iplanet.services.comm.share.Notification)7 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 PolicyException (com.sun.identity.policy.PolicyException)1 PolicyNotification (com.sun.identity.policy.remote.PolicyNotification)1 PolicyService (com.sun.identity.policy.remote.PolicyService)1