歡迎您光臨本站 註冊首頁

程序不能獲得LDAP條目

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

程序不能獲得LDAP條目

為什麼我自定義的objectClass搜索不到呢,我在命令行用命令可以搜到條目,用LdapBrowser也可以看到條目結構和內容。但是在程序裡面一直報異常。
異常:javax.naming.NameNotFoundException: ; remaining name ''這個是我的ldap一些配置和生成數據的ldif文件內容(部分無關內容不貼了):
1.slapd.confinclude                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:123456Java代碼: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;
                }
        }
《解決方案》

之前參照網上的例子,用openldap自帶的objectClass是可以搜索到內容的,我現在不確定問題出在哪裡。順便附上我命令行窗口使用的命令
啟動ldap是:
slapd -d 1
添加條目是:
ldapadd -D "relationName=relation,dc=example,dc=com" -w secret -x -v -f init.ldif
下面是我自定義的objectClassattributetype ( 1.3.6.1.1.1.1.0        NAME 'exampleSystemName'
        DESC 'a system of XX'
        EQUALITY caseIgnoreMatch
        SUBSTR caseIgnoreSubstringsMatch
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
        SINGLE-VALUE )

attributetype ( 1.3.6.1.1.1.1.1        NAME 'exampleUserName'
        DESC 'user name of in this system'
        EQUALITY caseIgnoreMatch
        SUBSTR caseIgnoreSubstringsMatch
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
        SINGLE-VALUE )

attributetype ( 1.3.6.1.1.1.1.2        NAME 'exampleUserPassword'
        DESC 'user password of this user'
        EQUALITY caseIgnoreMatch
        SUBSTR caseIgnoreSubstringsMatch
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
        SINGLE-VALUE )

objectclass ( 1.3.6.1.1.1.2.0 NAME 'userSystemRelationObject' SUP top STRUCTURAL
        DESC 'relation between user and system'
        MUST exampleSystemName
        MAY (exampleUserName $ exampleUserPassword) )另外一個:attributetype ( 2.16.840.1.113730.3.1.13 NAME 'relationName'
        DESC 'relationName'
        EQUALITY caseIgnoreMatch
        SUBSTR caseIgnoreSubstringsMatch
        SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
        SINGLE-VALUE )
       
objectclass ( 1.3.6.1.4.1.42.2.27.1.2.5 NAME 'systemRelationObject' SUP top STRUCTURAL
        DESC 'relation between user and system'
        MUST relationName )
《解決方案》

《解決方案》

今天上班了該有個人回答了吧:cry:

[火星人 ] 程序不能獲得LDAP條目已經有885次圍觀

http://coctec.com/docs/service/show-post-13368.html