【问题标题】:How to fix the user account control attribute to 512 in Ldap如何在 Ldap 中将用户帐户控制属性修复为 512
【发布时间】:2019-08-17 16:26:07
【问题描述】:

使用 Java 代码我试图在 AD LDAP 中创建用户,但我无法将 userAccountControl 状态设置为 512,尽管我试图通过我的代码将状态作为 512 传递,但用户是用不同的 @ 创建的987654322@ 状态为 544。

创建用户后,我无法使用他的 ID (DN) 和密码登录 LDAP。

我正在使用代码:

attributes.add(new LDAPAttribute("userAccountControl", "512"));
attributes.add(new LDAPAttribute("userPassword", "Password@1"));

有没有其他方法可以将userAccountControl 设置为 512?

【问题讨论】:

    标签: java active-directory ldap


    【解决方案1】:

    userAccountControl 的值 544 是 512 + 32,即 means NORMAL_ACCOUNT + PASSWD_NOTREQD,可能是因为它在创建时没有密码。如果没有密码,则不能设置为 512。

    必须在创建帐户后的第二步中设置密码。 AD 有点奇怪,因为 userPassword 属性甚至存在,但它只是有时表现得像你想象的那样。如果你愿意,你可以阅读here。但是你最好只设置unicodePwd,它总是以同样的方式工作,虽然它有点奇怪的格式。

    有一个这样做的Java示例here

    public void updateUserPassword(String username, String password)
    {
        try
        {
            System.out.println("updating password...\n");
            String quotedPassword = "\"" + password + "\"";
            char unicodePwd[] = quotedPassword.toCharArray();
            byte pwdArray[] = new byte[unicodePwd.length * 2];
            for (int i = 0; i < unicodePwd.length; i++)
            {
                pwdArray[i * 2 + 1] = (byte) (unicodePwd[i] >>> 8);
                pwdArray[i * 2 + 0] = (byte) (unicodePwd[i] & 0xff);
            }
            System.out.print("encoded password: ");
            for (int i = 0; i < pwdArray.length; i++)
            {
                System.out.print(pwdArray[i] + " ");
            }
            System.out.println();
            ModificationItem[] mods = new ModificationItem[1];
            mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("UnicodePwd", pwdArray));
            ldapContext.modifyAttributes("cn=" + username + BASE_NAME, mods);
        }
        catch (Exception e)
        {
            System.out.println("update password error: " + e);
        }
    }
    

    请注意,您必须使用 LDAPS(LDAP over SSL,通常在端口 636 上)才能设置密码。

    您可以在设置密码的同一请求中将 userAccountControl 设置为 512。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      相关资源
      最近更新 更多