<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 搜索/身份验证

      时间:2023-10-14
      <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 搜索/身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何解决“WILL_NOT_PERFORM"?尝试使用 unboundid LDAP SDK 在 scala 下一篇:尝试在 Tomcat 中将 LDAP 配置为 JNDI 资源

                相关文章

              2. <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>

                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>