org.jivesoftware.openfire.interceptor.InterceptorManager Java Examples

The following examples show how to use org.jivesoftware.openfire.interceptor.InterceptorManager. 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: AuditManagerImpl.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private void processEnabled(boolean enabled) {
    // Add or remove the auditor interceptor depending on the enabled status
    if (enabled) {
        InterceptorManager.getInstance().addInterceptor(interceptor);
    } else {
        InterceptorManager.getInstance().removeInterceptor(interceptor);
    }
}
 
Example #2
Source File: GcmPlugin.java    From Openfire-GCM with Apache License 2.0 4 votes vote down vote up
public GcmPlugin() {
	interceptorManager = InterceptorManager.getInstance();
}
 
Example #3
Source File: PresenceRouter.java    From Openfire with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
            }
        }
    }
}
 
Example #4
Source File: DefaultFileTransferManager.java    From Openfire with Apache License 2.0 4 votes vote down vote up
/**
 * Default constructor creates the cache.
 */
public DefaultFileTransferManager() {
    super("File Transfer Manager");
    fileTransferMap = CacheFactory.createCache(CACHE_NAME);
    InterceptorManager.getInstance().addInterceptor(new MetaFileTransferInterceptor());
}
 
Example #5
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 );
    }
}