Search in sources :

Example 1 with LocalSession

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

the class WebSocketPlugin method destroyPlugin.

@Override
public void destroyPlugin() {
    // terminate any active websocket sessions
    SessionManager sm = XMPPServer.getInstance().getSessionManager();
    for (ClientSession session : sm.getSessions()) {
        if (session instanceof LocalSession) {
            Object ws = ((LocalSession) session).getSessionData("ws");
            if (ws != null && (Boolean) ws) {
                session.close();
            }
        }
    }
    ContextHandlerCollection contexts = HttpBindManager.getInstance().getContexts();
    contexts.removeHandler(contextHandler);
    contextHandler = null;
    pluginClassLoader = null;
}
Also used : SessionManager(org.jivesoftware.openfire.SessionManager) ClientSession(org.jivesoftware.openfire.session.ClientSession) LocalSession(org.jivesoftware.openfire.session.LocalSession) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection)

Example 2 with LocalSession

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

the class NIOConnection method reinit.

@Override
public void reinit(LocalSession owner) {
    session = owner;
    StanzaHandler stanzaHandler = getStanzaHandler();
    stanzaHandler.setSession(owner);
    // during the callback. OF-2014
    for (final Map.Entry<ConnectionCloseListener, Object> entry : closeListeners.entrySet()) {
        if (entry.getValue() instanceof LocalSession) {
            entry.setValue(owner);
        }
    }
}
Also used : StanzaHandler(org.jivesoftware.openfire.net.StanzaHandler) LocalSession(org.jivesoftware.openfire.session.LocalSession) ConnectionCloseListener(org.jivesoftware.openfire.ConnectionCloseListener)

Example 3 with LocalSession

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

the class LocalSessionManager method stop.

public void stop() {
    try {
        // Send the close stream header to all connected connections
        Set<LocalSession> sessions = new HashSet<>();
        sessions.addAll(preAuthenticatedSessions.values());
        sessions.addAll(componentsSessions);
        for (LocalIncomingServerSession incomingSession : incomingServerSessions.values()) {
            sessions.add(incomingSession);
        }
        for (LocalConnectionMultiplexerSession multiplexer : connnectionManagerSessions.values()) {
            sessions.add(multiplexer);
        }
        for (LocalSession session : sessions) {
            try {
                // Notify connected client that the server is being shut down
                if (!session.isDetached()) {
                    session.getConnection().systemShutdown();
                }
            } catch (Throwable t) {
            // Ignore.
            }
        }
    } catch (Exception e) {
    // Ignore.
    }
}
Also used : LocalConnectionMultiplexerSession(org.jivesoftware.openfire.session.LocalConnectionMultiplexerSession) LocalIncomingServerSession(org.jivesoftware.openfire.session.LocalIncomingServerSession) LocalSession(org.jivesoftware.openfire.session.LocalSession) HashSet(java.util.HashSet)

Example 4 with LocalSession

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

the class SaslServerFactoryImpl method createSaslServer.

@Override
public SaslServer createSaslServer(String mechanism, String protocol, String serverName, Map<String, ?> props, CallbackHandler cbh) throws SaslException {
    if (!Arrays.asList(getMechanismNames(props)).contains(mechanism)) {
        Log.debug("This implementation is unable to create a SaslServer instance for the {} mechanism using the provided properties.", mechanism);
        return null;
    }
    switch(mechanism.toUpperCase()) {
        case "PLAIN":
            if (cbh == null) {
                Log.debug("Unable to instantiate {} SaslServer: A callbackHandler with support for Password, Name, and AuthorizeCallback required.", mechanism);
                return null;
            }
            return new SaslServerPlainImpl(protocol, serverName, props, cbh);
        case "SCRAM-SHA-1":
            return new ScramSha1SaslServer();
        case "ANONYMOUS":
            if (!props.containsKey(LocalSession.class.getCanonicalName())) {
                Log.debug("Unable to instantiate {} SaslServer: Provided properties do not contain a LocalSession instance.", mechanism);
                return null;
            } else {
                final LocalSession session = (LocalSession) props.get(LocalSession.class.getCanonicalName());
                return new AnonymousSaslServer(session);
            }
        case "EXTERNAL":
            if (!props.containsKey(LocalSession.class.getCanonicalName())) {
                Log.debug("Unable to instantiate {} SaslServer: Provided properties do not contain a LocalSession instance.", mechanism);
                return null;
            } else {
                final Object session = props.get(LocalSession.class.getCanonicalName());
                if (session instanceof LocalClientSession) {
                    return new ExternalClientSaslServer((LocalClientSession) session);
                }
                if (session instanceof LocalIncomingServerSession) {
                    return new ExternalServerSaslServer((LocalIncomingServerSession) session);
                }
                Log.debug("Unable to instantiate {} Sasl Server: Provided properties contains neither LocalClientSession nor LocalIncomingServerSession instance.", mechanism);
                return null;
            }
        case JiveSharedSecretSaslServer.NAME:
            return new JiveSharedSecretSaslServer();
        default:
            // Fail fast - this should not be possible, as the first check in this method already verifies wether the mechanism is supported.
            throw new IllegalStateException();
    }
}
Also used : LocalClientSession(org.jivesoftware.openfire.session.LocalClientSession) LocalIncomingServerSession(org.jivesoftware.openfire.session.LocalIncomingServerSession) LocalSession(org.jivesoftware.openfire.session.LocalSession)

Example 5 with LocalSession

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

the class OpenfireWebSocketServlet method destroy.

@Override
public void destroy() {
    // terminate any active websocket sessions
    SessionManager sm = XMPPServer.getInstance().getSessionManager();
    for (ClientSession session : sm.getSessions()) {
        if (session instanceof LocalSession) {
            Object ws = ((LocalSession) session).getSessionData("ws");
            if (ws != null && (Boolean) ws) {
                Log.debug("Closing session as websocket servlet is being destroyed: {}", session);
                session.close();
            }
        }
    }
    super.destroy();
}
Also used : SessionManager(org.jivesoftware.openfire.SessionManager) ClientSession(org.jivesoftware.openfire.session.ClientSession) LocalSession(org.jivesoftware.openfire.session.LocalSession)

Aggregations

LocalSession (org.jivesoftware.openfire.session.LocalSession)7 LocalIncomingServerSession (org.jivesoftware.openfire.session.LocalIncomingServerSession)3 SessionManager (org.jivesoftware.openfire.SessionManager)2 ClientSession (org.jivesoftware.openfire.session.ClientSession)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 SaslException (javax.security.sasl.SaslException)1 SaslServer (javax.security.sasl.SaslServer)1 Element (org.dom4j.Element)1 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)1 ConnectionCloseListener (org.jivesoftware.openfire.ConnectionCloseListener)1 XMPPServerInfo (org.jivesoftware.openfire.XMPPServerInfo)1 StanzaHandler (org.jivesoftware.openfire.net.StanzaHandler)1 AnonymousSaslServer (org.jivesoftware.openfire.sasl.AnonymousSaslServer)1 Failure (org.jivesoftware.openfire.sasl.Failure)1 JiveSharedSecretSaslServer (org.jivesoftware.openfire.sasl.JiveSharedSecretSaslServer)1 SaslFailureException (org.jivesoftware.openfire.sasl.SaslFailureException)1 IncomingServerSession (org.jivesoftware.openfire.session.IncomingServerSession)1 LocalClientSession (org.jivesoftware.openfire.session.LocalClientSession)1 LocalConnectionMultiplexerSession (org.jivesoftware.openfire.session.LocalConnectionMultiplexerSession)1