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;
import org.dom4j.QName;
import org.jivesoftware.openfire.XMPPServer;
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.roster.RosterManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID;
......@@ -46,28 +49,31 @@ public class RosterAccess extends AccessModel {
}
@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
if (node.isAdmin(subscriber)) {
if (node.isAdmin(owner)) {
return true;
}
for (JID nodeOwner : node.getOwners()) {
if (nodeOwner.equals(subscriber)) {
if (nodeOwner.equals(owner)) {
return true;
}
}
// Check that the subscriber is a local user
XMPPServer server = XMPPServer.getInstance();
if (server.isLocal(subscriber)) {
if (server.isLocal(owner)) {
GroupManager gMgr = GroupManager.getInstance();
Collection<String> nodeGroups = node.getRosterGroupsAllowed();
for (Group group : server.getRosterManager().getSharedGroups(subscriber.getNode())) {
if (nodeGroups.contains(group.getName())) {
if (Log.isDebugEnabled()) {
Log.debug("Subscriber (" + subscriber +
") is a member of node group " + group.getName());
}
for (String groupName : nodeGroups) {
try {
Group group = gMgr.getGroup(groupName);
// access allowed if the node group is visible to the subscriber
if (server.getRosterManager().isGroupVisible(group, owner)) {
return true;
}
} catch (GroupNotFoundException gnfe){
// ignore
}
}
}
else {
......
......@@ -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.
* @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");
if ("everybody".equals(showInRoster)) {
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