gpt4 book ai didi

java - 无法通过 java 使用 ldap 创建组。创建用户作品

转载 作者:行者123 更新时间:2023-11-30 01:56:27 29 4
gpt4 key购买 nike

我正在尝试通过我的 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:错误代码 53 - 00002077:SvcErr:DSID-0319088A,问题 5003 (WILL_NOT_PERFORM)

我发现这方面的资料不多,所以感觉有点失落。希望有人能帮助我。

最佳答案

Ldap 错误代码 53 相当广泛,但希望以下内容可能有所帮助(取自 here )

Indicates that the LDAP server cannot process the request because of server-defined restrictions. This error is returned for the following reasons:

  • The Add Request violates the server's structure rules.
  • The Modify Request specifies attributes that users cannot modify.
  • Password restrictions prevent the action.
  • Connection restrictions prevent the action.

当您尝试添加组(并且已经成功连接以创建用户)时,我建议这可能是由于第一个原因 - 您尝试创建的组可能违反了 AD 服务器结构规则。

关于java - 无法通过 java 使用 ldap 创建组。创建用户作品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54328116/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com