37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
|
|
# import ldap
|
||
|
|
# from flask import current_app
|
||
|
|
# from flask_login import current_user, LoginManager
|
||
|
|
#
|
||
|
|
# login_manager = LoginManager()
|
||
|
|
#
|
||
|
|
#
|
||
|
|
# def make_ldap_connection():
|
||
|
|
# ldap_connection = ldap.initialize('ldap://ldap.quarter.int')
|
||
|
|
# ldap_connection.protocol_version = 3
|
||
|
|
# ldap_connection.set_option(ldap.OPT_REFERRALS, 0)
|
||
|
|
# return ldap_connection
|
||
|
|
#
|
||
|
|
#
|
||
|
|
# def close_ldap_connection(connection):
|
||
|
|
# connection.unbind_s()
|
||
|
|
#
|
||
|
|
#
|
||
|
|
# def search_users():
|
||
|
|
# ldap_connection = make_ldap_connection()
|
||
|
|
# try:
|
||
|
|
# raw_users = ldap_connection.search_s(current_app.config['LDAP_BASE_DN'], ldap.SCOPE_SUBTREE, '(objectClass=posixAccount)')
|
||
|
|
# return [current_user.from_raw_ldap(u) for u in raw_users]
|
||
|
|
# except Exception as ex:
|
||
|
|
# current_app.logger.error(str(ex))
|
||
|
|
# finally:
|
||
|
|
# close_ldap_connection(ldap_connection)
|
||
|
|
#
|
||
|
|
#
|
||
|
|
# def parse_user_dn(user_dn):
|
||
|
|
# group = user_dn.split(',')
|
||
|
|
# result = {}
|
||
|
|
# for g in group:
|
||
|
|
# split = g.split('=')
|
||
|
|
# result[split[0]] = split[1]
|
||
|
|
# return result
|