當前位置: 首頁>>代碼示例>>Python>>正文


Python falcon.HTTP_401屬性代碼示例

本文整理匯總了Python中falcon.HTTP_401屬性的典型用法代碼示例。如果您正苦於以下問題:Python falcon.HTTP_401屬性的具體用法?Python falcon.HTTP_401怎麽用?Python falcon.HTTP_401使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在falcon的用法示例。


在下文中一共展示了falcon.HTTP_401屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __call__

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_401 [as 別名]
def __call__(self, f):
        @functools.wraps(f)
        def secure_handler(slf, req, resp, *args, **kwargs):
            ctx = req.context

            policy_engine = ctx.policy_engine

            self.logger.debug("Enforcing policy %s on request %s" %
                              (self.action, ctx.request_id))

            if policy_engine is not None and policy_engine.authorize(
                    self.action, ctx):
                return f(slf, req, resp, *args, **kwargs)
            else:
                if ctx.authenticated:
                    slf.info(
                        ctx,
                        "Error - Forbidden access - action: %s" % self.action)
                    slf.return_error(
                        resp,
                        falcon.HTTP_403,
                        message="Forbidden",
                        retry=False)
                else:
                    slf.info(ctx, "Error - Unauthenticated access")
                    slf.return_error(
                        resp,
                        falcon.HTTP_401,
                        message="Unauthenticated",
                        retry=False)

        return secure_handler 
開發者ID:airshipit,項目名稱:drydock,代碼行數:34,代碼來源:policy.py

示例2: on_post

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_401 [as 別名]
def on_post(self, req, resp):
        validRequest = authenticate(req)

        if not validRequest:
            resp.body = "Invalid username/password"
            resp.status = falcon.HTTP_401
            return

        session = Session(engine)
        valueDict = getJson(req)

        signatureQuery = getSignatureQuery(req, session)

        message = "Unable to add Signature"
        resp.status = falcon.HTTP_400

        if "Signature" in valueDict.keys() and signatureQuery is None:
            signatureRow = createSignatureRow(session, valueDict)
            message = "Unable to create signature row"
            if signatureRow is not None:
                session.add(signatureRow)
                message = "Added signature to database: {}".format(signatureRow.PrimaryKey)
                resp.status = falcon.HTTP_200

        elif "Signature" in valueDict.keys():
            message = "Unable to add Signature, already exists in database"

        resp.body = message
        print(message)

        session.commit()
        session.close() 
開發者ID:pyskell,項目名稱:LicenseServer,代碼行數:34,代碼來源:insert.py

示例3: authenticate

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_401 [as 別名]
def authenticate(self, req):
        if req.auth is None:
            raise falcon.HTTPError(
                status=falcon.HTTP_401,
                title='Authentication failed',
                description='Authorization header is missing'
                )

        auth_type, credentials = req.auth.split(' ')
              
        if auth_type.lower() != 'basic':
            raise falcon.HTTPError(
                status=falcon.HTTP_401,
                title='Authentication failed',
                description="Expected 'Authorization: Basic <credentials>' header"
                )

        try:
            decoded_credentials = base64.b64decode(credentials)
            login, password = decoded_credentials.decode().split(':')
        except Exception as e:
            raise falcon.HTTPError(
                status=falcon.HTTP_401,
                title='Authentication failed',
                description='Invalid credentials ({})'.format(e)
                )
        user = self._users_repository.get_user_by_login_and_password(login, password)

        if user is None:
            raise falcon.HTTPError(
                status=falcon.HTTP_401,
                title='Authentication failed',
                description='Invalid credentials'
                )
        return user 
開發者ID:Ermlab,項目名稱:python-ddd,代碼行數:37,代碼來源:authentication.py

示例4: test_should_fail_not_delegate_ok_cross_tenant_id

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_401 [as 別名]
def test_should_fail_not_delegate_ok_cross_tenant_id(self, _, __):
        _init_resource(self)
        res = self.simulate_request(
            path='/log/single',
            method='POST',
            query_string='tenant_id=1',
            headers={
                'Content-Type': 'application/json',
                'Content-Length': '0'
            }
        )
        self.assertEqual(falcon.HTTP_401, res.status) 
