当前位置: 首页>>代码示例>>Python>>正文


Python Auth.find_user_dn方法代码示例

本文整理汇总了Python中pykolab.auth.Auth.find_user_dn方法的典型用法代码示例。如果您正苦于以下问题:Python Auth.find_user_dn方法的具体用法?Python Auth.find_user_dn怎么用?Python Auth.find_user_dn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pykolab.auth.Auth的用法示例。


在下文中一共展示了Auth.find_user_dn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: LDAPDataHandler

# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import find_user_dn [as 别名]
class LDAPDataHandler(object):
    """
        Collector handler to provide user data from LDAP
    """

    def __init__(self, *args, **kw):
        # load pykolab conf
        self.pykolab_conf = pykolab.getConf()
        if not hasattr(self.pykolab_conf, 'defaults'):
            self.pykolab_conf.finalize_conf(fatal=False)

        self.ldap = Auth()
        self.ldap.connect()

    def register(self, callback):
        interests = {
                'GETUSERDATA': { 'callback': self.get_user_data }
            }

        callback(interests)

    def get_user_data(self, notification):
        notification = json.loads(notification)
        log.debug("GETUSERDATA for %r" % (notification), level=9)

        if notification.has_key('user'):
            try:
                user_dn = self.ldap.find_user_dn(notification['user'], True)
                log.debug("User DN for %s: %r" % (notification['user'], user_dn), level=8)
            except Exception, e:
                log.error("LDAP connection error: %r", e)
                user_dn = None

            if user_dn:
                unique_attr = self.pykolab_conf.get('ldap', 'unique_attribute', 'nsuniqueid')
                user_rec = self.ldap.get_entry_attributes(None, user_dn, [unique_attr, 'cn'])
                log.debug("User attributes: %r" % (user_rec), level=8)

                if user_rec and user_rec.has_key(unique_attr):
                    user_rec['dn'] = user_dn
                    user_rec['id'] = user_rec[unique_attr]
                    del user_rec[unique_attr]
            else:
                user_rec = None

            notification['user_data'] = user_rec

        return json.dumps(notification)
开发者ID:kolab-groupware,项目名称:bonnie,代码行数:50,代码来源:ldapdata.py

示例2: user_dn_from_email_address

# 需要导入模块: from pykolab.auth import Auth [as 别名]
# 或者: from pykolab.auth.Auth import find_user_dn [as 别名]
def user_dn_from_email_address(email_address):
    """
        Resolves the given email address to a Kolab user entity
    """
    global auth

    if not auth:
        auth = Auth()
        auth.connect()

    # return cached value
    if user_dn_from_email_address.cache.has_key(email_address):
        return user_dn_from_email_address.cache[email_address]

    local_domains = auth.list_domains()

    if not local_domains == None:
        local_domains = list(set(local_domains.keys()))

    if not email_address.split('@')[1] in local_domains:
        user_dn_from_email_address.cache[email_address] = None
        return None

    log.debug(_("Checking if email address %r belongs to a local user") % (email_address), level=8)

    user_dn = auth.find_user_dn(email_address, True)

    if isinstance(user_dn, basestring):
        log.debug(_("User DN: %r") % (user_dn), level=8)
    else:
        log.debug(_("No user record(s) found for %r") % (email_address), level=9)

    # remember this lookup
    user_dn_from_email_address.cache[email_address] = user_dn

    return user_dn
开发者ID:tpokorra,项目名称:pykolab,代码行数:38,代码来源:module_invitationpolicy.py


注:本文中的pykolab.auth.Auth.find_user_dn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。