def test_sqla_auth_logging_stderr(self): past_config_sa_auth = config.sa_auth config.sa_auth = {} package = PackageWithModel() conf = AppConfig(minimal=True, root_controller=None) conf.package = package conf.model = package.model conf.auth_backend = 'sqlalchemy' conf.use_sqlalchemy = True conf['sqlalchemy.url'] = 'sqlite://' alwaysadmin = _AuthenticationForgerPlugin(fake_user_key='FAKE_USER') conf['sa_auth'] = {'authmetadata': ApplicationAuthMetadata(), 'cookie_secret':'12345', 'form_plugin':alwaysadmin, 'log_level':'DEBUG', 'authenticators':UncopiableList([('alwaysadmin', alwaysadmin)]), 'identifiers':[('alwaysadmin', alwaysadmin)], 'challengers':[]} conf['sa_auth']['log_file'] = 'stderr' app = conf.make_wsgi_app() conf['sa_auth']['log_file'] = 'stdout' app = conf.make_wsgi_app() import tempfile f = tempfile.NamedTemporaryFile() conf['sa_auth']['log_file'] = f.name app = conf.make_wsgi_app() self.config['sa_auth'] = {} self.config.auth_backend = None config.sa_auth = past_config_sa_auth
def test_setup_sqla_auth(self): if PY3: raise SkipTest() class RootController(TGController): @expose() def test(self): return str(request.environ) package = PackageWithModel() conf = AppConfig(minimal=True, root_controller=RootController()) conf.package = package conf.model = package.model conf.auth_backend = 'sqlalchemy' conf.use_sqlalchemy = True conf['sa_auth'] = {'authmetadata': ApplicationAuthMetadata(), 'dbsession': None, 'user_class': None, 'cookie_secret':'12345'} conf['sqlalchemy.url'] = 'sqlite://' app = conf.make_wsgi_app() app = TestApp(app) assert 'repoze.who.plugins' in app.get('/test') self.config.auth_backend = None
def test_setup_sqla_auth(self): if PY3: raise SkipTest() class RootController(TGController): @expose() def test(self): return str(request.environ) package = PackageWithModel() conf = AppConfig(minimal=True, root_controller=RootController()) conf.package = package conf.model = package.model conf.auth_backend = 'sqlalchemy' conf.use_sqlalchemy = True conf['sa_auth'] = { 'authmetadata': ApplicationAuthMetadata(), 'dbsession': None, 'user_class': None, 'cookie_secret': '12345' } conf['sqlalchemy.url'] = 'sqlite://' app = conf.make_wsgi_app() app = TestApp(app) assert 'repoze.who.plugins' in app.get('/test') self.config.auth_backend = None
def test_sqla_auth_middleware_only_mine(self): past_config_sa_auth = config.sa_auth config.sa_auth = {} class RootController(TGController): @expose() def test(self): return str(request.environ) @expose() def forbidden(self): response.status = "401" package = PackageWithModel() conf = AppConfig(minimal=True, root_controller=RootController()) conf.package = package conf.model = package.model conf.auth_backend = 'sqlalchemy' conf.use_sqlalchemy = True conf['sqlalchemy.url'] = 'sqlite://' alwaysadmin = _AuthenticationForgerPlugin(fake_user_key='FAKE_USER') conf['sa_auth'] = { 'authmetadata': ApplicationAuthMetadata(), 'cookie_secret': '12345', 'form_plugin': alwaysadmin, 'authenticators': UncopiableList([('alwaysadmin', alwaysadmin)]), 'identifiers': [('alwaysadmin', alwaysadmin)], 'challengers': [] } app = conf.make_wsgi_app() authenticators = [x[0] for x in conf['sa_auth']['authenticators']] assert authenticators[0] == 'alwaysadmin' assert 'sqlauth' not in authenticators challengers = [x[1] for x in conf['sa_auth']['challengers']] assert alwaysadmin in challengers app = TestApp(app) assert 'repoze.who.identity' in app.get( '/test', extra_environ={'FAKE_USER': '******'}) assert app.get('/forbidden', status=401) self.config['sa_auth'] = {} self.config.auth_backend = None config.sa_auth = past_config_sa_auth
def test_sqla_auth_middleware_only_mine(self): past_config_sa_auth = config.sa_auth config.sa_auth = {} class RootController(TGController): @expose() def test(self): return str(request.environ) @expose() def forbidden(self): response.status = "401" package = PackageWithModel() conf = AppConfig(minimal=True, root_controller=RootController()) conf.package = package conf.model = package.model conf.auth_backend = 'sqlalchemy' conf.use_sqlalchemy = True conf['sqlalchemy.url'] = 'sqlite://' alwaysadmin = _AuthenticationForgerPlugin(fake_user_key='FAKE_USER') conf['sa_auth'] = {'authmetadata': ApplicationAuthMetadata(), 'cookie_secret':'12345', 'form_plugin':alwaysadmin, 'authenticators':UncopiableList([('alwaysadmin', alwaysadmin)]), 'identifiers':[('alwaysadmin', alwaysadmin)], 'challengers':[]} app = conf.make_wsgi_app() authenticators = [x[0] for x in conf['sa_auth']['authenticators']] assert authenticators[0] == 'alwaysadmin' assert 'sqlauth' not in authenticators challengers = [x[1] for x in conf['sa_auth']['challengers']] assert alwaysadmin in challengers app = TestApp(app) assert 'repoze.who.identity' in app.get('/test', extra_environ={'FAKE_USER':'******'}) assert app.get('/forbidden', status=401) self.config['sa_auth'] = {} self.config.auth_backend = None config.sa_auth = past_config_sa_auth
def test_sqla_auth_logging_stderr(self): past_config_sa_auth = config.sa_auth config.sa_auth = {} package = PackageWithModel() conf = AppConfig(minimal=True, root_controller=None) conf.package = package conf.model = package.model conf.auth_backend = 'sqlalchemy' conf.use_sqlalchemy = True conf['sqlalchemy.url'] = 'sqlite://' alwaysadmin = _AuthenticationForgerPlugin(fake_user_key='FAKE_USER') conf['sa_auth'] = { 'authmetadata': ApplicationAuthMetadata(), 'cookie_secret': '12345', 'form_plugin': alwaysadmin, 'log_level': 'DEBUG', 'authenticators': UncopiableList([('alwaysadmin', alwaysadmin)]), 'identifiers': [('alwaysadmin', alwaysadmin)], 'challengers': [] } conf['sa_auth']['log_file'] = 'stderr' app = conf.make_wsgi_app() conf['sa_auth']['log_file'] = 'stdout' app = conf.make_wsgi_app() import tempfile f = tempfile.NamedTemporaryFile() conf['sa_auth']['log_file'] = f.name app = conf.make_wsgi_app() self.config['sa_auth'] = {} self.config.auth_backend = None config.sa_auth = past_config_sa_auth
base_config.default_renderer = 'genshi' base_config.renderers.append('genshi') # if you want raw speed and have installed chameleon.genshi # you should try to use this renderer instead. # warning: for the moment chameleon does not handle i18n translations #base_config.renderers.append('chameleon_genshi') #Configure the base SQLALchemy Setup base_config.use_sqlalchemy = True base_config.model = wsginiu.model base_config.DBSession = wsginiu.model.DBSession # YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP base_config.sa_auth.cookie_secret = "ChangeME" # Configure the authentication backend base_config.auth_backend = 'sqlalchemy' base_config.sa_auth.dbsession = model.DBSession # what is the class you want to use to search for users in the database base_config.sa_auth.user_class = model.User # what is the class you want to use to search for groups in the database base_config.sa_auth.group_class = model.Group # what is the class you want to use to search for permissions in the database base_config.sa_auth.permission_class = model.Permission # override this if you would like to provide a different who plugin for # managing login and logout of your application base_config.sa_auth.form_plugin = None # You may optionally define a page where you want users to be redirected to # on login:
# Enable json in expose base_config.renderers.append('json') # Enable genshi in expose to have a lingua franca # for extensions and pluggable apps. # You can remove this if you don't plan to use it. base_config.renderers.append('genshi') # Set the default renderer base_config.default_renderer = 'mako' base_config.renderers.append('mako') # Configure the base SQLALchemy Setup base_config.use_sqlalchemy = True base_config.model = pyjobsweb.model base_config.DBSession = pyjobsweb.model.DBSession # Configure the authentication backend base_config.auth_backend = 'sqlalchemy' # YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP base_config.sa_auth.cookie_secret = "61e866fc-c1ef-41f1-90ef-46054f5ab28d" # what is the class you want to use to search for users in the database base_config.sa_auth.user_class = model.User from tg.configuration.auth import TGAuthMetadata # This tells to TurboGears how to retrieve the data for your user class ApplicationAuthMetadata(TGAuthMetadata): def __init__(self, sa_auth): self.sa_auth = sa_auth def authenticate(self, environ, identity): login = identity['login']
# Enable genshi in expose to have a lingua franca # for extensions and pluggable apps. # You can remove this if you don't plan to use it. base_config.renderers.append('genshi') # Set the default renderer base_config.default_renderer = 'genshi' # Configure the base Ming Setup base_config.use_sqlalchemy = False base_config['tm.enabled'] = False base_config.use_ming = True base_config.model = genfunc.model base_config.DBSession = genfunc.model.DBSession # Configure the authentication backend base_config.auth_backend = 'ming' # YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP base_config.sa_auth.cookie_secret = "db50d94a-1248-4dba-b571-9de0fdc98af0" # what is the class you want to use to search for users in the database base_config.sa_auth.user_class = model.User from tg.configuration.auth import TGAuthMetadata # This tells to TurboGears how to retrieve the data for your user class ApplicationAuthMetadata(TGAuthMetadata): def __init__(self, sa_auth): self.sa_auth = sa_auth def authenticate(self, environ, identity): login = identity['login']
# if you want raw speed and have installed chameleon.genshi # you should try to use this renderer instead. # warning: for the moment chameleon does not handle i18n translations # base_config.renderers.append('chameleon_genshi') # Configure the base SQLALchemy Setup base_config.use_sqlalchemy = True base_config.model = spam.model base_config.DBSession = spam.model.DBSession # YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP base_config.sa_auth.cookie_secret = "ChangeME" # Configure the authentication backend base_config.auth_backend = "sqlalchemy" base_config.sa_auth.dbsession = model.DBSession # what is the class you want to use to search for users in the database base_config.sa_auth.user_class = model.User # what is the class you want to use to search for groups in the database base_config.sa_auth.group_class = model.Group # what is the class you want to use to search for permissions in the database base_config.sa_auth.permission_class = model.Permission # override this if you would like to provide a different who plugin for # managing login and logout of your application base_config.sa_auth.form_plugin = None # You may optionally define a page where you want users to be redirected to # on login:
# Set the default renderer base_config.default_renderer = 'kajiki' base_config.renderers.append('kajiki') # Configure Sessions, store data as JSON to avoid pickle security issues base_config['session.enabled'] = True base_config['session.data_serializer'] = 'json' # Configure the base Ming Setup base_config.use_sqlalchemy = False base_config['tm.enabled'] = False base_config.use_ming = True base_config.model = ksweb.model base_config.DBSession = ksweb.model.DBSession # Configure the authentication backend base_config.auth_backend = 'ming' # YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP base_config.sa_auth.cookie_secret = "dbb29b2e-2633-486b-88a4-2f5d75ebdc6d" # what is the class you want to use to search for users in the database base_config.sa_auth.user_class = model.User from tg.configuration.auth import TGAuthMetadata # This tells to TurboGears how to retrieve the data for your user class ApplicationAuthMetadata(TGAuthMetadata): def __init__(self, sa_auth): self.sa_auth = sa_auth def authenticate(self, environ, identity): login = identity['login']
Please note that **all the argument values are strings**. If you want to convert them into boolean, for example, you should use the :func:`paste.deploy.converters.asbool` function, as in:: from paste.deploy.converters import asbool setting = asbool(global_conf.get('the_setting')) """ from tg.configuration import AppConfig import tg2raptorized from tg2raptorized import model from tg2raptorized.lib import app_globals, helpers base_config = AppConfig() base_config.renderers = [] base_config.package = tg2raptorized #Enable json in expose base_config.renderers.append('json') #Set the default renderer base_config.default_renderer = 'mako' base_config.renderers.append('mako') base_config.use_sqlalchemy = False base_config.use_ming = False base_config.use_transaction_manager = False base_config.auth_backend = None base_config.use_toscawidgets = False
WSGIHTTPException.body_template_obj = Template('${detail}') WSGIHTTPException.html_template_obj = Template('${body}') from weberror import errormiddleware errormiddleware.error_template = lambda *a: "" from tg.configuration import AppConfig import erebot from erebot.lib import app_globals, helpers base_config = AppConfig() base_config.renderers = [] base_config.package = erebot #Enable json in expose base_config.renderers.append('json') #Set the default renderer base_config.default_renderer = 'genshi' base_config.renderers.append('genshi') # if you want raw speed and have installed chameleon.genshi # you should try to use this renderer instead. # warning: for the moment chameleon does not handle i18n translations #base_config.renderers.append('chameleon_genshi') #Configure the base SQLALchemy Setup base_config.use_sqlalchemy = False # Configure the authentication backend base_config.auth_backend = None
# You can remove this if you don't plan to use it. base_config.renderers.append("genshi") # Set the default renderer base_config.default_renderer = "jinja" base_config.renderers.append("jinja") base_config.jinja_extensions = ["jinja2.ext.with_"] # Configure the base Ming Setup base_config.use_sqlalchemy = False base_config.use_transaction_manager = False base_config.use_ming = True base_config.model = jeyzth42.model base_config.DBSession = jeyzth42.model.DBSession # Configure the authentication backend base_config.auth_backend = "ming" # YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP base_config.sa_auth.cookie_secret = "ee7240e9-ec48-4f41-b684-74ca205dea28" # what is the class you want to use to search for users in the database base_config.sa_auth.user_class = model.User from tg.configuration.auth import TGAuthMetadata # This tells to TurboGears how to retrieve the data for your user class ApplicationAuthMetadata(TGAuthMetadata): def __init__(self, sa_auth): self.sa_auth = sa_auth def authenticate(self, environ, identity): login = identity["login"]
base_config.renderers.append('kajiki') base_config[ 'templating.kajiki.strip_text'] = False # Change this in setup.py too for i18n to work. base_config.default_renderer = 'mako' base_config.sa_auth.cookie_secret = "2a817308-b0ea-4ca7-bb42-00a20c941280" # Configure Sessions, store data as JSON to avoid pickle security issues base_config['session.enabled'] = True base_config['session.data_serializer'] = 'json' # Configure the base SQLALchemy Setup base_config.use_sqlalchemy = True base_config.model = pythondispatchms.model base_config.DBSession = pythondispatchms.model.DBSession # Configure the authentication backend base_config.auth_backend = 'htpasswd' # YOU MUST CHANGE THIS VALUE IN PRODUCTION TO SECURE YOUR APP # what is the class you want to use to search for users in the database from tg.configuration.auth import TGAuthMetadata # This tells to TurboGears how to retrieve the data for your user class ApplicationAuthMetadata(TGAuthMetadata): def __init__(self, sa_auth): self.sa_auth = sa_auth def get_user(self, identity, userid): # As we use htpasswd for authentication # we cannot lookup the user in a database,