<tfoot id='4TstT'></tfoot>
  1. <i id='4TstT'><tr id='4TstT'><dt id='4TstT'><q id='4TstT'><span id='4TstT'><b id='4TstT'><form id='4TstT'><ins id='4TstT'></ins><ul id='4TstT'></ul><sub id='4TstT'></sub></form><legend id='4TstT'></legend><bdo id='4TstT'><pre id='4TstT'><center id='4TstT'></center></pre></bdo></b><th id='4TstT'></th></span></q></dt></tr></i><div id='4TstT'><tfoot id='4TstT'></tfoot><dl id='4TstT'><fieldset id='4TstT'></fieldset></dl></div>

    <small id='4TstT'></small><noframes id='4TstT'>

    <legend id='4TstT'><style id='4TstT'><dir id='4TstT'><q id='4TstT'></q></dir></style></legend>
    • <bdo id='4TstT'></bdo><ul id='4TstT'></ul>
    1. 如何在 Java 中针对此 LDAP 进行 LDAP 搜索/身份验证

      How do a LDAP search/authenticate against this LDAP in Java(如何在 Java 中针对此 LDAP 进行 LDAP 搜索/身份验证)
      <legend id='LFfcs'><style id='LFfcs'><dir id='LFfcs'><q id='LFfcs'></q></dir></style></legend>
    2. <tfoot id='LFfcs'></tfoot>

            <tbody id='LFfcs'></tbody>
            <bdo id='LFfcs'></bdo><ul id='LFfcs'></ul>
          • <i id='LFfcs'><tr id='LFfcs'><dt id='LFfcs'><q id='LFfcs'><span id='LFfcs'><b id='LFfcs'><form id='LFfcs'><ins id='LFfcs'></ins><ul id='LFfcs'></ul><sub id='LFfcs'></sub></form><legend id='LFfcs'></legend><bdo id='LFfcs'><pre id='LFfcs'><center id='LFfcs'></center></pre></bdo></b><th id='LFfcs'></th></span></q></dt></tr></i><div id='LFfcs'><tfoot id='LFfcs'></tfoot><dl id='LFfcs'><fieldset id='LFfcs'></fieldset></dl></div>

                <small id='LFfcs'></small><noframes id='LFfcs'>

              1. 本文介绍了如何在 Java 中针对此 LDAP 进行 LDAP 搜索/身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 LDAP 和 Java 搜索.这是我的 LDIF 导出的简单组织

                I am playing with LDAP and Java search. Here's my LDIF export with a simple organization

                version: 1
                
                dn: dc=example,dc=com
                objectClass: organization
                objectClass: dcObject
                objectClass: top
                dc: example
                o: MyOrganization
                description: Test Description
                
                dn: ou=people, dc=example,dc=com
                objectClass: organizationalUnit
                objectClass: top
                ou: people
                description: All users in demo company
                
                dn: cn=Johnny Doe,ou=people,dc=example,dc=com
                objectClass: organizationalPerson
                objectClass: person
                objectClass: inetOrgPerson
                objectClass: top
                cn: Johnny Doe
                sn: Johnny
                homephone: 123-456-7890
                mail: johnny@johnny.com
                ou: Development
                uid: jjohnny
                userpassword:: johnny
                
                dn: cn=Samuel Johnson,ou=people,dc=example,dc=com
                objectClass: organizationalPerson
                objectClass: person
                objectClass: inetOrgPerson
                objectClass: top
                cn: Samuel Johnson
                sn: Samuel
                homephone: 123-456-7890
                mail: sam@ssam.com
                ou: Accounts
                uid: ssam
                userpassword:: sammy
                

                如何运行 Java 片段以从 LDAP 服务器获取所有用户?我的 Apache DS 目录服务器上没有身份验证设置.

                How do I run a Java snippet to get all users from the LDAP server? There's no authentication set-up on my Apache DS Directory Server.

                Hashtable env = new Hashtable(11);
                env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                env.put(Context.PROVIDER_URL, "ldap://localhost:10389/dc=example,dc=com");
                env.put(Context.SECURITY_AUTHENTICATION, "none");
                
                try {
                    // Create initial context
                    DirContext ctx = new InitialDirContext(env);
                    Object obj = new Object();
                    // want to print all users from the LDAP server
                    System.out.println(obj.toString());
                    ctx.close();
                }
                

                推荐答案

                try {
                    LdapContext ctx = new InitialLdapContext(env, null);
                    ctx.setRequestControls(null);
                    NamingEnumeration<?> namingEnum = ctx.search("ou=people,dc=example,dc=com", "(objectclass=user)", getSimpleSearchControls());
                    while (namingEnum.hasMore ()) {
                        SearchResult result = (SearchResult) namingEnum.next ();    
                        Attributes attrs = result.getAttributes ();
                        System.out.println(attrs.get("cn"));
                
                    } 
                    namingEnum.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                
                private SearchControls getSimpleSearchControls() {
                    SearchControls searchControls = new SearchControls();
                    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
                    searchControls.setTimeLimit(30000);
                    //String[] attrIDs = {"objectGUID"};
                    //searchControls.setReturningAttributes(attrIDs);
                    return searchControls;
                }
                

                这篇关于如何在 Java 中针对此 LDAP 进行 LDAP 搜索/身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  • <i id='BE2wg'><tr id='BE2wg'><dt id='BE2wg'><q id='BE2wg'><span id='BE2wg'><b id='BE2wg'><form id='BE2wg'><ins id='BE2wg'></ins><ul id='BE2wg'></ul><sub id='BE2wg'></sub></form><legend id='BE2wg'></legend><bdo id='BE2wg'><pre id='BE2wg'><center id='BE2wg'></center></pre></bdo></b><th id='BE2wg'></th></span></q></dt></tr></i><div id='BE2wg'><tfoot id='BE2wg'></tfoot><dl id='BE2wg'><fieldset id='BE2wg'></fieldset></dl></div>

                        <tbody id='BE2wg'></tbody>

                    1. <legend id='BE2wg'><style id='BE2wg'><dir id='BE2wg'><q id='BE2wg'></q></dir></style></legend>

                        <small id='BE2wg'></small><noframes id='BE2wg'>

                        <tfoot id='BE2wg'></tfoot>
                        • <bdo id='BE2wg'></bdo><ul id='BE2wg'></ul>