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,34 +120,52 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener ...@@ -121,34 +120,52 @@ 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. Message error = new Message();
JID address = new JID(message.getFrom().toBareJID()); if (message.getID() != null) {
if (!allowedUsers.contains(address)) { error.setID(message.getID());
Message error = new Message();
if (message.getID() != null) {
error.setID(message.getID());
}
error.setError(PacketError.Condition.not_allowed);
error.setTo(message.getFrom());
error.setSubject("Error sending broadcast message");
error.setBody("Not allowed to send a broadcast message to " +
message.getTo());
try {
componentManager.sendPacket(this, error);
}
catch (Exception e) {
componentManager.getLog().error(e);
}
return;
} }
error.setError(PacketError.Condition.not_allowed);
error.setTo(message.getFrom());
error.setSubject("Error sending broadcast message");
error.setBody("Not allowed to send a broadcast message to " +
message.getTo());
try {
componentManager.sendPacket(this, error);
}
catch (Exception e) {
componentManager.getLog().error(e);
}
return;
} }
try { try {
sessionManager.broadcast(message); sessionManager.broadcast(message);
...@@ -159,42 +176,39 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener ...@@ -159,42 +176,39 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener
} }
// See if the name is a group. // See if the name is a group.
else { else {
try { if (group == null) {
Group group = groupManager.getGroup(toNode); // The address is not recognized so send an error message back.
if (disableGroupPermissions || Message error = new Message();
(groupMembersAllowed && group.isUser(message.getFrom())) || if (message.getID() != null) {
allowedUsers.contains(message.getFrom().toBareJID())) { error.setID(message.getID());
for (JID userJID : group.getMembers()) {
Message newMessage = message.createCopy();
newMessage.setTo(userJID);
try {
componentManager.sendPacket(this, newMessage);
}
catch (Exception e) {
componentManager.getLog().error(e);
}
}
} }
else { error.setTo(message.getFrom());
// Otherwise, the address is recognized so send an error message back. error.setError(PacketError.Condition.not_allowed);
Message error = new Message(); error.setSubject("Error sending broadcast message");
if (message.getID() != null) { error.setBody("Address not valid: " +
error.setID(message.getID()); message.getTo());
} try {
error.setTo(message.getFrom()); componentManager.sendPacket(this, error);
error.setError(PacketError.Condition.not_allowed); }
error.setSubject("Error sending broadcast message"); catch (Exception e) {
error.setBody("Not allowed to send a broadcast message to " + componentManager.getLog().error(e);
message.getTo()); }
}
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()) {
Message newMessage = message.createCopy();
newMessage.setTo(userJID);
try { try {
componentManager.sendPacket(this, error); componentManager.sendPacket(this, newMessage);
} }
catch (Exception e) { catch (Exception e) {
componentManager.getLog().error(e); componentManager.getLog().error(e);
} }
} }
} }
catch (GroupNotFoundException gnfe) { else {
// Otherwise, the address is recognized so send an error message back. // Otherwise, the address is recognized so send an error message back.
Message error = new Message(); Message error = new Message();
if (message.getID() != null) { if (message.getID() != null) {
...@@ -203,7 +217,7 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener ...@@ -203,7 +217,7 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener
error.setTo(message.getFrom()); error.setTo(message.getFrom());
error.setError(PacketError.Condition.not_allowed); error.setError(PacketError.Condition.not_allowed);
error.setSubject("Error sending broadcast message"); error.setSubject("Error sending broadcast message");
error.setBody("Address not valid: " + error.setBody("Not allowed to send a broadcast message to " +
message.getTo()); message.getTo());
try { try {
componentManager.sendPacket(this, error); componentManager.sendPacket(this, error);
...@@ -214,6 +228,60 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener ...@@ -214,6 +228,60 @@ public class BroadcastPlugin implements Plugin, Component, PropertyEventListener
} }
} }
} }
else if (packet instanceof Presence) {
Presence presence = (Presence) packet;
try {
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;
}
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);
}
}
} }
// 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