Skip to content

Commit

Permalink
[更新] 修复 LDAP 登录失败的问题 (#336)
Browse files Browse the repository at this point in the history
Co-authored-by: sherlock <[email protected]>
  • Loading branch information
kdyq007 and sherlockazulu authored Dec 25, 2023
1 parent 3919dfd commit b093569
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions cmdb-api/api/lib/perm/authentication/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
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)
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion cmdb-api/api/views/acl/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def post(self):
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:
Expand Down

0 comments on commit b093569

Please sign in to comment.