From 0be31d0bfed1d65f1e5e6b4f02fa2c2009ac1fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 21 Nov 2021 15:11:37 +0100 Subject: [PATCH] [auth_ldap] sync ldap_users to Database --- run_flaschengeist | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/run_flaschengeist b/run_flaschengeist index e11271e..55fabad 100644 --- a/run_flaschengeist +++ b/run_flaschengeist @@ -167,6 +167,28 @@ def export(arguments): gen.write() +def ldap_sync(arguments): + from flaschengeist.app import create_app + from flaschengeist.controller import userController + from flaschengeist.plugins.auth_ldap import AuthLDAP + from ldap3 import SUBTREE + + app = create_app() + with app.app_context(): + auth_ldap: AuthLDAP = app.config.get("FG_PLUGINS").get("auth_ldap") + if auth_ldap: + conn = auth_ldap.ldap.connection + if not conn: + conn = auth_ldap.ldap.connect(auth_ldap.root_dn, auth_ldap.root_secret) + conn.search(auth_ldap.search_dn, "(uid=*)", SUBTREE, attributes=["uid", "givenName", "sn", "mail"]) + ldap_users_response = conn.response + for ldap_user in ldap_users_response: + uid = ldap_user["attributes"]["uid"][0] + userController.find_user(uid) + exit() + raise Exception("auth_ldap not found") + + if __name__ == "__main__": # create the top-level parser parser = argparse.ArgumentParser() @@ -192,5 +214,8 @@ if __name__ == "__main__": ) parser_export.add_argument("--plugins", help="Also export plugins (none means all)", nargs="*") + parser_ldap_sync = subparsers.add_parser("ldap_sync", help="synch ldap-users with database") + parser_ldap_sync.set_defaults(func=ldap_sync) + args = parser.parse_args() args.func(args)