spring-boot - LDAP 身份验证错误 Spring Boot 安全性
问题描述
我遵循指南(https://spring.io/guides/gs/authenticating-ldap/)并有以下课程:
配置类
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected 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")
.and()
.passwordCompare()
.passwordEncoder(new BCryptPasswordEncoder())
.passwordAttribute("userPassword");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and().formLogin();
}
}
控制器类
@RestController
public class HomeController {
@GetMapping("/")
public String getAll()
{
return "Welcome All";
}
}
LDAP 配置文件(在类路径中)
dn: dc=springframework,dc=org
objectclass: top
objectclass: domain
objectclass: extensibleObject
dc: springframework
dn: ou=groups,dc=springframework,dc=org
objectclass: top
objectclass: organizationalUnit
ou: groups
dn: ou=subgroups,ou=groups,dc=springframework,dc=org
objectclass: top
objectclass: organizationalUnit
ou: subgroups
dn: ou=people,dc=springframework,dc=org
objectclass: top
objectclass: organizationalUnit
ou: people
dn: ou=space cadets,dc=springframework,dc=org
objectclass: top
objectclass: organizationalUnit
ou: space cadets
dn: ou=\"quoted people\",dc=springframework,dc=org
objectclass: top
objectclass: organizationalUnit
ou: "quoted people"
dn: ou=otherpeople,dc=springframework,dc=org
objectclass: top
objectclass: organizationalUnit
ou: otherpeople
dn: uid=ben,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Ben Alex
sn: Alex
uid: ben
userPassword: $2a$10$c6bSeWPhg06xB1lvmaWNNe4NROmZiSpYhlocU/98HNr2MhIOiSt36
dn: uid=bob,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Bob Hamilton
sn: Hamilton
uid: bob
userPassword: bobspassword
dn: uid=joe,ou=otherpeople,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Joe Smeth
sn: Smeth
uid: joe
userPassword: joespassword
dn: cn=mouse\, jerry,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Mouse, Jerry
sn: Mouse
uid: jerry
userPassword: jerryspassword
dn: cn=slash/guy,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: slash/guy
sn: Slash
uid: slashguy
userPassword: slashguyspassword
我尝试通过表单登录使用给定的uid和密码登录多次,每次浏览器中都会出现以下错误
Caused by: javax.naming.CommunicationException: localhost:8389
Caused by: java.net.ConnectException: Connection refused: connect
我是否必须在其他地方明确启动 LDAP 服务器,或者我错过了什么?
编辑 - application.yml
spring:
ldap:
embedded:
port: 8389
ldif: "classpath:ldap-data.ldif"
base-dn: "dc=springframework,dc=org"
url: "ldap://localhost:8389/"
解决方案
推荐阅读
- python - 删除彼此相邻的重复值 - 字典中的 Python 列表
- dolphindb - 如何获取 DolphinDB 中的非 NULL 数据?
- qt - QML SwipeView 或 Tumbler 在内容更改时重新加载
- python - 谷歌地球引擎python API
- postgresql - 我正在关注 PostgreSQL 教程。无法从 psql --help 在 psql shell 中获取结果
- swift - 邮件附件中的空 Core Data Sqlite 数据库
- firebase - flutter 状态管理失败
- c# - Microsoft.Office.Interop.Excel.dll' 引用相同的元数据,但只有一个是链接引用
- python - 按标准差大熊猫分组
- yaml - Open API:从 yaml 文件生成属性模式 JSON 以在 UI 上添加验证