Ejemplo n.º 1
0
 def auth(self, user, password, resource='', sasl=1):
     """ Authenticate connnection and bind resource. If resource is not provided
         random one or library name used. """
     self._User, self._Password, self._Resource = user, password, resource
     while not self.Dispatcher.Stream._document_attrs and self.Process(1):
         pass
     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(1):
             pass  # If we get version 1.0 stream the features tag MUST BE presented
     if sasl: auth.SASL(user, password).PlugIn(self)
     if not sasl or self.SASL.startsasl == 'not-supported':
         if not resource: resource = 'xmpppy'
         if auth.NonSASL(user, password, resource).PlugIn(self):
             self.connected += '+old_auth'
             return 'old_auth'
         return
     self.SASL.auth()
     while self.SASL.startsasl == 'in-process' and self.Process(1):
         pass
     if self.SASL.startsasl == 'success':
         auth.Bind().PlugIn(self)
         while self.Bind.bound is None and self.Process(1):
             pass
         if self.Bind.Bind(resource):
             self.connected += '+sasl'
             return 'sasl'
     else:
         if self.__dict__.has_key('SASL'): self.SASL.PlugOut()
Ejemplo n.º 2
0
 def auth(self,name,password,dup=None,sasl=0):
     """ Authenticate component "name" with password "password"."""
     self._User,self._Password,self._Resource=name,password,''
     try:
         if self.component: sasl=1
         if sasl: auth.SASL(name,password).PlugIn(self)
         if not sasl or self.SASL.startsasl=='not-supported':
             if auth.NonSASL(name,password,'').PlugIn(self):
                 self.connected+='+old_auth'
                 return 'old_auth'
             return
         self.SASL.auth()
         while self.SASL.startsasl=='in-process' and self.Process(): pass
         if self.SASL.startsasl=='success':
             if self.component:
                 self._component=self.component
                 for domain in self.domains:
                     auth.ComponentBind().PlugIn(self)
                     while self.ComponentBind.bound is None: self.Process()
                     if (not self.ComponentBind.Bind(domain)):
                         self.ComponentBind.PlugOut()
                         return
                     self.ComponentBind.PlugOut()
             self.connected+='+sasl'
             return 'sasl'
         else:
             raise auth.NotAuthorized(self.SASL.startsasl)
     except Exception:
         self.DEBUG(self.DBG,"Failed to authenticate %s"%name,'error')
Ejemplo n.º 3
0
 def auth(self, user, password, resource=''):
     self._User, self._Password, self._Resource = user, password, resource
     auth.SASL(user, password).PlugIn(self)
     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':
         while not self.Dispatcher.Stream.features and self.Process():
             pass  # If we get version 1.0 stream the features tag MUST BE presented
         while self.SASL.startsasl == 'in-process' and self.Process():
             pass
     else:
         self.SASL.startsasl = 'failure'
     if self.SASL.startsasl == 'failure':
         if not resource: resource = 'xmpppy'
         if auth.NonSASL(user, password, resource).PlugIn(self):
             self.connected += '+old_auth'
             return 'old_auth'
     else:
         auth.Bind().PlugIn(self)
         while self.Bind.bound is None:
             self.Process()
         if self.Bind.Bind(resource):
             self.connected += '+sasl'
             return 'sasl'
Ejemplo n.º 4
0
 def auth(self,name,password,dup=None):
     """ Authenticate component "name" with password "password"."""
     self._User,self._Password,self._Resource=name,password,''
     try:
         if self.sasl: auth.SASL(name,password).PlugIn(self)
         if not self.sasl or self.SASL.startsasl=='not-supported':
             if auth.NonSASL(name,password,'').PlugIn(self):
                 self.dobind(sasl=False)
                 self.connected+='+old_auth'
                 return 'old_auth'
             return
         self.SASL.auth()
         while self.SASL.startsasl=='in-process' and self.Process(1): pass
         if self.SASL.startsasl=='success':
             self.dobind(sasl=True)
             self.connected+='+sasl'
             return 'sasl'
         else:
             raise auth.NotAuthorized(self.SASL.startsasl)
     except:
         self.DEBUG(self.DBG,"Failed to authenticate %s"%name,'error')
Ejemplo n.º 5
0
 def auth(self, name, password, dup=None):
     self._User, self._Password, self._Resource = name, password, ''
     return auth.NonSASL(name, password, '').PlugIn(self)