Spring Boot 入门指南“使用 LDAP 验证用户”给出了 java.net.ConnectException: Connection denied
我刚刚按照本入门指南中的分步说明进行操作 -
https://spring.io/guides/gs/authenticating-ldap/
在 STS 中进行开发
与上面 spring.io 的示例相同
最后,指南指出用户名= bob 和密码= bobspassword 应该有一个干净的登录
当我在登录表单中输入相同的凭据时,我的另一个应用程序生成了此错误 -
本地主机:8389; 嵌套异常是 javax.naming.CommunicationException: localhost:8389 [Root 异常是 java.net.ConnectException: 连接被拒绝(连接被拒绝)]
该指南的完整版甚至对我来说都不是开箱即用的。经过相当多的实验,最终下面是我的结果:
(1) application.properties
spring.ldap.embedded.ldif=classpath:test-server.ldif
spring.ldap.embedded.base-dn=dc=springframework,dc=org
spring.ldap.embedded.port=8399
Run Code Online (Sandbox Code Playgroud)
注意这里是 8399,而不是 8389。8389 正在我的 Windows 10 上监听,我通过执行 netstat -an |find /i "389" 验证了这一点。但即使这样工作,Spring Security 登录页面仍然抱怨嵌入式 ldap 连接拒绝端口 8399。这就是激发我将端口号从 8389 更改为 8399 的原因。请注意,我首先在 Windows 防火墙中添加了一个新的“入站规则”为 8399。按照此链接有关如何打开或关闭端口的说明https://docs.bitnami.com/installer/faq/windows-faq/administration/use-firewall-windows/

(2) 根据 Spring Guides 提供的示例代码,更改/删除两行,如下所示:
@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");
}
}
Run Code Online (Sandbox Code Playgroud)
如果您刚开始使用此 Spring Guides 教程进行 LDAP 身份验证,则删除 .passwordEncoder(new BCryptPasswordEncoder()) 会降低复杂性。如果您不喜欢偷工减料,您需要参考其他一些很棒的 Stackoverflow 帖子,了解如何使 passwordEncoder 工作。现在,我的解决方案仅适用于进行最简单的测试,例如 uid 的“bob”和 userPassword 的“bobspassword”才能工作。如上所示,如果不删除 BCrytPasswordEncoder(),在使用“bob”和“bobspassword”进行测试时,您将看到警告:“编码密码看起来不像 BCrypt”。

这就是我偏离指南的全部内容,然后我可以使用 test-server.ldif 中预定义的“bob”和“bobspassword”等登录。
| 归档时间: |
|
| 查看次数: |
3424 次 |
| 最近记录: |