@webob.dec.wsgify(RequestClass=wsgi.Request)
    def __call__(self, req):
        if not self.has_authentication(req):
            return self.authenticate(req)
        user_id = self.get_user_by_authentication(req)
        if not user_id:
            token = req.headers["X-Auth-Token"]
            msg = _("%(user_id)s could not be found with token '%(token)s'")
            LOG.warn(msg % locals())
            return faults.Fault(webob.exc.HTTPUnauthorized())

        # Get all valid projects for the user
        projects = self.auth.get_projects(user_id)
        if not projects:
            return faults.Fault(webob.exc.HTTPUnauthorized())

        project_id = ""
        path_parts = req.path.split('/')
        # TODO(wwolf): this v1.1 check will be temporary as
        # keystone should be taking this over at some point
        if len(path_parts) > 1 and path_parts[1] == 'v1.1':
            project_id = path_parts[2]
            # Check that the project for project_id exists, and that user
            # is authorized to use it
            try:
                project = self.auth.get_project(project_id)
            except exception.ProjectNotFound:
                return faults.Fault(webob.exc.HTTPUnauthorized())
            if [p.id for p in projects] not in project_id:
                return faults.Fault(webob.exc.HTTPUnauthorized())
        else:
            # As a fallback, set project_id from the headers, which is the v1.0
            # behavior. As a last resort, be forgiving to the user and set
            # project_id based on a valid project of theirs.
            try:
                project_id = req.headers["X-Auth-Project-Id"]
            except KeyError:
                project_id = projects[0].id

        is_admin = self.auth.is_admin(user_id)
        remote_address = getattr(req, 'remote_address', '127.0.0.1')
        if FLAGS.use_forwarded_for:
            remote_address = req.headers.get('X-Forwarded-For', remote_address)
        ctx = context.RequestContext(user_id,
                                     project_id,
                                     is_admin=is_admin,
                                     remote_address=remote_address)
        req.environ['nova.context'] = ctx

        if not is_admin and not self.auth.is_project_member(user_id,
                                                            project_id):
            msg = _("%(user_id)s must be an admin or a "
                    "member of %(project_id)s")
            LOG.warn(msg % locals())
            return faults.Fault(webob.exc.HTTPUnauthorized())

        return self.application
dataset/ETHPy150Open nii-cloud/dodai-compute/nova/api/openstack/auth.py/AuthMiddleware.__call__/swapped operands of `not in`