我正在尝试使用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) at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.modifyAttributes(Partial CompositeDirContext.java:161) at javax.naming.directory.InitialDirContext.modifyAttributes(InitialDirContext. java:146) at be.ideal.LDAP.newuser.main(newuser.java:61) Exception in thread "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);
}
}
提示:我正在使用AD LDS作为我的活动目录