|
|
@ -20,7 +20,7 @@ from __future__ import division, print_function, unicode_literals
|
|
|
|
import base64
|
|
|
|
import base64
|
|
|
|
|
|
|
|
|
|
|
|
from flask_simpleldap import LDAP, LDAPException
|
|
|
|
from flask_simpleldap import LDAP, LDAPException
|
|
|
|
|
|
|
|
from flask_simpleldap import ldap as pyLDAP
|
|
|
|
from .. import constants, logger
|
|
|
|
from .. import constants, logger
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -54,8 +54,16 @@ def init_app(app, config):
|
|
|
|
app.config['LDAP_USERNAME'] = ""
|
|
|
|
app.config['LDAP_USERNAME'] = ""
|
|
|
|
app.config['LDAP_PASSWORD'] = base64.b64decode("")
|
|
|
|
app.config['LDAP_PASSWORD'] = base64.b64decode("")
|
|
|
|
if bool(config.config_ldap_cert_path):
|
|
|
|
if bool(config.config_ldap_cert_path):
|
|
|
|
app.config['LDAP_REQUIRE_CERT'] = True
|
|
|
|
# app.config['LDAP_REQUIRE_CERT'] = True
|
|
|
|
app.config['LDAP_CERT_PATH'] = config.config_ldap_cert_path
|
|
|
|
# app.config['LDAP_CERT_PATH'] = config.config_ldap_cert_path
|
|
|
|
|
|
|
|
app.config['LDAP_CUSTOM_OPTIONS'] = {
|
|
|
|
|
|
|
|
pyLDAP.OPT_X_TLS_REQUIRE_CERT: pyLDAP.OPT_X_TLS_DEMAND,
|
|
|
|
|
|
|
|
pyLDAP.OPT_X_TLS_CACERTFILE: config.config_ldap_cacert_path,
|
|
|
|
|
|
|
|
pyLDAP.OPT_X_TLS_CERTFILE: config.config_ldap_cert_path,
|
|
|
|
|
|
|
|
pyLDAP.OPT_X_TLS_KEYFILE: config.config_ldap_key_path,
|
|
|
|
|
|
|
|
pyLDAP.OPT_X_TLS_NEWCTX: 0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.config['LDAP_BASE_DN'] = config.config_ldap_dn
|
|
|
|
app.config['LDAP_BASE_DN'] = config.config_ldap_dn
|
|
|
|
app.config['LDAP_USER_OBJECT_FILTER'] = config.config_ldap_user_object
|
|
|
|
app.config['LDAP_USER_OBJECT_FILTER'] = config.config_ldap_user_object
|
|
|
|
|
|
|
|
|
|
|
@ -65,10 +73,23 @@ def init_app(app, config):
|
|
|
|
app.config['LDAP_GROUP_OBJECT_FILTER'] = config.config_ldap_group_object_filter
|
|
|
|
app.config['LDAP_GROUP_OBJECT_FILTER'] = config.config_ldap_group_object_filter
|
|
|
|
app.config['LDAP_GROUP_MEMBERS_FIELD'] = config.config_ldap_group_members_field
|
|
|
|
app.config['LDAP_GROUP_MEMBERS_FIELD'] = config.config_ldap_group_members_field
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
_ldap.init_app(app)
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
if bool(config.config_ldap_cert_path):
|
|
|
|
|
|
|
|
app.config['LDAP_CUSTOM_OPTIONS'] = {
|
|
|
|
|
|
|
|
pyLDAP.OPT_X_TLS_REQUIRE_CERT: pyLDAP.OPT_X_TLS_DEMAND,
|
|
|
|
|
|
|
|
pyLDAP.OPT_X_TLS_CACERTFILE: config.config_ldap_cacert_path,
|
|
|
|
|
|
|
|
pyLDAP.OPT_X_TLS_CERTFILE: config.config_ldap_cert_path,
|
|
|
|
|
|
|
|
pyLDAP.OPT_X_TLS_KEYFILE: config.config_ldap_key_path,
|
|
|
|
|
|
|
|
}
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
_ldap.init_app(app)
|
|
|
|
_ldap.init_app(app)
|
|
|
|
except RuntimeError as e:
|
|
|
|
except RuntimeError as e:
|
|
|
|
log.error(e)
|
|
|
|
log.error(e)
|
|
|
|
|
|
|
|
except RuntimeError as e:
|
|
|
|
|
|
|
|
log.error(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_object_details(user=None, group=None, query_filter=None, dn_only=False):
|
|
|
|
def get_object_details(user=None, group=None, query_filter=None, dn_only=False):
|
|
|
|