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

    2. <small id='nCfYR'></small><noframes id='nCfYR'>

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

      LDAP 处理期间发生未分类异常;嵌套异常是 javax.naming.NamingException

      时间:2024-05-10
      <legend id='4GhmN'><style id='4GhmN'><dir id='4GhmN'><q id='4GhmN'></q></dir></style></legend>

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

                  <tbody id='4GhmN'></tbody>

                <tfoot id='4GhmN'></tfoot>

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

                本文介绍了LDAP 处理期间发生未分类异常;嵌套异常是 javax.naming.NamingException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试在 oauth2 中使用带有 Spring Boot 安全性的 LDAP 进行身份验证.我的配置如下所示

                I am trying to authenticate using LDAP in oauth2 with spring boot security. My configuration is as given below

                @Configuration
                @Order(Ordered.HIGHEST_PRECEDENCE)
                @EnableWebSecurity
                public class LdapConfiguration extends WebSecurityConfigurerAdapter {
                
                    private static String url ="ldap://myldapdomain.com:389/OU=Users,OU=Accounts,DC=myldapdomain,DC=com";
                
                    @Override
                    protected void configure(HttpSecurity http) throws Exception {
                        http
                        .csrf()
                        .disable()
                        .authorizeRequests()
                        .anyRequest()
                        .authenticated()
                        .and()
                        .httpBasic();
                
                    }
                
                    @Configuration
                    protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {
                        @Override
                        public void init(AuthenticationManagerBuilder auth) throws Exception {
                            auth
                            .ldapAuthentication()
                            .userSearchFilter("(uid={0})")
                            .contextSource().url(url);
                        }
                    }
                }
                

                当我尝试登录 http://localhost:9000/api/oauth/带有所需 LDAP 用户名和密码的令牌 我收到以下异常

                When I tried to login to http://localhost:9000/api/oauth/token with the required LDAP userid and password I am getting the following exception

                {
                    "timestamp": 1508848799342,
                    "status": 401,
                    "error": "Unauthorized",
                    "message": "Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C090749, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v2580u0000]; remaining name '/'",
                    "path": "/api/oauth/token"
                }
                

                谁能帮我解决这个问题

                更新 1

                我使用下面的代码 authenticateUser 函数创建了一个用于 LDAP 身份验证的 Java 独立应用程序.在那里我可以成功登录

                I have created a java standalone application for LDAP authentication using the below code authenticateUser function. There I am able to login successfully

                private String ldapURL = "ldap://myldapdomain:389";
                
                private String ldapDomain = "myldapdomain.com";
                
                
                public void authenticateUser(String username, String password) throws NamingException {
                        Hashtable<String, String> env = new Hashtable<>();
                        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                        env.put(Context.SECURITY_AUTHENTICATION, "simple");
                        env.put(Context.PROVIDER_URL, ldapURL);
                        env.put(Context.SECURITY_PRINCIPAL, username + "@" + ldapDomain);
                        env.put(Context.SECURITY_CREDENTIALS, password);
                
                        DirContext context = null;
                        try {
                            context = new InitialDirContext(env);
                        } catch (Exception e) {
                            if (context != null) {
                                context.close();
                            }
                            System.out.println("LDAP auth Failed:::"+ e.getMessage());
                            //throw new LoginFailedException("Invalid User Id orPassword");
                        }
                }
                

                推荐答案

                您必须定义一个 managerDn 用于绑定到您的 LDAP.

                You have to define a managerDn which is used to bind to your LDAP.

                例如ldapAuthentication().contextSource().url(securityConfigProperties.getUrl()).port(securityConfigProperties.getPort()).managerDn(securityConfigProperties.getManagerDn()).managerPassword(securityConfigProperties.getManagerPassword())

                这篇关于LDAP 处理期间发生未分类异常;嵌套异常是 javax.naming.NamingException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 Java LDAP 连接上指定 SSL/TLS 版本? 下一篇:使用 LDAP 从 Active Directory 检索用户属性 - JAVA

                相关文章

                1. <tfoot id='qP1HD'></tfoot>

                2. <small id='qP1HD'></small><noframes id='qP1HD'>

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