|
|
|
@ -1,5 +1,6 @@
@@ -1,5 +1,6 @@
|
|
|
|
|
''' User Authentication and Authorization ''' |
|
|
|
|
|
|
|
|
|
from passlib.context import CryptContext |
|
|
|
|
from pyramid.authentication import AuthTktAuthenticationPolicy |
|
|
|
|
from pyramid.authorization import ACLAuthorizationPolicy |
|
|
|
|
from pyramid.security import Authenticated, Everyone |
|
|
|
@ -7,6 +8,10 @@ from pyramid.security import Authenticated, Everyone
@@ -7,6 +8,10 @@ from pyramid.security import Authenticated, Everyone
|
|
|
|
|
from .models import User |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#: create a crypt context for password hashes, configured in :func:`includeme()` |
|
|
|
|
passlib_context = CryptContext() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AuthenticationPolicy(AuthTktAuthenticationPolicy): |
|
|
|
|
''' How to authenticate users ''' |
|
|
|
|
|
|
|
|
@ -54,6 +59,11 @@ def includeme(config):
@@ -54,6 +59,11 @@ def includeme(config):
|
|
|
|
|
Activate this setup using ``config.include('ordr2.security')``. |
|
|
|
|
''' |
|
|
|
|
settings = config.get_settings() |
|
|
|
|
|
|
|
|
|
# configure the passlib context manager for hashing user passwords |
|
|
|
|
passlib_context.load_path(settings['passlib.config']) |
|
|
|
|
|
|
|
|
|
# config for authentication and authorization |
|
|
|
|
authn_policy = AuthenticationPolicy( |
|
|
|
|
settings['auth.secret'], |
|
|
|
|
hashalg='sha512', |
|
|
|
@ -61,3 +71,4 @@ def includeme(config):
@@ -61,3 +71,4 @@ def includeme(config):
|
|
|
|
|
config.set_authentication_policy(authn_policy) |
|
|
|
|
config.set_authorization_policy(ACLAuthorizationPolicy()) |
|
|
|
|
config.add_request_method(get_user, 'user', reify=True) |
|
|
|
|
|
|
|
|
|