Пример #1
0
	def auth(self, username, password, resource=None):
		""" Authenticate connnection and bind resource. If resource is not provided
			random one or library name used.
		"""
		self.username, self.password, self.resource = username, password, resource
		while not self.Dispatcher.stream._document_attrs and self.process(1):
			pass
		# If we get version 1.0 stream the features tag MUST BE presented
		if self.Dispatcher.stream._document_attrs.get("version") == "1.0":
			while not self.Dispatcher.features and self.process(1):
				pass
		auth.SASL(username, password).plugIn(self)
		self.SASL.auth()
		while auth.AUTH_WAITING == self.SASL.state and self.process(1):
			pass
		if auth.AUTH_SUCCESS == self.SASL.state:
			self.SASL.plugOut()
			auth.Bind().plugIn(self)
			if auth.BIND_SUCCESS == self.Bind.bind(resource):
				self.Bind.plugOut()
				return True
			else:
				self.Bind.plugOut()
				return False				
		else:
			self.SASL.plugOut()
			return False
Пример #2
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()
Пример #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'