Java Code Examples for org.jivesoftware.openfire.session.Session#close()

The following examples show how to use org.jivesoftware.openfire.session.Session#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExternalComponentManager.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Blocks an external component from connecting to the local server. If the component was
 * connected when the permission was revoked then the connection of the entity will be closed.
 *
 * @param subdomain the subdomain of the external component that is not allowed to connect.
 * @throws ModificationNotAllowedException if the operation was denied.
 */
public static void blockAccess(String subdomain) throws ModificationNotAllowedException {
    // Alert listeners about this event
    for (ExternalComponentManagerListener listener : listeners) {
        try {
            listener.componentBlocked(subdomain);
        } catch (Exception e) {
            Log.warn("An exception occurred while dispatching a 'componentBlocked' event!", e);
        }
    }
    // Remove any previous configuration for this external component
    deleteConfigurationFromDB(getConfiguration(subdomain, false));
    // Update the database with the new revoked permission
    ExternalComponentConfiguration config = new ExternalComponentConfiguration(subdomain, false, Permission.blocked, null);
    addConfiguration(config);
    // Check if the component was connected and proceed to close the connection
    String domain = subdomain + "." + XMPPServer.getInstance().getServerInfo().getXMPPDomain();
    Session session = SessionManager.getInstance().getComponentSession(domain);
    if (session != null) {
        Log.debug( "Closing session for external component '{}' as the domain is being blocked. Affected session: {}", domain, session );
        session.close();
    }
}
 
Example 2
Source File: ConnectionMultiplexerManager.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Closes an existing client session that was established through a connection manager.
 *
 * @param connectionManagerDomain the connection manager that is handling the connection
 *        of the session.
 * @param streamID the stream ID created by the connection manager for the session.
 */
public void closeClientSession(String connectionManagerDomain, StreamID streamID) {
    Map<StreamID, LocalClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
    if (sessions != null) {
        Session session = sessions.remove(streamID);
        if (session != null) {
            Log.debug( "Closing session: {}", session );
            session.close();
        }
    }
}
 
Example 3
Source File: Channel.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Enqueus a message to be handled by this channel. After the ChannelHandler is done
 * processing the message, it will be sent to the next channel. Messages with a higher
 * priority will be handled first.
 *
 * @param packet an XMPP packet to add to the channel for processing.
 */
public void add( final T packet )
{
    Runnable r = new Runnable()
    {
        @Override
        public void run()
        {
            try
            {
                channelHandler.process( packet );
            }
            catch ( Exception e )
            {
                Log.error( LocaleUtils.getLocalizedString( "admin.error" ), e );

                try
                {
                    Session session = SessionManager.getInstance().getSession( packet.getFrom() );
                    if ( session != null )
                    {
                        Log.debug( "Closing session of '{}': {}", packet.getFrom(), session );
                        session.close();
                    }
                }
                catch ( Exception e1 )
                {
                    Log.error( "Unexpected exception while trying to close session of '{}'.", packet.getFrom(), e1 );
                }
            }
        }
    };
    executor.execute(r);
}
 
Example 4
Source File: S2STestService.java    From Openfire with Apache License 2.0 4 votes vote down vote up
/**
 * Run a test against the domain.
 * @return K-V pairs of debug information.
 * @throws Exception On error.
 */
public Map<String, String> run() throws Exception {
    waitUntil = new Semaphore(0);
    Map<String, String> results = new HashMap<>();
    final DomainPair pair = new DomainPair(XMPPServer.getInstance().getServerInfo().getXMPPDomain(), domain);

    // Tear down existing routes.
    final SessionManager sessionManager = SessionManager.getInstance();
    for (final Session incomingServerSession : sessionManager.getIncomingServerSessions( domain ) )
    {
        incomingServerSession.close();
    }

    final Session outgoingServerSession = sessionManager.getOutgoingServerSession( pair );
    if ( outgoingServerSession != null )
    {
        outgoingServerSession.close();
    }

    final IQ pingRequest = new IQ( Type.get );
    pingRequest.setChildElement( "ping", IQPingHandler.NAMESPACE );
    pingRequest.setFrom( pair.getLocal() );
    pingRequest.setTo( domain );

    // Intercept logging.
    final Writer logs = new StringWriter();
    final String appenderName = addAppender( logs );

    // Intercept packets.
    final PacketInterceptor interceptor = new S2SInterceptor( pingRequest );
    InterceptorManager.getInstance().addInterceptor(interceptor);

    // Send ping.
    try
    {
        Log.info( "Sending server to server ping request to " + domain );
        XMPPServer.getInstance().getIQRouter().route( pingRequest );

        // Wait for success or exceed socket timeout.
        waitUntil.tryAcquire( RemoteServerManager.getSocketTimeout(), TimeUnit.MILLISECONDS );

        // Check on the connection status.
        logSessionStatus();

        // Prepare response.
        results.put( "certs", getCertificates() );
        results.put( "stanzas", interceptor.toString() );
        results.put( "logs", logs.toString() );

        return results;
    }
    finally
    {
        // Cleanup
        InterceptorManager.getInstance().removeInterceptor( interceptor );
        removeAppender( appenderName );
    }
}