diff --git a/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/PubSubElementProcessorAbstract.java b/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/PubSubElementProcessorAbstract.java index b614635e..8c5a37d8 100644 --- a/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/PubSubElementProcessorAbstract.java +++ b/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/PubSubElementProcessorAbstract.java @@ -38,8 +38,6 @@ public abstract class PubSubElementProcessorAbstract implements PubSubElementPro protected IQ response; protected IQ request; protected JID actor; - protected String serverDomain; - protected String topicsDomain; protected String node = null; protected Helper configurationHelper; protected Map nodeConfiguration; @@ -68,17 +66,6 @@ public void setChannelManager(ChannelManager channelManager) { this.channelManager = channelManager; } - public void setServerDomain(String domain) { - serverDomain = domain; - } - - protected String getServerDomain() { - if (null == serverDomain) { - serverDomain = Configuration.getInstance().getProperty("server.domain"); - } - return serverDomain; - } - protected Collection getAdminUsers() { if (null == adminUsers) { adminUsers = Configuration.getInstance().getAdminUsers(); @@ -86,21 +73,10 @@ protected Collection getAdminUsers() { return adminUsers; } - public void setTopicsDomain(String domain) { - topicsDomain = domain; - } - public void setNode(String node) { this.node = node; } - protected String getTopicsDomain() { - if (null == topicsDomain) { - topicsDomain = Configuration.getInstance().getProperty("server.domain.topics"); - } - return topicsDomain; - } - public void setConfigurationHelper(Helper helper) { configurationHelper = helper; } @@ -200,7 +176,7 @@ private AccessModels getNodeAccessModel() { } protected boolean actorIsRegistered() { - if (actor.getDomain().equals(getServerDomain())) { + if (Configuration.getInstance().isLocalJID(actor)) { return true; } else { setErrorCondition(PacketError.Type.auth, PacketError.Condition.forbidden); diff --git a/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/ItemDelete.java b/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/ItemDelete.java index cf29b729..66f0876a 100644 --- a/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/ItemDelete.java +++ b/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/ItemDelete.java @@ -97,7 +97,8 @@ private void deleteReplies() throws NodeStoreException { reply = replies.next(); channelManager.deleteNodeItemById(reply.getNodeId(), reply.getId()); - sendNotifications(node, new GlobalItemIDImpl(new JID(this.getServerDomain()), reply.getNodeId(), reply.getId())); + sendNotifications(node, new GlobalItemIDImpl(new JID( + Configuration.getInstance().getServerDomain()), reply.getNodeId(), reply.getId())); } } @@ -206,7 +207,8 @@ private boolean itemIdProvided() { if (GlobalItemIDImpl.isGlobalId(id)) { itemId = GlobalItemIDImpl.fromBuddycloudString(id); } else { - itemId = new GlobalItemIDImpl(new JID(this.getServerDomain()), node, id); + itemId = new GlobalItemIDImpl(new JID( + Configuration.getInstance().getServerDomain()), node, id); } return true; } diff --git a/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeCreate.java b/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeCreate.java index a7e86c5b..11d7667e 100644 --- a/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeCreate.java +++ b/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeCreate.java @@ -42,7 +42,7 @@ public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm) throws Exc if (null == actorJID) { actor = request.getFrom(); } - if (!nodePresent()) { + if (!nodePresent() || !isNodeValid()) { outQueue.put(response); return; } @@ -50,8 +50,7 @@ public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm) throws Exc makeRemoteRequest(); return; } - if ((checkNodeExists()) || (!actorIsRegistered()) || (!nodeHandledByThisServer())) { - + if ((checkNodeExists()) || (!actorIsRegistered())) { outQueue.put(response); return; } @@ -100,16 +99,11 @@ protected boolean checkNodeExists() throws NodeStoreException { return true; } - private boolean nodeHandledByThisServer() { + private boolean isNodeValid() { if (!node.matches(NODE_REG_EX)) { setErrorCondition(PacketError.Type.modify, PacketError.Condition.bad_request); return false; } - - if ((!node.contains("@" + getServerDomain())) && (!node.contains("@" + getTopicsDomain()))) { - setErrorCondition(PacketError.Type.modify, PacketError.Condition.not_acceptable); - return false; - } return true; } } diff --git a/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeDelete.java b/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeDelete.java index 3a9779c4..1cb56d59 100644 --- a/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeDelete.java +++ b/src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeDelete.java @@ -57,7 +57,7 @@ public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm) throws Exc makeRemoteRequest(); return; } - if (!checkNodeExists() || !actorIsRegistered() || !nodeHandledByThisServer() + if (!checkNodeExists() || !actorIsRegistered() || isEphemeralNode() || !actorAllowedToDelete()) { outQueue.put(response); return; @@ -137,14 +137,6 @@ private boolean actorAllowedToDelete() throws NodeStoreException { return false; } - private boolean nodeHandledByThisServer() { - if (!node.contains("@" + getServerDomain()) && !node.contains("@" + getTopicsDomain())) { - setErrorCondition(PacketError.Type.modify, PacketError.Condition.not_acceptable); - return false; - } - return true; - } - private boolean nodeValid() { if (!node.matches(NODE_REG_EX)) { setErrorCondition(PacketError.Type.modify, PacketError.Condition.bad_request); diff --git a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/AffiliationEventTest.java b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/AffiliationEventTest.java index 2d6483ed..5960af12 100644 --- a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/AffiliationEventTest.java +++ b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/AffiliationEventTest.java @@ -64,7 +64,6 @@ public void setUp() throws Exception { queue = new LinkedBlockingQueue(); event = new AffiliationEvent(queue, channelManager); request = readStanzaAsIq("/iq/pubsub/affiliation/affiliationChange.stanza"); - event.setServerDomain("shakespeare.lit"); element = new BaseElement("affiliations"); element.addAttribute("node", node); diff --git a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/ItemDeleteTest.java b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/ItemDeleteTest.java index bccbaa74..5dd4f6ff 100644 --- a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/ItemDeleteTest.java +++ b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/ItemDeleteTest.java @@ -52,8 +52,6 @@ public void setUp() throws Exception { itemDelete = new ItemDelete(queue, channelManager); request = readStanzaAsIq("/iq/pubsub/item/delete/request.stanza"); - itemDelete.setServerDomain("shakespeare.lit"); - element = new BaseElement("retract"); element.addAttribute("node", node); diff --git a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeConfigureTest.java b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeConfigureTest.java index 3e41e5e9..4a22c5f0 100644 --- a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeConfigureTest.java +++ b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeConfigureTest.java @@ -50,8 +50,6 @@ public void setUp() throws Exception { jid = new JID("juliet@shakespeare.lit"); request = readStanzaAsIq("/iq/pubsub/channel/configure/request.stanza"); - nodeConfigure.setServerDomain("shakespeare.lit"); - element = new BaseElement("create"); element.addAttribute("node", "/user/capulet@shakespeare.lit/posts"); } diff --git a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeCreateTest.java b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeCreateTest.java index 134b35e8..d26ff442 100644 --- a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeCreateTest.java +++ b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeCreateTest.java @@ -46,8 +46,6 @@ public void setUp() throws Exception { jid = new JID("juliet@shakespeare.lit"); request = readStanzaAsIq("/iq/pubsub/channel/create/request.stanza"); - nodeCreate.setServerDomain("shakespeare.lit"); - element = new BaseElement("create"); element.addAttribute("node", node); } @@ -106,6 +104,11 @@ public void testRequestingAlreadyExistingNodeReturnsErrorStanza() public void testUnauthenticatedUserCanNotCreateNode() throws Exception { JID jid = new JID("juliet@anon.shakespeare.lit"); + Configuration.getInstance().remove( + Configuration.CONFIGURATION_LOCAL_DOMAIN_CHECKER); + Configuration.getInstance().putProperty( + Configuration.CONFIGURATION_SERVER_DOMAIN, "shakespeare.lit"); + nodeCreate.process(element, jid, request, null); Packet response = queue.poll(100, TimeUnit.MILLISECONDS); @@ -139,26 +142,24 @@ public void testInvalidlyFormattedNodeReturnsError() throws Exception { } @Test - public void testNewNodeMustBeOnADomainSupportedByCurrentServer() - throws Exception { + public void testNodeFromUnknownDomain() throws Exception { element.addAttribute("node", "/user/capulet@shakespearelit/posts"); - nodeCreate.setTopicsDomain("topics.shakespeare.lit"); - + Configuration.getInstance().putProperty( + Configuration.CONFIGURATION_LOCAL_DOMAIN_CHECKER, Boolean.FALSE.toString()); + nodeCreate.process(element, jid, request, null); Packet response = queue.poll(100, TimeUnit.MILLISECONDS); - PacketError error = response.getError(); - Assert.assertNotNull(error); - Assert.assertEquals(PacketError.Type.modify, error.getType()); - Assert.assertEquals(PacketError.Condition.not_acceptable, error.getCondition()); + Assert.assertNull(response.getError()); + Assert.assertNotNull(response.getElement().element("pubsub").element("actor")); /** * Add this check back in once Tinder supports xmlns on standard * conditions Assert.assertEquals(JabberPubsub.NS_XMPP_STANZAS, * error.getApplicationConditionNamespaceURI()); */ } - + @Test public void testchannelManagerFailureReturnsInternalServerErrorResponse() throws Exception { @@ -270,4 +271,5 @@ public void testFailingNodeConfigurationReturnsErrorStanza() * error.getApplicationConditionNamespaceURI()); */ } + } diff --git a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeDeleteTest.java b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeDeleteTest.java index 717795db..46c1bd47 100644 --- a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeDeleteTest.java +++ b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/NodeDeleteTest.java @@ -49,7 +49,6 @@ public void setUp() throws Exception { this.queue = new LinkedBlockingQueue(); this.nodeDelete = new NodeDelete(queue, channelManager); - this.nodeDelete.setServerDomain("shakespeare.lit"); this.element = new BaseElement("delete"); Configuration.getInstance().putProperty(Configuration.CONFIGURATION_LOCAL_DOMAIN_CHECKER, Boolean.TRUE.toString()); @@ -139,8 +138,13 @@ public void testNotRegisteredActor() throws Exception { String node = deleteEl.attributeValue("node"); Mockito.when(channelManager.nodeExists(node)).thenReturn(true); - nodeDelete.setServerDomain("fake.domain"); + + Configuration.getInstance().remove( + Configuration.CONFIGURATION_LOCAL_DOMAIN_CHECKER); + Configuration.getInstance().putProperty( + Configuration.CONFIGURATION_SERVER_DOMAIN, "shakespeare.lit"); + JID jid = new JID("juliet@anon.shakespeare.lit"); nodeDelete.process(deleteEl, jid, request, null); Packet response = queue.poll(); @@ -214,13 +218,14 @@ public void testNodeFromUnknownDomain() throws Exception { String node = deleteEl.attributeValue("node"); Mockito.when(channelManager.nodeExists(node)).thenReturn(true); + Configuration.getInstance().putProperty( + Configuration.CONFIGURATION_LOCAL_DOMAIN_CHECKER, Boolean.FALSE.toString()); + nodeDelete.process(deleteEl, jid, request, null); Packet response = queue.poll(); - PacketError error = response.getError(); - Assert.assertNotNull(error); - Assert.assertEquals(PacketError.Type.modify, error.getType()); - Assert.assertEquals(PacketError.Condition.not_acceptable, error.getCondition()); + Assert.assertNull(response.getError()); + Assert.assertNotNull(response.getElement().element("pubsub").element("actor")); } @Test diff --git a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/PublishTest.java b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/PublishTest.java index 3943b22f..ef619c66 100644 --- a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/PublishTest.java +++ b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/PublishTest.java @@ -59,7 +59,6 @@ public void setUp() throws Exception { jid = new JID("juliet@shakespeare.lit/balcony"); request = readStanzaAsIq("/iq/pubsub/publish/request.stanza"); - publish.setServerDomain("shakespeare.lit"); publish.setChannelManager(channelManager); publish.setEntryValidator(validateEntry); diff --git a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/SubscribeSetTest.java b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/SubscribeSetTest.java index d8402ad0..9a1ef808 100644 --- a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/SubscribeSetTest.java +++ b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/SubscribeSetTest.java @@ -55,7 +55,6 @@ public void setUp() throws Exception { queue = new LinkedBlockingQueue(); subscribe = new SubscribeSet(queue, channelManager); request = readStanzaAsIq("/iq/pubsub/subscribe/request.stanza"); - subscribe.setServerDomain("shakespeare.lit"); element = new BaseElement("subscribe"); element.addAttribute("node", node); diff --git a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/SubscriptionEventTest.java b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/SubscriptionEventTest.java index 5127af38..730d5a8c 100644 --- a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/SubscriptionEventTest.java +++ b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/SubscriptionEventTest.java @@ -57,7 +57,6 @@ public void setUp() throws Exception { queue = new LinkedBlockingQueue(); event = new SubscriptionEvent(queue, dataStore); request = readStanzaAsIq("/iq/pubsub/subscribe/authorizationPendingGrantReply.stanza"); - event.setServerDomain("shakespeare.lit"); element = new BaseElement("subscriptions"); element.addAttribute("node", node); diff --git a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/UnsubscribeSetTest.java b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/UnsubscribeSetTest.java index 96d7fa6f..8c897eba 100644 --- a/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/UnsubscribeSetTest.java +++ b/src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/UnsubscribeSetTest.java @@ -55,7 +55,6 @@ public void setUp() throws Exception { queue = new LinkedBlockingQueue(); unsubscribe = new UnsubscribeSet(queue, channelManager); request = readStanzaAsIq("/iq/pubsub/unsubscribe/request.stanza"); - unsubscribe.setServerDomain("shakespeare.lit"); element = new BaseElement("unsubscribe"); element.addAttribute("node", node);