Issue
Since WebSecurityConfigurerAdapter was deprecated in 5.7 I've got a question how to replace old config
Old config:
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication()
.userSearchFilter(usersFilter)
.contextSource()
.url(url)
.managerDn("login")
.managerPassword("password");
}
}
In spring.io not said how to replace .url(), .managerDn() and .managerPassword()
Solution
@Bean
public DefaultSpringSecurityContextSource defaultSpringSecurityContextSource() {
var contextSourceFromProviderUrl = new DefaultSpringSecurityContextSource(url);
contextSourceFromProviderUrl.setUserDn("login");
contextSourceFromProviderUrl.setPassword("password");
return contextSourceFromProviderUrl;
}
@Bean
AuthenticationManager ldapAuthenticationManager(BaseLdapPathContextSource defaultSpringSecurityContextSource) {
var factory = new LdapBindAuthenticationManagerFactory(defaultSpringSecurityContextSource);
factory.setUserSearchFilter(usersFilter);
return factory.createAuthenticationManager();
}
Answered By - littl3rud3
Answer Checked By - Cary Denson (JavaFixing Admin)