本文整理汇总了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
示例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()
示例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
示例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