当前位置: 首页>>代码示例>>Python>>正文


Python exc.HTTPUnauthorized方法代码示例

本文整理汇总了Python中webob.exc.HTTPUnauthorized方法的典型用法代码示例。如果您正苦于以下问题:Python exc.HTTPUnauthorized方法的具体用法?Python exc.HTTPUnauthorized怎么用?Python exc.HTTPUnauthorized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webob.exc的用法示例。


在下文中一共展示了exc.HTTPUnauthorized方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: change_password

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def change_password(self, **kw):
        ap = plugin.AuthenticationProvider.get(request)
        try:
            enforce_hibp_password_check(ap, kw['pw'], '.')

            ap.set_password(c.user, kw['oldpw'], kw['pw'])
            session['_id'] = _session_id()  # new one so even if this session had been intercepted somehow, its invalid
            session.save()
            c.user.set_tool_data('allura', pwd_reset_preserve_session=session.id)
            c.user.set_tool_data('AuthPasswordReset', hash='', hash_expiry='')

        except wexc.HTTPUnauthorized:
            flash('Incorrect password', 'error')
            redirect('.')
        flash('Password changed')
        h.auditlog_user('Password changed')
        email_body = g.jinja2_env.get_template('allura:templates/mail/password_changed.md').render(dict(
            user=c.user,
            config=config,
        ))
        send_system_mail_to_user(c.user, 'Password Changed', email_body)
        redirect('.') 
开发者ID:apache,项目名称:allura,代码行数:24,代码来源:auth.py

示例2: set_password

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def set_password(self, user, old_password, new_password):
        dn = ldap_user_dn(user.username)
        if old_password:
            ldap_ident = dn
            ldap_pass = old_password.encode('utf-8')
        else:
            ldap_ident = ldap_pass = None
        try:
            con = ldap_conn(ldap_ident, ldap_pass)
            new_password = self._encode_password(new_password)
            con.modify_s(
                dn, [(ldap.MOD_REPLACE, b'userPassword', new_password)])
            con.unbind_s()
            user.last_password_updated = datetime.utcnow()
            session(user).flush(user)
        except ldap.INVALID_CREDENTIALS:
            raise exc.HTTPUnauthorized() 
开发者ID:apache,项目名称:allura,代码行数:19,代码来源:plugin.py

示例3: validate

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def validate(self, value, state=None):
        super(LoginForm, self).validate(value, state=state)
        auth_provider = plugin.AuthenticationProvider.get(request)

        # can't use a validator attr on the username TextField, since the antispam encoded name changes and doesn't
        # match the name used in the form submission
        auth_provider.username_validator(long_message=False).to_python(value['username'])

        try:
            auth_provider.login()
        except exc.HTTPUnauthorized:
            msg = 'Invalid login'
            raise Invalid(
                msg,
                dict(username=value['username'], rememberme=value.get('rememberme'),
                     return_to=value.get('return_to')),
                None)
        except exc.HTTPBadRequest as e:
            raise Invalid(
                e.args[0],
                dict(username=value['username'], rememberme=value.get('rememberme'),
                     return_to=value.get('return_to')),
                None)
        return value 
开发者ID:apache,项目名称:allura,代码行数:26,代码来源:auth_widgets.py

示例4: test_login_overlay

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def test_login_overlay(self, c, require_access, request):
        pi = base.ProjectImporter(mock.Mock())
        require_access.side_effect = HTTPUnauthorized

        c.show_login_overlay = False
        request.path = '/test-importer/'
        pi._check_security()
        self.assertEqual(c.show_login_overlay, True)

        c.show_login_overlay = False
        request.path = '/test-importer/check_names/'
        pi._check_security()
        self.assertEqual(c.show_login_overlay, True)

        c.show_login_overlay = False
        request.path = '/test-importer/process/'
        with td.raises(HTTPUnauthorized):
            pi._check_security()
        self.assertEqual(c.show_login_overlay, False) 
开发者ID:apache,项目名称:allura,代码行数:21,代码来源:test_base.py

示例5: _check_access

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def _check_access(self, req, environ, start_response):
        if req.app.private_token:
            sent_private_token = req.GET.get("private_token", None)
            if not (req.app.private_token == sent_private_token):
                return exc.HTTPUnauthorized()(environ, start_response) 
开发者ID:galaxyproject,项目名称:pulsar,代码行数:7,代码来源:routes.py

