错误在 AD 上更改密码并强制控制密码历史记录时

ERROR When changing password on AD with enforcing control on password history

我正在尝试更改 Active Directory 上的用户密码,我使用的方法是:

        ldapContext = getContext(resourceName);

        String quotedPassword = '"' + password.decryptToString() + '"';

        ModificationItem[] modifications = new ModificationItem[1];
        modifications[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(PASSWORD_ATTRIBUTE_NAME, quotedPassword.getBytes("UTF-16LE")));

        ldapContext.modifyAttributes(dn, modifications);

这很好用。

现在我想添加对密码历史记录的控制,用户无法设置最后 x 组密码。

这行不通:

        final String LDAP_SERVER_POLICY_HINTS_OID = "1.2.840.113556.1.4.2239";
        ldapContext = getContext(resourceName);

        String quotedPassword = '"' + password.decryptToString() + '"';

        ModificationItem[] modifications = new ModificationItem[1];
        modifications[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(PASSWORD_ATTRIBUTE_NAME, quotedPassword.getBytes("UTF-16LE")));

        BasicControl[] controls = new BasicControl[1];
        final byte[] controlData = {48,(byte)132,0,0,0,3,2,1,1};
        controls[0] = new BasicControl(LDAP_SERVER_POLICY_HINTS_OID, true, controlData);
        ldapContext.setRequestControls(controls);

        ldapContext.modifyAttributes(dn, modifications);

知道我正在使用 SSL 连接,并且我设置的 OID 列在 ROOT DSE 的受支持控件中,我收到此错误:

        javax.naming.OperationNotSupportedException: [LDAP: error code 53 - 0000052D: SvcErr: DSID-031A12D2, problem 5003 (WILL_NOT_PERFORM), data 0

我被卡住了,因为我不知道问题的确切来源,感谢任何帮助。

提前致谢

Active Directory 真的很糟糕,因为它很难解决这样的问题,但秘密在于诊断消息中给出的“0000052D”。这是对 Active Directory 系统错误代码 0x52D 的引用,它是十进制的 1325。系统错误代码记录在 http://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx

遵守密码政策来解决这个错误。