我正在尝试
SpringBoot
here中的LDAP身份验证示例
它使用的是我认为不适用于我的要求的ldif方法,因为我们的ldap管理员不会告诉我在哪里可以找到我需要的ldif.
在springboot之前,我曾经使用过自己的ldap实现而不是使用ldif.有没有办法验证不使用ldif只是SECURITY_AUTHENTICATION.simple?
下面是我如何在基本Java没有弹簧的情况下执行ldap安全性.如何在不使用ldif基本用户名密码的情况下在春天这样做.
下面是SpringBoots示例需要使用我的凭据而不是ldif.
@H_404_15@@Configuration protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter { @Override public void init(AuthenticationManagerBuilder auth) throws Exception { auth .ldapAuthentication() .userDnPatterns("uid={0},ou=people") .groupSearchBase("ou=groups") .contextSource().ldif("classpath:test-server.ldif"); } }解决方法
没有LDIF,使用Spring,你可以做类似的事情:
@H_404_15@@Configuration
@EnableWebSecurity
public class HttpSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(ldapAuthenticationProvider());
}
@Bean
public AuthenticationProvider ldapAuthenticationProvider() throws Exception {
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(ldapServerUrl);
contextSource.setUserDn(ldapManagerDn);
contextSource.setPassword(ldapManagerPassword);
contextSource.afterPropertiesSet();
LdapUserSearch ldapUserSearch = new FilterBasedLdapUserSearch(ldapUserSearchBase,ldapUserSearchFilter,contextSource);
BindAuthenticator bindAuthenticator = new BindAuthenticator(contextSource);
bindAuthenticator.setUserSearch(ldapUserSearch);
LdapAuthenticationProvider ldapAuthenticationProvider = new LdapAuthenticationProvider(bindAuthenticator,new DefaultLdapAuthoritiesPopulator(contextSource,ldapGroupSearchBase));
return ldapAuthenticationProvider;
}
}