Mercurial > libervia-pubsub
comparison sat_pubsub/backend.py @ 237:6596730685e8
added creator check support
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 17 May 2012 13:15:11 +0200 |
parents | 65bc75603539 |
children | 70c8bb90d75f |
comparison
equal
deleted
inserted
replaced
236:65bc75603539 | 237:6596730685e8 |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 #-*- coding: utf-8 -*- | 2 #-*- coding: utf-8 -*- |
3 | 3 # |
4 """ | 4 """ |
5 Copyright (c) 2003-2011 Ralph Meijer | 5 Copyright (c) 2003-2011 Ralph Meijer |
6 Copyright (c) 2012 Jérôme Poisson | 6 Copyright (c) 2012 Jérôme Poisson |
7 | 7 |
8 | 8 |
68 | 68 |
69 from twisted.application import service | 69 from twisted.application import service |
70 from twisted.python import components, log | 70 from twisted.python import components, log |
71 from twisted.internet import defer, reactor | 71 from twisted.internet import defer, reactor |
72 from twisted.words.protocols.jabber.error import StanzaError | 72 from twisted.words.protocols.jabber.error import StanzaError |
73 from twisted.words.protocols.jabber.jid import JID | |
73 from twisted.words.xish import utility | 74 from twisted.words.xish import utility |
74 | 75 |
75 from wokkel import disco | 76 from wokkel import disco |
76 from wokkel.iwokkel import IPubSubResource | 77 from wokkel.iwokkel import IPubSubResource |
77 from wokkel.pubsub import PubSubResource, PubSubError | 78 from wokkel.pubsub import PubSubResource, PubSubError |
338 return self.storage.getSubscriptions(entity) | 339 return self.storage.getSubscriptions(entity) |
339 | 340 |
340 def supportsAutoCreate(self): | 341 def supportsAutoCreate(self): |
341 return True | 342 return True |
342 | 343 |
344 def supportsCreatorCheck(self): | |
345 return True | |
346 | |
343 def supportsInstantNodes(self): | 347 def supportsInstantNodes(self): |
344 return True | 348 return True |
345 | 349 |
346 | 350 |
347 def createNode(self, nodeIdentifier, requestor): | 351 def createNode(self, nodeIdentifier, requestor): |
348 if not nodeIdentifier: | 352 if not nodeIdentifier: |
349 nodeIdentifier = 'generic/%s' % uuid.uuid4() | 353 nodeIdentifier = 'generic/%s' % uuid.uuid4() |
354 | |
355 if self.supportsCreatorCheck(): | |
356 try: | |
357 nodeIdentifierJID = JID(nodeIdentifier) | |
358 except InvalidFormat: | |
359 is_user_jid = False | |
360 else: | |
361 is_user_jid = bool(nodeIdentifierJID.user) | |
362 | |
363 if is_user_jid and nodeIdentifierJID.userhost() != requestor.userhost(): | |
364 #we have an user jid node, but not created by the owner of this jid | |
365 print "Wrong creator" | |
366 raise error.Forbidden() | |
350 | 367 |
351 nodeType = 'leaf' | 368 nodeType = 'leaf' |
352 config = self.storage.getDefaultConfiguration(nodeType) | 369 config = self.storage.getDefaultConfiguration(nodeType) |
353 config['pubsub#node_type'] = nodeType | 370 config['pubsub#node_type'] = nodeType |
354 | 371 |
584 self.backend = backend | 601 self.backend = backend |
585 self.hideNodes = False | 602 self.hideNodes = False |
586 | 603 |
587 self.backend.registerNotifier(self._notify) | 604 self.backend.registerNotifier(self._notify) |
588 self.backend.registerPreDelete(self._preDelete) | 605 self.backend.registerPreDelete(self._preDelete) |
606 if self.backend.supportsCreatorCheck(): | |
607 self.features.append("creator-jid-check") #SàT custom feature: Check that a node (which correspond to | |
608 # a jid in this server) is created by the right jid | |
589 | 609 |
590 if self.backend.supportsAutoCreate(): | 610 if self.backend.supportsAutoCreate(): |
591 self.features.append("auto-create") | 611 self.features.append("auto-create") |
592 | 612 |
593 if self.backend.supportsInstantNodes(): | 613 if self.backend.supportsInstantNodes(): |