Active Directory对我来说是一个非常新的东西,有人可以帮助我设置WebSecurityConfig
以便通过Spring Security正确进行AD身份验证。
广告就像:
CN=myCN,OU=OU_1,OU=OU_2,DC=example,DC=com
我正在使用本教程https://spring.io/guides/gs/authenticating-ldap/,并且具有configure
方法,例如(这是kotlin代码):
@Throws(Exception::class)
override fun configure(auth: AuthenticationManagerBuilder) {
auth
.ldapAuthentication()
.userDnPatterns("uid={0},ou=OU_1,ou=OU_2")
.groupSearchBase("")
.userSearchFilter("CN=myCN")
.contextSource()
.url("ldap://{targeted AD IP:389}/dc=example,dc=com")
.and()
.passwordCompare()
.passwordEncoder(LdapShaPasswordEncoder())
.passwordAttribute("userPassword")
}
问题是我无法使用此代码进行身份验证。我收到的错误消息是:
Failed to bind as uid=username,CN=myCN,OU=OU_1, OU=OU_2: org.springframework.ldap.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090400, comment: AcceptSecurityContext error, data 52e, v1db1]; nested exception is javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C090400, comment: AcceptSecurityContext error, data 52e, v1db1]
我确定用户存在并且使用的凭据正确。