首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Django 添加ldap认证细节注意

Django 添加ldap认证细节注意

作者头像
cuijianzhe
发布2022-06-14 19:36:48
发布2022-06-14 19:36:48
73900
代码可运行
举报
文章被收录于专栏:cuijianzhecuijianzhe
运行总次数:0
代码可运行

项目地址

https://github.com/etianen/django-python3-ldap

LDAP

代码语言:javascript
代码运行次数:0
运行
复制
django_python3_ldap

如果不添加 cn 查找用户会出现同步时出现如下报错:

代码语言:javascript
代码运行次数:0
运行
复制
LDAP bind failed: LDAPInvalidCredentialsResult - 49 - invalidCredentials - None - None - bindResponse - None
CommandError: Could not connect to LDAP server

添加 admin Generic: Posix Group (posixGroup),并且增加 password 属性,用于登录查找,或者个人用户也可以

代码语言:javascript
代码运行次数:0
运行
复制
### LDAP

# The URL of the LDAP server.
LDAP_AUTH_URL = "ldap://172.16.16.4:389"
# Initiate TLS on connection.
LDAP_AUTH_USE_TLS = False

# The LDAP search base for looking up users.
LDAP_AUTH_SEARCH_BASE = "ou=manager,dc=limikeji,dc=com"
# The LDAP class that represents a user.
LDAP_AUTH_OBJECT_CLASS = "inetOrgPerson"

# User model fields mapped to the LDAP
# attributes that represent them.
LDAP_AUTH_USER_FIELDS = {
    "username": "uid",
    "first_name": "sn",
    "last_name": "sn",
    "email": "mail",
}

# A tuple of django model fields used to uniquely identify a user.
LDAP_AUTH_USER_LOOKUP_FIELDS = ("username",)

# Path to a callable that takes a dict of {model_field_name: value},
# returning a dict of clean model data.
# Use this to customize how data loaded from LDAP is saved to the User model.
LDAP_AUTH_CLEAN_USER_DATA = "django_python3_ldap.utils.clean_user_data"
LDAP_AUTH_SYNC_USER_RELATIONS = "django_python3_ldap.utils.sync_user_relations"
LDAP_AUTH_FORMAT_SEARCH_FILTERS = "django_python3_ldap.utils.format_search_filters"
LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_openldap"


# The LDAP username and password of a user for querying the LDAP database for user
# details. If None, then the authenticated user will be used for querying, and
# the `ldap_sync_users` command will perform an anonymous query.
#同步用户:python manage.py ldap_sync_users

LDAP_AUTH_CONNECTION_USERNAME = 'cuijianzhe'
LDAP_AUTH_CONNECTION_PASSWORD = '97583758032750875'

AUTHENTICATION_BACKENDS = {"django_python3_ldap.auth.LDAPBackend",'django.contrib.auth.backends.ModelBackend',}

登陆时可直接使用 ldap 的用户进行登录,这样就会自动同步到 django 后台 user。

同步用户

代码语言:javascript
代码运行次数:0
运行
复制
python manager.py ldap_sync_users

标题:Django 添加ldap认证细节注意

作者:cuijianzhe

地址:https://cloud.tencent.com/developer/article/2022879

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 项目地址
  • LDAP
    • 同步用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档