java的ldap的过滤,LDAP过滤器 - 搜索特定OU的所有用户

I am having trouble with an LDAP Search Filter. What I am needing to retrieve is all the users of a specific LDAP group that is OU=Staff,OU=Users,OU=Accounts,DC=test,DC=local

My search is:

(&(objectCategory=user)(OU=Staff,OU=Users,OU=Accounts,DC=test,DC=local))

Currently it is returning no results. What am I missing?

解决方案

You must do two things

Set the base of the search OU=Staff,OU=Users,OU=Accounts,DC=test,DC=local

Search for the objects with the objectClass.

Using PHP, the search would look like this (based on this PHP sample):

//You must bind, first

// using ldap bind

$ldaprdn = 'yourdomain\nic_hubbard'; // ldap rdn or dn

$ldappass = 'password'; // associated password

// connect to ldap server

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Java中的JNDI(Java Naming and Directory Interface)API来连接LDAP服务器,并执行添加用户的操作。以下是一个简单的Java代码示例: ```java import javax.naming.*; import javax.naming.directory.*; public class LDAPAddUserExample { public static void main(String[] args) { // LDAP服务器信息 String ldapURL = "ldap://localhost:389"; String ldapUser = "cn=admin,dc=mydomain,dc=com"; String ldapPassword = "adminpassword"; // 用户信息 String username = "newuser"; String userPassword = "password"; String userFullName = "New User"; String userDescription = "A new user account"; try { // 创建LDAP连接 Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, ldapURL); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, ldapUser); env.put(Context.SECURITY_CREDENTIALS, ldapPassword); DirContext ctx = new InitialDirContext(env); // 创建用户对象 Attributes attrs = new BasicAttributes(); attrs.put("objectClass", "top"); attrs.put("objectClass", "person"); attrs.put("objectClass", "organizationalPerson"); attrs.put("objectClass", "inetOrgPerson"); attrs.put("uid", username); attrs.put("cn", userFullName); attrs.put("sn", username); attrs.put("userPassword", userPassword); attrs.put("description", userDescription); // 添加用户 ctx.createSubcontext("uid=" + username + ",ou=users,dc=mydomain,dc=com", attrs); // 关闭LDAP连接 ctx.close(); System.out.println("User added successfully!"); } catch (NamingException e) { e.printStackTrace(); } } } ``` 需要替换代码中的LDAP服务器信息和用户信息为实际值,并确保LDAP服务器已启动并可用。此代码将在LDAP服务器的“ou=users,dc=mydomain,dc=com”组织单元中创建一个名为“newuser”的用户

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值