本文整理汇总了Python中django_auth_ldap.config.LDAPSearch方法的典型用法代码示例。如果您正苦于以下问题:Python config.LDAPSearch方法的具体用法?Python config.LDAPSearch怎么用?Python config.LDAPSearch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_auth_ldap.config
的用法示例。
在下文中一共展示了config.LDAPSearch方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _search_for_user_dn
# 需要导入模块: from django_auth_ldap import config [as 别名]
# 或者: from django_auth_ldap.config import LDAPSearch [as 别名]
def _search_for_user_dn(self):
user_search_union = [
LDAPSearch(
USER_SEARCH, ldap.SCOPE_SUBTREE,
settings.AUTH_LDAP_SEARCH_FILTER
)
for USER_SEARCH in str(settings.AUTH_LDAP_SEARCH_OU).split("|")
]
search = LDAPSearchUnion(*user_search_union)
if search is None:
raise ImproperlyConfigured(
'AUTH_LDAP_USER_SEARCH must be an LDAPSearch instance.'
)
results = search.execute(self.connection, {'user': self._username})
if results is not None and len(results) == 1:
(user_dn, self._user_attrs) = next(iter(results))
else:
user_dn = None
return user_dn
示例2: refresh_setting
# 需要导入模块: from django_auth_ldap import config [as 别名]
# 或者: from django_auth_ldap.config import LDAPSearch [as 别名]
def refresh_setting(self):
try:
value = json.loads(self.value)
except json.JSONDecodeError:
return
setattr(settings, self.name, value)
if self.name == "AUTH_LDAP":
if self.cleaned_value and settings.AUTH_LDAP_BACKEND not in settings.AUTHENTICATION_BACKENDS:
settings.AUTHENTICATION_BACKENDS.insert(0, settings.AUTH_LDAP_BACKEND)
elif not self.cleaned_value and settings.AUTH_LDAP_BACKEND in settings.AUTHENTICATION_BACKENDS:
settings.AUTHENTICATION_BACKENDS.remove(settings.AUTH_LDAP_BACKEND)
if self.name == "AUTH_LDAP_SEARCH_FILTER":
settings.AUTH_LDAP_USER_SEARCH = LDAPSearch(
settings.AUTH_LDAP_SEARCH_OU, ldap.SCOPE_SUBTREE,
settings.AUTH_LDAP_SEARCH_FILTER,
)
示例3: configure_ldap_auth
# 需要导入模块: from django_auth_ldap import config [as 别名]
# 或者: from django_auth_ldap.config import LDAPSearch [as 别名]
def configure_ldap_auth(config, settings):
if not config.has_section("auth_ldap"):
return
from django_auth_ldap.config import LDAPSearch, MemberDNGroupType
from ldap import SCOPE_SUBTREE
settings.AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
settings.AUTH_LDAP_SERVER_URI = config.get("auth_ldap", "server_uri")
settings.AUTH_LDAP_BIND_DN = config.get("auth_ldap", "bind_dn")
settings.AUTH_LDAP_BIND_PASSWORD = config.get("auth_ldap", "password")
settings.AUTH_LDAP_USER_SEARCH = LDAPSearch(
config.get("auth_ldap", "user_base_dn"),
SCOPE_SUBTREE,
get_from_config(config, "auth_ldap", "user_search_filter", "(cn=%(user)s)"),
)
settings.AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
config.get("auth_ldap", "group_base_dn"),
SCOPE_SUBTREE,
get_from_config(config, "auth_ldap", "group_search_filter", "(objectClass=group)"),
)
settings.AUTH_LDAP_GROUP_TYPE = MemberDNGroupType('member')
settings.AUTH_LDAP_REQUIRE_GROUP = get_from_config(config, "auth_ldap", "require_group", None)
settings.AUTH_LDAP_USER_ATTR_MAP = {
"email": get_from_config(config, "auth_ldap", "attr_email", "mail"),
"first_name": get_from_config(config, "auth_ldap", "attr_first_name", "givenName"),
"last_name": get_from_config(config, "auth_ldap", "attr_last_name", "sn"),
}
settings.AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_staff": config.get("auth_ldap", "admin_group"),
"is_superuser": config.get("auth_ldap", "admin_group"),
}
settings.AUTH_LDAP_ALWAYS_UPDATE_USER = True
settings.AUTH_LDAP_FIND_GROUP_PERMS = False
settings.AUTH_LDAP_MIRROR_GROUPS = True
settings.AUTH_LDAP_CACHE_GROUPS = True
settings.AUTH_LDAP_GROUP_CACHE_TIMEOUT = 900