Changeset 72:727b4d29c48e in ralphm-patches for client_listen_authenticator.patch
- Timestamp:
- Jan 27, 2013, 10:40:32 PM (9 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client_listen_authenticator.patch
r66 r72 1 1 # HG changeset patch 2 # Parent a1648553ea06b7f0b38fec775db71ac03782e3d62 # Parent c22caa54600c4f85db2a400c7fbea5497f943aa1 3 3 Add authenticator for accepting XMPP client connections. 4 4 5 The new authenticator XMPPClientListenAuthenticator is to be used together6 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.5 The new authenticator XMPPClientListenAuthenticator is to be used 6 together with an `XmlStream` created for an incoming XMPP stream. It 7 uses the new initializers for SASL (PLAIN only), resource binding and 8 session establishement. 9 9 10 10 This authenticator needs at least one Twisted Cred portal to hold the … … 56 56 def __init__(self, jid, password): 57 57 xmlstream.ConnectAuthenticator.__init__(self, jid.host) 58 @@ -186,3 +199,2 46@@58 @@ -186,3 +199,284 @@ 59 59 c = XMPPClientConnector(reactor, domain, factory) 60 60 c.connect() … … 80 80 + """ 81 81 + 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. 82 93 + """ 83 94 + 84 95 + required = True 96 + _mechanisms = None 97 + __credentialsMap = { 98 + credentials.IAnonymous: 'ANONYMOUS', 99 + credentials.IUsernamePassword: 'PLAIN', 100 + } 85 101 + 86 102 + def __init__(self, name, xs, portal): … … 92 108 + def getFeatures(self): 93 109 + 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 + 95 123 + return [feature] 96 124 + … … 142 170 + 143 171 + 144 + def _credentialsFrom Plain(self, auth):172 + def _credentialsFrom_PLAIN(self, auth): 145 173 + """ 146 174 + Create credentials from the initial response for PLAIN. … … 157 185 + 158 186 + 187 + def _credentialsFrom_ANONYMOUS(self, auth): 188 + """ 189 + Create credentials from the initial response for ANONYMOUS. 190 + """ 191 + return credentials.Anonymous() 192 + 193 + 159 194 + def _doAuth(self, auth): 160 195 + """ 161 196 + Start authentication. 162 197 + """ 163 + if auth.getAttribute('mechanism') != 'PLAIN': 198 + mechanism = auth.getAttribute('mechanism') 199 + 200 + if mechanism not in self._mechanisms: 164 201 + raise InvalidMechanism() 165 202 + 166 + creds = self._credentialsFromPlain(auth)203 + creds = getattr(self, '_credentialsFrom_' + mechanism)(auth) 167 204 + 168 205 + def cb((iface, avatar, logout)): … … 180 217 + """ 181 218 + 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. 182 222 + """ 183 223 + … … 282 322 + return [BindReceivingInitializer('bind', self.xmlstream), 283 323 + SessionReceivingInitializer('session', self.xmlstream)] 284 + else:285 + return []286 324 + 287 325 + … … 306 344 --- a/wokkel/generic.py 307 345 +++ b/wokkel/generic.py 308 @@ -46 5,6 +465,7 @@346 @@ -467,6 +467,7 @@ 309 347 310 348 def __init__(self): … … 314 352 315 353 def _onElementFallback(self, element): 316 @@ -55 6,11 +557,12 @@354 @@ -558,11 +559,12 @@ 317 355 318 356 self.xmlstream.send(features) … … 331 369 --- a/wokkel/iwokkel.py 332 370 +++ b/wokkel/iwokkel.py 333 @@ -985,6 +985, 45 @@371 @@ -985,6 +985,55 @@ 334 372 335 373 336 374 337 375 +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 + 338 386 + def loggedIn(realm, mind): 339 387 + """ … … 413 461 class XMPPClientTest(unittest.TestCase): 414 462 """ 415 @@ -1 55,3 +168,505 @@463 @@ -164,3 +177,505 @@ 416 464 self.assertEqual(factory.deferred, d2) 417 465
Note: See TracChangeset
for help on using the changeset viewer.