使用UNBoundID SDK解锁用户帐户

时间:2014-06-11 13:32:36

标签: windows active-directory ldap jndi unboundid-ldap-sdk

我正在尝试使用UNBoundID解锁AD帐户,但我无法成功。有谁可以帮我这个。?

我的一个尝试如下,

    byte[] quotedPasswordBytes=null;
    final String quotedPassword = '"' + flag + '"';
    try {
    quotedPasswordBytes = quotedPassword.getBytes("UTF-16LE");
    } catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    Modification mod=new Modification(ModificationType.REPLACE, "msDS-User-Account-Control-Computed",quotedPasswordBytes);
    ModifyRequest modifyRequest= new ModifyRequest(userDn, mod);
    /*ModifyRequest mr = new ModifyRequest(userDn, 
    [new Modification(ModificationType.REPLACE, "msDS-UserAccountDisabled", "TRUE".bytes)]);*/
    connection.modify(modifyRequest);

FYI,

enter image description here

提前致谢,

2 个答案:

答案 0 :(得分:1)

您应该修改userAccountControl属性。诀窍是知道将它设置为什么值。

  • 512启用帐户
  • 514已停用帐户
  • 启用544,不需要密码
  • 546已停用,密码不需要
  • 66048已启用,密码未过期
  • 66050已停用,密码未过期
  • 66080已启用,密码不会过期&不需要
  • 66082已停用,密码不会过期&不需要

参考http://www.netvision.com/ad_useraccountcontrol.phphttp://rajnishbhatia19.blogspot.com.au/2008/11/active-directory-useraccountcontrol.html或谷歌搜索代码。

    try {
        Modification mod = new Modification(ModificationType.REPLACE,"userAccountControl","512");
        ModifyRequest mr = new ModifyRequest(userdn,mod);

        LDAPResult lr = ldapcon.modify(mr);
        ResultCode rc = lr.getResultCode();
        if (!rc.equals(ResultCode.SUCCESS)) {
            System.out.println("Something went wrong enabling the account for "+userdn);
        }
    } catch (LDAPException ex) {
        System.out.println(ex.getMessage());
    }

答案 1 :(得分:0)

自从被问到这个问题已经有一段时间了,但要改变的属性是lockoutTime,应该是0来解锁