From fe22e363b436bf799bee3ac4aafa2a5b6bdb3042 Mon Sep 17 00:00:00 2001 From: pycook Date: Tue, 19 Dec 2023 00:16:56 +0800 Subject: [PATCH] fix(api): ldap authentication --- cmdb-api/api/lib/common_setting/resp_format.py | 2 +- cmdb-api/api/lib/perm/authentication/ldap.py | 2 +- cmdb-api/api/views/acl/login.py | 2 +- cmdb-api/api/views/common_setting/auth_config.py | 5 +++-- cmdb-ui/src/views/setting/auth/index.vue | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmdb-api/api/lib/common_setting/resp_format.py b/cmdb-api/api/lib/common_setting/resp_format.py index 1d8c6fc..52274fd 100644 --- a/cmdb-api/api/lib/common_setting/resp_format.py +++ b/cmdb-api/api/lib/common_setting/resp_format.py @@ -59,6 +59,7 @@ class ErrFormat(CommonErrFormat): email_send_timeout = "邮件发送超时" common_data_not_found = "ID {} 找不到记录" + common_data_already_existed = "{} 已存在" notice_platform_existed = "{} 已存在" notice_not_existed = "{} 配置项不存在" notice_please_config_messenger_first = "请先配置 messenger" @@ -74,4 +75,3 @@ class ErrFormat(CommonErrFormat): ldap_test_unknown_error = "LDAP测试未知错误: {}" common_data_not_support_auth_type = "通用数据不支持auth类型: {}" ldap_test_username_required = "LDAP测试用户名必填" - diff --git a/cmdb-api/api/lib/perm/authentication/ldap.py b/cmdb-api/api/lib/perm/authentication/ldap.py index a747ae6..4de1f93 100644 --- a/cmdb-api/api/lib/perm/authentication/ldap.py +++ b/cmdb-api/api/lib/perm/authentication/ldap.py @@ -21,7 +21,7 @@ from api.models.acl import User def authenticate_with_ldap(username, password): - config = AuthenticateDataCRUD(AuthenticateType.CAS).get() + config = AuthenticateDataCRUD(AuthenticateType.LDAP).get() server = Server(config.get('LDAP').get('ldap_server'), get_info=ALL, connect_timeout=3) if '@' in username: diff --git a/cmdb-api/api/views/acl/login.py b/cmdb-api/api/views/acl/login.py index 7164d54..d73a7ef 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'): + if config.get('LDAP', {}).get('enabled') or config.get('LDAP', {}).get('enable'): from api.lib.perm.authentication.ldap import authenticate_with_ldap user, authenticated = authenticate_with_ldap(username, password) else: diff --git a/cmdb-api/api/views/common_setting/auth_config.py b/cmdb-api/api/views/common_setting/auth_config.py index 6bb4f30..5ec2840 100644 --- a/cmdb-api/api/views/common_setting/auth_config.py +++ b/cmdb-api/api/views/common_setting/auth_config.py @@ -1,9 +1,10 @@ from flask import abort, request +from api.lib.common_setting.common_data import AuthenticateDataCRUD +from api.lib.common_setting.const import TestType +from api.lib.common_setting.resp_format import ErrFormat from api.lib.perm.acl.acl import role_required from api.resource import APIView -from api.lib.common_setting.common_data import AuthenticateDataCRUD -from api.lib.common_setting.resp_format import ErrFormat prefix = '/auth_config' diff --git a/cmdb-ui/src/views/setting/auth/index.vue b/cmdb-ui/src/views/setting/auth/index.vue index 5218429..7166689 100644 --- a/cmdb-ui/src/views/setting/auth/index.vue +++ b/cmdb-ui/src/views/setting/auth/index.vue @@ -17,7 +17,7 @@ 保存 重置