當前位置: 首頁>>代碼示例>>Python>>正文


Python ldap3.LEVEL屬性代碼示例

本文整理匯總了Python中ldap3.LEVEL屬性的典型用法代碼示例。如果您正苦於以下問題:Python ldap3.LEVEL屬性的具體用法?Python ldap3.LEVEL怎麽用?Python ldap3.LEVEL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在ldap3的用法示例。


在下文中一共展示了ldap3.LEVEL屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: search

# 需要導入模塊: import ldap3 [as 別名]
# 或者: from ldap3 import LEVEL [as 別名]
def search(self, base, filter=None, scope=None, attrs=None):
        filter = filter or "(objectClass=*)"
        scope = {
            "base":         ldap3.BASE,
            "subtree":      ldap3.SUBTREE,
            "sub":          ldap3.SUBTREE,
            "onelevel":     ldap3.LEVEL,
            "one":          ldap3.LEVEL,
            # not natively supported by ldap3
            #"subordinate":  ldap3.SUBORDINATE,
            #"child":        ldap3.SUBORDINATE,
        }[scope or "subtree"]
        attrs = [*attrs] if attrs else ["*"]
        ok = self.conn.search(base, filter,
                              search_scope=scope,
                              attributes=attrs)
        entries = self.conn.entries
        entries = [(entry.entry_dn, entry.entry_raw_attributes) for entry in entries]
        return entries 
開發者ID:grawity,項目名稱:code,代碼行數:21,代碼來源:client_ldap3.py

示例2: bind_search

# 需要導入模塊: import ldap3 [as 別名]
# 或者: from ldap3 import LEVEL [as 別名]
def bind_search(self):
        logger = logging.getLogger("realms.auth.ldap")
        bind_dn = self.config.get('BIND_DN') or None
        base_dn = self.config['USER_SEARCH']['base']
        filtr = self.config['USER_SEARCH']['filter'] % {'username': self.userid}
        scope = self.config['USER_SEARCH'].get('scope', 'subtree').lower().strip()
        if scope == "level":
            scope = ldap3.LEVEL
        elif scope == "base":
            scope = ldap3.BASE
        else:
            scope = ldap3.SUBTREE

        self.conn = ldap3.Connection(
            self.server,
            user=bind_dn,
            password=self.config.get('BIND_AUTH') or None,
            version=self.version
        )

        if not self.start_tls():
            return None

        if not self.conn.bind():
            logger.error("Can't bind to the LDAP server with provided credentials ({})'".format(bind_dn))
            return None

        logger.debug("Successfull BIND for '{}'".format(bind_dn))

        try:
            if not self.conn.search(base_dn, filtr, attributes=ldap3.ALL_ATTRIBUTES, search_scope=scope):
                logger.info("User was not found in LDAP: '{}'".format(self.userid))
                return None
            user_dn = self.conn.response[0]['dn']
            attrs = self._get_attributes(self.conn.response)
            # the user was found in LDAP, now let's try a BIND to check the password
            return attrs if self.conn.rebind(user=user_dn, password=self.password) else None
        finally:
            self.close() 
開發者ID:scragg0x,項目名稱:realms-wiki,代碼行數:41,代碼來源:models.py

示例3: get_dns_zones

# 需要導入模塊: import ldap3 [as 別名]
# 或者: from ldap3 import LEVEL [as 別名]
def get_dns_zones(connection, root):
    connection.search(root, '(objectClass=dnsZone)', search_scope=LEVEL, attributes=['dc'])
    zones = []
    for entry in connection.response:
        if entry['type'] != 'searchResEntry':
            continue
        zones.append(entry['attributes']['dc'])
    return zones 
開發者ID:dirkjanm,項目名稱:krbrelayx,代碼行數:10,代碼來源:dnstool.py

示例4: get_dns_zones

# 需要導入模塊: import ldap3 [as 別名]
# 或者: from ldap3 import LEVEL [as 別名]
def get_dns_zones(connection, root, debug=False):
    connection.search(root, '(objectClass=dnsZone)', search_scope=LEVEL, attributes=['dc'])
    zones = []
    for entry in connection.response:
        if entry['type'] != 'searchResEntry':
            continue
        if debug:
            print(entry['dn'])
        zones.append(entry['attributes']['dc'])
    return zones 
開發者ID:dirkjanm,項目名稱:adidnsdump,代碼行數:12,代碼來源:dnsdump.py


注:本文中的ldap3.LEVEL屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。