本文整理匯總了Python中ldap.MOD_REPLACE屬性的典型用法代碼示例。如果您正苦於以下問題:Python ldap.MOD_REPLACE屬性的具體用法?Python ldap.MOD_REPLACE怎麽用?Python ldap.MOD_REPLACE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類ldap
的用法示例。
在下文中一共展示了ldap.MOD_REPLACE屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: exact
# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import MOD_REPLACE [as 別名]
def exact(self):
try:
results = self.connection.search_s(
self.dn, ldap.SCOPE_BASE, attrlist=[self.name])
except ldap.LDAPError:
e = get_exception()
self.module.fail_json(
msg="Cannot search for attribute %s" % self.name,
details=str(e))
current = results[0][1].get(self.name, [])
modlist = []
if frozenset(self.values) != frozenset(current):
if len(current) == 0:
modlist = [(ldap.MOD_ADD, self.name, self.values)]
elif len(self.values) == 0:
modlist = [(ldap.MOD_DELETE, self.name, None)]
else:
modlist = [(ldap.MOD_REPLACE, self.name, self.values)]
return modlist
示例2: post_ldap_update
# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import MOD_REPLACE [as 別名]
def post_ldap_update(ldap_bind_dn, ldap_bind_pw):
conn = ldap.initialize('ldaps://localhost:1636')
conn.protocol_version = 3
conn.simple_bind_s(ldap_bind_dn, ldap_bind_pw)
result = conn.search_s('ou=appliances,o=gluu',ldap.SCOPE_SUBTREE,'(oxIDPAuthentication=*)',['oxIDPAuthentication'])
dn = result[0][0]
oxIDPAuthentication = json.loads(result[0][1]['oxIDPAuthentication'][0])
config = json.loads(oxIDPAuthentication['config'])
if config['servers'][0]=='localhost:1636' and config['bindDN'].lower()=='cn=directory manager,o=gluu':
config['bindDN'] = 'cn=Directory Manager'
oxIDPAuthentication['config'] = json.dumps(config)
oxIDPAuthentication = json.dumps(oxIDPAuthentication, indent=2)
conn.modify_s(dn, [( ldap.MOD_REPLACE, 'oxIDPAuthentication', oxIDPAuthentication)])
result = conn.search_s('ou=appliances,o=gluu',ldap.SCOPE_SUBTREE,'(oxTrustConfCacheRefresh=*)',['oxTrustConfCacheRefresh'])
dn = result[0][0]
oxTrustConfCacheRefresh = json.loads(result[0][1]['oxTrustConfCacheRefresh'][0])
oxTrustConfCacheRefresh['inumConfig']['bindDN'] = 'cn=Directory Manager'
oxTrustConfCacheRefresh = json.dumps(oxTrustConfCacheRefresh, indent=2)
conn.modify_s(dn, [( ldap.MOD_REPLACE, 'oxTrustConfCacheRefresh', oxTrustConfCacheRefresh)])
示例3: ldap_update_password
# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import MOD_REPLACE [as 別名]
def ldap_update_password(self, uid, new_password=None, old_password=None):
"""
更新密碼
:param uid: 用戶uid,新password
:return: True|None
"""
result = None
try:
obj = self.ldapconn
obj.protocal_version = ldap.VERSION3
modifyDN = "uid=%s,%s" % (uid, BASE_DN)
new_password_encrypt = pass_encrypt(new_password)
#有old_password情況下
if old_password:
obj.passwd_s(modifyDN, [str(old_password).encode('utf-8')], [new_password_encrypt.encode('utf-8')])
result = True
else:
obj.modify_s(modifyDN, [(ldap.MOD_REPLACE, 'userPassword', [new_password_encrypt.encode('utf-8')])])
result = True
obj.unbind_s()
except ldap.LDAPError as e:
logger.error("%s 密碼更新失敗,原因為: %s" % (uid, str(e)))
return False
return result
示例4: set_password
# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import MOD_REPLACE [as 別名]
def set_password(self, user, old_password, new_password):
dn = ldap_user_dn(user.username)
if old_password:
ldap_ident = dn
ldap_pass = old_password.encode('utf-8')
else:
ldap_ident = ldap_pass = None
try:
con = ldap_conn(ldap_ident, ldap_pass)
new_password = self._encode_password(new_password)
con.modify_s(
dn, [(ldap.MOD_REPLACE, b'userPassword', new_password)])
con.unbind_s()
user.last_password_updated = datetime.utcnow()
session(user).flush(user)
except ldap.INVALID_CREDENTIALS:
raise exc.HTTPUnauthorized()
示例5: set_pref
# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import MOD_REPLACE [as 別名]
def set_pref(self, user, pref_name, pref_value):
if pref_name in self.fields:
con = ldap_conn()
ldap_attr = self.fields[pref_name]
con.modify_s(ldap_user_dn(user.username),
[(ldap.MOD_REPLACE, ldap_attr.encode('utf-8'), pref_value.encode('utf-8'))])
con.unbind_s()
else:
return LocalUserPreferencesProvider().set_pref(user, pref_name, pref_value)
示例6: ldap_update_pass
# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import MOD_REPLACE [as 別名]
def ldap_update_pass(self,uid=None,oldpass=None,newpass=None):
modify_entry = [(ldap.MOD_REPLACE,'userpassword',newpass)]
obj = self.ldapconn
target_cn = self.ldap_search_dn(uid)
try:
obj.simple_bind_s(target_cn,oldpass)
obj.passwd_s(target_cn,oldpass,newpass)
return True
except ldap.LDAPError,e:
return False