I'm using Spring-Security and ldap for authentication.My frontend is Angular.
When i will test ldap authentication ,login page show
Bad credentials
but my password and username is correct
please help me.
@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");
}
}
Try this found for my:
@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);
}
}
Use .httpBasic();
And put in application.properties (but if you want put in class)
#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}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.