首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Boot Guide的问题-使用LDAP验证用户

Spring Boot Guide的问题-使用LDAP验证用户
EN

Stack Overflow用户
提问于 2019-10-04 23:37:39
回答 3查看 4.1K关注 0票数 3

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

我只是按照本入门指南中的步骤进行了说明-

https://spring.io/guides/gs/authenticating-ldap/

STS中的Did开发

与上面示例中的spring.io相同

在接近尾声时,该指南指出应该有一个干净的登录username= bob和password=bobspassword

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

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

EN

回答 3

Stack Overflow用户

发布于 2020-09-02 08:23:05

指南的完整版本对我来说甚至不是开箱即用的。经过相当多的实验,最终是如何在我这一端工作的:

(1) application.properties

代码语言:javascript
复制
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 Security登录页面仍不断抱怨嵌入式ldap连接拒绝端口8399。这就是我将端口号从8389更改为8399的原因。请注意,我首先在Windows防火墙中为8399添加了一个新的“入站规则”。有关如何打开或关闭端口https://docs.bitnami.com/installer/faq/windows-faq/administration/use-firewall-windows/的说明,请访问此链接

(2)根据Spring Guides提供的示例代码,更改/删除下面注释的两行代码:

代码语言:javascript
复制
  @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");
  }
}

如果您刚刚开始学习使用.passwordEncoder进行身份验证的Spring Guides教程,那么删除LDAP (新的LDAP())可以减少复杂性。如果你不喜欢偷工减料,你需要参考其他一些很棒的Stackoverflow帖子,了解如何让passwordEncoder工作。现在,我的解决方案只适用于进行最简单的测试,比如uid使用"bob“,userPassword使用"bobspassword”。如果不删除如上所示的BCrytPasswordEncoder(),在使用"bob“和”bobspassword“进行测试时,您将看到一条警告:"Encoded passoword看起来不像BCrypt”。

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

票数 7
EN

Stack Overflow用户

发布于 2020-04-28 12:33:10

问题是https://spring.io/guides/gs/authenticating-ldap/的指南没有提到如何设置您的application.properties文件。

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

代码语言:javascript
复制
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的代码,我才发现了这一点。

票数 2
EN

Stack Overflow用户

发布于 2020-03-19 00:46:29

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

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

代码语言:javascript
复制
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.ldap:spring-ldap-core' // Essential
    implementation 'org.springframework.security:spring-security-ldap'
    implementation 'com.unboundid:unboundid-ldapsdk' // (not using testImplementation)
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'org.springframework.security:spring-security-test'
}

这是我从javabrains.io教程中学到的自己的存储库的链接。https://github.com/tkhenghong/spring-security-ldap

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58239499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档