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 {
if (node.isAdmin(owner)) {
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();
// Check that the node owner is a local user
if (server.isLocal(nodeOwner)) {
try {
Roster roster = server.getRosterManager().getRoster(nodeOwner.getNode());
RosterItem item = roster.getRosterItem(owner);
// 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());
}
catch (UserNotFoundException e) {
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;
for (JID nodeOwner : node.getOwners()) {
// Give access to the owner of the roster :)
if (nodeOwner.equals(owner.toBareJID())) {
return true;
}
// Check that the node owner is a local user
if (server.isLocal(nodeOwner)) {
try {
Roster roster = server.getRosterManager().getRoster(nodeOwner.getNode());
RosterItem item = roster.getRosterItem(owner);
// 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());
}
catch (UserNotFoundException e) {
// Do nothing
}
}
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
......
......@@ -55,44 +55,43 @@ public class RosterAccess extends AccessModel {
if (node.isAdmin(owner)) {
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();
// Check that the node owner is a local user
if (server.isLocal(nodeOwner)) {
try {
Roster roster = server.getRosterManager().getRoster(nodeOwner.getNode());
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());
}
for (JID nodeOwner : node.getOwners()) {
// Give access to the owner of the roster :)
if (nodeOwner.equals(owner.toBareJID())) {
return true;
}
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());
// Check that the node owner is a local user
if (server.isLocal(nodeOwner)) {
try {
Roster roster = server.getRosterManager().getRoster(nodeOwner.getNode());
RosterItem item = roster.getRosterItem(owner);
// Check that the subscriber is subscribed 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) {
// 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;
}
......
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