[英]Bad Credentials when authenticating with active directory LDAP with Spring Security
[英]Bad credentials when using ldap in spring boot
我正在使用 Spring-Security 和 ldap 進行身份驗證。我的前端是 Angular。
當我將測試 ldap 身份驗證時,登錄頁面顯示
不好的信用史
但我的密碼和用戶名是正確的
請幫我。
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().fullyAuthenticated().and().formLogin();
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication().userDnPatterns("CN={0}")
.contextSource().url("ldap://dc.msv.net:389/dc=msv,dc=net")
.managerDn("CN=automation,CN=Users,DC=msv,DC=net").managerPassword("Y@sin@72");
}
}
試試這個為我找到的:
@Configuration
@EnableWebSecurity
@RestController
public class AutentificacionLdap extends WebSecurityConfigurerAdapter {
@Value("${config.url_ldap}")
String url_ldap;
@Value("${config.usuario_ldap}")
String usuario_ldap;
@Value("${config.password_ldap}")
String password_ldap;
@Value("${config.userSearchFilter}")
String userSearchFilter;
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/**").permitAll()
.antMatchers("/users/login/**").permitAll()
.antMatchers("/datawatcher/").authenticated()
.anyRequest()
.authenticated()
.and()
.httpBasic();
}
@Override
protected void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
authenticationManagerBuilder
.ldapAuthentication()
.contextSource()
.url(url_ldap)
.managerDn(usuario_ldap)
.managerPassword(password_ldap)
.and()
.userSearchFilter(userSearchFilter);
}
}
使用 .httpBasic();
並放入 application.properties (但如果你想放入課堂)
#Conectar y Autentificar con LDAP
config.url_ldap=ldap://localhost:3268/dc=javadev,dc=com
config.usuario_ldap=CN=userforConnect,CN=Users,DC=javadev,DC=com
config.password_ldap=password
config.userSearchFilter=CN={0}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.