2
我有一个搜索LDAP的问题。如果我使用下面的代码,我可以使用下面的代码获得2级。 但我想获得4级对象。感谢您的任何帮助。LDAP JNDI子树搜索
当前的搜索基础:ou=HQ2-BR
,过滤器:"(ou=*)";
问候, 朴文香,戴夫 [email protected] [email protected]
LDAP结构
- o = com,dc = rabbitforever#(等级0)
- ou = HQ2-BR // referal其他广告#(水平1)
- OU = TSB //#(级别2)
- OU = BM1 //#(2级)
- OU = IIC //#(级别2)
- OU =人们//#(3级)
- UID = IICCIO //#(4级)
- UID = IICSIO1 //#(4级)
- OU =人们//#(3级)
- ou = HQ2-BR // referal其他广告#(水平1)
代码:
public void loopLDAP() {
String adminName = "uid=writer,ou=People,o=com,dc=rabbitforever";
String adminPassword = "password";
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
//env.put(Context.PROVIDER_URL,
// "ldap://192.168.1.127:389/dc=rabbitforever,dc=com");
env.put(Context.PROVIDER_URL,
"ldap://10.10.176.156:389/o=com,dc=rabbitforever");
//env.put(Context.SECURITY_AUTHENTICATION, "none");
env.put(Context.SECURITY_PRINCIPAL, adminName);
env.put(Context.SECURITY_CREDENTIALS, adminPassword);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.REFERRAL, "follow");
try {
LdapContext ctx = new InitialLdapContext(env, null);
ctx.setRequestControls(null);
String filter = "(ou=*)";
NamingEnumeration<?> namingEnum = ctx.search("ou=HQ2-BR", filter,
getSimpleSearchControls());
while (namingEnum.hasMore()) {
SearchResult result = (SearchResult) namingEnum.next();
Attributes attrs = result.getAttributes();
String cn = "";
String sn = "";
String description = "";
String uid = "";
if (null != attrs.get(cn)) {
cn = attrs.get("cn").toString();
}
if (null != attrs.get("sn")) {
sn = attrs.get("sn").toString();
}
if (null != attrs.get("description")) {
description = attrs.get("description").toString();
}
if (null != attrs.get("uid")) {
uid = attrs.get("uid").toString();
}
System.out.println(cn + " | " + sn + " | " + description
+ " | " + uid);
}
} catch (Exception ex) {
ex.printStackTrace();
}
} // end loopLDAP()