python-ldap更改unicodePwd问题

时间:2016-05-26 10:56:49

标签: active-directory ldap python-ldap

我已经使用代码管理不同用户的AD attrs:

public class WordPlay {
    public boolean isVowel(char c) {
        if(c=='a' || c=='A' || c=='e' || c=='E' || c=='i' || c=='I' || c=='o' || c=='O' ||     c=='u' || c=='U') {    
            return true;
        }    
        else
        {
            return false;
        }    
    }
    public void testIsVowel () {
        System.out.println(isVowel('F'));
    }
    public String replaceVowels (String phrase, char ch){
        StringBuilder replaced = new StringBuilder(phrase);
        for (int i = 0; i<phrase.length(); i++) {
            char currChar = phrase.charAt(i);
            if (isVowel(currChar)){

                    //the line below causes the error
                    replaced.setCharAt(currChar, ch);
            }    
        }    
        return replaced.toString();    
    }
    public void testReplaceVowels() {
        System.out.println(replaceVowels("Hello World", '*'));

    }    
}

除了unicodePwd之外,它适用于所有nessesary attrubutes。 在寻找解决方案后,我发现应该使用ldaps连接和端口636更改unicodePwd (Python+LDAP+SSL)。 所以我试图使用那个例子:

l = ldap.initialize('ldap://172.25.1.2')        
    l.simple_bind_s(admin_dn, admin_pw)

    user_dn="dn_here"
    change_attr = [(ldap.MOD_REPLACE, 'attr_to_change', new_value)]

    l.modify_s(user_dn,change_attr)
    l.unbind_s()

但收到了错误:

    ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
    l = ldap.initialize('ldaps://172.25.1.2:636')
    l.set_option(ldap.OPT_REFERRALS, 0)
    l.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
    l.set_option(ldap.OPT_X_TLS,ldap.OPT_X_TLS_DEMAND)
    l.set_option( ldap.OPT_X_TLS_DEMAND, True )
    l.set_option( ldap.OPT_DEBUG_LEVEL, 255 )
    l.simple_bind_s(admin_dn, admin_pw)
    #change unicodePwdCOde here
    l.unbind_s()

我的代码中是否有任何解决方案,或者应该从AD服务器配置修复? 谢谢你的帮助。 Sry语法错误。

0 个答案:

没有答案