我正在尝试使用 LDAP 和 Java (1.4) 在 Active Directory 中启用用户。但是我不断收到以下错误:
java.lang.NullPointerException at com.sun.jndi.ldap.LdapCtx.c_modifyAttributes(LdapCtx.java:1432) at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_modifyAttributes(ComponentDir Context.java:255) at com.sun .jndi.toolkit.ctx.PartialCompositeDirContext.modifyAttributes(Partial CompositeDirContext.java:172) 在 com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.modifyAttributes(Partial CompositeDirContext.java:161) 在 javax.naming.directory.InitialDirContext.modifyAttributes (InitialDirContext.java:146) 在 be.ideal.LDAP.newuser.main(newuser.java:61) 线程“main”中的异常
我已经确认我的用户有密码,但我似乎无法将他的状态更改为活动
我的代码:
public static void main(String[] args) {
String userName = "cn=Albert Einstein,ou=Accounts,DC=PORTAL,DC=COMPANY,DC=BE";
String groupName = "cn=Administrators,cn=Roles,DC=PORTAL,DC=COMPANY,DC=BE";
boolean isDisabled = false;
try {
System.out.println("Creating initial directory context...");
LdapContext ctx = new InitialLdapContext(X_Ldap.getEnvironment(),
null);
Attributes attrs = new BasicAttributes(true);
attrs.put("objectClass", "user");
attrs.put("cn", "Albert Einstein");
String newQuotedPassword = "\"Pass123\"";
byte[] newUnicodePassword = newQuotedPassword.getBytes("UTF-16LE");
attrs.put(new BasicAttribute("unicodePwd", newUnicodePassword));
attrs.put(new BasicAttribute("msDS-UserAccountDisabled", "FALSE"));
System.out.println("Creating context...");
Context result = ctx.createSubcontext(userName, attrs);
System.out.println("Created account for: " + userName);
System.out.println("Creating context...");
Context result = ctx.createSubcontext(userName, attrs);
System.out.println("Created account for: " + userName);
try {
ModificationItem member[] = new ModificationItem[1];
member[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
new BasicAttribute("member", userName));
ctx.modifyAttributes(groupName, member);
System.out.println("Added user to group: " + groupName);
} catch (NamingException e) {
System.err.println("Problem adding user to group: " + e);
}
ctx.close();
System.out.println("Successfully created User: " + userName);
} catch (NamingException e) {
System.err.println("Problem creating object: " + e);
}
catch (IOException e) {
System.err.println("Problem creating object: " + e);
}
}
PS:我正在为我的活动目录使用 AD LDS