Changeset - dba6c44f0a30
[Not reviewed]
stable
0 1 0
Robert James Dennington - 10 years ago 2016-01-15 15:55:27
tinytimrob@googlemail.com
auth: Fix bug where usernames are not consistently capitalized when using crowd login

If you try to log in to Kallithea via the Crowd auth module then the
capitalization of your username in Kallithea changes on every login based on
how you capitalized it in the login form.

E.g. Log in with "TestDude", username is entered as "TestDude" then log in
again, but this time as "tesTduDe", and your username gets changed to
"tesTduDe". etc.

Fix for this is to use the 'name' field returned from Crowd when saving the
username. This way the username is always capitalized identically to the record
in Crowd.
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/auth_modules/auth_crowd.py
Show inline comments
 
@@ -201,45 +201,45 @@ class KallitheaAuthPlugin(auth_modules.K
 
        if not username or not password:
 
            log.debug('Empty username or password skipping...')
 
            return None
 

	
 
        log.debug("Crowd settings: \n%s", formatted_json(settings))
 
        server = CrowdServer(**settings)
 
        server.set_credentials(settings["app_name"], settings["app_password"])
 
        crowd_user = server.user_auth(username, password)
 
        log.debug("Crowd returned: \n%s", formatted_json(crowd_user))
 
        if not crowd_user["status"]:
 
            return None
 

	
 
        res = server.user_groups(crowd_user["name"])
 
        log.debug("Crowd groups: \n%s", formatted_json(res))
 
        crowd_user["groups"] = [x["name"] for x in res["groups"]]
 

	
 
        # old attrs fetched from Kallithea database
 
        admin = getattr(userobj, 'admin', False)
 
        active = getattr(userobj, 'active', True)
 
        email = getattr(userobj, 'email', '')
 
        firstname = getattr(userobj, 'firstname', '')
 
        lastname = getattr(userobj, 'lastname', '')
 

	
 
        user_data = {
 
            'username': username,
 
            'username': crowd_user["name"] or username,
 
            'firstname': crowd_user["first-name"] or firstname,
 
            'lastname': crowd_user["last-name"] or lastname,
 
            'groups': crowd_user["groups"],
 
            'email': crowd_user["email"] or email,
 
            'admin': admin,
 
            'active': active,
 
            'active_from_extern': crowd_user.get('active'), # ???
 
            'extern_name': crowd_user["name"],
 
        }
 

	
 
        # set an admin if we're in admin_groups of crowd
 
        for group in settings["admin_groups"].split(","):
 
            if group in user_data["groups"]:
 
                user_data["admin"] = True
 
        log.debug("Final crowd user object: \n%s", formatted_json(user_data))
 
        log.info('user %s authenticated correctly', user_data['username'])
 
        return user_data
 

	
 
    def get_managed_fields(self):
 
        return ['username', 'firstname', 'lastname', 'email', 'password']
0 comments (0 inline, 0 general)