Search in sources :

Example 11 with PacketRejectedException

use of org.jivesoftware.openfire.interceptor.PacketRejectedException in project Openfire by igniterealtime.

the class Reject method doAction.

@Override
public Packet doAction(Packet packet) throws PacketRejectedException {
    SessionManager sessionManager = SessionManager.getInstance();
    ClientSession clientSession = sessionManager.getSession(packet.getFrom());
    Packet rejectPacket;
    String pfFrom = JiveGlobals.getProperty("pf.From", "packetfilter");
    if (packet instanceof Message) {
        Message in = (Message) packet.createCopy();
        if (clientSession != null && in.getBody() != null) {
            in.setFrom(new JID(pfFrom));
            String rejectMessage = JiveGlobals.getProperty("pf.rejectMessage", "Your message was rejected by the packet filter");
            in.setBody(rejectMessage);
            in.setType(Message.Type.error);
            in.setTo(packet.getFrom());
            String rejectSubject = JiveGlobals.getProperty("pf.rejectSubject", "Rejected");
            in.setSubject(rejectSubject);
            clientSession.process(in);
        }
    } else if (packet instanceof Presence) {
        rejectPacket = new Presence();
        rejectPacket.setTo(packet.getFrom());
        rejectPacket.setError(PacketError.Condition.forbidden);
    } else if (packet instanceof IQ) {
        rejectPacket = new IQ();
        rejectPacket.setTo(packet.getFrom());
        rejectPacket.setError(PacketError.Condition.forbidden);
    }
    if (doLog()) {
        Log.info("Rejecting packet from " + packet.getFrom() + " to " + packet.getTo());
    }
    throw new PacketRejectedException();
}
Also used : Packet(org.xmpp.packet.Packet) Message(org.xmpp.packet.Message) JID(org.xmpp.packet.JID) SessionManager(org.jivesoftware.openfire.SessionManager) ClientSession(org.jivesoftware.openfire.session.ClientSession) IQ(org.xmpp.packet.IQ) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException) Presence(org.xmpp.packet.Presence)

Aggregations

PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)11 JID (org.xmpp.packet.JID)5 ClientSession (org.jivesoftware.openfire.session.ClientSession)4 IQ (org.xmpp.packet.IQ)4 Message (org.xmpp.packet.Message)4 Element (org.dom4j.Element)3 Packet (org.xmpp.packet.Packet)3 Presence (org.xmpp.packet.Presence)3 Node (org.dom4j.Node)2 Roster (org.jivesoftware.openfire.roster.Roster)2 RosterItem (org.jivesoftware.openfire.roster.RosterItem)2 LocalClientSession (org.jivesoftware.openfire.session.LocalClientSession)2 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)2 ArrayList (java.util.ArrayList)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1 Attribute (org.dom4j.Attribute)1 DefaultAttribute (org.dom4j.tree.DefaultAttribute)1