Trees | Indices | Help |
---|
|
1 # $Id: sobzprovider.py,v 1.2 2007/01/03 21:21:18 lmacken Exp $ 2 # This program is free software; you can redistribute it and/or modify 3 # it under the terms of the GNU General Public License as published by 4 # the Free Software Foundation; version 2 of the License. 5 # 6 # This program is distributed in the hope that it will be useful, 7 # but WITHOUT ANY WARRANTY; without even the implied warranty of 8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 # GNU Library General Public License for more details. 10 # 11 # You should have received a copy of the GNU General Public License 12 # along with this program; if not, write to the Free Software 13 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 14 15 """ 16 This plugin provides authentication of passwords against Bugzilla via XML-RPC 17 """ 18 19 import logging 20 import xmlrpclib 21 22 from turbogears.identity.soprovider import * 23 from turbogears import config 24 from bodhi.model import User, VisitIdentity 25 26 log = logging.getLogger(__name__) 2729 """ 30 IdentityProvider that authenticates users against Bugzilla via XML-RPC 31 """ 358337 newuser = False 38 user_name = to_db_encoding(user_name, self.user_class_db_encoding) 39 40 try: 41 user = User.by_user_name(user_name) 42 except SQLObjectNotFound: 43 log.info("Creating new user %s" % user_name) 44 user = User(user_name=user_name) 45 newuser = True 46 47 if not self.validate_password(user, user_name, password): 48 log.warning("Invalid password for %s" % user_name) 49 if newuser: 50 user.destroySelf() 51 return None 52 53 log.info("Login successful for %s" % user_name) 54 55 try: 56 link = VisitIdentity.by_visit_key(visit_key) 57 link.user_id = user.id 58 except SQLObjectNotFound: 59 link = VisitIdentity(visit_key=visit_key, user_id=user.id) 60 61 return SqlObjectIdentity(visit_key, user)6264 """ 65 Complete hack, but it works. 66 Request bug #1 with the given username and password. If a Fault is 67 thrown, the username/pass is invalid; else, we're good to go. 68 """ 69 # if there is a password in our local database, then authenticate 70 # against it (ie, guest, admin, etc) 71 if user.password: 72 log.debug("Authenticating against local password for %s" %user_name) 73 return user.password == self.encrypt_password(password) 74 75 # if there is no password stored, then try the supplied password against 76 # bugzilla by attempting to fetch bug #1 77 try: 78 server = xmlrpclib.Server(self.bz_server) 79 server.bugzilla.getBugSimple('1', user_name, password) 80 except xmlrpclib.Fault: 81 return False 82 return True
Trees | Indices | Help |
---|
Generated by Epydoc 3.0beta1 on Sun Sep 23 14:46:38 2007 | http://epydoc.sourceforge.net |