Search in sources :

Example 36 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class ContentFilterPlugin method sendViolationNotificationIM.

private void sendViolationNotificationIM(String subject, String body) {
    Message message = createServerMessage(subject, body);
    // TODO consider spining off a separate thread here,
    // in high volume situations, it will result in
    // in faster response and notification is not required
    // to be real time.
    messageRouter.route(message);
}
Also used : Message(org.xmpp.packet.Message)

Example 37 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class ContentFilterPlugin method sendViolationNotification.

private void sendViolationNotification(Packet originalPacket) {
    String subject = "Content filter notification! (" + originalPacket.getFrom().getNode() + ")";
    String body;
    if (originalPacket instanceof Message) {
        Message originalMsg = (Message) originalPacket;
        body = "Disallowed content detected in message from:" + originalMsg.getFrom() + " to:" + originalMsg.getTo() + ", message was " + (allowOnMatch ? "allowed" + (contentFilter.isMaskingContent() ? " and masked." : " but not masked.") : "rejected.") + (violationIncludeOriginalPacketEnabled ? "\nOriginal subject:" + (originalMsg.getSubject() != null ? originalMsg.getSubject() : "") + "\nOriginal content:" + (originalMsg.getBody() != null ? originalMsg.getBody() : "") : "");
    } else {
        // presence
        Presence originalPresence = (Presence) originalPacket;
        body = "Disallowed status detected in presence from:" + originalPresence.getFrom() + ", status was " + (allowOnMatch ? "allowed" + (contentFilter.isMaskingContent() ? " and masked." : " but not masked.") : "rejected.") + (violationIncludeOriginalPacketEnabled ? "\nOriginal status:" + originalPresence.getStatus() : "");
    }
    if (violationNotificationByIMEnabled) {
        if (Log.isDebugEnabled()) {
            Log.debug("Content filter: sending IM notification");
        }
        sendViolationNotificationIM(subject, body);
    }
    if (violationNotificationByEmailEnabled) {
        if (Log.isDebugEnabled()) {
            Log.debug("Content filter: sending email notification");
        }
        sendViolationNotificationEmail(subject, body);
    }
}
Also used : Message(org.xmpp.packet.Message) Presence(org.xmpp.packet.Presence)

Example 38 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class ContentFilterTest method testFilterMessageBodyWithMask.

@Test
public void testFilterMessageBodyWithMask() {
    // filter on the word "fox" and "dog"
    filter.setPatterns("fox,dog");
    filter.setMask("**");
    // test message
    Message message = new Message();
    message.setBody("the quick brown fox jumped over the lazy dog");
    boolean matched = filter.filter(message);
    // matches should not be found
    assertTrue(matched);
    // content has changed
    assertEquals("the quick brown ** jumped over the lazy **", message.getBody());
    assertNull(message.getSubject());
}
Also used : Message(org.xmpp.packet.Message) Test(org.junit.Test)

Example 39 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class ContentFilterTest method testFilterWithEmptyMessage.

@Test
public void testFilterWithEmptyMessage() {
    Message message = new Message();
    boolean matched = filter.filter(message);
    // no matches should be found
    assertFalse(matched);
    // message should not have changed
    assertEquals(new Message().toXML(), message.toXML());
}
Also used : Message(org.xmpp.packet.Message) Test(org.junit.Test)

Example 40 with Message

use of org.xmpp.packet.Message in project Openfire by igniterealtime.

the class ContentFilterTest method testFilterChatMessage.

@Test
public void testFilterChatMessage() throws DocumentException, IOException, XmlPullParserException {
    String chatXML = "<message to=\"doe@127.0.0.1/Adium\" type=\"chat\" id=\"iChat_E8B5ED64\" from=\"bob@127.0.0.1/frodo\">" + "<body>fox</body>" + "<html xmlns=\"http://jabber.org/protocol/xhtml-im\">" + "<body xmlns=\"http://www.w3.org/1999/xhtml\" style=\"background-color:#E8A630;color:#000000\">fox</body>" + "</html>" + "<x xmlns=\"jabber:x:event\">" + "<composing/>" + "</x>" + "</message>";
    XPPReader packetReader = new XPPReader();
    Document doc = packetReader.read(new StringReader(chatXML));
    Message m = new Message(doc.getRootElement());
    // filter on the word "fox" and "dog"
    filter.setPatterns("fox,dog,message");
    filter.setMask("**");
    String expectedXML = chatXML.replaceAll("fox", filter.getMask());
    // do filter
    boolean matched = filter.filter(m);
    assertTrue(matched);
    assertEquals(expectedXML, expectedXML, m.toXML());
}
Also used : Message(org.xmpp.packet.Message) StringReader(java.io.StringReader) XPPReader(org.dom4j.io.XPPReader) Document(org.dom4j.Document) Test(org.junit.Test)

Aggregations

Message (org.xmpp.packet.Message)111 Element (org.dom4j.Element)35 JID (org.xmpp.packet.JID)25 Test (org.junit.Test)23 Presence (org.xmpp.packet.Presence)18 IQ (org.xmpp.packet.IQ)16 ArrayList (java.util.ArrayList)10 Packet (org.xmpp.packet.Packet)10 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)9 Date (java.util.Date)6 ClientSession (org.jivesoftware.openfire.session.ClientSession)6 NotFoundException (org.jivesoftware.util.NotFoundException)6 StringReader (java.io.StringReader)4 List (java.util.List)4 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)4 User (org.jivesoftware.openfire.user.User)4 IOException (java.io.IOException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 SAXReader (org.dom4j.io.SAXReader)3 DefaultElement (org.dom4j.tree.DefaultElement)3