Commit 93d9bd14 authored by Robin Collier's avatar Robin Collier Committed by rcollier

OF-5 Added checks for more than 1 subscription

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@11273 b35dd754-fafc-0310-a699-88a17e54d16e
parent f423089e
...@@ -1738,7 +1738,7 @@ public abstract class Node { ...@@ -1738,7 +1738,7 @@ public abstract class Node {
*/ */
public NodeSubscription getSubscription(JID subscriberJID) { public NodeSubscription getSubscription(JID subscriberJID) {
// Check that node does not support multiple subscriptions // Check that node does not support multiple subscriptions
if (isMultipleSubscriptionsEnabled()) { if (isMultipleSubscriptionsEnabled() && (getSubscriptions(subscriberJID).size() > 1)) {
throw new IllegalStateException("Multiple subscriptions is enabled so subscriptions " + throw new IllegalStateException("Multiple subscriptions is enabled so subscriptions " +
"should be retrieved using subID."); "should be retrieved using subID.");
} }
......
...@@ -586,7 +586,18 @@ public class PubSubEngine { ...@@ -586,7 +586,18 @@ public class PubSubEngine {
private void unsubscribeNode(PubSubService service, IQ iq, Element unsubscribeElement) { private void unsubscribeNode(PubSubService service, IQ iq, Element unsubscribeElement) {
String nodeID = unsubscribeElement.attributeValue("node"); String nodeID = unsubscribeElement.attributeValue("node");
String subID = unsubscribeElement.attributeValue("subid"); String subID = unsubscribeElement.attributeValue("subid");
String jidAttribute = unsubscribeElement.attributeValue("jid");
// Check if the specified JID has a subscription with the node
if (jidAttribute == null) {
// No JID was specified so return an error indicating that jid is required
Element pubsubError = DocumentHelper.createElement(
QName.get("jid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
Node node; Node node;
if (nodeID == null) { if (nodeID == null) {
if (service.isCollectionNodesSupported()) { if (service.isCollectionNodesSupported()) {
// Entity unsubscribes from root collection node // Entity unsubscribes from root collection node
...@@ -610,7 +621,9 @@ public class PubSubEngine { ...@@ -610,7 +621,9 @@ public class PubSubEngine {
} }
} }
NodeSubscription subscription; NodeSubscription subscription;
if (node.isMultipleSubscriptionsEnabled()) { JID owner = new JID(jidAttribute);
if (node.isMultipleSubscriptionsEnabled() && node.getSubscriptions(owner).size() > 1) {
if (subID == null) { if (subID == null) {
// No subid was specified and the node supports multiple subscriptions // No subid was specified and the node supports multiple subscriptions
Element pubsubError = DocumentHelper.createElement( Element pubsubError = DocumentHelper.createElement(
...@@ -630,15 +643,6 @@ public class PubSubEngine { ...@@ -630,15 +643,6 @@ public class PubSubEngine {
} }
} }
else { else {
String jidAttribute = unsubscribeElement.attributeValue("jid");
// Check if the specified JID has a subscription with the node
if (jidAttribute == null) {
// No JID was specified so return an error indicating that jid is required
Element pubsubError = DocumentHelper.createElement(
QName.get("jid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
JID subscriberJID = new JID(jidAttribute); JID subscriberJID = new JID(jidAttribute);
subscription = node.getSubscription(subscriberJID); subscription = node.getSubscription(subscriberJID);
if (subscription == null) { if (subscription == null) {
...@@ -656,8 +660,6 @@ public class PubSubEngine { ...@@ -656,8 +660,6 @@ public class PubSubEngine {
return; return;
} }
// TODO Assumed that the owner of the subscription is the bare JID of the subscription JID. Waiting StPeter answer for explicit field.
JID owner = new JID(from.toBareJID());
// A subscription was found so check if the user is allowed to cancel the subscription // A subscription was found so check if the user is allowed to cancel the subscription
if (!subscription.canModify(from) && !subscription.canModify(owner)) { if (!subscription.canModify(from) && !subscription.canModify(owner)) {
// Requestor is prohibited from unsubscribing entity // Requestor is prohibited from unsubscribing entity
...@@ -955,9 +957,10 @@ public class PubSubEngine { ...@@ -955,9 +957,10 @@ public class PubSubEngine {
// Get the user's subscription // Get the user's subscription
NodeSubscription subscription = null; NodeSubscription subscription = null;
if (node.isMultipleSubscriptionsEnabled() && !node.getSubscriptions(owner).isEmpty()) { if (node.isMultipleSubscriptionsEnabled() && (node.getSubscriptions(owner).size() > 1)) {
if (subID == null) { if (subID == null) {
// No subid was specified and the node supports multiple subscriptions // No subid was specified and the node supports multiple subscriptions and the user
// has multiple subscriptions
Element pubsubError = DocumentHelper.createElement( Element pubsubError = DocumentHelper.createElement(
QName.get("subid-required", "http://jabber.org/protocol/pubsub#errors")); QName.get("subid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError); sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
......
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