From b093569453e1eb77f41e2b95a096bd56a4e20e56 Mon Sep 17 00:00:00 2001 From: kdyq007 Date: Mon, 25 Dec 2023 09:36:31 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=20=E4=BF=AE=E5=A4=8D=20LDA?= =?UTF-8?q?P=20=E7=99=BB=E5=BD=95=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#336)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: sherlock --- cmdb-api/api/lib/perm/authentication/ldap.py | 10 +++++----- cmdb-api/api/views/acl/login.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmdb-api/api/lib/perm/authentication/ldap.py b/cmdb-api/api/lib/perm/authentication/ldap.py index 4de1f93..64e3239 100644 --- a/cmdb-api/api/lib/perm/authentication/ldap.py +++ b/cmdb-api/api/lib/perm/authentication/ldap.py @@ -23,13 +23,13 @@ from api.models.acl import User def authenticate_with_ldap(username, password): config = AuthenticateDataCRUD(AuthenticateType.LDAP).get() - server = Server(config.get('LDAP').get('ldap_server'), get_info=ALL, connect_timeout=3) + server = Server(config.get('ldap_server'), get_info=ALL, connect_timeout=3) if '@' in username: email = username - who = config['LDAP'].get('ldap_user_dn').format(username.split('@')[0]) + who = config.get('ldap_user_dn').format(username.split('@')[0]) else: - who = config['LDAP'].get('ldap_user_dn').format(username) - email = "{}@{}".format(who, config['LDAP'].get('ldap_domain')) + who = config.get('ldap_user_dn').format(username) + email = "{}@{}".format(who, config.get('ldap_domain')) username = username.split('@')[0] user = User.query.get_by_username(username) @@ -41,7 +41,7 @@ def authenticate_with_ldap(username, password): conn = Connection(server, user=who, password=password, auto_bind=AUTO_BIND_NO_TLS) except LDAPBindError: conn = Connection(server, - user=f"{username}@{config['LDAP'].get('ldap_domain')}", + user=f"{username}@{config.get('ldap_domain')}", password=password, auto_bind=AUTO_BIND_NO_TLS) diff --git a/cmdb-api/api/views/acl/login.py b/cmdb-api/api/views/acl/login.py index d73a7ef..ed459de 100644 --- a/cmdb-api/api/views/acl/login.py +++ b/cmdb-api/api/views/acl/login.py @@ -39,7 +39,7 @@ class LoginView(APIView): password = request.values.get("password") _role = None config = AuthenticateDataCRUD(AuthenticateType.LDAP).get() - if config.get('LDAP', {}).get('enabled') or config.get('LDAP', {}).get('enable'): + if config.get('enabled') or config.get('enable'): from api.lib.perm.authentication.ldap import authenticate_with_ldap user, authenticated = authenticate_with_ldap(username, password) else: