How to use the webob.exc.HTTPUnauthorized function in WebOb

To help you get started, we’ve selected a few WebOb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TurboGears / tg2 / tests / test_fastform.py View on Github external
def test_logout_handler_no_came_from(self):
        env = build_env('/logout_handler')
        self.fform.identify(env)

        assert isinstance(env['repoze.who.application'], HTTPUnauthorized)
        assert env['came_from'] == '/'
github openstack / nova / nova / api / ec2 / __init__.py View on Github external
    @webob.dec.wsgify(RequestClass=wsgi.Request)
    def __call__(self, req):
        context = req.environ['nova.context']
        controller = req.environ['ec2.request'].controller.__class__.__name__
        action = req.environ['ec2.request'].action
        allowed_roles = self.action_roles[controller].get(action, ['none'])
        if self._matches_any_role(context, allowed_roles):
            return self.application
        else:
            LOG.audit(_('Unauthorized request for controller=%(controller)s '
                        'and action=%(action)s') % locals(), context=context)
            raise webob.exc.HTTPUnauthorized()
github openstack / keystone / keystone / middleware / swift_auth.py View on Github external
def unauthorized_request(self, env, start_response):
        """Clinet provided a token that wasn't acceptable, error out."""
        return HTTPUnauthorized()(env, start_response)
github openstack / nova / nova / api / openstack / auth.py View on Github external
def authenticate(self, req):
        # Unless the request is explicitly made against // 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))

        try:
            username = req.headers['X-Auth-User']
            key = req.headers['X-Auth-Key']
        except KeyError as ex:
            LOG.warn(_("Could not find %s in request.") % ex)
            return faults.Fault(webob.exc.HTTPUnauthorized())

        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']
github termie / keystonelight / keystonelight / service.py View on Github external
def validate_token(self, context, token_id):
    token_info = self.token_api.validate_token(context, token_id)
    if not token_info:
      raise webob.exc.HTTPUnauthorized()
    return token_info
github openstack / swift / swift / common / middleware / auth.py View on Github external
def denied_response(self, req):
        """
        Returns a standard WSGI response callable with the status of 403 or 401
        depending on whether the REMOTE_USER is set or not.
        """
        if req.remote_user:
            return HTTPForbidden(request=req)
        else:
            return HTTPUnauthorized(request=req)
github openstack / heat / heat / common / auth_url.py View on Github external
def _validate_auth_url(self, auth_url):
        """Validate auth_url to ensure it can be used."""
        if not auth_url:
            raise exc.HTTPBadRequest(_('Request missing required header '
                                       'X-Auth-Url'))
        allowed = cfg.CONF.auth_password.allowed_auth_uris
        if auth_url not in allowed:
            raise exc.HTTPUnauthorized(_('Header X-Auth-Url "%s" not '
                                         'an allowed endpoint') % auth_url)
        return True
github sassoftware / conary / conary / web / repos_web.py View on Github external
def _requestAuth(self, detail=None):
        raise exc.HTTPUnauthorized(
                detail=detail,
                headers=[('WWW-Authenticate',
                    'Basic realm="Conary Repository"')],
                )
github openstack / sahara / sahara / api / middleware / auth_valid.py View on Github external
path = req.environ['PATH_INFO']
        if path != '/':
            try:
                version, possibly_url_tenant, rest = (
                    strutils.split_path(path, 2, 3, True)
                )
            except ValueError:
                LOG.warning("Incorrect path: {path}".format(path=path))
                raise ex.HTTPNotFound(_("Incorrect path"))

            if uuidutils.is_uuid_like(possibly_url_tenant):
                url_tenant = possibly_url_tenant
                if token_tenant != url_tenant:
                    LOG.debug("Unauthorized: token tenant != requested tenant")
                    raise ex.HTTPUnauthorized(
                        _('Token tenant != requested tenant'))
        return self.application
github openstack / glance / glance / registry / api / v1 / members.py View on Github external
def _check_can_access_image_members(self, context):
        if context.owner is None and not context.is_admin:
            raise webob.exc.HTTPUnauthorized(_("No authenticated user"))