【发布时间】:2013-01-20 05:10:03
【问题描述】:
我在 Pyramid 中的安全性正常工作时遇到了一些麻烦。我的安全本身似乎在起作用:如果用户尝试访问他们无权查看的资源,Pyramid 会抛出 HTTPForbidden 异常。问题在于,在这种情况下,它应该退回到登录视图,而这并没有发生。我只是通过堆栈跟踪获得默认的 Pyramid 异常屏幕。
我的登录视图:
from pyramid.httpexceptions import HTTPForbidden
@view_config(context = HTTPForbidden, renderer="login.mak")
@view_config(route_name = 'login', renderer='login.mak')
class Login(ViewBase):
def __init__(self, request):
super(Login, self).__init__(request)
self.data['title'] = "Login"
if request.method == 'POST':
name = request.params['username']
passwd = request.params['password']
validuser = User.check(name, passwd)
if validuser is None:
self.data['requested_path'] = request.params['requestpath']
self.__call__()
else:
headers = remember(request, str(validuser.id))
raise HTTPFound(
location = request.params['requestpath'],
headers = headers
)
else:
self.data['requested_path'] = request.url
def __call__(self):
return self.data
所有视图的默认权限设置为“视图”,我的acl 类如下所示:
from pyramid.security import Allow
from pyramid.security import Everyone
from pyramid.security import Authenticated
from pyramid.security import ALL_PERMISSIONS
# Handles ACL auth for the entire application
class RootFactory(object):
__acl__ = [
(Allow, Everyone, 'view'),
(Allow, 'Editor', 'edit'),
(Allow, 'Admin', ALL_PERMISSIONS)
]
def __init__(self, request):
pass
def groupfinder(userid, request):
from ctic.models import User
user = User.get(userid)
member_groups = []
if user != None:
member_groups.append(user.group.groupname)
return member_groups
else:
return None
正如我所说,ACL 方面似乎正在发挥作用。
有趣的是,如果我从 init.py 中删除 default_permission,一切都会正常进行。
任何关于我哪里出错的指针将不胜感激。
【问题讨论】:
标签: python authentication pyramid