1. <tfoot id='AKpvU'></tfoot>
      • <bdo id='AKpvU'></bdo><ul id='AKpvU'></ul>
    2. <small id='AKpvU'></small><noframes id='AKpvU'>

      <legend id='AKpvU'><style id='AKpvU'><dir id='AKpvU'><q id='AKpvU'></q></dir></style></legend>

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

      1. 从 Java 应用程序连接 LDAP 服务器

        Connecting LDAP server from java application(从 Java 应用程序连接 LDAP 服务器)

          1. <legend id='co1MA'><style id='co1MA'><dir id='co1MA'><q id='co1MA'></q></dir></style></legend>
              <tbody id='co1MA'></tbody>
            <tfoot id='co1MA'></tfoot>

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

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

                • <bdo id='co1MA'></bdo><ul id='co1MA'></ul>
                  本文介绍了从 Java 应用程序连接 LDAP 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在构建一个基于 GXT (J2EE) 的应用程序.现在的问题是我必须将应用程序连接到 LDAP 服务器.你能告诉我如何从我们的 java 应用程序连接 LDAP 服务器,以及我必须使用什么库或 API 吗?

                  I am building an application based on GXT (J2EE). Now the problem is that I have to connect the application to a LDAP server. Can you tell me how to connect a LDAP server from our java application and what Library or API I will have to use for that?

                  推荐答案

                  要连接到 LDAP,请查看以下包/类:

                  To connect to LDAP, check out the following packages/classes:

                  javax.naming.directory.*
                  javax.naming.ladp.*
                  com.sun.jndi.ldap.LdapCtxFactory
                  com.sun.jndi.ldap.ControlFactory
                  

                  示例代码:

                  //build a hashtable containing all the necessary configuration parameters
                  Hashtable<String, String> environment = new Hashtable<String, String>();
                  
                  environment.put(LdapContext.CONTROL_FACTORIES, conf.getProperty("ldap.factories.control"));
                  environment.put(Context.INITIAL_CONTEXT_FACTORY, conf.getProperty("ldap.factories.initctx"));
                  environment.put(Context.PROVIDER_URL, conf.getProperty("ldap.host"));
                  environment.put(Context.SECURITY_AUTHENTICATION, "simple");
                  environment.put(Context.SECURITY_PRINCIPAL, conf.getProperty("ldap.user"));
                  environment.put(Context.SECURITY_CREDENTIALS, conf.getProperty("ldap.password"));
                  environment.put(Context.STATE_FACTORIES, "PersonStateFactory");
                  environment.put(Context.OBJECT_FACTORIES, "PersonObjectFactory");
                  
                  // connect to LDAP
                  DirContext ctx = new InitialDirContext(environment);
                  
                  // Specify the search filter
                  String FILTER = "(&(objectClass=Person) ((sAMAccountName=" + user.getUsername() + ")))";
                  
                  // limit returned attributes to those we care about
                  String[] attrIDs = { "sn", "givenName" };
                  
                  SearchControls ctls = new SearchControls();
                  ctls.setReturningAttributes(attrIDs);
                  ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
                  
                  // Search for objects using filter and controls
                  NamingEnumeration answer = ctx.search(searchBase, FILTER, ctls);
                  
                  ...
                  
                  SearchResult sr = (SearchResult) answer.next();
                  Attributes attrs = sr.getAttributes();
                  surName = attrs.get("sn").toString();
                  givenName = attrs.get("givenName").toString();
                  ...
                  

                  在这个例子中,我有一个配置对象,它从配置文件中读取这些值.

                  In this example I have a Configuration object that reads these values from a config file.

                  值是:

                  # LDAP parameters
                  ldap.host = ldap://ldap.mydomain.com:389
                  ldap.factories.initctx = com.sun.jndi.ldap.LdapCtxFactory
                  ldap.factories.control = com.sun.jndi.ldap.ControlFactory
                  ldap.searchbase = dc=mydomain,dc=us
                  ldap.user = MYDOMAIN.COM\ldap-user
                  ldap.userBase= MYDOMAIN.COM\
                  ldap.password = ******
                  

                  这篇关于从 Java 应用程序连接 LDAP 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Slf4j LoggerFactory.getLogger and sonarqube(Slf4j LoggerFactory.getLogger 和 sonarqube)
                  Security - Array is stored directly(安全性 - 数组直接存储)
                  SonarQube quot;Class Not Foundquot; during Main AST Scan(SonarQube“找不到类在主 AST 扫描期间)
                  Integrate Spock#39;s test with Sonar(将 Spock 的测试与声纳集成)
                  How do I make Hudson/Jenkins fail if Sonar thresholds are breached?(如果违反声纳阈值,我如何让 Hudson/Jenkins 失败?)
                  automatically add curly brackets to all if/else/for/while etc. in a java code-base(自动将大括号添加到 java 代码库中的所有 if/else/for/while 等)

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

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

                  • <bdo id='mX16J'></bdo><ul id='mX16J'></ul>
                    • <legend id='mX16J'><style id='mX16J'><dir id='mX16J'><q id='mX16J'></q></dir></style></legend>