def getAuthorizedRoles(self, cu, user, password, allowAnonymous = True,
                           remoteIp = None):
        """
        Given a user and password, return the list of roles that are
        authorized via these credentials.

        Returns a dictionary where the key is a role ID and the value is a
        Flavor object holding the role's accept flags.
        """

        if isinstance(user, ValidUser):
            # Short-circuit for shim-using code that knows what roles
            # it wants.
            return self._rolesFromNames(cu, user.roles)

        cu.execute("""
        SELECT Users.salt, Users.password, UserGroupMembers.userGroupId,
               Users.userName, UserGroups.canMirror, UserGroups.accept_flags
        FROM Users
        JOIN UserGroupMembers USING(userId)
        JOIN UserGroups USING(userGroupId)
        WHERE Users.userName = ? OR Users.userName = 'anonymous'
        """, user)
        result = cu.fetchall()
        if not result:
            return {}

        canMirror = (0 > sum(x[4] for x in result))

        # each user can only appear once (by constraint), so we only
        # need to validate the password once. we don't validate the
        # password for 'anonymous'. Using a bad password still allows
        # anonymous access
        userPasswords = [ x for x in result if x[3] != 'anonymous' ]
        # mirror users do not have an anonymous fallback
        if userPasswords and canMirror:
            allowAnonymous = False
        if not allowAnonymous:
            result = userPasswords
        if userPasswords and not self._checkPassword(
                                        user,
                                        userPasswords[0][0].decode('hex'),
                                        userPasswords[0][1],
                                        password, remoteIp):
            result = [ x for x in result if x[3] == 'anonymous' ]
        return dict((x[2], deps.ThawFlavor(x[5])) for x in result)
dataset/ETHPy150Open sassoftware/conary/conary/repository/netrepos/netauth.py/UserAuthorization.getAuthorizedRoles/swapped operands of `>`