0 0

ldap DirContext search方法问题3

public static DirContext getLDAPConnection() throws NamingException {
		String root = "relationName=relation,dc=hisome,dc=com";
		String LDAPPassword = "secret";
		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/" + root);
		env.put(Context.SECURITY_AUTHENTICATION, "simple");
		env.put(Context.SECURITY_PRINCIPAL, root);
		env.put(Context.SECURITY_CREDENTIALS, LDAPPassword);
		DirContext ctx = null;
		ctx = new InitialDirContext(env);
		return ctx;
	}

public static NamingEnumeration<SearchResult> getLDAPResultList(
			DirContext ctx) {
		NamingEnumeration<SearchResult> enums = null;
		try {
			String filter = "(objectclass=*)";
			SearchControls sh = new SearchControls();
			enums = ctx.search("", filter, sh);
			if (ctx != null) {
				ctx.close();
			}
			return enums;
		} catch (javax.naming.AuthenticationException e) {
			e.printStackTrace();
			return enums;
		} catch (Exception e) {
			e.printStackTrace();
			return enums;
		}
	}

一直报NameNotFoundException异常
[LDAP: error code 32 - No Such Object]; remaining name ''
之前参照网上的实例是可以正常拿到SearchResult的,现在我换成自己定义的objectClass就不行了。请问是什么原因呢

问题补充:
xihuan&java 写道
 String filter = "(objectclass=*)";
()去掉试试

去掉了也不行

问题补充:
xihuan&java 写道
enums = ctx.search([color=red]""[/color], filter, sh);   
这里面还少一个参数

xihuan&java 写道
enums = ctx.search([color=red]""[/color], filter, sh);   
这里面还少一个参数

这个参数设置成rootdn或者suffix都不行,我用LdapBrowser可以看到我想要的目录结构和内容

问题补充:
xihuan&java 写道
dc=hisome,dc=com
写这个参数也不行吗

是的,不行。SearchControls 设置了级别也不行

问题补充:
xihuan&java 写道
objectclass大小写对吗

各种大小写组合都试过,应该不是这个问题
2012年2月02日 16:04

4个答案 按时间排序 按投票排序

0 0

objectclass大小写对吗

2012年2月03日 11:22
0 0

dc=hisome,dc=com
写这个参数也不行吗

2012年2月02日 17:50
0 0

enums = ctx.search([color=red]""[/color], filter, sh);   
这里面还少一个参数

2012年2月02日 17:37
0 0

 String filter = "(objectclass=*)";
()去掉试试

2012年2月02日 17:13

相关推荐

Global site tag (gtag.js) - Google Analytics