org.jivesoftware.openfire.interceptor.PacketRejectedException Java Examples

The following examples show how to use org.jivesoftware.openfire.interceptor.PacketRejectedException. 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: GcmPlugin.java    From Openfire-GCM with Apache License 2.0 6 votes vote down vote up
public void interceptPacket(Packet packet, Session session,
		boolean incoming, boolean processed) throws PacketRejectedException {

	if (processed) {
		return;
	}
	if (!incoming) {
		return;
	}

	if (packet instanceof Message) {
		Message msg = (Message) packet;
		process(msg);
	}

}
 
Example #2
Source File: DefaultFileTransferManager.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming,
                            boolean processed)
        throws PacketRejectedException
{
    // We only want packets received by the server
    if (!processed && incoming && packet instanceof IQ) {
        IQ iq = (IQ) packet;
        Element childElement = iq.getChildElement();
        if(childElement == null) {
            return;
        }
        String namespace = childElement.getNamespaceURI();
        String profile = childElement.attributeValue("profile");
        // Check that the SI is about file transfer and try creating a file transfer
        if (NAMESPACE_SI.equals(namespace) && NAMESPACE_SI_FILETRANSFER.equals(profile)) {
            // If this is a set, check the feature offer
            if (iq.getType().equals(IQ.Type.set)) {
                JID from = iq.getFrom();
                JID to = iq.getTo();

                FileTransfer transfer = createFileTransfer(from, to, childElement);

                try {
                    if (transfer == null || !acceptIncomingFileTransferRequest(transfer)) {
                        throw new PacketRejectedException();
                    }
                }
                catch (FileTransferRejectedException e) {
                    throw new PacketRejectedException(e);
                }
            }
        }
    }
}
 
Example #3
Source File: S2STestService.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Keeps a log of the XMPP traffic, releasing the wait lock on response received.
 */
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
        throws PacketRejectedException {

    if (ping.getTo() == null || packet.getFrom() == null || packet.getTo() == null) {
        return;
    }

    if (!processed
            && (ping.getTo().getDomain().equals(packet.getFrom().getDomain()) || ping.getTo().getDomain().equals(packet.getTo().getDomain()))) {

        // Log all traffic to and from the domain.
        xml.append(packet.toXML());
        xml.append('\n');

        // If we've received our IQ response, stop the test.
        if ( packet instanceof IQ )
        {
            final IQ iq = (IQ) packet;
            if ( iq.isResponse() && ping.getID().equals( iq.getID() ) && ping.getTo().equals( iq.getFrom() ) ) {
                Log.info("Successful server to server response received.");
                waitUntil.release();
            }
        }
    }
}
 
Example #4
Source File: BookmarkInterceptor.java    From openfire-ofmeet-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void interceptPacket( Packet packet,
                             Session session,
                             boolean incoming,
                             boolean processed ) throws PacketRejectedException
{
    // Interested only in pre-processed, outgoing stanzas.
    if ( processed || incoming )
    {
        return;
    }

    // OF-1591 - I can't quite explain these. Maybe the session has been closed before the outgoing server promise timed out?
    if ( session == null )
    {
        return;
    }

    // Only interested in stanzas that are either:
    // - from the server itself.
    // - sent 'on behalf of' the user that is the recipient of the stanza ('from' matches session address).
    if ( packet.getFrom() != null
        && !packet.getFrom().asBareJID().equals( session.getAddress().asBareJID() )
        && !packet.getFrom().toBareJID().equals( XMPPServer.getInstance().getServerInfo().getXMPPDomain() ) )
    {
        return;
    }

    final Element storageElement = findStorageElement( packet );

    if ( storageElement == null )
    {
        return;
    }

    final URL url = ofMeetPlugin.getWebappURL();
    if ( url == null )
    {
        return;
    }

    addBookmark( storageElement, url );
}
 
Example #5
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);
            }
        }
    }
}