開發者ID:openstack,項目名稱:monasca-log-api,代碼行數:14,代碼來源:test_logs.py

示例5: __call__

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_401 [as 別名]
def __call__(self, f):
        @functools.wraps(f)
        def secure_handler(slf, req, resp, *args, **kwargs):
            ctx = req.context
            policy_eng = ctx.policy_engine
            # policy engine must be configured
            if policy_eng is not None:
                LOG.debug(
                    'Enforcing policy %s on request %s using engine %s',
                    self.action,
                    ctx.request_id,
                    policy_eng.__class__.__name__,
                    ctx=ctx)
            else:
                LOG.error('No policy engine configured', ctx=ctx)
                raise ex.PromenadeException(
                    title="Auth is not being handled by any policy engine",
                    status=falcon.HTTP_500,
                    retry=False)

            authorized = False
            try:
                if policy_eng.authorize(self.action, ctx):
                    LOG.debug('Request is authorized', ctx=ctx)
                    authorized = True
            except Exception:
                LOG.exception(
                    'Error authorizing request for action %s',
                    self.action,
                    ctx=ctx)
                raise ex.ApiError(
                    title="Expectation Failed",
                    status=falcon.HTTP_417,
                    retry=False)

            if authorized:
                return f(slf, req, resp, *args, **kwargs)
            else:
                # raise the appropriate response exeception
                if ctx.authenticated:
                    LOG.error(
                        'Unauthorized access attempted for action %s',
                        self.action,
                        ctx=ctx)
                    raise ex.ApiError(
                        title="Forbidden",
                        status=falcon.HTTP_403,
                        description="Credentials do not permit access",
                        retry=False)
                else:
                    LOG.error(
                        'Unathenticated access attempted for action %s',
                        self.action,
                        ctx=ctx)
                    raise ex.ApiError(
                        title="Unauthenticated",
                        status=falcon.HTTP_401,
                        description="Credentials are not established",
                        retry=False)

        return secure_handler 
開發者ID:airshipit,項目名稱:promenade,代碼行數:63,代碼來源:policy.py

示例6: check_auth

# 需要導入模塊: import falcon [as 別名]
# 或者: from falcon import HTTP_401 [as 別名]
def check_auth(ctx, rule):
    """Checks the authorization to the requested rule

    :param ctx: the request context for the action being performed
    :param rule: the name of the policy rule to validate the user in the
        context against

    Returns if authorized, otherwise raises an ApiError.
    """
    try:
        policy_eng = ctx.policy_engine
        LOG.info("Policy Engine: %s", policy_eng.__class__.__name__)
        # perform auth
        LOG.info("Enforcing policy %s on request %s", rule, ctx.request_id)
        # policy engine must be configured
        if policy_eng is None:
            LOG.error(
                "Error-Policy engine required-action: %s", rule)
            raise AppError(
                title="Auth is not being handled by any policy engine",
                status=falcon.HTTP_500,
                retry=False
            )
        if policy_eng.authorize(rule, ctx):
            # authorized - log and return
            LOG.info("Request to %s is authorized", rule)
            return
    except Exception as ex:
        # couldn't service the auth request
        LOG.exception("Error - Expectation Failed - action: %s", rule)
        raise ApiError(
            title="Expectation Failed",
            status=falcon.HTTP_417,
            retry=False
        )
    # raise the appropriate response exeception
    if ctx.authenticated:
        # authenticated but not authorized
        LOG.error("Error: Forbidden access - action: %s", rule)
        raise ApiError(
            title="Forbidden",
            status=falcon.HTTP_403,
            description="Credentials do not permit access",
            retry=False
        )
    else:
        LOG.error("Error - Unauthenticated access")
        raise ApiError(
            title="Unauthenticated",
            status=falcon.HTTP_401,
            description="Credentials are not established",
            retry=False
        ) 
開發者ID:airshipit,項目名稱:shipyard,代碼行數:55,代碼來源:policy.py


注:本文中的falcon.HTTP_401屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。