SASL auth is back, ths Alexey

This commit is contained in:
Yann Leboulanger 2005-05-26 06:50:17 +00:00
parent 7c303ddcc3
commit 92b1c8226c
2 changed files with 13 additions and 9 deletions

View File

@ -96,6 +96,11 @@ class NonSASL(PlugIn):
class SASL(PlugIn): class SASL(PlugIn):
""" Implements SASL authentication. """ """ Implements SASL authentication. """
def __init__(self,username,password):
PlugIn.__init__(self)
self.username=username
self.password=password
def plugin(self,owner): def plugin(self,owner):
if not self._owner.Dispatcher.Stream._document_attrs.has_key('version'): self.startsasl='not-supported' if not self._owner.Dispatcher.Stream._document_attrs.has_key('version'): self.startsasl='not-supported'
elif self._owner.Dispatcher.Stream.features: elif self._owner.Dispatcher.Stream.features:
@ -103,13 +108,12 @@ class SASL(PlugIn):
except NodeProcessed: pass except NodeProcessed: pass
else: self.startsasl=None else: self.startsasl=None
def auth(self,username,password): def auth(self):
""" Start authentication. Result can be obtained via "SASL.startsasl" attribute and will be """ Start authentication. Result can be obtained via "SASL.startsasl" attribute and will be
either "success" or "failure". Note that successfull auth will take at least either "success" or "failure". Note that successfull auth will take at least
two Dispatcher.Process() calls. """ two Dispatcher.Process() calls. """
self.username=username if self.startsasl: pass
self.password=password elif self._owner.Dispatcher.Stream.features:
if self._owner.Dispatcher.Stream.features:
try: self.FeaturesHandler(self._owner.Dispatcher,self._owner.Dispatcher.Stream.features) try: self.FeaturesHandler(self._owner.Dispatcher,self._owner.Dispatcher.Stream.features)
except NodeProcessed: pass except NodeProcessed: pass
else: self._owner.RegisterHandler('features',self.FeaturesHandler,xmlns=NS_STREAMS) else: self._owner.RegisterHandler('features',self.FeaturesHandler,xmlns=NS_STREAMS)

View File

@ -189,14 +189,14 @@ class Client(CommonClient):
while not self.Dispatcher.Stream._document_attrs and self.Process(): pass while not self.Dispatcher.Stream._document_attrs and self.Process(): pass
if self.Dispatcher.Stream._document_attrs.has_key('version') and self.Dispatcher.Stream._document_attrs['version']=='1.0': if self.Dispatcher.Stream._document_attrs.has_key('version') and self.Dispatcher.Stream._document_attrs['version']=='1.0':
while not self.Dispatcher.Stream.features and self.Process(): pass # If we get version 1.0 stream the features tag MUST BE presented while not self.Dispatcher.Stream.features and self.Process(): pass # If we get version 1.0 stream the features tag MUST BE presented
if sasl: auth.SASL().PlugIn(self) if sasl: auth.SASL(user,password).PlugIn(self)
if not sasl or self.SASL.startsasl=='not-supported': if not sasl or self.SASL.startsasl=='not-supported':
if not resource: resource='xmpppy' if not resource: resource='xmpppy'
if auth.NonSASL(user,password,resource).PlugIn(self): if auth.NonSASL(user,password,resource).PlugIn(self):
self.connected+='+old_auth' self.connected+='+old_auth'
return 'old_auth' return 'old_auth'
return return
self.SASL.auth(user,password) self.SASL.auth()
while self.SASL.startsasl=='in-process' and self.Process(): pass while self.SASL.startsasl=='in-process' and self.Process(): pass
if self.SASL.startsasl=='success': if self.SASL.startsasl=='success':
auth.Bind().PlugIn(self) auth.Bind().PlugIn(self)