Skip to content
Snippets Groups Projects
Verified Commit f43bc6cd authored by nd's avatar nd
Browse files

cache ldap connection in request

parent b9ccfd55
Branches
Tags
1 merge request!18LDAP Object Mapper
...@@ -33,6 +33,8 @@ class FlaskLDAPMapper(LDAPMapper): ...@@ -33,6 +33,8 @@ class FlaskLDAPMapper(LDAPMapper):
return request.ldap_session return request.ldap_session
def get_connection(self): def get_connection(self):
if hasattr(request, 'ldap_connection'):
return request.ldap_connection
if current_app.config.get('LDAP_SERVICE_MOCK', False): if current_app.config.get('LDAP_SERVICE_MOCK', False):
if not current_app.debug: if not current_app.debug:
raise Exception('LDAP_SERVICE_MOCK cannot be enabled on production instances') raise Exception('LDAP_SERVICE_MOCK cannot be enabled on production instances')
...@@ -47,7 +49,8 @@ class FlaskLDAPMapper(LDAPMapper): ...@@ -47,7 +49,8 @@ class FlaskLDAPMapper(LDAPMapper):
return current_app.ldap_mock return current_app.ldap_mock
server = ldap3.Server(current_app.config["LDAP_SERVICE_URL"], get_info=ldap3.ALL) server = ldap3.Server(current_app.config["LDAP_SERVICE_URL"], get_info=ldap3.ALL)
auto_bind = ldap3.AUTO_BIND_TLS_BEFORE_BIND if current_app.config["LDAP_SERVICE_USE_STARTTLS"] else True auto_bind = ldap3.AUTO_BIND_TLS_BEFORE_BIND if current_app.config["LDAP_SERVICE_USE_STARTTLS"] else True
return ldap3.Connection(server, current_app.config["LDAP_SERVICE_BIND_DN"], request.ldap_connection = ldap3.Connection(server, current_app.config["LDAP_SERVICE_BIND_DN"],
current_app.config["LDAP_SERVICE_BIND_PASSWORD"], auto_bind=auto_bind) current_app.config["LDAP_SERVICE_BIND_PASSWORD"], auto_bind=auto_bind)
return request.ldap_connection
ldap = FlaskLDAPMapper() ldap = FlaskLDAPMapper()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment