Search in sources :

Example 1 with LocalIncomingServerSession

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

the class SessionManager method restoreCacheContent.

private void restoreCacheContent() {
    // Add external component sessions hosted locally to the cache (using new nodeID)
    for (Session session : localSessionManager.getComponentsSessions()) {
        componentSessionsCache.put(session.getAddress().toString(), server.getNodeID().toByteArray());
    }
    // Add connection multiplexer sessions hosted locally to the cache (using new nodeID)
    for (String address : localSessionManager.getConnnectionManagerSessions().keySet()) {
        multiplexerSessionsCache.put(address, server.getNodeID().toByteArray());
    }
    // Add incoming server sessions hosted locally to the cache (using new nodeID)
    for (LocalIncomingServerSession session : localSessionManager.getIncomingServerSessions()) {
        StreamID streamID = session.getStreamID();
        incomingServerSessionsCache.put(streamID, server.getNodeID().toByteArray());
        for (String hostname : session.getValidatedDomains()) {
            // Update list of sockets/sessions coming from the same remote hostname
            Lock lock = CacheFactory.getLock(hostname, hostnameSessionsCache);
            try {
                lock.lock();
                List<StreamID> streamIDs = hostnameSessionsCache.get(hostname);
                if (streamIDs == null) {
                    streamIDs = new ArrayList<>();
                }
                streamIDs.add(streamID);
                hostnameSessionsCache.put(hostname, streamIDs);
            } finally {
                lock.unlock();
            }
            // Add to clustered cache
            lock = CacheFactory.getLock(streamID, validatedDomainsCache);
            try {
                lock.lock();
                Set<String> validatedDomains = validatedDomainsCache.get(streamID);
                if (validatedDomains == null) {
                    validatedDomains = new HashSet<>();
                }
                boolean added = validatedDomains.add(hostname);
                if (added) {
                    validatedDomainsCache.put(streamID, validatedDomains);
                }
            } finally {
                lock.unlock();
            }
        }
    }
}
Also used : LocalIncomingServerSession(org.jivesoftware.openfire.session.LocalIncomingServerSession) LocalClientSession(org.jivesoftware.openfire.session.LocalClientSession) ClientSession(org.jivesoftware.openfire.session.ClientSession) LocalComponentSession(org.jivesoftware.openfire.session.LocalComponentSession) OutgoingServerSession(org.jivesoftware.openfire.session.OutgoingServerSession) ComponentSession(org.jivesoftware.openfire.session.ComponentSession) HttpSession(org.jivesoftware.openfire.http.HttpSession) LocalConnectionMultiplexerSession(org.jivesoftware.openfire.session.LocalConnectionMultiplexerSession) LocalOutgoingServerSession(org.jivesoftware.openfire.session.LocalOutgoingServerSession) Session(org.jivesoftware.openfire.session.Session) IncomingServerSession(org.jivesoftware.openfire.session.IncomingServerSession) LocalIncomingServerSession(org.jivesoftware.openfire.session.LocalIncomingServerSession) ConnectionMultiplexerSession(org.jivesoftware.openfire.session.ConnectionMultiplexerSession) Lock(java.util.concurrent.locks.Lock)

Example 2 with LocalIncomingServerSession

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

the class SessionManager method createIncomingServerSession.

/**
     * Creates a session for a remote server. The session should be created only after the
     * remote server has been authenticated either using "server dialback" or SASL.
     *
     * @param conn the connection to the remote server.
     * @param id the stream ID used in the stream element when authenticating the server.
     * @return the newly created {@link IncomingServerSession}.
     * @throws UnauthorizedException if the local server has not been initialized yet.
     */
public LocalIncomingServerSession createIncomingServerSession(Connection conn, StreamID id, String fromDomain) throws UnauthorizedException {
    if (serverName == null) {
        throw new UnauthorizedException("Server not initialized");
    }
    LocalIncomingServerSession session = new LocalIncomingServerSession(serverName, conn, id, fromDomain);
    conn.init(session);
    // Register to receive close notification on this session so we can
    // remove its route from the sessions set
    conn.registerCloseListener(incomingServerListener, session);
    return session;
}
Also used : LocalIncomingServerSession(org.jivesoftware.openfire.session.LocalIncomingServerSession) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException)

Example 3 with LocalIncomingServerSession

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

the class ServerSocketReader method packetReceived.

/**
 * Make sure that the received packet has a TO and FROM values defined and that it was sent
 * from a previously validated domain. If the packet does not matches any of the above
 * conditions then a PacketRejectedException will be thrown.
 *
 * @param packet the received packet.
 * @throws PacketRejectedException if the packet does not include a TO or FROM or if the packet
 *                                 was sent from a domain that was not previously validated.
 */
private void packetReceived(Packet packet) throws PacketRejectedException {
    if (packet.getTo() == null || packet.getFrom() == null) {
        Log.debug("Closing IncomingServerSession due to packet with no TO or FROM: " + packet.toXML());
        // Send a stream error saying that the packet includes no TO or FROM
        StreamError error = new StreamError(StreamError.Condition.improper_addressing);
        connection.deliverRawText(error.toXML());
        // Close the underlying connection
        connection.close();
        open = false;
        throw new PacketRejectedException("Packet with no TO or FROM attributes");
    } else if (!((LocalIncomingServerSession) session).isValidDomain(packet.getFrom().getDomain())) {
        Log.debug("Closing IncomingServerSession due to packet with invalid domain: " + packet.toXML());
        // Send a stream error saying that the packet includes an invalid FROM
        StreamError error = new StreamError(StreamError.Condition.invalid_from);
        connection.deliverRawText(error.toXML());
        // Close the underlying connection
        connection.close();
        open = false;
        throw new PacketRejectedException("Packet with no TO or FROM attributes");
    }
}
Also used : LocalIncomingServerSession(org.jivesoftware.openfire.session.LocalIncomingServerSession) StreamError(org.xmpp.packet.StreamError) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException)

Example 4 with LocalIncomingServerSession

use of org.jivesoftware.openfire.session.LocalIncomingServerSession 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 5 with LocalIncomingServerSession

use of org.jivesoftware.openfire.session.LocalIncomingServerSession 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)

Aggregations

LocalIncomingServerSession (org.jivesoftware.openfire.session.LocalIncomingServerSession)8 IncomingServerSession (org.jivesoftware.openfire.session.IncomingServerSession)3 LocalClientSession (org.jivesoftware.openfire.session.LocalClientSession)3 LocalSession (org.jivesoftware.openfire.session.LocalSession)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)2 ClientSession (org.jivesoftware.openfire.session.ClientSession)2 LocalConnectionMultiplexerSession (org.jivesoftware.openfire.session.LocalConnectionMultiplexerSession)2 StreamError (org.xmpp.packet.StreamError)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Lock (java.util.concurrent.locks.Lock)1 SaslException (javax.security.sasl.SaslException)1 SaslServer (javax.security.sasl.SaslServer)1 XMPPServerInfo (org.jivesoftware.openfire.XMPPServerInfo)1 AuthToken (org.jivesoftware.openfire.auth.AuthToken)1 HttpSession (org.jivesoftware.openfire.http.HttpSession)1 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)1 AnonymousSaslServer (org.jivesoftware.openfire.sasl.AnonymousSaslServer)1 Failure (org.jivesoftware.openfire.sasl.Failure)1 JiveSharedSecretSaslServer (org.jivesoftware.openfire.sasl.JiveSharedSecretSaslServer)1