Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Spring引导指南的问题-使用LDAP验证用户_Spring Boot_Ldap - Fatal编程技术网

Spring boot Spring引导指南的问题-使用LDAP验证用户

Spring boot Spring引导指南的问题-使用LDAP验证用户,spring-boot,ldap,Spring Boot,Ldap,Spring Boot入门指南“使用LDAP验证用户”给出了java.net.ConnectException:连接被拒绝 我刚刚按照本入门指南中的逐步说明进行了操作- STS的发展 与上面spring.io的示例相同 最后,指南指出username=bob和password=bobspassword应该有一个干净的登录名 当我在登录表单中输入相同的凭据时,另一台计算机上的应用程序会生成此错误- 本地主机:8389;嵌套异常为javax.naming.CommunicationExceptio

Spring Boot入门指南“使用LDAP验证用户”给出了java.net.ConnectException:连接被拒绝

我刚刚按照本入门指南中的逐步说明进行了操作-

STS的发展

与上面spring.io的示例相同

最后,指南指出username=bob和password=bobspassword应该有一个干净的登录名

当我在登录表单中输入相同的凭据时,另一台计算机上的应用程序会生成此错误-


本地主机:8389;嵌套异常为javax.naming.CommunicationException:localhost:8389[根异常为java.net.ConnectException:拒绝连接(拒绝连接)]

我也遇到了同样的问题,我发现我在build.gradle文件中配置了一些依赖项错误

以下是我的依赖项(修复后):

下面是我从javabrains.io教程中学习到的我自己的存储库的链接。


希望这能有所帮助。

问题在于,上的指南没有提到如何设置application.properties文件

解决方案:您需要在resources/application.properties文件中设置以下属性

spring.ldap.embedded.port=8389
spring.ldap.embedded.ldif=classpath:test-server.ldif
spring.ldap.embedded.base-dn=dc=springframework,dc=org
将上述代码复制到application.properties文件中,重新启动Spring应用程序,它就会工作


多亏了tkhenghong的回答和他上传到github的代码,我才发现了这一点。

指南的全部内容对我来说都不是现成的。经过多次试验,我最终得出以下结论:

(1) 应用程序属性

spring.ldap.embedded.ldif=classpath:test-server.ldif
spring.ldap.embedded.base-dn=dc=springframework,dc=org
spring.ldap.embedded.port=8399 
注意这里是8399,不是8389。8389在我的Windows10上监听,我通过netstat-an | find/I“389”验证了这一点。但即使这样,Spring安全登录页面仍不断抱怨嵌入式ldap连接拒绝端口8399。这就是促使我将端口号从8389更改为8399的原因。注意,我首先在8399的Windows防火墙中添加了一个新的“入站规则”。有关如何打开或关闭端口的说明,请遵循此链接

(2) 根据弹簧导轨提供的示例代码,更改/删除以下注释的两行:

  @Override
  public void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth
      .ldapAuthentication()
        .userDnPatterns("uid={0},ou=people")
        .groupSearchBase("ou=groups")
        .contextSource()
          .url("ldap://localhost:8389/dc=springframework,dc=org")//CHANGE 8389 to 8399
          .and()
        .passwordCompare()
          .passwordEncoder(new BCryptPasswordEncoder()) //REMOVE this line
          .passwordAttribute("userPassword");
  }
}
如果您刚开始学习本Spring指南教程中有关LDAP身份验证的内容,那么删除.passwordEncoder(新的BCryptPasswordEncoder())可以减少复杂性。如果你不喜欢走捷径,你需要参考其他一些很棒的Stackoverflow文章,了解如何让passwordEncoder工作。现在,我的解决方案仅限于进行最简单的测试,如uid的“bob”和userPassword的“bobspassword”。如上图所示,如果不删除BCrytPasswordEncoder(),则在使用“bob”和“bobspassword”进行测试时会看到一条警告:“编码的密码看起来不像BCrypt”。


这就是我偏离指南的全部内容,然后我可以使用test server.ldif中预定义的“bob”和“bobspassword”等登录。

“连接被拒绝”意味着没有服务在“localhost:8389”上侦听。您的ldap服务器是否在localhost:8389上运行?(这有点不寻常)显示代码、日志或结果并阅读:这个答案应该被接受这确实对我有用。。。我猜OP应该考虑接受答案。
  @Override
  public void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth
      .ldapAuthentication()
        .userDnPatterns("uid={0},ou=people")
        .groupSearchBase("ou=groups")
        .contextSource()
          .url("ldap://localhost:8389/dc=springframework,dc=org")//CHANGE 8389 to 8399
          .and()
        .passwordCompare()
          .passwordEncoder(new BCryptPasswordEncoder()) //REMOVE this line
          .passwordAttribute("userPassword");
  }
}