Changeset 72:727b4d29c48e in ralphm-patches for client_listen_authenticator.patch


Ignore:
Timestamp:
Jan 27, 2013, 10:40:32 PM (8 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Major reworking of avatars, session manager and stanza handlers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client_listen_authenticator.patch

    r66 r72  
    11# HG changeset patch
    2 # Parent a1648553ea06b7f0b38fec775db71ac03782e3d6
     2# Parent c22caa54600c4f85db2a400c7fbea5497f943aa1
    33Add authenticator for accepting XMPP client connections.
    44
    5 The new authenticator XMPPClientListenAuthenticator is to be used together
    6 with an `XmlStream` created for an incoming XMPP stream. It uses the
    7 new initializers for SASL (PLAIN only), resource binding and session
    8 establishement.
     5The new authenticator XMPPClientListenAuthenticator is to be used
     6together with an `XmlStream` created for an incoming XMPP stream. It
     7uses the new initializers for SASL (PLAIN only), resource binding and
     8session establishement.
    99
    1010This authenticator needs at least one Twisted Cred portal to hold the
     
    5656     def __init__(self, jid, password):
    5757         xmlstream.ConnectAuthenticator.__init__(self, jid.host)
    58 @@ -186,3 +199,246 @@
     58@@ -186,3 +199,284 @@
    5959     c = XMPPClientConnector(reactor, domain, factory)
    6060     c.connect()
     
    8080+    """
    8181+    Stream initializer for SASL authentication, receiving side.
     82+
     83+    This authenticator uses L{Twisted Cred<twisted.cred>}, the pluggable
     84+    authentication system. As such it takes a
     85+    L{Portal<twisted.cred.portal.Portal>} to select authentication mechanisms,
     86+    creates a credential object for the selected authentication mechanism and
     87+    passes it to the portal to login and acquire an avatar.
     88+
     89+    The avatar will be set on the C{avatar} attribute of the
     90+    L{xmlstream.XmlStream}.
     91+
     92+    Currently, only the C{PLAIN} SASL mechanism is supported.
    8293+    """
    8394+
    8495+    required = True
     96+    _mechanisms = None
     97+    __credentialsMap = {
     98+        credentials.IAnonymous: 'ANONYMOUS',
     99+        credentials.IUsernamePassword: 'PLAIN',
     100+        }
    85101+
    86102+    def __init__(self, name, xs, portal):
     
    92108+    def getFeatures(self):
    93109+        feature = domish.Element((sasl.NS_XMPP_SASL, 'mechanisms'))
    94 +        feature.addElement('mechanism', content='PLAIN')
     110+
     111+        # Advertise supported SASL mechanisms that have corresponding
     112+        # checkers in the Portal.
     113+        self._mechanisms = set()
     114+        for interface in self.portal.listCredentialsInterfaces():
     115+            try:
     116+                mechanism = self.__credentialsMap[interface]
     117+            except KeyError:
     118+                pass
     119+            else:
     120+                self._mechanisms.add(mechanism)
     121+                feature.addElement('mechanism', content=mechanism)
     122+
    95123+        return [feature]
    96124+
     
    142170+
    143171+
    144 +    def _credentialsFromPlain(self, auth):
     172+    def _credentialsFrom_PLAIN(self, auth):
    145173+        """
    146174+        Create credentials from the initial response for PLAIN.
     
    157185+
    158186+
     187+    def _credentialsFrom_ANONYMOUS(self, auth):
     188+        """
     189+        Create credentials from the initial response for ANONYMOUS.
     190+        """
     191+        return credentials.Anonymous()
     192+
     193+
    159194+    def _doAuth(self, auth):
    160195+        """
    161196+        Start authentication.
    162197+        """
    163 +        if auth.getAttribute('mechanism') != 'PLAIN':
     198+        mechanism = auth.getAttribute('mechanism')
     199+
     200+        if mechanism not in self._mechanisms:
    164201+            raise InvalidMechanism()
    165202+
    166 +        creds = self._credentialsFromPlain(auth)
     203+        creds = getattr(self, '_credentialsFrom_' + mechanism)(auth)
    167204+
    168205+        def cb((iface, avatar, logout)):
     
    180217+    """
    181218+    Stream initializer for resource binding, receiving side.
     219+
     220+    Upon a request for resource binding, this will call C{bindResource} on
     221+    the stream's avatar.
    182222+    """
    183223+
     
    282322+            return [BindReceivingInitializer('bind', self.xmlstream),
    283323+                    SessionReceivingInitializer('session', self.xmlstream)]
    284 +        else:
    285 +            return []
    286324+
    287325+
     
    306344--- a/wokkel/generic.py
    307345+++ b/wokkel/generic.py
    308 @@ -465,6 +465,7 @@
     346@@ -467,6 +467,7 @@
    309347 
    310348     def __init__(self):
     
    314352 
    315353     def _onElementFallback(self, element):
    316 @@ -556,11 +557,12 @@
     354@@ -558,11 +559,12 @@
    317355 
    318356         self.xmlstream.send(features)
     
    331369--- a/wokkel/iwokkel.py
    332370+++ b/wokkel/iwokkel.py
    333 @@ -985,6 +985,45 @@
     371@@ -985,6 +985,55 @@
    334372 
    335373 
    336374 
    337375+class IUserSession(Interface):
     376+    """
     377+    Interface for a XMPP user client session avatar.
     378+    """
     379+
     380+    entity = Attribute(
     381+        """
     382+        The JID for this session.
     383+        """)
     384+
     385+
    338386+    def loggedIn(realm, mind):
    339387+        """
     
    413461 class XMPPClientTest(unittest.TestCase):
    414462     """
    415 @@ -155,3 +168,505 @@
     463@@ -164,3 +177,505 @@
    416464         self.assertEqual(factory.deferred, d2)
    417465 
Note: See TracChangeset for help on using the changeset viewer.