免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2922 | 回复: 3
打印 上一主题 下一主题

程序不能获得LDAP条目 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-02-03 15:39 |只看该作者 |倒序浏览
为什么我自定义的objectClass搜索不到呢,我在命令行用命令可以搜到条目,用LdapBrowser也可以看到条目结构和内容。但是在程序里面一直报异常。
异常:
  1. javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name ''
复制代码
这个是我的ldap一些配置和生成数据的ldif文件内容(部分无关内容不贴了):
1.slapd.conf
  1. include                D:/install/OpenLDAP/schema/exampleUserInSystem.schema
  2. include                D:/install/OpenLDAP/schema/exampleSystemRelationSet.schema

  3. suffix                "dc=example,dc=com"
  4. rootdn                "relationName=relation,dc=example,dc=com"
复制代码
2.init.ldif(生成数据的文件)
  1. #init.ldif
  2. dn:dc=example,dc=com
  3. objectClass:dcObject
  4. objectClass:systemRelationObject
  5. dc:example
  6. relationName:relation

  7. dn:relationName=jyxk2relatevideo,dc=example,dc=com
  8. objectClass:systemRelationObject
  9. relationName:jyxk2relatevideo

  10. dn:exampleSystemName=jyxk2,relationName=jyxk2relatevideo,dc=example,dc=com
  11. objectClass:userSystemRelationObject
  12. exampleSystemName:jyxk2
  13. exampleUserName:admin
  14. exampleUserPassword:123456

  15. dn:exampleSystemName=video,relationName=jyxk2relatevideo,dc=example,dc=com
  16. objectClass:userSystemRelationObject
  17. exampleSystemName:video
  18. exampleUserName:admin
  19. exampleUserPassword:123456
复制代码
Java代码:
  1. public static DirContext getLDAPConnection() throws NamingException {
  2.                 String root = "relationName=relation,dc=example,dc=com";
  3.                 String LDAPPassword = "secret";
  4.                 Hashtable<String, String> env = new Hashtable<String, String>();
  5.                 env.put(Context.INITIAL_CONTEXT_FACTORY,
  6.                                 "com.sun.jndi.ldap.LdapCtxFactory");
  7.                 env.put(Context.PROVIDER_URL, "ldap://localhost:389");
  8.                 env.put(Context.SECURITY_AUTHENTICATION, "simple");
  9.                 env.put(Context.SECURITY_PRINCIPAL, root);
  10.                 env.put(Context.SECURITY_CREDENTIALS, LDAPPassword);
  11.                 DirContext ctx = new InitialDirContext(env);
  12.                 return ctx;
  13.         }
复制代码
  1. public static NamingEnumeration<SearchResult> getLDAPResultList(
  2.                         DirContext ctx) {
  3.                 NamingEnumeration<SearchResult> enums = null;
  4.                 try {
  5.                         String filter = "(objectclass=*)";
  6.                         SearchControls searchControls = new SearchControls();
  7.                         searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
  8.                         enums = ctx.search("", filter, searchControls);
  9.                         if (ctx != null) {
  10.                                 ctx.close();
  11.                         }
  12.                         return enums;
  13.                 } catch (javax.naming.AuthenticationException e) {
  14.                         e.printStackTrace();
  15.                         return enums;
  16.                 } catch (Exception e) {
  17.                         e.printStackTrace();
  18.                         return enums;
  19.                 }
  20.         }
复制代码

论坛徽章:
0
2 [报告]
发表于 2012-02-03 15:45 |只看该作者
之前参照网上的例子,用openldap自带的objectClass是可以搜索到内容的,我现在不确定问题出在哪里。顺便附上我命令行窗口使用的命令
启动ldap是:
slapd -d 1
添加条目是:
ldapadd -D "relationName=relation,dc=example,dc=com" -w secret -x -v -f init.ldif
下面是我自定义的objectClass
  1. attributetype ( 1.3.6.1.1.1.1.0        NAME 'exampleSystemName'
  2.         DESC 'a system of XX'
  3.         EQUALITY caseIgnoreMatch
  4.         SUBSTR caseIgnoreSubstringsMatch
  5.         SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
  6.         SINGLE-VALUE )

  7. attributetype ( 1.3.6.1.1.1.1.1        NAME 'exampleUserName'
  8.         DESC 'user name of in this system'
  9.         EQUALITY caseIgnoreMatch
  10.         SUBSTR caseIgnoreSubstringsMatch
  11.         SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
  12.         SINGLE-VALUE )

  13. attributetype ( 1.3.6.1.1.1.1.2        NAME 'exampleUserPassword'
  14.         DESC 'user password of this user'
  15.         EQUALITY caseIgnoreMatch
  16.         SUBSTR caseIgnoreSubstringsMatch
  17.         SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
  18.         SINGLE-VALUE )

  19. objectclass ( 1.3.6.1.1.1.2.0 NAME 'userSystemRelationObject' SUP top STRUCTURAL
  20.         DESC 'relation between user and system'
  21.         MUST exampleSystemName
  22.         MAY (exampleUserName $ exampleUserPassword) )
复制代码
另外一个:
  1. attributetype ( 2.16.840.1.113730.3.1.13 NAME 'relationName'
  2.         DESC 'relationName'
  3.         EQUALITY caseIgnoreMatch
  4.         SUBSTR caseIgnoreSubstringsMatch
  5.         SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
  6.         SINGLE-VALUE )
  7.        
  8. objectclass ( 1.3.6.1.4.1.42.2.27.1.2.5 NAME 'systemRelationObject' SUP top STRUCTURAL
  9.         DESC 'relation between user and system'
  10.         MUST relationName )
复制代码

论坛徽章:
0
3 [报告]
发表于 2012-02-03 16:05 |只看该作者

论坛徽章:
0
4 [报告]
发表于 2012-02-06 08:57 |只看该作者
今天上班了该有个人回答了吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP