Package org.jivesoftware.openfire.privacy

Examples of org.jivesoftware.openfire.privacy.PrivacyList


                    Message.Type.error == message.getType() ||
                    Message.Type.headline == message.getType()) {
                return;
            }
            // Do not store messages if communication is blocked
            PrivacyList list =
                    PrivacyListManager.getInstance().getDefaultPrivacyList(recipientJID.getNode());
            if (list != null && list.shouldBlockPacket(message)) {
                return;
            }

            if (type == Type.bounce) {
                bounce(message);
View Full Code Here


    public void broadcastPresence(Presence packet) {
        if (routingTable == null) {
            return;
        }
        // Get the privacy list of this user
        PrivacyList list = null;
        JID from = packet.getFrom();
        if (from != null) {
            // Try to use the active list of the session. If none was found then try to use
            // the default privacy list of the session
            ClientSession session = sessionManager.getSession(from);
            if (session != null) {
                list = session.getActiveList();
                list = list == null ? session.getDefaultList() : list;
            }
        }
        if (list == null) {
            // No privacy list was found (based on the session) so check if there is a default list
            list = PrivacyListManager.getInstance().getDefaultPrivacyList(username);
        }
        // Broadcast presence to subscribed entities
        for (RosterItem item : rosterItems.values()) {
            if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) {
                packet.setTo(item.getJid());
                if (list != null && list.shouldBlockPacket(packet)) {
                    // Outgoing presence notifications are blocked for this contact
                    continue;
                }
                JID searchNode = new JID(item.getJid().getNode(), item.getJid().getDomain(), null, true);
                for (JID jid : routingTable.getRoutes(searchNode, null)) {
                    try {
                        routingTable.routePacket(jid, packet, false);
                    }
                    catch (Exception e) {
                        // Theoretically only happens if session has been closed.
                        Log.debug(e.getMessage(), e);
                    }
                }
            }
        }
        // Broadcast presence to shared contacts whose subscription status is FROM
        for (String contact : implicitFrom.keySet()) {
            if (contact.contains("@")) {
                String node = contact.substring(0, contact.lastIndexOf("@"));
                String domain = contact.substring(contact.lastIndexOf("@")+1);
                node = JID.escapeNode(node);
                contact = new JID(node, domain, null).toBareJID();
            }

            packet.setTo(contact);
            if (list != null && list.shouldBlockPacket(packet)) {
                // Outgoing presence notifications are blocked for this contact
                continue;
            }
            for (JID jid: routingTable.getRoutes(new JID(contact), null)) {
                try {
View Full Code Here

            this.listName = list != null ? list.getName() : null;
        }

        public void run() {
            ClientSession session = ((ClientSession) getSession());
            PrivacyList list = null;
            // Get the privacy list to set
            if (listName != null) {
                try {
                    String username = session.getUsername();
                    list = PrivacyListManager.getInstance().getPrivacyList(username, listName);
View Full Code Here

                            // Create the presence from the parsed element
                            Presence presencePacket = new Presence(element.getRootElement());
                            presencePacket.setFrom(probee.toBareJID());
                            // Check if default privacy list of the probee blocks the
                            // outgoing presence
                            PrivacyList list = PrivacyListManager.getInstance()
                                    .getDefaultPrivacyList(probee.getNode());
                            // Send presence to all prober's resources
                            for (JID receipient : proberFullJIDs) {
                                presencePacket.setTo(receipient);
                                if (list == null || !list.shouldBlockPacket(presencePacket)) {
                                    // Send the presence to the prober
                                    deliverer.deliver(presencePacket);
                                }
                            }
                        }
                        catch (Exception e) {
                            Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
                        }
                    }
                }
                else {
                    // The contact is online so send to the prober all the resources where the
                    // probee is connected
                    for (ClientSession session : sessions) {
                        // Create presence to send from probee to prober
                        Presence presencePacket = session.getPresence().createCopy();
                        presencePacket.setFrom(session.getAddress());
                        // Check if a privacy list of the probee blocks the outgoing presence
                        PrivacyList list = session.getActiveList();
                        list = list == null ? session.getDefaultList() : list;
                        // Send presence to all prober's resources
                        for (JID receipient : proberFullJIDs) {
                            presencePacket.setTo(receipient);
                            if (list != null) {
                                if (list.shouldBlockPacket(presencePacket)) {
                                    // Default list blocked outgoing presence so skip this session
                                    continue;
                                }
                            }
                            try {
View Full Code Here

     * @param packet the packet to analyze if it must be blocked.
     * @return true if the specified packet must be blocked.
     */
    @Override
  public boolean canProcess(Packet packet) {
        PrivacyList list = getActiveList();
        if (list != null) {
            // If a privacy list is active then make sure that the packet is not blocked
            return !list.shouldBlockPacket(packet);
        }
        else {
            list = getDefaultList();
            // There is no active list so check if there exists a default list and make
            // sure that the packet is not blocked
            return list == null || !list.shouldBlockPacket(packet);
        }
    }
View Full Code Here

                    }
                }
                else {
                    // Check if communication to local users is allowed
                    if (recipientJID != null && userManager.isRegisteredUser(recipientJID.getNode())) {
                        PrivacyList list =
                                PrivacyListManager.getInstance().getDefaultPrivacyList(recipientJID.getNode());
                        if (list != null && list.shouldBlockPacket(packet)) {
                            // Communication is blocked
                            if (IQ.Type.set == packet.getType() || IQ.Type.get == packet.getType()) {
                                // Answer that the service is unavailable
                                sendErrorPacket(packet, PacketError.Condition.service_unavailable);
                            }
View Full Code Here

        if (lists.size() > 1) {
            result.setError(PacketError.Condition.bad_request);
        }
        else {
            String listName = lists.get(0).attributeValue("name");
            PrivacyList list = null;
            if (listName != null) {
                // A list name was specified so get it
                list = manager.getPrivacyList(from.getNode(), listName);
            }
            if (list != null) {
                // Add the privacy list to the result
                childElement = result.setChildElement("query", "jabber:iq:privacy");
                childElement.add(list.asElement());
            }
            else {
                // List not found
                result.setError(PacketError.Condition.item_not_found);
            }
View Full Code Here

        IQ result = IQ.createResultIQ(packet);
        Element childElement = packet.getChildElement().createCopy();
        result.setChildElement(childElement);

        // Get the list
        PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
        if (list != null) {
            // Get the user session
            ClientSession session = sessionManager.getSession(from);
            if (session != null) {
                // Set the new active list for this session
View Full Code Here

            // Current default list is being used by more than one session
            result.setError(PacketError.Condition.conflict);
        }
        else {
            // Get the list
            PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
            if (list != null) {
                // Get the user session
                ClientSession session = sessionManager.getSession(from);
                PrivacyList oldDefaultList = session.getDefaultList();
                manager.changeDefaultList(from.getNode(), list, oldDefaultList);
                // Set the new default list for this session (the only existing session)
                session.setDefaultList(list);
            }
            else {
View Full Code Here

        IQ result = IQ.createResultIQ(packet);
        Element childElement = packet.getChildElement().createCopy();
        result.setChildElement(childElement);

        String listName = listElement.attributeValue("name");
        PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
        if (list == null) {
            list = manager.createPrivacyList(from.getNode(), listName, listElement);
        }
        else {
            // Update existing list
            list.updateList(listElement);
            provider.updatePrivacyList(from.getNode(), list);
            // Make sure that existing user sessions that are using the updated list are poining
            // to the updated instance. This may happen since PrivacyListManager uses a Cache that
            // may expire so it's possible to have many instances representing the same privacy
            // list. Therefore, if a list is modified then we need to make sure that all
            // instances are replaced with the updated instance. An OR Mapping Tool would have
            // avoided this issue since identity is ensured.
            for (ClientSession session : sessionManager.getSessions(from.getNode())) {
                if (list.equals(session.getDefaultList())) {
                    session.setDefaultList(list);
                }
                if (list.equals(session.getActiveList())) {
                    session.setActiveList(list);
                }
            }
        }
        // Send a "privacy list push" to all connected resources
        IQ pushPacket = new IQ(IQ.Type.set);
        Element child = pushPacket.setChildElement("query", "jabber:iq:privacy");
        child.addElement("list").addAttribute("name", list.getName());
        sessionManager.userBroadcast(from.getNode(), pushPacket);

        return result;
    }
View Full Code Here

TOP

Related Classes of org.jivesoftware.openfire.privacy.PrivacyList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.