Search in sources :

Example 6 with SessionManager

use of org.jivesoftware.openfire.SessionManager 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

SessionManager (org.jivesoftware.openfire.SessionManager)6 ClientSession (org.jivesoftware.openfire.session.ClientSession)2 IOException (java.io.IOException)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 DocumentException (org.dom4j.DocumentException)1 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)1 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)1 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)1 LocalSession (org.jivesoftware.openfire.session.LocalSession)1 Session (org.jivesoftware.openfire.session.Session)1 Logger (org.slf4j.Logger)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1 DataForm (org.xmpp.forms.DataForm)1 FormField (org.xmpp.forms.FormField)1 IQ (org.xmpp.packet.IQ)1 JID (org.xmpp.packet.JID)1 Message (org.xmpp.packet.Message)1 Packet (org.xmpp.packet.Packet)1 Presence (org.xmpp.packet.Presence)1