'Raise an error if `user` is anonymous.'

def error_if_anonymous(self, user, msg='Log-in    required', **kwargs):

    if (user is None):
        raise exceptions.AuthenticationFailed(msg, **kwargs)
    return user