示例6: _unauthorized

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def _unauthorized(self, message):
        body = {'error': {
            'code': 401,
            'title': 'Unauthorized',
            'message': message,
        }}

        raise exc.HTTPUnauthorized(body=jsonutils.dumps(body),
                                   headers=self.reject_auth_headers,
                                   charset='UTF-8',
                                   content_type='application/json') 
开发者ID:openstack,项目名称:vitrage,代码行数:13,代码来源:keycloak.py

示例7: _unauthorized

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def _unauthorized(self, message):
        body = {'error': {
            'code': httplib.UNAUTHORIZED,
            'title': httplib.responses.get(httplib.UNAUTHORIZED),
            'message': message,
        }}

        raise exc.HTTPUnauthorized(body=jsonutils.dumps(body),
                                   headers=self.reject_auth_headers,
                                   charset='UTF-8',
                                   content_type='application/json') 
开发者ID:openstack,项目名称:vitrage,代码行数:13,代码来源:basic_and_keystone_auth.py

示例8: abort_unauthorized

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def abort_unauthorized(msg=None):
    raise exc.HTTPUnauthorized('Unauthorized - %s' % msg if msg else 'Unauthorized') 
开发者ID:StackStorm,项目名称:st2,代码行数:4,代码来源:router.py

示例9: _requestAuth

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def _requestAuth(self, detail=None):
        raise exc.HTTPUnauthorized(
                detail=detail,
                headers=[('WWW-Authenticate',
                    'Basic realm="Conary Repository"')],
                ) 
开发者ID:sassoftware,项目名称:conary,代码行数:8,代码来源:repos_web.py

示例10: _verify_addr

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def _verify_addr(self, addr, do_auth_check=True):
        confirmed_by_other = M.EmailAddress.find(dict(email=addr.email, confirmed=True)).all() if addr else []
        confirmed_by_other = [item for item in confirmed_by_other if item != addr]

        if addr and not confirmed_by_other:
            user = addr.claimed_by_user(include_pending=True)
            if do_auth_check and not user.pending:
                # pending is ok, since you can't be logged in to your account yet :)
                require_authenticated()
                if c.user != user:
                    flash('You must be logged in to the correct account', 'warning')
                    # raising HTTPUnauthorized does this same logic, but doesn't preserve the flash() message
                    # so we have to do similar logic as LoginRedirectMiddleware right here
                    login_url = tg.config.get('auth.login_url', '/auth/')
                    return_to = request.environ['PATH_INFO']
                    if request.environ.get('QUERY_STRING'):
                        return_to += '?' + request.environ['QUERY_STRING']
                    redirect(login_url, {'return_to': return_to})

            if do_auth_check:
                # don't send email when do_auth_check=False (e.g. admin panel move)
                email_body = g.jinja2_env.get_template('allura:templates/mail/email_added.md').render(dict(
                    user=user,
                    config=config,
                    addr=addr.email
                ))
                send_system_mail_to_user(user, 'New Email Address Added', email_body)

            addr.confirmed = True
            flash('Email address confirmed')
            h.auditlog_user('Email address verified: %s',  addr.email, user=user)
            if user.get_pref('email_address') is None:
                user.set_pref('email_address', addr.email)
            if user.pending:
                plugin.AuthenticationProvider.get(request).activate_user(user)
                projectname = plugin.AuthenticationProvider.get(request).user_project_shortname(user)
                n = M.Neighborhood.query.get(name='Users')
                n.register_project(projectname, user=user, user_project=True)

        else:
            flash('Unknown verification link', 'error') 
开发者ID:apache,项目名称:allura,代码行数:43,代码来源:auth.py

示例11: pwd_expired_change

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def pwd_expired_change(self, **kw):
        require_authenticated()
        return_to = kw.get('return_to')
        ap = plugin.AuthenticationProvider.get(request)
        failure_redirect_url = tg.url('/auth/pwd_expired', dict(return_to=return_to))

        enforce_hibp_password_check(ap, kw['pw'], failure_redirect_url)

        try:
            expired_username = session.get('expired-username')
            expired_user = M.User.query.get(username=expired_username) if expired_username else None
            ap.set_password(expired_user or c.user, kw['oldpw'], kw['pw'])
            expired_user.set_tool_data('allura', pwd_reset_preserve_session=session.id)
            expired_user.set_tool_data('AuthPasswordReset', hash='', hash_expiry='')  # Clear password reset token

        except wexc.HTTPUnauthorized:
            flash('Incorrect password', 'error')
            redirect(failure_redirect_url)

        flash('Password changed')
        session.pop('pwd-expired', None)
        session['username'] = session.get('expired-username')
        session.pop('expired-username', None)
        expired_reason = session.pop('expired-reason', None)

        session.save()
        h.auditlog_user('Password reset ({})'.format(expired_reason))
        if return_to and return_to != request.url:
            redirect(return_to)
        else:
            redirect('/') 
