Hi,
I've been using the following auth policies for years, it's been working fine:
authn_policy = CustomSessionAuthenticationPolicy()
authz_policy = ACLAuthorizationPolicy()
config = Configurator(
settings=settings,
root_factory=RootFactory,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
)
class RootFactory(object):
__acl__ = [
(Allow, Authenticated, 'user'),
(Allow, 'g:admin', 'admin'),
(Allow, 'g:superadmin', ALL_PERMISSIONS),
]
def __init__(self, request):
pass
class CustomSessionAuthenticationPolicy(SessionAuthenticationPolicy):
def authenticated_userid(self, request):
def effective_principals(self, request):
principals = [Everyone]
if request.user:
principals += [Authenticated]
principals += ['g:superadmin', 'g:admin']
return principals
---
I'm trying to migrate off from this, as I simply don't understand what is happening behind and I prefer a much simpler view deriver based approach.
Basically, with a couple of view derivers I could solve all my problems in a few hours, and it also allows me much more flexibility. For example for some views now I can do auth based on API tokens, while most of the views are using session based auth.
My questions is, how can I make the auth/security policies as simple as possible? All I need is working CSRF, remember and forget.
I'm on 1.10 but I'm happy to migrate to 2.0 if that allows a simplified approach.
So far I was able to get it down to this:
config = Configurator(
settings=settings,
root_factory=RootFactory,
authentication_policy=SessionAuthenticationPolicy(),
)
class RootFactory(object):
__acl__ = [
(Allow, Authenticated, 'user'),
]
def __init__(self, request):
pass
Session is via pyramid_session_redis.
Thanks,
Zsolt