我正在尝试通过我的 java 应用程序创建一个 AD 组。我已经成功创建了一个用户,现在我正在尝试创建一个组。我有以下代码:
public class ProjectActiveDirectoryUserGroupHandling extends ActiveDirectoryUserGroupHandling {
private static final String DOMAIN_NAME = "DOM01.local";
private static final String DOMAIN_ROOT = "DC=DOM01,DC=local";
private static final String DOMAIN_URL = "ldap://10.123.3.10";
private static final String ADMIN_NAME = "DOM01\\AdServiceUser";
private static final String ADMIN_PASS = "Password";
private String userName, firstName, lastName, password, organisationUnit, groupName, groupOU;
private LdapContext context;
public void newGroup(String groupName, String organisationUnit) {
this.groupName = groupName;
this.groupOU = organisationUnit;
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
// set security credentials, note using simple cleartext authentication
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, ADMIN_NAME);
env.put(Context.SECURITY_CREDENTIALS, ADMIN_PASS);
// connect to my domain controller
env.put(Context.PROVIDER_URL, DOMAIN_URL);
try {
this.context = new InitialLdapContext(env, null);
} catch (NamingException e) {
System.err.println("Problem creating object: ");
e.printStackTrace();
}
}
public boolean addGroup() throws NamingException {
// Create a container set of attributes
Attributes container = new BasicAttributes();
// Create the objectclass to add
Attribute objClasses = new BasicAttribute("objectClass");
objClasses.add("top");
objClasses.add("groupOfUniqueNames");
// Assign name to the group
Attribute cn = new BasicAttribute("cn", groupName);
Attribute groupType = new BasicAttribute("groupType", "2147483650"); // security group
Attribute desc = new BasicAttribute("description", "testDescription");
// Add these to the container
container.put(objClasses);
container.put(cn);
container.put(groupType);
container.put(desc);
// Create the entry
try {
context.createSubcontext(getGroupDN(groupName, groupOU), container);
return true;
} catch (Exception e) {
_log.error(e);
return false;
}
}
运行此程序时,出现以下异常:
javax.naming.OperationNotSupportedException: [LDAP: error code 53 - 00002077: SvcErr: DSID-0319088A, problem 5003 (WILL_NOT_PERFORM)
我发现关于这方面的信息并不多,所以我感到有些失落。希望可以有人帮帮我。