Commit dc47dd47 authored by Tom Evans's avatar Tom Evans Committed by tevans

OF-587: Allow multiple node owners for Roster/Presence access models

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13346 b35dd754-fafc-0310-a699-88a17e54d16e
parent a38803fd
...@@ -51,33 +51,32 @@ public class PresenceAccess extends AccessModel { ...@@ -51,33 +51,32 @@ public class PresenceAccess extends AccessModel {
if (node.isAdmin(owner)) { if (node.isAdmin(owner)) {
return true; return true;
} }
// Get the only owner of the node
JID nodeOwner = node.getOwners().iterator().next();
// Give access to the owner of the roster :)
if (nodeOwner.toBareJID().equals(owner.toBareJID())) {
return true;
}
// Get the roster of the node owner
XMPPServer server = XMPPServer.getInstance(); XMPPServer server = XMPPServer.getInstance();
// Check that the node owner is a local user for (JID nodeOwner : node.getOwners()) {
if (server.isLocal(nodeOwner)) { // Give access to the owner of the roster :)
try { if (nodeOwner.equals(owner.toBareJID())) {
Roster roster = server.getRosterManager().getRoster(nodeOwner.getNode()); return true;
RosterItem item = roster.getRosterItem(owner); }
// Check that the subscriber is subscribe to the node owner's presence // Check that the node owner is a local user
return item != null && (RosterItem.SUB_BOTH == item.getSubStatus() || if (server.isLocal(nodeOwner)) {
RosterItem.SUB_FROM == item.getSubStatus()); try {
} Roster roster = server.getRosterManager().getRoster(nodeOwner.getNode());
catch (UserNotFoundException e) { RosterItem item = roster.getRosterItem(owner);
return false; // Check that the subscriber is subscribe to the node owner's presence
} return item != null && (RosterItem.SUB_BOTH == item.getSubStatus() ||
} RosterItem.SUB_FROM == item.getSubStatus());
else { }
// Owner of the node is a remote user. This should never happen. catch (UserNotFoundException e) {
Log.warn("Node with access model Presence has a remote user as owner: " + // Do nothing
node.getNodeID()); }
return false; }
else {
// Owner of the node is a remote user. This should never happen.
Log.warn("Node with access model Presence has a remote user as owner: " +
node.getNodeID());
}
} }
return false;
} }
@Override @Override
......
...@@ -55,44 +55,43 @@ public class RosterAccess extends AccessModel { ...@@ -55,44 +55,43 @@ public class RosterAccess extends AccessModel {
if (node.isAdmin(owner)) { if (node.isAdmin(owner)) {
return true; return true;
} }
// Get the only owner of the node
JID nodeOwner = node.getOwners().iterator().next();
// Give access to the owner of the roster :)
if (nodeOwner.toBareJID().equals(owner.toBareJID())) {
return true;
}
// Get the roster of the node owner
XMPPServer server = XMPPServer.getInstance(); XMPPServer server = XMPPServer.getInstance();
// Check that the node owner is a local user for (JID nodeOwner : node.getOwners()) {
if (server.isLocal(nodeOwner)) { // Give access to the owner of the roster :)
try { if (nodeOwner.equals(owner.toBareJID())) {
Roster roster = server.getRosterManager().getRoster(nodeOwner.getNode()); return true;
RosterItem item = roster.getRosterItem(owner);
// Check that the subscriber is subscribe to the node owner's presence
boolean isSubscribed = item != null && (
RosterItem.SUB_BOTH == item.getSubStatus() ||
RosterItem.SUB_FROM == item.getSubStatus());
if (isSubscribed) {
// Get list of groups where the contact belongs
List<String> contactGroups = new ArrayList<String>(item.getGroups());
for (Group group : item.getSharedGroups()) {
contactGroups.add(group.getName());
}
for (Group group : item.getInvisibleSharedGroups()) {
contactGroups.add(group.getName());
}
// Check if subscriber is present in the allowed groups of the node
return contactGroups.removeAll(node.getRosterGroupsAllowed());
}
} }
catch (UserNotFoundException e) { // Check that the node owner is a local user
// Do nothing if (server.isLocal(nodeOwner)) {
} try {
} Roster roster = server.getRosterManager().getRoster(nodeOwner.getNode());
else { RosterItem item = roster.getRosterItem(owner);
// Owner of the node is a remote user. This should never happen. // Check that the subscriber is subscribed to the node owner's presence
Log.warn("Node with access model Roster has a remote user as owner: " + boolean isSubscribed = item != null && (
node.getNodeID()); RosterItem.SUB_BOTH == item.getSubStatus() ||
RosterItem.SUB_FROM == item.getSubStatus());
if (isSubscribed) {
// Get list of groups where the contact belongs
List<String> contactGroups = new ArrayList<String>(item.getGroups());
for (Group group : item.getSharedGroups()) {
contactGroups.add(group.getName());
}
for (Group group : item.getInvisibleSharedGroups()) {
contactGroups.add(group.getName());
}
// Check if subscriber is present in the allowed groups of the node
return contactGroups.removeAll(node.getRosterGroupsAllowed());
}
}
catch (UserNotFoundException e) {
// Do nothing
}
}
else {
// Owner of the node is a remote user. This should never happen.
Log.warn("Node with access model Roster has a remote user as owner: " +
node.getNodeID());
}
} }
return false; return false;
} }
......
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