AD如何添加用户

方法/步骤

  1. 在AD服务器上点击【Active Directory域服务】前的加号。

    AD如何添加用户

  2. 在树形菜单点击【点击Active Directory用户和计算机】。

    AD如何添加用户

  3. 在相应的用户组上右击--》【新建】--》【用户】。

    AD如何添加用户

  4. 在打开的对话框内输入用户信息后点击【下一步】。

    AD如何添加用户

  5. 输入用户密码点击【下一步】完成AD用户的创建。

    AD如何添加用户

    AD如何添加用户

AD中创建用户并将用户加入到AD组中,可以通过Java的LDAP API实现。下面是一个示例代码: ```java import javax.naming.*; import javax.naming.directory.*; public class AddUserToGroup { public static void main(String[] args) { String userName = "newuser"; String userPassword = "password"; String groupName = "group1"; try { // Set up the environment for creating the initial context Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, "ldap://localhost:389"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "admin"); env.put(Context.SECURITY_CREDENTIALS, "password"); // Create the initial context DirContext ctx = new InitialDirContext(env); // Create attributes for the user Attributes userAttrs = new BasicAttributes(); userAttrs.put("objectClass", "person"); userAttrs.put("sAMAccountName", userName); userAttrs.put("userPassword", userPassword); // Create the user ctx.createSubcontext("cn=" + userName + ",ou=users,dc=mydomain,dc=com", userAttrs); // Get the group SearchControls ctls = new SearchControls(); ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration<SearchResult> results = ctx.search("ou=groups,dc=mydomain,dc=com", "cn=" + groupName, ctls); SearchResult result = results.next(); // Add the user to the group Attribute member = new BasicAttribute("member", "cn=" + userName + ",ou=users,dc=mydomain,dc=com"); ModificationItem[] mods = new ModificationItem[1]; mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, member); ctx.modifyAttributes(result.getName(), mods); // Close the context ctx.close(); System.out.println("User " + userName + " added to group " + groupName); } catch (Exception e) { e.printStackTrace(); } } } ``` 在这个示例中,我们通过LDAP连接到AD,并创建了一个名为“newuser”的用户。然后,我们搜索名为“group1”的组,并将用户添加到该组中。请注意,我们需要在“member”属性中指定用户的完整DN,才能将其添加到组中。最后,我们关闭了LDAP连接。 请根据你的实际情况修改代码中的参数,例如LDAP服务器地址、管理员账号密码、用户和组名等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值