本文整理汇总了Python中ldap3.ALL属性的典型用法代码示例。如果您正苦于以下问题:Python ldap3.ALL属性的具体用法?Python ldap3.ALL怎么用?Python ldap3.ALL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ldap3
的用法示例。
在下文中一共展示了ldap3.ALL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: try_ldap_login
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def try_ldap_login(login, password):
""" Connect to a LDAP directory to verify user login/passwords"""
result = "Wrong login/password"
s = Server(config.LDAPURI, port=config.LDAPPORT,
use_ssl=False, get_info=ALL)
# 1. connection with service account to find the user uid
uid = useruid(s, login)
if uid:
# 2. Try to bind the user to the LDAP
c = Connection(s, user = uid , password = password, auto_bind = True)
c.open()
c.bind()
result = c.result["description"] # "success" if bind is ok
c.unbind()
return result
示例2: main
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def main():
# Create the Server object with the given address.
server = Server(LDAP_SERVER, get_info=ALL)
#Create a connection object, and bind with the given DN and password.
try:
conn = Connection(server, LDAP_USER, LDAP_PASSWORD, auto_bind=True)
print('LDAP Bind Successful.')
# Perform a search for a pre-defined criteria.
# Mention the search filter / filter type and attributes.
conn.search('dc=demo1,dc=freeipa,dc=org', LDAP_FILTER , attributes=LDAP_ATTRS)
# Print the resulting entries.
for entry in conn.entries:
print(entry)
except core.exceptions.LDAPBindError as e:
# If the LDAP bind failed for reasons such as authentication failure.
print('LDAP Bind Failed: ', e)
开发者ID:PacktPublishing,项目名称:Learning-Python-Networking-Second-Edition,代码行数:18,代码来源:entries_ldap_server.py
示例3: doLdapLogin
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def doLdapLogin(username, password):
if LdapServer == None or LdapServer == "":
return False
try:
from ldap3 import Server, Connection, ALL, NTLM
except ImportError as importException:
LogError("LDAP3 import not found, run 'sudo pip install ldap3 && sudo pip3 install ldap3'")
LogError(importException)
return False
HasAdmin = False
HasReadOnly = False
SplitName = username.split('\\')
DomainName = SplitName[0]
DomainName = DomainName.strip()
AccountName = SplitName[1]
AccountName = AccountName.strip()
server = Server(LdapServer, get_info=ALL)
conn = Connection(server, user='{}\\{}'.format(DomainName, AccountName), password=password, authentication=NTLM, auto_bind=True)
conn.search('dc=skipfire,dc=local', '(&(objectclass=user)(sAMAccountName='+AccountName+'))', attributes=['memberOf'])
for user in sorted(conn.entries):
for group in user.memberOf:
if group.upper().find("CN="+LdapAdminGroup.upper()) >= 0:
HasAdmin = True
elif group.upper().find("CN="+LdapReadOnlyGroup.upper()) >= 0:
HasReadOnly = True
session['logged_in'] = HasAdmin or HasReadOnly
session['write_access'] = HasAdmin
if HasAdmin:
LogError("Admin Login via LDAP")
elif HasReadOnly:
LogError("Limited Rights Login via LDAP")
else:
LogError("No rights for valid login via LDAP")
return HasAdmin or HasReadOnly
#-------------------------------------------------------------------------------
示例4: init_connection
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def init_connection(self):
self.server = Server(self.target, get_info=ALL)
self.connection = Connection(self.server, user="a", password="b", authentication=NTLM)
self.connection.open(False)
示例5: ldap_query
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def ldap_query(self, query):
if not self.ldap_enabled:
return None
from ldap3 import Server, Connection, SIMPLE, SYNC, ASYNC, SUBTREE, ALL, ALL_ATTRIBUTES
import json
try:
logging.debug("connecting to ldap server {} on port {}".format(self.ldap_server, self.ldap_port))
with Connection(
Server(self.ldap_server, port = self.ldap_port, get_info = ALL),
auto_bind = True,
client_strategy = SYNC,
user=self.ldap_bind_user,
password=self.ldap_bind_password,
authentication=SIMPLE,
check_names=True) as c:
logging.debug("running ldap query for ({})".format(query))
c.search(self.ldap_base_dn, '({})'.format(query), SUBTREE, attributes = ALL_ATTRIBUTES)
# a little hack to move the result into json
response = json.loads(c.response_to_json())
result = c.result
if len(response['entries']) < 1:
return None
# XXX not sure about the 0 here, I guess only if we only looking for one thing at a time
return response['entries'][0]['attributes']
except Exception as e:
logging.warning("failed ldap query {}: {}".format(query, e))
return None
示例6: tivoli_ldap_query
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def tivoli_ldap_query(self, query):
if not self.tivoli_ldap_enabled:
return None
from ldap3 import Server, Connection, SIMPLE, SYNC, ASYNC, SUBTREE, ALL, ALL_ATTRIBUTES
import json
try:
logging.debug("connecting to tivoli ldap server {} on port {}".format(self.tivoli_server, self.tivoli_ldap_port))
with Connection(
Server(self.tivoli_server, port = self.tivoli_ldap_port , get_info = ALL),
auto_bind = False,
client_strategy = SYNC,
user=self.tivoli_bind_user,
password=self.tivoli_bind_password,
authentication=SIMPLE,
check_names=True) as c:
logging.debug("running tivoli ldap query for ({})".format(query))
c.search(self.tivoli_base_dn, '({})'.format(query), SUBTREE, attributes = ALL_ATTRIBUTES)
# a little hack to move the result into json
response = json.loads(c.response_to_json())
result = c.result
if len(response['entries']) < 1:
return None
# XXX not sure about the 0 here, I guess only if we only looking for one thing at a time
return response['entries'][0]['attributes']
except Exception as e:
logging.warning("failed tivoli ldap query {}: {}".format(query, e))
return None
示例7: get_serverpool_instance
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def get_serverpool_instance(self, get_info=None):
"""
Return a ``ServerPool`` instance that should be used. If ``SERVERPOOL_PERSISTENT``
is enabled, invoke ``get_persistent_serverpool`` to retrieve a per-process
server pool instance. If it is not enabled, invoke ``create_serverpool``
to retrieve a per-request server pool instance.
:param get_info: one of ldap3.SCHEMA, ldap3.NONE, ldap3.ALL
:return: a ``ServerPool``/``LockingServerPool`` instance
"""
if self.serverpool_persistent:
return self.get_persistent_serverpool(get_info)
else:
return self.create_serverpool(self.uri, self.timeout, get_info,
self.tls_context, self.serverpool_rounds, self.serverpool_skip)
示例8: get_persistent_serverpool
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def get_persistent_serverpool(self, get_info=None):
"""
Return a process-level instance of ``LockingServerPool`` for the current LDAP resolver
configuration. Retrieve it from the app-local store. If such an instance does not exist
yet, create one.
:param get_info: one of ldap3.SCHEMA, ldap3.NONE, ldap3.ALL
:return: a ``LockingServerPool`` instance
"""
if not get_info:
get_info = ldap3.SCHEMA
pools = get_app_local_store().setdefault('ldap_server_pools', {})
# Create a hashable tuple that describes the current server pool configuration
pool_description = (self.uri,
self.timeout,
get_info,
repr(self.tls_context), # this is the string representation of the TLS context
self.serverpool_rounds,
self.serverpool_skip)
if pool_description not in pools:
log.debug("Creating a persistent server pool instance for {!r} ...".format(pool_description))
# Create a suitable instance of ``LockingServerPool``
server_pool = self.create_serverpool(self.uri, self.timeout, get_info,
self.tls_context, self.serverpool_rounds, self.serverpool_skip,
pool_cls=LockingServerPool)
# It may happen that another thread tries to add an instance to the dictionary concurrently.
# However, only one of them will win, and the other ``LockingServerPool`` instance will be
# garbage-collected eventually.
return pools.setdefault(pool_description, server_pool)
else:
# If there is already a ``LockingServerPool`` instance, return it.
# We never remove instances from the dictionary, so a ``KeyError`` cannot occur.
# As a side effect, when we change the LDAP Id resolver configuration,
# outdated ``LockingServerPool`` instances will survive until the next server restart.
return pools[pool_description]
示例9: ldap_authenticate
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def ldap_authenticate(request,username,password,groups_allowed=True):
#change these values to what is appropriate for your environment
id_name="uid"
ldap_host="192.168.0.2"
ldap_port="389"
bind_dn="cn=Manager,dc=bbotte,dc=com"
bind_pass="123456"
user_base="ou=People,dc=bbotte,dc=com"
#bind with service account
s = Server(ldap_host, port=int(ldap_port), get_info=ALL)
c = Connection(
s,
authentication=SIMPLE,
user=bind_dn,
password=bind_pass,
check_names=True,
lazy=False,
client_strategy=SYNC,
raise_exceptions=False)
c.open()
c.bind()
if c.bound:
#once bound, check username provided and get cn, memberOf list and mail
# get cn_name
c.search(user_base,'(%s=%s)'%(id_name,username),attributes=['cn','mail'])
c.unbind
try:
cn_name=c.entries[0].cn
except:
print("user cn cannot be found")
auth_logger.error("user cn cannot be found")
session['username']=username
return True
else:
auth_logger.debug('ldap bind failed')
c.unbind()
return False
示例10: main
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def main(address):
# Create the Server object with the given address.
# Get ALL information.
server = Server(address, get_info=ALL)
#Create a connection object, and bind with auto bind set to true.
conn = Connection(server, auto_bind=True)
# Print the LDAP Server Information.
print('******************Server Info**************')
print(server.info)
开发者ID:PacktPublishing,项目名称:Learning-Python-Networking-Second-Edition,代码行数:12,代码来源:connect_ldap_server.py
示例11: _get_server
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def _get_server(self):
return Server(main_config.ldap_account[self.domain]["server"], get_info=ALL)
示例12: initConnection
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def initConnection(self):
self.server = Server("ldap://%s:%s" % (self.targetHost, self.targetPort), get_info=ALL)
self.session = Connection(self.server, user="a", password="b", authentication=NTLM)
self.session.open(False)
return True
示例13: initConnection
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def initConnection(self, authdata, kdc=None):
if not kdc:
kdc = authdata['domain']
self.server = Server("ldap://%s:%s" % (self.targetHost, self.targetPort), get_info=ALL)
self.session = Connection(self.server, user="a", password="b", authentication=SASL, sasl_mechanism=KERBEROS)
ldap_kerberos(authdata['domain'], kdc, authdata['tgt'], authdata['username'], self.session, self.targetHost)
示例14: init
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def init(self):
if not self.app.config.get('LDAP_SERVER'):
raise RuntimeError(
"Use of LDAP authentication requires specification of the LDAP_SERVER configuration variable.")
self.server = Server(self.app.config['LDAP_SERVER'], get_info=ALL)
示例15: main
# 需要导入模块: import ldap3 [as 别名]
# 或者: from ldap3 import ALL [as 别名]
def main(address):
# Create the Server object with the given address.
# Get ALL information.
server = Server(address, get_info=ALL)
#Create a connection object, and bind with auto bind set to true.
conn = Connection(server, auto_bind=True)
# Print the LDAP Server Information.
print('******************Server Info**************')
print(server.info)
# Print the LDAP Server Detailed Schema.
print('******************Server Schema**************')
print(server.schema)
开发者ID:PacktPublishing,项目名称:Python-Network-Programming-Cookbook-Second-Edition,代码行数:16,代码来源:11_6_connect_ldap_server.py