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);
}
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);
}
}
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());
}
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());
}
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());
}
Aggregations