【问题标题】:How to enable user via LDAP in AD?如何在 AD 中通过 LDAP 启用用户?
【发布时间】:2011-08-23 08:04:42
【问题描述】:

在我的程序(基于 jldap)中,我尝试通过将 userAccountControl 值设置为 512 来启用 AD 中的用户。 使用以下属性创建的用户:

objectClass=user
cn=username
name=username
userAccountControl=512
userPassword={BASE64}<base64 encoded password>
sAMAccountName=username
distinguishedName=username,CN=Users,DC=company,DC=com

但我得到了例外:

LDAPException: Unwilling To Perform (53) Unwilling To Perform
LDAPException: Server Message: 0000052D: SvcErr: DSID-031A0FC0, problem 5003 (WILL_NOT_PERFORM), data 0

可能有人可以告诉我我在哪里犯了错误?也许我忘记了一些必需的属性?

编辑:

我的代码(很简单,我认为其中没有错误):

LDAPConnection connection;
LDAPMessageQueue messageQueue;
...
LDAPAttributeSet attributes = new LDAPAttributeSet();
attributes.add(new LDAPAttribute("objectClass", "user"));
attributes.add(new LDAPAttribute("cn", "username"));
attributes.add(new LDAPAttribute("name", "username"));
attributes.add(new LDAPAttribute("userAccountControl", "512"));
attributes.add(new LDAPAttribute("userPassword", "{BASE64}<base64 encoded password>"));
attributes.add(new LDAPAttribute("sAMAccountName", "username"));
attributes.add(new LDAPAttribute("distinguishedName", "username,CN=Users,DC=company,DC=com"));

LDAPEntry entry = new LDAPEntry("CN=username,CN=Users,DC=company,DC=com", attributes);
connection.add(entry);

【问题讨论】:

  • 请显示一些代码作为您如何设置这些值。可能有错误。
  • 我不认为,代码中的错误,因为我可以创建禁用用户,但是当我尝试启用用户时,我收到异常。

标签: java active-directory ldap


【解决方案1】:

当密码未正确编码时,可能会出现此错误。确保它是 Base64 编码的 UTF-16LE 字符串。

示例(如果您使用的是 Oracle JVM)

String pass = "password";
sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder();
String encoded = enc.encode(pass.getBytes("UTF-16LE"));

更新 1: 您是否尝试过在没有 userAccountControl 属性的情况下运行代码(以排除或排除实际上是该属性导致问题)?

我注意到您的专有名称属性看起来也有些奇怪。它应该看起来像CN=username,OU=Users,DC=company,DC=com

更新 2:见 Adding a user with a password in Active Directory LDAP。如果您尝试通过非 SSL 连接为条目设置密码(您是,因为您正在创建它),则可以返回 WILL_NOT_PERFORM。您需要确保通过 SSL 连接到 AD 服务器(并根据需要设置证书)。

【讨论】:

  • 谢谢你,但是当我尝试你的例子时,我遇到了一些异常。
  • 哪个例外?和以前一样吗?请发布您如何创建/更新用户的代码。
  • 是的,异常和以前一样。我添加了有问题的代码。
  • 谢谢,我在编写代码示例时犯了错误。在现实世界的应用程序中,我以正确的格式设置了专有名称。感谢您对 SSL 的注意——我认为这是我的问题的根源。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多