本文整理汇总了Python中pyramid.config.Configurator.ldap_set_login_query方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.ldap_set_login_query方法的具体用法?Python Configurator.ldap_set_login_query怎么用?Python Configurator.ldap_set_login_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.config.Configurator
的用法示例。
在下文中一共展示了Configurator.ldap_set_login_query方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_ldap
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import ldap_set_login_query [as 别名]
def init_ldap(self):
"""Lazy LDAP connector construction"""
if not self.request.ldap_activated:
# Warn if LDAP is about to be used but not set up.
self.session.flash('<strong>Error</strong>:LDAP does not seem to be set up correctly!', queue='danger')
elif getattr(self.request, 'ldap_connector', None) is None:
LOGGER.debug('Set up LDAP connector...')
ldap_settings = self.request.db.ldap.find_one()
# Set LDAP settings
from . import ldap
if ldap_settings['scope'] == 'ONELEVEL':
ldap_scope = ldap.SCOPE_ONELEVEL
else:
ldap_scope = ldap.SCOPE_SUBTREE
# FK: Do we have to think about race conditions here?
from pyramid.config import Configurator
config = Configurator(registry=self.request.registry)
config.ldap_setup(ldap_settings['server'],
bind=ldap_settings['bind'],
passwd=ldap_settings['passwd'])
config.ldap_set_login_query(
base_dn=ldap_settings['base_dn'],
filter_tmpl=ldap_settings['filter_tmpl'],
scope=ldap_scope)
config.commit()
示例2: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import ldap_set_login_query [as 别名]
def main(global_config, **settings):
config = Configurator(settings=settings, root_factory=RootFactory)
config.include('pyramid_ldap3')
config.include('pyramid_chameleon')
config.set_authentication_policy(
AuthTktAuthenticationPolicy('seekr1t', callback=groupfinder))
config.set_authorization_policy(
ACLAuthorizationPolicy())
config.ldap_setup(
'ldap://localhost',
bind='CN=ldap user,CN=Users,DC=example,DC=com',
passwd='[email protected]')
config.ldap_set_login_query(
'CN=Users,DC=example,DC=com',
'(sAMAccountName=%(login)s)',
scope=ldap3.SEARCH_SCOPE_WHOLE_SUBTREE,
cache_period=0)
config.ldap_set_groups_query(
'CN=Users,DC=example,DC=com',
#'(member:1.2.840.113556.1.4.1941:=%(userdn)s)',
'(&(objectCategory=group)(member=%(userdn)s))',
cache_period=60)
config.add_route('sampleapp.root', '/')
config.add_route('sampleapp.login', '/login')
config.add_route('sampleapp.logout', '/logout')
config.scan('.views')
return config.make_wsgi_app()
示例3: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import ldap_set_login_query [as 别名]
def main(global_config, **settings):
config = Configurator(settings=settings, root_factory=RootFactory)
config.include('pyramid_ldap3')
config.include('pyramid_chameleon')
config.set_authentication_policy(
AuthTktAuthenticationPolicy('seekr1t', callback=groupfinder))
config.set_authorization_policy(
ACLAuthorizationPolicy())
config.ldap_setup(
'ldap://ldap.forumsys.com',
bind='cn=read-only-admin,dc=example,dc=com',
passwd='password')
config.ldap_set_login_query(
'dc=example,dc=com',
# '(sAMAccountName=%(login)s)',
'(uid=%(login)s)',
scope=ldap3.SUBTREE,
cache_period=0)
config.ldap_set_groups_query(
'dc=example,dc=com',
# '(member:1.2.840.113556.1.4.1941:=%(userdn)s)',
# '(&(objectCategory=group)(member=%(userdn)s))',
'(&(objectClass=groupOfUniqueNames)(uniqueMember=%(userdn)s))',
cache_period=60)
config.add_route('sampleapp.root', '/')
config.add_route('sampleapp.login', '/login')
config.add_route('sampleapp.logout', '/logout')
config.scan('.views')
return config.make_wsgi_app()
示例4: ldap_prepare
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import ldap_set_login_query [as 别名]
def ldap_prepare(self):
"""Lazy LDAP connector construction"""
ldap_settings = self.db.ldap.find_one()
if ldap_settings is None:
# Warn if LDAP is about to be used but not set up.
self.session.flash("LDAP does not seem to be set up correctly!", queue="danger")
elif getattr(self.request, "ldap_connector", None) is None:
logger.debug("Set up LDAP connector...")
# Set LDAP settings
import ldap
if ldap_settings["scope"] == "ONELEVEL":
ldap_scope = ldap.SCOPE_ONELEVEL
else:
ldap_scope = ldap.SCOPE_SUBTREE
# FK: Do we have to think about race conditions here?
from pyramid.config import Configurator
config = Configurator(registry=self.request.registry)
config.ldap_setup(ldap_settings["server"], bind=ldap_settings["bind"], passwd=ldap_settings["passwd"])
config.ldap_set_login_query(
base_dn=ldap_settings["base_dn"], filter_tmpl=ldap_settings["filter_tmpl"], scope=ldap_scope
)
config.commit()
示例5: view
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import ldap_set_login_query [as 别名]
def view(self):
# Get LDAP settings
ldap_settings = self.request.db.ldap.find_one()
if ldap_settings is None:
ldap_settings = dict()
# Generate form
from phoenix.settings.schema import LdapSchema
ldap_form = Form(schema=LdapSchema().bind(request=self.request), buttons=('submit',), formid='deform')
if 'submit' in self.request.params:
check_csrf_token(self.request)
try:
# Validate form
appstruct = ldap_form.validate(list(self.request.params.items()))
except ValidationFailure as e:
LOGGER.exception('Validation failed!')
return dict(title='LDAP Settings', form=e.render())
else:
# Update LDAP settings
ldap_settings['server'] = appstruct['server']
ldap_settings['use_tls'] = appstruct['use_tls']
ldap_settings['bind'] = appstruct['bind']
ldap_settings['passwd'] = appstruct['passwd']
ldap_settings['base_dn'] = appstruct['base_dn']
ldap_settings['filter_tmpl'] = appstruct['filter_tmpl']
ldap_settings['scope'] = appstruct['scope']
# Optional:
ldap_settings['name'] = appstruct['name']
ldap_settings['email'] = appstruct['email']
self.request.db.ldap.save(ldap_settings)
import ldap
if ldap_settings['scope'] == 'ONELEVEL':
ldap_scope = ldap.SCOPE_ONELEVEL
else:
ldap_scope = ldap.SCOPE_SUBTREE
from pyramid.config import Configurator
config = Configurator(registry=self.request.registry)
config.ldap_setup(
ldap_settings['server'],
bind=ldap_settings['bind'],
passwd=ldap_settings['passwd'],
use_tls=ldap_settings['use_tls'])
config.ldap_set_login_query(
base_dn=ldap_settings['base_dn'],
filter_tmpl=ldap_settings['filter_tmpl'],
scope=ldap_scope)
config.commit()
self.session.flash('Successfully updated LDAP settings!', queue='success')
# Display form
return dict(title='LDAP Settings', form=ldap_form.render(ldap_settings))
示例6: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import ldap_set_login_query [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
settings['mako.directories'] = os.path.join(here, 'templates')
# afegit del auth module
authn_policy = AuthTktAuthenticationPolicy(
'sosecret', callback=groupfinder, hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
config = Configurator(root_factory='.models.RootFactory', settings=settings)
# setup LDAP server
config.include("pyramid_ldap")
config.ldap_setup('ldap://enric.tk',
bind="",passwd="", # anonymous bind
# bind = 'CN=admin,DC=enric,DC=tk',
# passwd = 'tralala'
)
config.ldap_set_login_query(
base_dn = "ou=usuaris,dc=enric,dc=tk",
filter_tmpl = "(uid=%(login)s)",
scope = ldap.SCOPE_ONELEVEL,
)
config.ldap_set_groups_query(
base_dn='ou=grups,dc=enric,dc=tk',
filter_tmpl='(&(objectClass=groupOfNames)(member=%(userdn)s))',
scope = ldap.SCOPE_SUBTREE,
# cache_period = 600,
)
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(authz_policy)
# static view setup
#config.add_static_view('static', os.path.join(here, 'static'))
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('keops', '/keops')
config.add_route('temple', '/temple')
config.add_route('cairo', '/cairo')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.scan()
return config.make_wsgi_app()
示例7: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import ldap_set_login_query [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(
root_factory=Root, settings=settings,
locale_negotiator=locale_negotiator,
authentication_policy=create_authentication(settings)
)
# overwrite print routes
config.add_route(
"lux_printproxy_report_create",
"/printproxy/report.{format}",
request_method="POST"
)
config.add_route(
"lux_printproxy_report_get",
"/printproxy/report/{ref}",
request_method="GET"
)
config.add_route(
"lux_printproxy_report_cancel",
"/printproxy/cancel/{ref}",
request_method="DELETE"
)
config.include('c2cgeoportal')
config.include('pyramid_closure')
ldap_settings = config.get_settings()['ldap']
if ldap_settings:
config.include('pyramid_ldap')
"""Config the ldap connection.
"""
config.ldap_setup(
ldap_settings['url'],
ldap_settings['bind'],
ldap_settings['passwd'],
)
config.ldap_set_login_query(
ldap_settings['base_dn'],
filter_tmpl='(login=%(login)s)',
scope=ldap.SCOPE_SUBTREE,
)
config.set_request_property(
get_user_from_request,
name='user',
reify=True
)
set_user_validator(config, ldap_user_validator)
config.add_translation_dirs('geoportailv3:locale/')
# initialize database
engines = config.get_settings()['sqlalchemy_engines']
if engines:
for engine in engines:
sqlahelper.add_engine(
sqlalchemy.create_engine(engines[engine]), name=engine)
json_renderer = JSON()
json_renderer.add_adapter(datetime.date, datetime_adapter)
json_renderer.add_adapter(datetime.datetime, datetime_adapter)
json_renderer.add_adapter(Decimal, decimal_adapter)
config.add_renderer('json', json_renderer)
# scan view decorator for adding routes
config.scan()
# add the interfaces
add_interface(config, interface_type=INTERFACE_TYPE_NGEO_CATALOGUE)
config.add_route('getuserinfo', '/getuserinfo')
config.add_route('wms', '/ogcproxywms')
config.add_route('download_sketch', '/downloadsketch')
config.add_route('qr', '/qr')
config.add_route('getfeatureinfo', '/getfeatureinfo')
config.add_route('getpoitemplate', '/getpoitemplate')
config.add_route('getremotetemplate', '/getremotetemplate')
config.add_route('isthemeprivate', '/isthemeprivate')
return config.make_wsgi_app()
示例8: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import ldap_set_login_query [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
settings = getSettings(global_config['__file__'], settings)
log = logging.getLogger(__name__)
engine = engine_from_config(settings, 'sqlalchemy.')
event.listen(engine, 'checkout', checkout_listener)
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings, root_factory=RootFactory)
config.include('pyramid_chameleon')
config.include('pyramid_ldap')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_route('home', '/')
config.add_route('user', '/user')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.add_route('signup', '/signup')
config.add_route('help', '/help')
config.add_route('search', '/search')
config.add_route('nodes', '/nodes')
config.add_route('node', '/nodes/{id}')
config.add_route('node_groups', '/node_groups')
config.add_route('node_group', '/node_groups/{id}')
config.add_route('statuses', '/statuses')
config.add_route('status', '/statuses/{id}')
config.add_route('tags', '/tags')
config.add_route('tag', '/tags/{id}')
config.add_route('hardware_profiles', '/hardware_profiles')
config.add_route('hardware_profile', '/hardware_profiles/{id}')
config.add_route('operating_systems', '/operating_systems')
config.add_route('operating_system', '/operating_systems/{id}')
config.add_route('test', '/test')
config.add_route('test2', '/test2')
config.add_route('test3', '/test3')
# API Endpoints. Order matters.
# FIXME: api_register is a special endpoint in order to use pyramid
# secirty to control access to node registrations. Don't love it
# but can't use request_param on a put request.
config.add_route('api_register', '/api/register')
config.add_route('api_nodes', '/api/nodes')
config.add_route('api_node_r', '/api/nodes/{id}/{resource}')
config.add_route('api_node', '/api/nodes/{id}')
config.add_route('api_statuses', '/api/statuses')
config.add_route('api_status_r', '/api/statuses/{id}/{resource}')
config.add_route('api_status', '/api/statuses/{id}')
config.add_route('api_tags', '/api/tags')
config.add_route('api_tag_r', '/api/tags/{id}/{resource}')
config.add_route('api_tag', '/api/tags/{id}')
config.add_route('api_tag_node_assignments', '/api/tag_node_assignments')
config.add_route('api_tag_node_assignment_r', '/api/tag_node_assignments/{id}/{resource}')
config.add_route('api_tag_node_assignment', '/api/tag_node_assignments/{id}')
config.add_route('api_tag_node_group_assignments', '/api/tag_node_group_assignments')
config.add_route('api_tag_node_group_assignment_r', '/api/tag_node_group_assignments/{id}/{resource}')
config.add_route('api_tag_node_group_assignment', '/api/tag_node_group_assignments/{id}')
config.add_route('api_hardware_profiles', '/api/hardware_profiles')
config.add_route('api_hardware_profile_r', '/api/hardware_profiles/{id}/{resource}')
config.add_route('api_hardware_profile', '/api/hardware_profiles/{id}')
config.add_route('api_operating_systems', '/api/operating_systems')
config.add_route('api_operating_system_r', '/api/operating_systems/{id}/{resource}')
config.add_route('api_operating_system', '/api/operating_systems/{id}')
config.add_route('api_node_groups', '/api/node_groups')
config.add_route('api_node_group_r', '/api/node_groups/{id}/{resource}')
config.add_route('api_node_group', '/api/node_groups/{id}')
config.add_route('api_node_group_assignments', '/api/node_group_assignments')
config.add_route('api_node_group_assignment_r', '/api/node_group_assignments/{id}/{resource}')
config.add_route('api_node_group_assignment', '/api/node_group_assignments/{id}')
config.add_route('api_hypervisor_vm_assignments', '/api/hypervisor_vm_assignments')
config.add_route('api_hypervisor_vm_assignment_r', '/api/hypervisor_vm_assignments/{id}/{resource}')
config.add_route('api_hypervisor_vm_assignment', '/api/hypervisor_vm_assignments/{id}')
config.add_route('api_ec2_objects', '/api/ec2_objects')
config.add_route('api_ec2_object_r', '/api/ec2_objects/{id}/{resource}')
config.add_route('api_ec2_object', '/api/ec2_objects/{id}')
config.add_renderer('json', JSON(indent=2))
config.add_renderer('xml', XML())
if settings['arsenal.use_ldap']:
log.info('Configuring ldap users and groups')
# Load the cert if it's defined and exists
if os.path.isfile(settings['arsenal.ldap_cert']):
ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, settings['arsenal.ldap_cert'])
config.ldap_setup(
settings['arsenal.ldap_server'] + ':' + settings['arsenal.ldap_port'],
bind = settings['arsenal.ldap_bind'],
passwd = settings['arsenal.ldap_password'],
)
config.ldap_set_login_query(
base_dn = settings['arsenal.login_base_dn'],
filter_tmpl = settings['arsenal.login_filter'],
scope = ldap.SCOPE_SUBTREE,
cache_period = 600,
)
config.ldap_set_groups_query(
#.........这里部分代码省略.........
示例9: web
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import ldap_set_login_query [as 别名]
def web(global_config, **local_settings):
""" This function returns a Pyramid WSGI application.
"""
settings = global_config
settings.update(local_settings)
# set CFG object
app_config = CFG(settings)
app_config.configure_filedepot()
settings['CFG'] = app_config
configurator = Configurator(settings=settings, autocommit=True)
# Add AuthPolicy
configurator.include("pyramid_beaker")
configurator.include("pyramid_multiauth")
policies = []
if app_config.REMOTE_USER_HEADER:
policies.append(
RemoteAuthentificationPolicy(
remote_user_email_login_header=app_config.REMOTE_USER_HEADER,
)
)
policies.append(
CookieSessionAuthentificationPolicy(
reissue_time=app_config.SESSION_REISSUE_TIME), # nopep8
)
if app_config.API_KEY:
policies.append(
ApiTokenAuthentificationPolicy(
api_key_header=TRACIM_API_KEY_HEADER,
api_user_email_login_header=TRACIM_API_USER_EMAIL_LOGIN_HEADER
),
)
policies.append(
TracimBasicAuthAuthenticationPolicy(
realm=BASIC_AUTH_WEBUI_REALM
),
)
# Hack for ldap
if AuthType.LDAP in app_config.AUTH_TYPES:
import ldap3
configurator.include('pyramid_ldap3')
configurator.ldap_setup(
app_config.LDAP_URL,
bind=app_config.LDAP_BIND_DN,
passwd=app_config.LDAP_BIND_PASS,
use_tls=app_config.LDAP_TLS,
use_pool=app_config.LDAP_USE_POOL,
pool_size=app_config.LDAP_POOL_SIZE,
pool_lifetime=app_config.LDAP_POOL_LIFETIME,
get_info=app_config.LDAP_GET_INFO
)
configurator.ldap_set_login_query(
base_dn=app_config.LDAP_USER_BASE_DN,
filter_tmpl=app_config.LDAP_USER_FILTER,
scope=ldap3.LEVEL,
attributes=ldap3.ALL_ATTRIBUTES
)
configurator.include(add_cors_support)
# make sure to add this before other routes to intercept OPTIONS
configurator.add_cors_preflight_handler()
# Default authorization : Accept anything.
configurator.set_authorization_policy(AcceptAllAuthorizationPolicy())
authn_policy = MultiAuthenticationPolicy(policies)
configurator.set_authentication_policy(authn_policy)
# INFO - GM - 11-04-2018 - set default perm
# setting default perm is needed to force authentification
# mecanism in all views.
configurator.set_default_permission(TRACIM_DEFAULT_PERM)
# Override default request
configurator.set_request_factory(TracimRequest)
# Pyramids "plugin" include.
configurator.include('pyramid_jinja2')
# Add SqlAlchemy DB
configurator.include('.models.setup_models')
# set Hapic
context = PyramidContext(
configurator=configurator,
default_error_builder=ErrorSchema(),
debug=app_config.DEBUG,
)
hapic.set_context(context)
# INFO - G.M - 2018-07-04 - global-context exceptions
# Not found
context.handle_exception(PageNotFound, HTTPStatus.NOT_FOUND)
# Bad request
context.handle_exception(WorkspaceNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST) # nopep8
context.handle_exception(UserNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST) # nopep8
context.handle_exception(ContentNotFoundInTracimRequest, HTTPStatus.BAD_REQUEST) # nopep8
context.handle_exception(WorkspaceNotFound, HTTPStatus.BAD_REQUEST)
context.handle_exception(UserDoesNotExist, HTTPStatus.BAD_REQUEST)
context.handle_exception(ContentNotFound, HTTPStatus.BAD_REQUEST)
context.handle_exception(ContentTypeNotExist, HTTPStatus.BAD_REQUEST)
context.handle_exception(ContentInNotEditableState, HTTPStatus.BAD_REQUEST)
context.handle_exception(ContentTypeNotAllowed, HTTPStatus.BAD_REQUEST)
context.handle_exception(InvalidId, HTTPStatus.BAD_REQUEST)
context.handle_exception(SameValueError, HTTPStatus.BAD_REQUEST)
# Auth exception
context.handle_exception(NotAuthenticated, HTTPStatus.UNAUTHORIZED)
context.handle_exception(UserAuthenticatedIsNotActive, HTTPStatus.FORBIDDEN)
context.handle_exception(AuthenticationFailed, HTTPStatus.FORBIDDEN)
#.........这里部分代码省略.........
示例10: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import ldap_set_login_query [as 别名]
#.........这里部分代码省略.........
)
config.add_route(
"exportgpxkml",
"/mymaps/exportgpxkml",
request_method="POST"
)
# geocoder routes
config.add_route(
"reverse_geocode",
"/geocode/reverse"
)
# pag routes
config.add_route(
"pag_url",
"/pag"
)
# pag routes
config.add_route(
"pag_report",
"/pag/report/{oid}.pdf"
)
config.add_route(
"pag_files",
"/pag/files/{_file}"
)
# full text search routes
config.add_route("fulltextsearch", "/fulltextsearch")
# layer search routes
config.add_route("layersearch", "/layersearch")
config.include('c2cgeoportal')
config.include('pyramid_closure')
config.add_translation_dirs('geoportailv3:locale/')
# initialize database
engines = config.get_settings()['sqlalchemy_engines']
if engines:
for engine in engines:
sqlahelper.add_engine(
sqlalchemy.create_engine(engines[engine]), name=engine)
from geoportailv3.views.authentication import ldap_user_validator, \
get_user_from_request
ldap_settings = config.get_settings()['ldap']
if False:
config.include('pyramid_ldap')
"""Config the ldap connection.
"""
config.ldap_setup(
ldap_settings['url'],
ldap_settings['bind'],
ldap_settings['passwd'],
)
config.ldap_set_login_query(
ldap_settings['base_dn'],
filter_tmpl='(login=%(login)s)',
scope=ldap.SCOPE_SUBTREE,
)
config.set_request_property(
get_user_from_request,
name='user',
reify=True
)
set_user_validator(config, ldap_user_validator)
json_renderer = JSON()
json_renderer.add_adapter(datetime.date, datetime_adapter)
json_renderer.add_adapter(datetime.datetime, datetime_adapter)
json_renderer.add_adapter(Decimal, decimal_adapter)
config.add_renderer('json', json_renderer)
mail_config = config.get_settings()['turbomail']
if mail_config:
interface.start(mail_config)
# scan view decorator for adding routes
config.scan()
# add the interfaces
add_interface(config, interface_type=INTERFACE_TYPE_NGEO_CATALOGUE)
config.add_route("echocsv", "/profile/echocsv", request_method="POST")
config.add_route('getuserinfo', '/getuserinfo')
config.add_route('wms', '/ogcproxywms')
config.add_route('download_sketch', '/downloadsketch')
config.add_route('download_measurement', '/downloadmeasurement')
config.add_route('qr', '/qr')
config.add_route('getfeatureinfo', '/getfeatureinfo')
config.add_route('getpoitemplate', '/getpoitemplate')
config.add_route('getremotetemplate', '/getremotetemplate')
config.add_route('isthemeprivate', '/isthemeprivate')
return config.make_wsgi_app()
示例11: main
# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import ldap_set_login_query [as 别名]
#.........这里部分代码省略.........
config.add_route(
'jsapiexample',
'/api-example'
)
config.add_route(
'jsapilayers',
'/jsapilayers'
)
config.include('c2cgeoportal')
config.include('pyramid_closure')
add_mako_renderer(config, '.appcache')
config.add_translation_dirs('geoportailv3:locale/')
# initialize database
engines = config.get_settings()['sqlalchemy_engines']
if engines:
config.registry.dbmakers = {}
for engine in engines:
if 'url' not in engines[engine]:
sqlahelper.add_engine(
sqlalchemy.create_engine(engines[engine]), name=engine)
else:
sqlahelper.add_engine(
sqlalchemy.create_engine(engines[engine]['url']),
name=engine)
config.registry.dbmakers[engine] = sessionmaker(
bind=sqlahelper.get_engine(engine))
config.add_request_method(init_db(engine),
'db_'+engine, reify=True)
from geoportailv3.views.authentication import ldap_user_validator, \
get_user_from_request
ldap_settings = config.get_settings()['ldap']
if ldap_settings:
config.include('pyramid_ldap')
"""Config the ldap connection.
"""
config.ldap_setup(
ldap_settings['url'],
ldap_settings['bind'],
ldap_settings['passwd'],
)
config.ldap_set_login_query(
ldap_settings['base_dn'],
filter_tmpl='(login=%(login)s)',
scope=ldap.SCOPE_SUBTREE,
)
config.set_request_property(
get_user_from_request,
name='user',
reify=True
)
set_user_validator(config, ldap_user_validator)
json_renderer = JSON()
json_renderer.add_adapter(datetime.date, datetime_adapter)
json_renderer.add_adapter(datetime.datetime, datetime_adapter)
json_renderer.add_adapter(Decimal, decimal_adapter)
config.add_renderer('json', json_renderer)
mail_config = config.get_settings()['turbomail']
if mail_config:
interface.start(mail_config)
# scan view decorator for adding routes
config.scan()
# add the interfaces
add_interface(config, interface_type=INTERFACE_TYPE_NGEO_CATALOGUE)
config.add_route("echocsv", "/profile/echocsv", request_method="POST")
config.add_route('getuserinfo', '/getuserinfo')
config.add_route('wms', '/ogcproxywms')
config.add_route('https_proxy', '/httpsproxy')
config.add_route('download_sketch', '/downloadsketch')
config.add_route('download', '/download')
config.add_route('download_measurement', '/downloadmeasurement')
config.add_route('preview_measurement', '/previewmeasurement')
config.add_route('qr', '/qr')
config.add_route('getfeatureinfo', '/getfeatureinfo')
config.add_route('getpoitemplate', '/getpoitemplate')
config.add_route('getremotetemplate', '/getremotetemplate')
config.add_route('isthemeprivate', '/isthemeprivate')
config.add_route('download_resource', '/downloadresource')
# Appcache manifest
config.add_route(
'appcache',
'/geoportailv3.appcache'
)
return config.make_wsgi_app()