1

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()

1 Answer 1

2
@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();
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! it asks me to fill dn patterns beacause I doesnt have the searchfilter, so: factory.setUserDnPatterns(ldapUserDnPattern);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.