Permalink
Browse files

configure a session authentication policy by default

  • Loading branch information...
1 parent dd22aa7 commit c62ab12187126b4d3fd79f48710ccc4579c3ae11 @mcdonc mcdonc committed Apr 8, 2012
Showing with 9 additions and 6 deletions.
  1. +0 −4 demo/demo/__init__.py
  2. +2 −0 substanced/principal/__init__.py
  3. +6 −2 substanced/sdi/__init__.py
  4. +1 −0 substanced/sdi/helpers.py
View
@@ -1,15 +1,11 @@
from pyramid.config import Configurator
from substanced.site import Site
-from pyramid.session import UnencryptedCookieSessionFactoryConfig
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(settings=settings, root_factory=Site.root_factory)
config.add_static_view('static', 'static', cache_max_age=3600)
config.include('substanced')
- secret = settings['substanced.secret']
- session_factory = UnencryptedCookieSessionFactoryConfig(secret)
- config.set_session_factory(session_factory)
config.scan()
return config.make_wsgi_app()
@@ -341,6 +341,8 @@ def group_modified(group, event):
def groupfinder(userid, request):
context = request.context
objectmap = find_service(context, 'objectmap')
+ if objectmap is None:
+ return None
user = objectmap.object_for(userid)
if user is None:
return None
@@ -1,13 +1,14 @@
import inspect
import venusian
-from pyramid.authentication import AuthTktAuthenticationPolicy
+from pyramid.authentication import SessionAuthenticationPolicy
from pyramid.exceptions import ConfigurationError
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.security import authenticated_userid
from pyramid.compat import is_nonstr_iter
from pyramid.traversal import resource_path_tuple
from pyramid.httpexceptions import HTTPFound
+from pyramid.session import UnencryptedCookieSessionFactoryConfig
from pyramid.view import view_config
from pyramid.interfaces import IView
from pyramid.events import (
@@ -17,6 +18,7 @@
from . import helpers
from ..service import find_service
+from ..principal import groupfinder
def as_sorted_tuple(val):
if not is_nonstr_iter(val):
@@ -173,7 +175,9 @@ def includeme(config): # pragma: no cover
if secret is None:
raise ConfigurationError(
'You must set a substanced.secret key in your .ini file')
- authn_policy = AuthTktAuthenticationPolicy(secret)
+ session_factory = UnencryptedCookieSessionFactoryConfig(secret)
+ config.set_session_factory(session_factory)
+ authn_policy = SessionAuthenticationPolicy(callback=groupfinder)
authz_policy = ACLAuthorizationPolicy()
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
@@ -41,6 +41,7 @@ def get_mgmt_views(request, context=None):
req.context = context
req.matched_route = request.matched_route
req.method = 'GET'
+ req.registry = request.registry
for data in introspector.get_category('sdi views'):
related = data['related']

0 comments on commit c62ab12

Please sign in to comment.