authentication.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:dila 作者: socialwifi 项目源码 文件源码
def check_group_membership(username, group=None):
    with initialize_connection() as connection:
        connection.simple_bind_s(config.LDAP_BIND_DN, config.LDAP_BIND_PASSWORD)
        if group is None:
            query = config.LDAP_GROUP_ALL
        else:
            query = config.LDAP_GROUP_OBJECT_FILTER % {'group': ldap_filter.escape_filter_chars(group)}
        results = connection.search_s(config.LDAP_GROUP_BASE_DN, ldap.SCOPE_SUBTREE, query)
        members = itertools.chain.from_iterable([result[1]['memberUid']for result in results])
        encoding = config.LDAP_ENCODING
        members = [member.decode(encoding) for member in members]
        is_member = username in members
        return is_member
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号