Search in sources :

Example 11 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 12 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 13 with PrivacyList

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

the class IQPrivacyHandler method updateOrCreateList.

/**
 * Updates an existing privacy list or creates a new one with the specified items list. The
 * new list will not become the active or default list by default. The user will have to
 * send another packet to set the new list as active or default.<p>
 *
 * Once the list was updated or created a "privacy list push" will be sent to all
 * connected resources of the user.
 *
 * @param packet IQ packet updating or creating a new privacy list.
 * @param from sender of the IQ packet.
 * @param listElement the element containing the list and its items.
 * @return acknowledge of success.
 */
private IQ updateOrCreateList(IQ packet, JID from, Element listElement) {
    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);
        // 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;
}
Also used : Element(org.dom4j.Element) PrivacyList(org.jivesoftware.openfire.privacy.PrivacyList) ClientSession(org.jivesoftware.openfire.session.ClientSession) IQ(org.xmpp.packet.IQ)

Aggregations

PrivacyList (org.jivesoftware.openfire.privacy.PrivacyList)13 Element (org.dom4j.Element)9 ClientSession (org.jivesoftware.openfire.session.ClientSession)7 IQ (org.xmpp.packet.IQ)5 JID (org.xmpp.packet.JID)5 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 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)1 IQResultListenerTask (org.jivesoftware.openfire.cluster.IQResultListenerTask)1 NodeID (org.jivesoftware.openfire.cluster.NodeID)1 IQHandler (org.jivesoftware.openfire.handler.IQHandler)1 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)1 DomainPair (org.jivesoftware.openfire.session.DomainPair)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