开发者ID:apache,项目名称:allura,代码行数:33,代码来源:auth.py

示例12: request_token

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def request_token(self, **kw):
        req = oauth.Request.from_request(
            request.method,
            request.url.split('?')[0],
            headers=request.headers,
            parameters=dict(request.params),
            query_string=request.query_string
        )
        consumer_token = M.OAuthConsumerToken.query.get(
            api_key=req['oauth_consumer_key'])
        if consumer_token is None:
            log.error('Invalid consumer token')
            raise exc.HTTPUnauthorized
        consumer = consumer_token.consumer
        try:
            self.server.verify_request(req, consumer, None)
        except oauth.Error as e:
            log.error('Invalid signature %s %s', type(e), e)
            raise exc.HTTPUnauthorized
        req_token = M.OAuthRequestToken(
            consumer_token_id=consumer_token._id,
            callback=req.get('oauth_callback', 'oob')
        )
        session(req_token).flush()
        log.info('Saving new request token with key: %s', req_token.api_key)
        return req_token.to_string() 
开发者ID:apache,项目名称:allura,代码行数:28,代码来源:rest.py

示例13: access_token

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def access_token(self, **kw):
        req = oauth.Request.from_request(
            request.method,
            request.url.split('?')[0],
            headers=request.headers,
            parameters=dict(request.params),
            query_string=request.query_string
        )
        consumer_token = M.OAuthConsumerToken.query.get(
            api_key=req['oauth_consumer_key'])
        request_token = M.OAuthRequestToken.query.get(
            api_key=req['oauth_token'])
        if consumer_token is None:
            log.error('Invalid consumer token')
            raise exc.HTTPUnauthorized
        if request_token is None:
            log.error('Invalid request token')
            raise exc.HTTPUnauthorized
        pin = req['oauth_verifier']
        if pin != request_token.validation_pin:
            log.error('Invalid verifier')
            raise exc.HTTPUnauthorized
        rtok = request_token.as_token()
        rtok.set_verifier(pin)
        consumer = consumer_token.consumer
        try:
            self.server.verify_request(req, consumer, rtok)
        except oauth.Error as e:
            log.error('Invalid signature %s %s', type(e), e)
            raise exc.HTTPUnauthorized
        acc_token = M.OAuthAccessToken(
            consumer_token_id=consumer_token._id,
            request_token_id=request_token._id,
            user_id=request_token.user_id,
        )
        return acc_token.to_string() 
开发者ID:apache,项目名称:allura,代码行数:38,代码来源:rest.py

示例14: test_set_password_with_old_password

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def test_set_password_with_old_password(self):
        user = Mock()
        user.__ming__ = Mock()
        self.provider.validate_password = lambda u, p: False
        self.provider._encode_password = Mock()
        assert_raises(
            exc.HTTPUnauthorized,
            self.provider.set_password, user, 'old', 'new')
        assert_equal(self.provider._encode_password.call_count, 0)

        self.provider.validate_password = lambda u, p: True
        self.provider.set_password(user, 'old', 'new')
        self.provider._encode_password.assert_called_once_with('new') 
开发者ID:apache,项目名称:allura,代码行数:15,代码来源:test_plugin.py

示例15: test_post_permission_check

# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPUnauthorized [as 别名]
def test_post_permission_check():
    d = M.Discussion(shortname='test', name='test')
    t = M.Thread.new(discussion_id=d._id, subject='Test Thread')
    c.user = M.User.anonymous()
    try:
        t.post('This post will fail the check.')
        assert False, "Expected an anonymous post to fail."
    except exc.HTTPUnauthorized:
        pass
    t.post('This post will pass the check.', ignore_security=True) 
开发者ID:apache,项目名称:allura,代码行数:12,代码来源:test_discussion.py


注:本文中的webob.exc.HTTPUnauthorized方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。