Commit 87dc8786 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

1. Broadcast service can now be added as a roster contact.

2. Fixed checking to figure out if a user belongs to a group.
3. Fixed checking to figure out if a user was allowed to send a message to a group.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3511 b35dd754-fafc-0310-a699-88a17e54d16e
parent 43d72a9e
...@@ -43,6 +43,13 @@ ...@@ -43,6 +43,13 @@
<h1> <h1>
Broadcast Plugin Changelog Broadcast Plugin Changelog
</h1> </h1>
<p><b>1.4.0</b> -- March 02, 2006</p>
<ul>
<li>Broadcast service can now be added as a roster contact.</li>
<li>Fixed checking to figure out if a user belongs to a group.</li>
<li>Fixed checking to figure out if a user was allowed to send a message to a group.</li>
</ul>
<p><b>1.3.1</b> -- December 15, 2005</p> <p><b>1.3.1</b> -- December 15, 2005</p>
<ul> <ul>
<li>Now requires Wildfire 2.4.0</li> <li>Now requires Wildfire 2.4.0</li>
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
<name>Broadcast</name> <name>Broadcast</name>
<description>Broadcasts messages to users.</description> <description>Broadcasts messages to users.</description>
<author>Jive Software</author> <author>Jive Software</author>
<version>1.3.1</version> <version>1.4.0</version>
<date>12/15/2005</date> <date>3/2/2006</date>
<url>http://www.jivesoftware.org</url> <url>http://www.jivesoftware.org</url>
<minServerVersion>2.4.0</minServerVersion> <minServerVersion>2.4.0</minServerVersion>
</plugin> </plugin>
\ No newline at end of file
...@@ -11,24 +11,23 @@ ...@@ -11,24 +11,23 @@
package org.jivesoftware.wildfire.plugin; package org.jivesoftware.wildfire.plugin;
import org.jivesoftware.wildfire.container.Plugin; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.wildfire.container.PluginManager; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.*;
import org.jivesoftware.util.PropertyEventListener;
import org.jivesoftware.util.PropertyEventDispatcher; import org.jivesoftware.util.PropertyEventDispatcher;
import org.jivesoftware.util.PropertyEventListener;
import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.group.GroupManager; import org.jivesoftware.wildfire.container.Plugin;
import org.jivesoftware.wildfire.container.PluginManager;
import org.jivesoftware.wildfire.group.Group; import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.group.GroupNotFoundException; import org.jivesoftware.wildfire.group.GroupNotFoundException;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.JiveGlobals;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError;
import org.xmpp.packet.JID;
import org.xmpp.component.Component; import org.xmpp.component.Component;
import org.xmpp.component.ComponentException;
import org.xmpp.component.ComponentManager; import org.xmpp.component.ComponentManager;
import org.xmpp.component.ComponentManagerFactory; import org.xmpp.component.ComponentManagerFactory;
import org.xmpp.packet.*;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
...@@ -121,17 +120,36 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener ...@@ -121,17 +120,36 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener
} }
public void processPacket(Packet packet) { public void processPacket(Packet packet) {
boolean canProceed = false;
Group group = null;
String toNode = packet.getTo().getNode();
// Check if user is allowed to send packet to this service[+group]
if ("all".equals(toNode)) {
// See if the user is allowed to send the packet.
JID address = new JID(packet.getFrom().toBareJID());
if (allowedUsers.isEmpty() || allowedUsers.contains(address)) {
canProceed = true;
}
}
else {
try {
group = groupManager.getGroup(toNode);
boolean isGroupUser = group.isUser(packet.getFrom()) ||
group.isUser(new JID(packet.getFrom().toBareJID()));
if (disableGroupPermissions || (groupMembersAllowed && isGroupUser) ||
allowedUsers.contains(new JID(packet.getFrom().toBareJID()))) {
canProceed = true;
}
}
catch (GroupNotFoundException e) {
}
}
// Only respond to incoming messages. TODO: handle disco, presence, etc. // Only respond to incoming messages. TODO: handle disco, presence, etc.
if (packet instanceof Message) { if (packet instanceof Message) {
Message message = (Message)packet; Message message = (Message)packet;
String toNode = message.getTo().getNode();
String fromNode = message.getFrom().getNode();
// Check to see if trying to broadcast to all connected users. // Check to see if trying to broadcast to all connected users.
if ("all".equals(toNode)) { if ("all".equals(toNode)) {
if (allowedUsers.size() > 0) { if (!canProceed) {
// See if the user is allowed to send the message.
JID address = new JID(message.getFrom().toBareJID());
if (!allowedUsers.contains(address)) {
Message error = new Message(); Message error = new Message();
if (message.getID() != null) { if (message.getID() != null) {
error.setID(message.getID()); error.setID(message.getID());
...@@ -149,7 +167,6 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener ...@@ -149,7 +167,6 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener
} }
return; return;
} }
}
try { try {
sessionManager.broadcast(message); sessionManager.broadcast(message);
} }
...@@ -159,11 +176,27 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener ...@@ -159,11 +176,27 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener
} }
// See if the name is a group. // See if the name is a group.
else { else {
if (group == null) {
// The address is not recognized so send an error message back.
Message error = new Message();
if (message.getID() != null) {
error.setID(message.getID());
}
error.setTo(message.getFrom());
error.setError(PacketError.Condition.not_allowed);
error.setSubject("Error sending broadcast message");
error.setBody("Address not valid: " +
message.getTo());
try { try {
Group group = groupManager.getGroup(toNode); componentManager.sendPacket(this, error);
if (disableGroupPermissions || }
(groupMembersAllowed && group.isUser(message.getFrom())) || catch (Exception e) {
allowedUsers.contains(message.getFrom().toBareJID())) { componentManager.getLog().error(e);
}
}
else if (canProceed) {
// Broadcast message to group users. Users that are offline will get
// the message when they come back online
for (JID userJID : group.getMembers()) { for (JID userJID : group.getMembers()) {
Message newMessage = message.createCopy(); Message newMessage = message.createCopy();
newMessage.setTo(userJID); newMessage.setTo(userJID);
...@@ -194,27 +227,62 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener ...@@ -194,27 +227,62 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener
} }
} }
} }
catch (GroupNotFoundException gnfe) {
// Otherwise, the address is recognized so send an error message back.
Message error = new Message();
if (message.getID() != null) {
error.setID(message.getID());
} }
error.setTo(message.getFrom()); else if (packet instanceof Presence) {
error.setError(PacketError.Condition.not_allowed); Presence presence = (Presence) packet;
error.setSubject("Error sending broadcast message");
error.setBody("Address not valid: " +
message.getTo());
try { try {
componentManager.sendPacket(this, error); if (!canProceed) {
// Send forbidden error since user is not allowed
Presence reply = new Presence();
reply.setID(presence.getID());
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
reply.setError(PacketError.Condition.forbidden);
componentManager.sendPacket(this, reply);
return;
} }
catch (Exception e) {
if (Presence.Type.subscribe == presence.getType()) {
// Accept all presence requests
// Reply that the subscription request was approved
Presence reply = new Presence();
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
reply.setType(Presence.Type.subscribed);
componentManager.sendPacket(this, reply);
// Send that the service is available
/*reply = new Presence();
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
componentManager.sendPacket(this, reply);*/
}
else if (Presence.Type.unsubscribe == presence.getType()) {
// Send confirmation of unsubscription
Presence reply = new Presence();
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
reply.setType(Presence.Type.unsubscribed);
componentManager.sendPacket(this, reply);
// Send unavailable presence of the service
reply = new Presence();
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
reply.setType(Presence.Type.unavailable);
componentManager.sendPacket(this, reply);
}
else if (Presence.Type.probe == presence.getType()) {
// Send that the service is available
Presence reply = new Presence();
reply.setTo(presence.getFrom());
reply.setFrom(presence.getTo());
componentManager.sendPacket(this, reply);
}
}
catch (ComponentException e) {
componentManager.getLog().error(e); componentManager.getLog().error(e);
} }
} }
} }
}
}
// Other Methods // Other Methods
......
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