Commit 3b485c7f authored by Tom Evans's avatar Tom Evans Committed by tevans

OF-205: Update RosterAccess to use more efficient isGroupVisible() method in...

OF-205: Update RosterAccess to use more efficient isGroupVisible() method in RosterManager (now public)

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13376 b35dd754-fafc-0310-a699-88a17e54d16e
parent a2295729
...@@ -27,7 +27,10 @@ import org.dom4j.Element; ...@@ -27,7 +27,10 @@ import org.dom4j.Element;
import org.dom4j.QName; import org.dom4j.QName;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.group.Group; import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.jivesoftware.openfire.pubsub.Node; import org.jivesoftware.openfire.pubsub.Node;
import org.jivesoftware.openfire.roster.RosterManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
...@@ -46,27 +49,30 @@ public class RosterAccess extends AccessModel { ...@@ -46,27 +49,30 @@ public class RosterAccess extends AccessModel {
} }
@Override @Override
public boolean canSubscribe(Node node, JID subscriber, JID subJID) { public boolean canSubscribe(Node node, JID owner, JID subscriber) {
// Let node owners and sysadmins always subscribe to the node // Let node owners and sysadmins always subscribe to the node
if (node.isAdmin(subscriber)) { if (node.isAdmin(owner)) {
return true; return true;
} }
for (JID nodeOwner : node.getOwners()) { for (JID nodeOwner : node.getOwners()) {
if (nodeOwner.equals(subscriber)) { if (nodeOwner.equals(owner)) {
return true; return true;
} }
} }
// Check that the subscriber is a local user // Check that the subscriber is a local user
XMPPServer server = XMPPServer.getInstance(); XMPPServer server = XMPPServer.getInstance();
if (server.isLocal(subscriber)) { if (server.isLocal(owner)) {
GroupManager gMgr = GroupManager.getInstance();
Collection<String> nodeGroups = node.getRosterGroupsAllowed(); Collection<String> nodeGroups = node.getRosterGroupsAllowed();
for (Group group : server.getRosterManager().getSharedGroups(subscriber.getNode())) { for (String groupName : nodeGroups) {
if (nodeGroups.contains(group.getName())) { try {
if (Log.isDebugEnabled()) { Group group = gMgr.getGroup(groupName);
Log.debug("Subscriber (" + subscriber + // access allowed if the node group is visible to the subscriber
") is a member of node group " + group.getName()); if (server.getRosterManager().isGroupVisible(group, owner)) {
} return true;
return true; }
} catch (GroupNotFoundException gnfe){
// ignore
} }
} }
} }
......
...@@ -783,7 +783,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us ...@@ -783,7 +783,7 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
* @param user the JID of the user to check if he may see the group. * @param user the JID of the user to check if he may see the group.
* @return true if a given group is visible to a given user. * @return true if a given group is visible to a given user.
*/ */
boolean isGroupVisible(Group group, JID user) { public boolean isGroupVisible(Group group, JID user) {
String showInRoster = group.getProperties().get("sharedRoster.showInRoster"); String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
if ("everybody".equals(showInRoster)) { if ("everybody".equals(showInRoster)) {
return true; return true;
......
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