{{cookiecutter.project_slug}}/{{cookiecutter.webapp_name}}/__init__.py
changeset 17 ac2ef0786756
parent 15 046513e8c864
equal deleted inserted replaced
16:00fd75ce868e 17:ac2ef0786756
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
    10 # FOR A PARTICULAR PURPOSE.
    10 # FOR A PARTICULAR PURPOSE.
    11 #
    11 #
    12 
    12 
    13 # import standard packages
    13 from pyramid.authorization import ACLAuthorizationPolicy
       
    14 from pyramid.config import Configurator
       
    15 from pyramid.settings import asbool
    14 
    16 
    15 # import interfaces
    17 from pyams_security.utility import PyAMSAuthenticationPolicy
    16 
    18 from pyams_utils.registry import get_global_registry, set_local_registry
    17 # import packages
       
    18 from pyams_utils.registry import set_local_registry, get_global_registry
       
    19 from pyramid.config import Configurator
       
    20 
    19 
    21 
    20 
    22 def main(global_config, **settings):
    21 def main(global_config, **settings):
    23     """ This function returns a Pyramid WSGI application.
    22     """ This function returns a Pyramid WSGI application.
    24     """
    23     """
    26     set_local_registry(registry)
    25     set_local_registry(registry)
    27 
    26 
    28     config = Configurator(registry=registry)
    27     config = Configurator(registry=registry)
    29     config.setup_registry(settings=settings)
    28     config.setup_registry(settings=settings)
    30 
    29 
       
    30     authn_policy = PyAMSAuthenticationPolicy(secret='PyAMS 0.1.0',
       
    31                                              http_only=True,
       
    32                                              secure=asbool(settings.get('pyams.authentication_policy.secure', True)),
       
    33                                              credentials=('http',))
       
    34     config.set_authentication_policy(authn_policy)
       
    35     config.set_authorization_policy(ACLAuthorizationPolicy())
       
    36 
    31     config.scan()
    37     config.scan()
    32     return config.make_wsgi_app()
    38     return config.make_wsgi_app()