我想使用 Spring Boot 为 Web 应用程序实现 LDAP 身份验证。这是我的WebSecurityConfig课程:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin();
}
@Configuration
protected static class AuthenticationConfiguration extends
GlobalAuthenticationConfigurerAdapter {
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userDnPatterns("cn={0},ou=institution,ou=people")
.contextSource()
.url("ldap://ldap.mdanderson.edu:389/dc=mdanderson,dc=edu");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我用我的凭据测试了它。以下是 LDAP 服务器上我的用户信息的屏幕截图:
在登录页面上,如果我输入 djiao 作为我的用户名和错误的密码,它会显示Bad credentials。但是如果我给出正确的密码,我会得到 500:
There was an unexpected error (type=Internal Server Error, status=500).
Uncategorized exception occured during …Run Code Online (Sandbox Code Playgroud)