[英]Search DirContext without name
I use a service account to connect to Active Directory and then search for a user using the context like : 我使用服务帐户连接到Active Directory,然后使用如下上下文搜索用户:
String searchBase = "DC=extLDAP,DC=com";
String query = "(&(objectCategory=person)(objectClass=user)(SAMAccountName=batty))";
final SearchControls constraints = new SearchControls();
final NamingEnumeration<?> searchResults = dirContext.search(searchBase,searchQuery,constraints);
But I have a scenario when searchBase is not given to me. 但是我有一个场景,没有给我searchBase。 In this case, I need to search through complete active directory.
在这种情况下,我需要搜索完整的活动目录。
I tried to use searchBase=null;
我尝试使用
searchBase=null;
and searchBase="";
和
searchBase="";
but in both cases I get NullPointerException
and NameNotFoundException
respectively. 但在两种情况下,我分别得到
NullPointerException
和NameNotFoundException
。
Is there any way I can search through complete active directory without knowing searchBase
or domain name. 有什么方法可以在不知道
searchBase
或域名的情况下搜索完整的活动目录。
Note : I am making connection using full dn of service account. 注意 :我正在使用服务帐户的完整dn建立连接。 So, not knowing domain name specifically.
因此,不知道具体的域名。
The searchbase is always the domain root DC=extLDAP,DC=com
- you cannot search more objects in your AD. 搜索库始终是域根
DC=extLDAP,DC=com
您无法在AD中搜索更多对象。
However, if you do not know the domain root context beforehand, you can do either of three things: 但是,如果您事先不知道域根上下文,则可以执行以下三种操作之一:
Of course all Microsoft examples are in C# or worse, but you should be able to translate to proper Java. 当然,所有Microsoft示例都使用C#或更糟糕的版本,但是您应该能够转换为适当的Java。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.