Search in sources :

Example 11 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class IQPrivacyHandler method declineActiveList.

/**
     * User has requested that no active list should be used for the current session. Return
     * acknowledge of success.
     *
     * @param packet IQ packet declining active list for the current session.
     * @param from sender of the IQ packet.
     * @return acknowledge of success.
     */
private IQ declineActiveList(IQ packet, JID from) {
    // Get the user session
    ClientSession session = sessionManager.getSession(from);
    // Set that there is no active list for this session
    session.setActiveList(null);
    // Return acknowledge of success
    return IQ.createResultIQ(packet);
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession)

Example 12 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class IQPrivacyHandler method deleteList.

private IQ deleteList(IQ packet, JID from, String listName) {
    ClientSession currentSession;
    IQ result = IQ.createResultIQ(packet);
    Element childElement = packet.getChildElement().createCopy();
    result.setChildElement(childElement);
    // Get the list to delete
    PrivacyList list = manager.getPrivacyList(from.getNode(), listName);
    if (list == null) {
        // List to delete was not found
        result.setError(PacketError.Condition.item_not_found);
        return result;
    } else {
        currentSession = sessionManager.getSession(from);
        // Check if the list is being used by another session
        for (ClientSession session : sessionManager.getSessions(from.getNode())) {
            if (currentSession == session) {
                // Ignore the active session for this checking
                continue;
            }
            if (list.equals(session.getDefaultList()) || list.equals(session.getActiveList())) {
                // List to delete is being used by another session so return a conflict error
                result.setError(PacketError.Condition.conflict);
                return result;
            }
        }
    }
    // Remove the list from the active session (if it was being used)
    if (list.equals(currentSession.getDefaultList())) {
        currentSession.setDefaultList(null);
    }
    if (list.equals(currentSession.getActiveList())) {
        currentSession.setActiveList(null);
    }
    manager.deletePrivacyList(from.getNode(), listName);
    return result;
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) Element(org.dom4j.Element) PrivacyList(org.jivesoftware.openfire.privacy.PrivacyList) IQ(org.xmpp.packet.IQ)

Example 13 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class TransportSessionRouter method leftCluster.

/**
     * @see org.jivesoftware.openfire.cluster.ClusterEventListener#leftCluster(byte[])
     */
public void leftCluster(byte[] leavingNodeID) {
    KrakenPlugin plugin = getPlugin();
    // TODO: Is this correct?  Lets say another node updates an entry before I get to it, will I see the update?
    for (Map.Entry<String, byte[]> entry : sessionLocations.entrySet()) {
        if (Arrays.equals(entry.getValue(), leavingNodeID)) {
            Lock l = CacheFactory.getLock(entry.getKey() + "lc", sessionLocations);
            try {
                l.lock();
                String jid = entry.getKey().substring(0, entry.getKey().lastIndexOf("@"));
                String trType = entry.getKey().substring(entry.getKey().lastIndexOf("@") + 1);
                Log.debug("Kraken: Node handling session " + jid + " on " + trType + " lost, taking over session...");
                sessionLocations.remove(jid + "@" + trType);
                TransportInstance trInstance = plugin.getTransportInstance(trType);
                if (trInstance != null) {
                    BaseTransport<? extends TransportBuddy> transport = trInstance.getTransport();
                    if (transport != null) {
                        Collection<ClientSession> sessions = XMPPServer.getInstance().getSessionManager().getSessions(new JID(jid).getNode());
                        for (ClientSession session : sessions) {
                            transport.processPacket(session.getPresence());
                        }
                    }
                }
            } finally {
                l.unlock();
            }
        }
    }
}
Also used : JID(org.xmpp.packet.JID) ClientSession(org.jivesoftware.openfire.session.ClientSession) TransportInstance(net.sf.kraken.TransportInstance) KrakenPlugin(net.sf.kraken.KrakenPlugin) Map(java.util.Map) Lock(java.util.concurrent.locks.Lock)

Example 14 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class PresenceRouter method route.

/**
     * Routes presence packets.
     *
     * @param packet the packet to route.
     * @throws NullPointerException if the packet is null.
     */
public void route(Presence packet) {
    if (packet == null) {
        throw new NullPointerException();
    }
    ClientSession session = sessionManager.getSession(packet.getFrom());
    try {
        // Invoke the interceptors before we process the read packet
        InterceptorManager.getInstance().invokeInterceptors(packet, session, true, false);
        if (session == null || session.getStatus() != Session.STATUS_CONNECTED) {
            handle(packet);
        } else {
            packet.setTo(session.getAddress());
            packet.setFrom((JID) null);
            packet.setError(PacketError.Condition.not_authorized);
            session.process(packet);
        }
        // Invoke the interceptors after we have processed the read packet
        InterceptorManager.getInstance().invokeInterceptors(packet, session, true, true);
    } catch (PacketRejectedException e) {
        if (session != null) {
            // An interceptor rejected this packet so answer a not_allowed error
            Presence reply = new Presence();
            reply.setID(packet.getID());
            reply.setTo(session.getAddress());
            reply.setFrom(packet.getTo());
            reply.setError(PacketError.Condition.not_allowed);
            session.process(reply);
            // Check if a message notifying the rejection should be sent
            if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) {
                // A message for the rejection will be sent to the sender of the rejected packet
                Message notification = new Message();
                notification.setTo(session.getAddress());
                notification.setFrom(packet.getTo());
                notification.setBody(e.getRejectionMessage());
                session.process(notification);
            }
        }
    }
}
Also used : ClientSession(org.jivesoftware.openfire.session.ClientSession) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException)

Example 15 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class SessionManager method broadcastPresenceOfOtherResource.

/**
     * Sends the presences of other connected resources to the resource that just connected.
     *
     * @param session the newly created session.
     */
private void broadcastPresenceOfOtherResource(LocalClientSession session) {
    if (!SessionManager.isOtherResourcePresenceEnabled()) {
        return;
    }
    Presence presence;
    // Get list of sessions of the same user
    JID searchJID = new JID(session.getAddress().getNode(), session.getAddress().getDomain(), null);
    List<JID> addresses = routingTable.getRoutes(searchJID, null);
    for (JID address : addresses) {
        if (address.equals(session.getAddress())) {
            continue;
        }
        // Send the presence of an existing session to the session that has just changed
        // the presence
        ClientSession userSession = routingTable.getClientRoute(address);
        presence = userSession.getPresence().createCopy();
        presence.setTo(session.getAddress());
        session.process(presence);
    }
}
Also used : JID(org.xmpp.packet.JID) LocalClientSession(org.jivesoftware.openfire.session.LocalClientSession) ClientSession(org.jivesoftware.openfire.session.ClientSession) Presence(org.xmpp.packet.Presence)

Aggregations

ClientSession (org.jivesoftware.openfire.session.ClientSession)49 JID (org.xmpp.packet.JID)15 Element (org.dom4j.Element)14 LocalClientSession (org.jivesoftware.openfire.session.LocalClientSession)14 IQ (org.xmpp.packet.IQ)12 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)8 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)7 PrivacyList (org.jivesoftware.openfire.privacy.PrivacyList)7 StreamError (org.xmpp.packet.StreamError)7 DataForm (org.xmpp.forms.DataForm)6 FormField (org.xmpp.forms.FormField)6 Message (org.xmpp.packet.Message)6 Presence (org.xmpp.packet.Presence)6 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)5 StringprepException (gnu.inet.encoding.StringprepException)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)3 SessionEntities (org.jivesoftware.openfire.plugin.rest.entity.SessionEntities)3 SQLException (java.sql.SQLException)2