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

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

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

        • <bdo id='zEPWg'></bdo><ul id='zEPWg'></ul>

      2. 使用带有 spring LDAP API 的 LDAP 进行身份验证,而不使用 spring 安全性

        Authenticating using LDAP with spring LDAP API and without using spring security(使用带有 spring LDAP API 的 LDAP 进行身份验证,而不使用 spring 安全性)

          • <bdo id='ENRV4'></bdo><ul id='ENRV4'></ul>
                <tbody id='ENRV4'></tbody>
            1. <small id='ENRV4'></small><noframes id='ENRV4'>

              <tfoot id='ENRV4'></tfoot>

                  <legend id='ENRV4'><style id='ENRV4'><dir id='ENRV4'><q id='ENRV4'></q></dir></style></legend>
                  <i id='ENRV4'><tr id='ENRV4'><dt id='ENRV4'><q id='ENRV4'><span id='ENRV4'><b id='ENRV4'><form id='ENRV4'><ins id='ENRV4'></ins><ul id='ENRV4'></ul><sub id='ENRV4'></sub></form><legend id='ENRV4'></legend><bdo id='ENRV4'><pre id='ENRV4'><center id='ENRV4'></center></pre></bdo></b><th id='ENRV4'></th></span></q></dt></tr></i><div id='ENRV4'><tfoot id='ENRV4'></tfoot><dl id='ENRV4'><fieldset id='ENRV4'></fieldset></dl></div>
                • 本文介绍了使用带有 spring LDAP API 的 LDAP 进行身份验证,而不使用 spring 安全性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在我的 Sprint 启动应用程序中使用 spring-ldap-core 插件.基本上,LDAPTemplate - http://docs.spring.io/spring-ldap/docs/current/apidocs/org/springframework/ldap/core/LdapTemplate.html

                  I am using spring-ldap-core plugin in my Sprint boot application. Basically, the LDAPTemplate - http://docs.spring.io/spring-ldap/docs/current/apidocs/org/springframework/ldap/core/LdapTemplate.html

                  我基本上想使用 Spring LDAP API 将下面的 xml 配置转换为 java,并希望避免使用 Spring Security.

                  I basically want to convert the xml configuration below into java using Spring LDAP API and want to avoid using spring security.

                  我要转换的xml配置是-

                  The xml configuration that I want to convert is -

                   <ldap-server id="ldapServer"
                                   url="ldap://ad.company.com:389"
                                   manager-dn="CN=serviceaccount,OU=Service Accounts,DC=ad,DC=company,DC=com"
                                   manager-password="password"/>
                  
                      <authentication-manager>
                          <ldap-authentication-provider
                                  server-ref="ldapServer"
                                  user-search-base="dc=ad,dc=company,dc=com"
                                  user-search-filter="sAMAccountName={0}"
                                  group-search-filter="member={0}"
                                  group-search-base="ou=Groups,dc=ad,dc=company,dc=com"
                                  group-role-attribute="cn"/>
                      </authentication-manager>
                  

                  下面是我的java代码-

                  Here is my java code below-

                  import org.springframework.context.annotation.Bean;
                  import org.springframework.context.annotation.Configuration;
                  import org.springframework.ldap.core.LdapTemplate;
                  import org.springframework.ldap.core.support.LdapContextSource;
                  import org.springframework.ldap.authentication.DefaultValuesAuthenticationSourceDecorator;
                  
                  @Configuration
                  public class LdapConfiguration {
                  
                      @Bean
                      public LdapContextSource contextSource(){
                          LdapContextSource contextSource = new LdapContextSource();
                  
                          contextSource.setUrl("ldap://ad.company.com:389");
                          contextSource.setBase("DC=ad,DC=company,DC=com");
                          contextSource.setUserDn("CN=serviceaccount,OU=Service Accounts,DC=ad,DC=company,DC=com");
                          contextSource.setPassword("password");
                          contextSource.afterPropertiesSet();
                          return contextSource;
                      }
                  
                  
                      @Bean
                      public LdapTemplate ldapTemplate(){
                  
                          LdapTemplate template = new LdapTemplate(contextSource());
                          try {
                              template.afterPropertiesSet();
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
                          return template;
                      }
                  }
                  

                  这就是我尝试调用身份验证的方式 -如果发生身份验证,此代码段所属的方法将返回一个布尔值

                  This is how I am trying to invoke authentication - The method that this snippet is a part of returns a boolean value if authentication happens

                   AndFilter filter = new AndFilter();
                  
                      filter.and(new EqualsFilter("sAMAccountName", userloginName));
                  
                      return ldapTemplate.authenticate("OU=Service Accounts", filter.encode(), userPassword);
                  

                  这不起作用,我得到的错误是:

                  This is not working and the error I get is that :

                  No results found for search, base: 'OU=Service Accounts'; filter: '(sAMAccountName=usernameIinput)'.
                  

                  我想知道如何使用 LDAP API 配置以下 xml 属性?

                  I want to know how the following xml properties can be configured using LDAP API?

                  group-search-filter="member={0}"
                  group-search-base="ou=Groups,dc=ad,dc=company,dc=com"
                  group-role-attribute="cn"/>
                  

                  另外,我还缺少什么?为什么这不起作用?任何帮助将不胜感激!

                  Also, what else am I missing? Why is this not working? Any help will be really appreciated!

                  推荐答案

                  我能够解决这个问题.

                  //使用LDAPTemplate的LDAP连接

                  //LDAP connection using LDAPTemplate

                  @Configuration
                  public class LdapConfiguration {
                  
                      @Bean
                      public LdapContextSource contextSource(){
                          LdapContextSource contextSource = new LdapContextSource();
                          contextSource.setUrl("ldap://companyurl.com:389");
                          contextSource.setUserDn("CN=serviceaccount,OU=Service Accounts,DC=ad,DC=company,DC=com");
                          contextSource.setPassword("secretpassword");
                          return contextSource;
                      }
                  
                      @Bean
                      public LdapTemplate ldapTemplate(){
                          LdapTemplate template = new LdapTemplate(contextSource());
                          return template;
                      }
                  }
                  

                  //认证部分

                  AndFilter filter = new AndFilter();
                  filter.and(new EqualsFilter("mailNickname", username));
                  
                  Boolean authenticate = ldapTemplate.authenticate(base, filter.encode(), userpassword);
                  

                  这篇关于使用带有 spring LDAP API 的 LDAP 进行身份验证,而不使用 spring 安全性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 中的默认语言环境设置以使其保持一致?)
                • <tfoot id='mLcdq'></tfoot>

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

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

                    • <bdo id='mLcdq'></bdo><ul id='mLcdq'></ul>