Commit 4fe03d7f authored by Ryan Graham's avatar Ryan Graham Committed by ryang

initial check-in

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4544 b35dd754-fafc-0310-a699-88a17e54d16e
parent 982afadb
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Subscription Plugin Changelog</title>
<style type="text/css">
BODY {
font-size : 100%;
}
BODY, TD, TH {
font-family : tahoma, verdana, arial, helvetica, sans-serif;
font-size : 0.8em;
}
H2 {
font-size : 10pt;
font-weight : bold;
padding-left : 1em;
}
A:hover {
text-decoration : none;
}
H1 {
font-family : tahoma, arial, helvetica, sans-serif;
font-size : 1.4em;
font-weight: bold;
border-bottom : 1px #ccc solid;
padding-bottom : 2px;
}
TT {
font-family : courier new;
font-weight : bold;
color : #060;
}
PRE {
font-family : courier new;
font-size : 100%;
}
</style>
</head>
<body>
<h1>
Subscription Plugin Changelog
</h1>
<p><b>1.0.0</b> -- July 17, 2006</p>
<ul>
<li>Initial release.</li>
</ul>
<p><b>1.0.0 - Beta 4</b> -- June 9, 2006</p>
<ul>
<li>Added the ability to specify a "white list" of users who can still manage their own subscriptions.</li>
</ul>
<p><b>1.0.0 - Beta 3</b> -- April, 18 2006</p>
<ul>
<li>Added the ability to automatically reject all subscription requests.</li>
</ul>
<p><b>1.0.0 - Beta 2</b> -- February, 17 2006</p>
<ul>
<li>Added the ability to set subscription service properties via the Admin Console.</li>
<li>Fixed potential NullPointerException in packet interceptor.
</ul>
<p><b>1.0.0 - Beta 1</b> -- February, 16 2006</p>
<ul>
<li>Initial beta release.</li>
</ul>
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<class>org.jivesoftware.wildfire.plugin.SubscriptionPlugin</class>
<name>Subscription</name>
<description>Automatically accepts or rejects subsription requests</description>
<author>Ryan Graham</author>
<version>1.0.0</version>
<date>07/17/2006</date>
<url>http://www.jivesoftware.org</url>
<minServerVersion>2.6.0</minServerVersion>
<adminconsole>
<tab id="tab-server">
<sidebar id="sidebar-server-settings">
<item id="subscription-plugin-properties"
name="Subscription Properties"
url="subscription-plugin-properties.jsp"
description="Edit subscription plugin properties" />
</sidebar>
</tab>
</adminconsole>
</plugin>
\ No newline at end of file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Subscription Plugin Readme</title>
<style type="text/css">
BODY {
font-size : 100%;
}
BODY, TD, TH {
font-family : tahoma, verdana, arial, helvetica, sans-serif;
font-size : 0.8em;
}
H2 {
font-size : 10pt;
font-weight : bold;
}
A:hover {
text-decoration : none;
}
H1 {
font-family : tahoma, arial, helvetica, sans-serif;
font-size : 1.4em;
font-weight: bold;
border-bottom : 1px #ccc solid;
padding-bottom : 2px;
}
TT {
font-family : courier new;
font-weight : bold;
color : #060;
}
PRE {
font-family : courier new;
font-size : 100%;
}
</style>
</head>
<body>
<h1>
Subscription Plugin Readme
</h1>
<h2>Overview</h2>
<p>
This plugin can be configuured to automatically accept or reject subscription requests. When set to accept
subscription requests users will be able to add someone to their roster (aka "Buddy List" or "Contacts")
without having to wait for a manual subscription acceptance from the requested user. Conversely, when the
plugin is set to reject subscription requests users will not be able to add people to their roster.
</p>
<h2>Installation</h2>
<p>
Copy the file, subscription.jar into the plugins directory of your Wildfire installation. The plugin will
then be automatically deployed. To upgrade to a new version: 1) go to the plugin screen of the Admin
Console, 2) click on the delete icon on the same row as the currently installed subscription plugin, 3)
copy the new subscription.jar into the plugins directory of your Wildfire installation.
</p>
<h2>Configuration</h2>
<p>
The subscription plugin is configured via Subscription Properties sidebar item which can found under the
Sever tab in Wildfire Admin Console. The subscription plugin can be configured in the following ways:
<ul>
<p>
<li>Disabled (Default setting) - Subscription requests will not be intercepted.</li>
</p>
<p>
<li>Accept - Subscription requests will be intercepted and accepted.</li>
<ul>
<li>Local - Only subscription requests sent by users <u>who have</u> an account on the Wildfire server on which
the plugin is installed, will be intercepted and accepted.</li>
<li>All - All subscription requests, regardless of which server the user account resides on, will be
intercepted and accepted. Selecting this level can make Wildfire vulnerable to spIM*.</li>
</ul>
</p>
<p>
<li>Reject - Subscription requests will be intercepted and rejected. NOTE: At the time of this writing the latest
release of Spark (v1.1.4) has an <a href="http://www.jivesoftware.org/issues/browse/SPARK-300">issue</a> where
subscription rejection packets are not processed properly so this feature will not work correctly with Spark. To have
the plugin attempt to work around this issue create a "plugin.subscription.sparkCheck" system property and set its
value to "true".</li>
<ul>
<li>Local - Only subscription requests sent by users <u>who do not have</u> an account on the Wildfire server on which
the plugin is installed, will be intercepted and rejected.</li>
<li>All - All subscription requests, regardless of which server the user account resides on, will be
intercepted and rejected.</li>
</ul>
</p>
</ul>
It is also possible to create a "white list" of users. The users in the list still maintain full control over accepting
and rejecting subscription requests.
</p>
<h2>Using the Plugin</h2>
<p>
Once the plugin has been installed and configured there is no additional steps are required to use the plugin.
</p>
<br>
<p>
* spIM is unsolicited messages sent via an instant messaging system; similiar in nature to email SPAM.
</p>
</body>
</html>
/**
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.plugin;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.wildfire.PresenceRouter;
import org.jivesoftware.wildfire.Session;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.container.Plugin;
import org.jivesoftware.wildfire.container.PluginManager;
import org.jivesoftware.wildfire.interceptor.InterceptorManager;
import org.jivesoftware.wildfire.interceptor.PacketInterceptor;
import org.jivesoftware.wildfire.interceptor.PacketRejectedException;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
import org.xmpp.packet.Presence.Type;
/**
* This plugin can be configuured to automatically accept or reject subscription
* requests. When set to accept subscription requests users will be able to add
* someone to their roster without having to wait for a manual subscription
* acceptance from the other person. Conversely, when the plugin is set to
* reject subscription requests users will not be able to add people to their
* roster.
*
* @author <a href="mailto:ryan@version2software.com">Ryan Graham</a>
*/
public class SubscriptionPlugin implements Plugin {
public static final String DISABLED = "disabled";
public static final String ACCEPT = "accept";
public static final String REJECT = "reject";
public static final String LOCAL = "local";
public static final String ALL = "all";
private static final String SUBSCRIPTION_TYPE = "plugin.subscription.type";
private static final String SUBSCRIPTION_LEVEL = "plugin.subscription.level";
private static final String WHITE_LIST = "plugin.subscription.whiteList";
private List<String> whiteList = new ArrayList<String>();
private SuscriptionPacketInterceptor interceptor = new SuscriptionPacketInterceptor();
private PresenceRouter router;
private String serverName;
public SubscriptionPlugin() {
XMPPServer server = XMPPServer.getInstance();
router = server.getPresenceRouter();
serverName = server.getServerInfo().getName();
String list = JiveGlobals.getProperty(WHITE_LIST);
if (list != null) {
whiteList.addAll(csvToList(list));
}
}
public void initializePlugin(PluginManager manager, File pluginDirectory) {
InterceptorManager.getInstance().addInterceptor(interceptor);
}
public void destroyPlugin() {
InterceptorManager.getInstance().removeInterceptor(interceptor);
interceptor = null;
router = null;
serverName = null;
whiteList = null;
}
public void setSubscriptionType(String type) {
JiveGlobals.setProperty(SUBSCRIPTION_TYPE, type);
}
public String getSubscriptionType() {
return JiveGlobals.getProperty(SUBSCRIPTION_TYPE, DISABLED);
}
public void setSubscriptionLevel(String level) {
JiveGlobals.setProperty(SUBSCRIPTION_LEVEL, level);
}
public String getSubscriptionLevel() {
return JiveGlobals.getProperty(SUBSCRIPTION_LEVEL, LOCAL);
}
public Collection<String> getWhiteListUsers() {
Collections.sort(whiteList);
return whiteList;
}
public void addWhiteListUser(String user) {
if (!whiteList.contains(user.trim().toLowerCase())) {
whiteList.add(user.trim().toLowerCase());
JiveGlobals.setProperty(WHITE_LIST, listToCSV(whiteList));
}
}
public void removeWhiteListUser(String user) {
whiteList.remove(user.trim().toLowerCase());
if (whiteList.size() == 0) {
JiveGlobals.deleteProperty(WHITE_LIST);
}
else {
JiveGlobals.setProperty(WHITE_LIST, listToCSV(whiteList));
}
}
private String listToCSV(List<String> list) {
StringBuilder sb = new StringBuilder();
Iterator<String> iter = list.iterator();
while (iter.hasNext()) {
String s = iter.next();
sb.append(s);
if (iter.hasNext()) {
sb.append(",");
}
}
return sb.toString();
}
private List<String> csvToList(String csv) {
List<String> list = new ArrayList<String>();
for (String s : csv.split(",")) {
list.add(s);
}
return list;
}
private class SuscriptionPacketInterceptor implements PacketInterceptor {
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
String type = getSubscriptionType();
if (type.equals(DISABLED)) {
return;
}
if ((packet instanceof Presence) && !processed) {
Presence presencePacket = (Presence) packet;
Type presenceType = presencePacket.getType();
if (presenceType != null && presenceType.equals(Presence.Type.subscribe)) {
JID toJID = presencePacket.getTo();
JID fromJID = presencePacket.getFrom();
String toNode = toJID.getNode();
if (whiteList.contains(toNode)) {
return;
}
if (type.equals(ACCEPT)) {
acceptSubscription(toJID, fromJID);
}
if (type.equals(REJECT)) {
rejectSubscription(toJID, fromJID);
}
}
}
}
private void acceptSubscription(JID toJID, JID fromJID) throws PacketRejectedException {
if (getSubscriptionLevel().equals(LOCAL)) {
String toDomain = toJID.getDomain();
String fromDomain = fromJID.getDomain();
if (!toDomain.equals(serverName) || !fromDomain.equals(serverName)) {
return;
}
}
Presence presence = new Presence();
presence.setType(Presence.Type.subscribed);
presence.setTo(toJID);
presence.setFrom(fromJID);
router.route(presence);
presence.setTo(fromJID);
presence.setFrom(toJID);
router.route(presence);
throw new PacketRejectedException();
}
private void rejectSubscription(JID toJID, JID fromJID) throws PacketRejectedException {
if (getSubscriptionLevel().equals(LOCAL)) {
String toDomain = toJID.getDomain();
String fromDomain = fromJID.getDomain();
if (toDomain.equals(serverName) && fromDomain.equals(serverName)) {
return;
}
}
Presence presence = new Presence();
presence.setType(Presence.Type.unsubscribe);
// This is to get around an issue in Spark
// (http://www.jivesoftware.org/issues/browse/SPARK-300).
// Unfortunately, this is a bit of a hack and can easily be defeated
// if a user changes their resource when using Spark.
if (JiveGlobals.getBooleanProperty("plugin.subscription.sparkCheck", false)) {
String resource = fromJID.getResource();
if (resource != null && resource.equalsIgnoreCase("Spark")) {
presence.setType(Presence.Type.unsubscribed);
}
}
presence.setTo(fromJID);
presence.setFrom(toJID);
router.route(presence);
throw new PacketRejectedException();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment