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)
,369
- OU = 사람 // # (레벨 3)
- ou = HQ2-BR // referal 다른 광고 번호 (레벨 1)
1,363,210 코드 :
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()