Skip to content
Snippets Groups Projects
Commit de62f54d authored by Julian's avatar Julian
Browse files

Readded ldap starttls support after accidentally removing it in a721ff1b

parent 997f3a65
No related branches found
No related tags found
No related merge requests found
...@@ -46,7 +46,8 @@ class FlaskLDAPMapper(LDAPMapper): ...@@ -46,7 +46,8 @@ class FlaskLDAPMapper(LDAPMapper):
current_app.ldap_mock.bind() current_app.ldap_mock.bind()
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
return ldap3.Connection(server, current_app.config["LDAP_SERVICE_BIND_DN"], return ldap3.Connection(server, current_app.config["LDAP_SERVICE_BIND_DN"],
current_app.config["LDAP_SERVICE_BIND_PASSWORD"], auto_bind=True) current_app.config["LDAP_SERVICE_BIND_PASSWORD"], auto_bind=auto_bind)
ldap = FlaskLDAPMapper() ldap = FlaskLDAPMapper()
...@@ -6,6 +6,7 @@ from flask import Blueprint, render_template, request, url_for, redirect, flash, ...@@ -6,6 +6,7 @@ from flask import Blueprint, render_template, request, url_for, redirect, flash,
import ldap3 import ldap3
from ldap3.core.exceptions import LDAPBindError, LDAPPasswordIsMandatoryError from ldap3.core.exceptions import LDAPBindError, LDAPPasswordIsMandatoryError
from ldapalchemy.core import encode_filter
from uffd.user.models import User from uffd.user.models import User
from uffd.ldap import ldap from uffd.ldap import ldap
...@@ -31,11 +32,12 @@ def login_get_user(loginname, password): ...@@ -31,11 +32,12 @@ def login_get_user(loginname, password):
return None return None
else: else:
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
try: try:
conn = ldap3.Connection(server, dn, password, auto_bind=True) conn = ldap3.Connection(server, dn, password, auto_bind=auto_bind)
except (LDAPBindError, LDAPPasswordIsMandatoryError): except (LDAPBindError, LDAPPasswordIsMandatoryError):
return None return None
conn.search(conn.user, '(objectClass=person)') conn.search(conn.user, encode_filter(current_app.config["LDAP_USER_SEARCH_FILTER"]))
if len(conn.entries) != 1: if len(conn.entries) != 1:
return None return None
return User.query.get(dn) return User.query.get(dn)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment