- 论坛徽章:
- 0
|
为什么我自定义的objectClass搜索不到呢,我在命令行用命令可以搜到条目,用LdapBrowser也可以看到条目结构和内容。但是在程序里面一直报异常。
异常:- javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name ''
复制代码 这个是我的ldap一些配置和生成数据的ldif文件内容(部分无关内容不贴了):
1.slapd.conf- include D:/install/OpenLDAP/schema/exampleUserInSystem.schema
- include D:/install/OpenLDAP/schema/exampleSystemRelationSet.schema
- suffix "dc=example,dc=com"
- rootdn "relationName=relation,dc=example,dc=com"
复制代码 2.init.ldif(生成数据的文件)- #init.ldif
- dn:dc=example,dc=com
- objectClass:dcObject
- objectClass:systemRelationObject
- dc:example
- relationName:relation
- dn:relationName=jyxk2relatevideo,dc=example,dc=com
- objectClass:systemRelationObject
- relationName:jyxk2relatevideo
- dn:exampleSystemName=jyxk2,relationName=jyxk2relatevideo,dc=example,dc=com
- objectClass:userSystemRelationObject
- exampleSystemName:jyxk2
- exampleUserName:admin
- exampleUserPassword:123456
- dn:exampleSystemName=video,relationName=jyxk2relatevideo,dc=example,dc=com
- objectClass:userSystemRelationObject
- exampleSystemName:video
- exampleUserName:admin
- exampleUserPassword:123456
复制代码 Java代码:- public static DirContext getLDAPConnection() throws NamingException {
- String root = "relationName=relation,dc=example,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:389");
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL, root);
- env.put(Context.SECURITY_CREDENTIALS, LDAPPassword);
- DirContext ctx = new InitialDirContext(env);
- return ctx;
- }
复制代码- public static NamingEnumeration<SearchResult> getLDAPResultList(
- DirContext ctx) {
- NamingEnumeration<SearchResult> enums = null;
- try {
- String filter = "(objectclass=*)";
- SearchControls searchControls = new SearchControls();
- searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
- enums = ctx.search("", filter, searchControls);
- if (ctx != null) {
- ctx.close();
- }
- return enums;
- } catch (javax.naming.AuthenticationException e) {
- e.printStackTrace();
- return enums;
- } catch (Exception e) {
- e.printStackTrace();
- return enums;
- }
- }
复制代码 |
|