def authenticate(self, req):
        # Unless the request is explicitly made against /<version>/ don't
        # honor it
        path_info = req.path_info
        if len(path_info) > 1:
            msg = _("Authentication requests must be made against a version "
                    "root (e.g. /v1.0 or /v1.1).")
            LOG.warn(msg)
            return faults.Fault(webob.exc.HTTPUnauthorized(explanation=msg))

        def _get_auth_header(key):
            """Ensures that the KeyError returned is meaningful."""
            try:
                return req.headers[key]
            except KeyError as ex:
                raise KeyError(key)
        try:
            username = _get_auth_header('X-Auth-User')
            key = _get_auth_header('X-Auth-Key')
        except KeyError as ex:
            msg = _("Could not find %s in request.") % ex
            LOG.warn(msg)
            return faults.Fault(webob.exc.HTTPUnauthorized(explanation=msg))

        token, user = self._authorize_user(username, key, req)
        if user and token:
            res = webob.Response()
            res.headers['X-Auth-Token'] = token['token_hash']
            res.headers['X-Server-Management-Url'] = \
                token['server_management_url']
            res.headers['X-Storage-Url'] = token['storage_url']
            res.headers['X-CDN-Management-Url'] = token['cdn_management_url']
            res.content_type = 'text/plain'
            res.status = '204'
            LOG.debug(_("Successfully authenticated '%s'") % username)
            return res
        else:
            return faults.Fault(webob.exc.HTTPUnauthorized())
dataset/ETHPy150Open nii-cloud/dodai-compute/nova/api/openstack/auth.py/AuthMiddleware.authenticate/original