【发布时间】:2021-11-10 12:17:43
【问题描述】:
我需要创建一个 SpringBoot 服务并使用 LDAP 提供一个身份验证服务。 我关注了这个example,它使用嵌入式本地 ldap 服务器对我来说很好(如教程中所建议的那样)
现在我尝试使用官方的公司 LDAP 服务器,但我收到了这个错误:
Uncategorized exception occured during LDAP processing; nested exception is javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C090A5C, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v4563];
此错误似乎与必需的 LDAP 绑定请求有关。但是如何将其添加到 Spring Security LDAP 中?
这是我尝试集成公司 LDAP 连接的代码:
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userDnPatterns("userPrincipalName={0},ou=users")
.groupSearchBase("ou=users")
.contextSource()
.url("ldap://companyhost:389/dc=aa,dc=company,dc=com")
.and()
.passwordCompare()
.passwordEncoder(new BCryptPasswordEncoder())
.passwordAttribute("userPassword");
}
我也尝试了我的 PHP 示例(使用官方公司活动目录,这工作正常)
// connect to ldap server
$ad = ldap_connect("ldap://".LDAP_HOST, LDAP_PORT)
or die("Could not connect to LDAP server.");
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
$user = $_POST['username'];
$password = $_POST['password'];
if (ldap_bind($ad, "$user"."@".LDAP_HOST, $password)) {
// User authenticated
}
【问题讨论】:
标签: php spring spring-security ldap spring-security-ldap