【发布时间】:2016-12-22 00:50:59
【问题描述】:
DefaultLdapAuthoritiesPopulator 将搜索范围设置为“ONE_LEVEL”,但我需要搜索“SUBSCOPE”以获取用户所属的组列表。
我一直在遵循“配置”风格的 Spring 设置(代码,而不是 XML)。虽然有大量关于如何在 XML 中配置自定义 LdapAuthoritiesPopulator 的示例,但我对如何在代码中执行此操作有点坚持。
这是我目前所拥有的:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication()
.contextSource().url("ldap://ldap.company.org/")
.and()
.userSearchBase("o=company.org,c=us")
.userSearchFilter("(uid={0})")
.groupSearchBase("o=company.org,c=us")
.groupSearchFilter("(&(objectClass=groupOfUniqueNames)(uniqueMember={0}))");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin().and().authorizeRequests()
.antMatchers("/api/**").authenticated()
.anyRequest().permitAll();
}
}
缺少的是我需要能够在 DefaultLdapAuthoritiesPopulator 上设置搜索范围。该类本身公开了一个“setSearchSubtree”方法,但 LdapAuthenticationProviderConfigurer 没有提供配置它的方法。
有什么建议吗?
【问题讨论】:
-
你找到解决办法了吗?
标签: spring spring-security ldap spring-security-ldap