本文整理汇总了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