spring-security Spring安全性LDAP Web安全性配置器适配器已过时

x3naxklr  于 2022-11-11  发布在  Spring
关注(0)|答案(1)|浏览(170)

由于WebSecurityConfigurerAdapter在5.7中已弃用,因此我遇到了一个问题,即如何替换旧配置
旧配置:

public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {

    auth.ldapAuthentication()
        .userSearchFilter(usersFilter)
            .contextSource()
            .url(url)
            .managerDn("login")
            .managerPassword("password");
    }                                                                       
}

spring.io中没有表示如何替换.url()、.managerDn()和.managerPassword()

xytpbqjk

xytpbqjk1#

@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();
}

相关问题