Search in sources :

Example 6 with PrivacyList

use of org.jivesoftware.openfire.privacy.PrivacyList in project Openfire by igniterealtime.

the class IQPrivacyHandler method getPrivacyList.

/**
     * Returns the IQ packet containing the details of the specified list. If no list
     * was found or the IQ request contains more than one specified list then an error will
     * be returned.
     *
     * @param packet IQ packet requesting a given list.
     * @param from sender of the IQ packet.
     * @return the IQ packet containing the details of the specified list.
     */
private IQ getPrivacyList(IQ packet, JID from) {
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);
    // Check that only one list was requested
    List<Element> lists = childElement.elements("list");
    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);
        }
    }
    return result;
}
Also used : Element(org.dom4j.Element) PrivacyList(org.jivesoftware.openfire.privacy.PrivacyList) IQ(org.xmpp.packet.IQ)

Example 7 with PrivacyList

use of org.jivesoftware.openfire.privacy.PrivacyList in project Openfire by igniterealtime.

the class IQPrivacyHandler method setActiveList.

/**
     * User has specified a new active list that should be used for the current session.
     *
     * @param packet IQ packet setting new active list for the current session.
     * @param from sender of the IQ packet.
     * @param listName name of the new active list for the current session.
     * @return acknowledge of success.
     */
private IQ setActiveList(IQ packet, JID from, String listName) {
    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
            session.setActiveList(list);
        }
    } else {
        // List not found
        result.setError(PacketError.Condition.item_not_found);
    }
    return result;
}
Also used : Element(org.dom4j.Element) PrivacyList(org.jivesoftware.openfire.privacy.PrivacyList) ClientSession(org.jivesoftware.openfire.session.ClientSession) IQ(org.xmpp.packet.IQ)

Example 8 with PrivacyList

use of org.jivesoftware.openfire.privacy.PrivacyList in project Openfire by igniterealtime.

the class IQPrivacyHandler method setDefaultList.

/**
     * User has specified a new default list that should be used for all session.
     *
     * @param packet IQ packet setting new default list for all sessions.
     * @param from sender of the IQ packet.
     * @param listName name of the new default list for all sessions.
     * @return acknowledge of success.
     */
private IQ setDefaultList(IQ packet, JID from, String listName) {
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);
    if (sessionManager.getSessionCount(from.getNode()) > 1) {
        // 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 {
            // List not found
            result.setError(PacketError.Condition.item_not_found);
        }
    }
    return result;
}
Also used : Element(org.dom4j.Element) PrivacyList(org.jivesoftware.openfire.privacy.PrivacyList) ClientSession(org.jivesoftware.openfire.session.ClientSession) IQ(org.xmpp.packet.IQ)

Example 9 with PrivacyList

use of org.jivesoftware.openfire.privacy.PrivacyList in project Openfire by igniterealtime.

the class PresenceManagerImpl method probePresence.

@Override
public void probePresence(JID prober, JID probee) {
    try {
        if (server.isLocal(probee)) {
            // Local probers should receive presences of probee in all connected resources
            Collection<JID> proberFullJIDs = new ArrayList<>();
            if (prober.getResource() == null && server.isLocal(prober)) {
                for (ClientSession session : sessionManager.getSessions(prober.getNode())) {
                    proberFullJIDs.add(session.getAddress());
                }
            } else {
                proberFullJIDs.add(prober);
            }
            // If the probee is a local user then don't send a probe to the contact's server.
            // But instead just send the contact's presence to the prober
            Collection<ClientSession> sessions = sessionManager.getSessions(probee.getNode());
            if (sessions.isEmpty()) {
                // If the probee is not online then try to retrieve his last unavailable
                // presence which may contain particular information and send it to the
                // prober
                String presenceXML = offlinePresenceCache.get(probee.getNode());
                if (presenceXML == null) {
                    loadOfflinePresence(probee.getNode());
                }
                presenceXML = offlinePresenceCache.get(probee.getNode());
                if (presenceXML != null && !NULL_STRING.equals(presenceXML)) {
                    try {
                        // Parse the element
                        Document element = DocumentHelper.parseText(presenceXML);
                        // 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 {
                // 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 {
                            deliverer.deliver(presencePacket);
                        } catch (Exception e) {
                            Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
                        }
                    }
                }
            }
        } else {
            if (routingTable.hasComponentRoute(probee)) {
                // If the probee belongs to a component then ask the component to process the
                // probe presence
                Presence presence = new Presence();
                presence.setType(Presence.Type.probe);
                presence.setFrom(prober);
                presence.setTo(probee);
                routingTable.routePacket(probee, presence, true);
            } else {
                /*String serverDomain = server.getServerInfo().getName();
                    if (!probee.getDomain().contains(serverDomain)) {*/
                if (server.isRemote(probee)) {
                    // Send the probe presence to the remote server
                    Presence probePresence = new Presence();
                    probePresence.setType(Presence.Type.probe);
                    probePresence.setFrom(prober);
                    probePresence.setTo(probee.toBareJID());
                    // Send the probe presence
                    deliverer.deliver(probePresence);
                } else {
                    // The probee may be related to a component that has not yet been connected so
                    // we will keep a registry of this presence probe. The component will answer
                    // this presence probe when he becomes online
                    componentManager.addPresenceRequest(prober, probee);
                }
            }
        }
    } catch (Exception e) {
        Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
    }
}
Also used : JID(org.xmpp.packet.JID) ClientSession(org.jivesoftware.openfire.session.ClientSession) PrivacyList(org.jivesoftware.openfire.privacy.PrivacyList) Presence(org.xmpp.packet.Presence) Document(org.dom4j.Document) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) SQLException(java.sql.SQLException) DocumentException(org.dom4j.DocumentException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Aggregations

PrivacyList (org.jivesoftware.openfire.privacy.PrivacyList)9 ClientSession (org.jivesoftware.openfire.session.ClientSession)7 Element (org.dom4j.Element)6 IQ (org.xmpp.packet.IQ)5 JID (org.xmpp.packet.JID)3 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 Document (org.dom4j.Document)1 DocumentException (org.dom4j.DocumentException)1 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)1 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)1 IQHandler (org.jivesoftware.openfire.handler.IQHandler)1 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)1 LocalClientSession (org.jivesoftware.openfire.session.LocalClientSession)1 Session (org.jivesoftware.openfire.session.Session)1 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)1 CannotCalculateSizeException (org.jivesoftware.util.cache.CannotCalculateSizeException)1 IQResultListener (org.xmpp.component.IQResultListener)1 Message (org.xmpp.packet.Message)1