def authenticate(self, pxt_session=None): pxt = pxt_session.split("x")[0] space_db = SpacewalkDB() result = space_db.get_web_user(pxt) web_user_id = result[0] if web_user_id == 'None': _LOG.error('spacewalk session has expired') return None result = space_db.get_login(web_user_id) db_user_login = result[0] _LOG.info('DB USER: %s' % (db_user_login)) try: user = User.objects.get(username=db_user_login) _LOG.info('report server username: %s' % (user.username)) except User.DoesNotExist: # Create a new user. Note that we can set password # to anything, because it won't be checked; the password # Another option is to decode the spacewalk user passwd _LOG.debug("The user %s does not exist, and will be created" % (db_user_login)) user = User(username=db_user_login, password="******") user.is_active = True user.is_staff = False user.is_superuser = False user.save() return user
def authenticate(self, request=None, username=None, password=None): try: space_db = SpacewalkDB() result = space_db.execute_one("select * FROM web_contact WHERE LOGIN = '******'" % (username)) if config.CONFIG.get('spacewalk', 'db_backend') == 'postgresql': passwd_to_match = result[4] else: passwd_to_match = result[4] salt = passwd_to_match.split("$")[2] passwd_hash = md5_crypt.encrypt(password, salt=salt) if passwd_to_match == passwd_hash: try: user = User.objects.get(username=username) except Exception as e: _LOG.debug("User not found or exception: %s" % (str(e))) # Create a new user. Note that we can set password # to anything, because it won't be checked; the password # from settings.py will. user = User(username=username, password=password) user.is_active = True user.is_staff = False user.is_superuser = False user.save() return user return None except IndexError: _LOG.error('authentication failed, user does not exist in spacewalk') return None