金字塔中的身份验证

时间:2015-04-08 11:38:16

标签: python-2.7 pyramid

我正在尝试在金字塔中设置基本导航(1.4a1)。根据{{​​3}} 上给出的教程,在登录成功之后,我们会记住,召集组。这适用于我的本地,但是当我在服务器上尝试相同时,它根本不会调用groupfinder并且在两个路由之间保持循环。这是我的代码片段:

from pyramid.security import remember, forget, authenticated_userid
from pyramid.httpexceptions import HTTPFound, HTTPForbidden
from pyramid.threadlocal import get_current_registry
from pyramid.url import route_url
from pyramid.view import view_config, forbidden_view_config


@view_config(route_name='index',
    renderer='templates:templates/index.pt',
    permission='Authenticated')
def index_view(request):
    try:
        full_name = (request.user.first_name + ' ' + request.user.last_name)
    except:
        full_name = "Anonymous"
    return {"label": label, "user_name": full_name}

@forbidden_view_config()
def forbidden(request):

    if authenticated_userid(request):
        return HTTPForbidden()

    loc = request.route_url('login.view', _query=(('next', request.path),))
    return HTTPFound(location=loc)

@view_config(route_name='login.view')
def login_view(request):

    came_from =  request.route_url('index')

    #perform some authentication
    username = 'xyz'
    if authenticate(username):
        headers = remember(request, username)
        #user was authenticated. Must call groupfinder internally and set principal as authenticated.
        return HTTPFound(location=came_from, headers=headers)
    else:
        return HTTPForbidden('Could not authenticate.')

    return HTTPForbidden('Could not authenticate.')

另外,我的ACL看起来像: __acl__ = [(Allow, Authenticated, 'Authenticated'), DENY_ALL]

有人可以告诉我为什么没有调用groupfinder吗?请求路由是否正确发生?此外,相同的代码适用于我的本地安装程序。因此,在groupfinder或ACL授权设置中没有问题。

非常感谢!

1 个答案:

答案 0 :(得分:1)

经过大量的调试和挖掘后,我发现问题非常简单。不知道行为的原因,但在调用secure = True时我添加了AuthTktAuthenticationPolicy()属性。当我删除此属性时,它开始工作。