我使用Spring Boot和Spring Security实现了LDAP身份验证。配置非常简单。
@Configuration
protected static class AuthenticationConfiguration extends
GlobalAuthenticationConfigurerAdapter {
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(url);
contextSource.setUserDn(userDn);
contextSource.setPassword(userPass);
contextSource.setReferral("follow");
contextSource.afterPropertiesSet();
LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthenticationProviderConfigurer = auth.ldapAuthentication();
ldapAuthenticationProviderConfigurer
.userDnPatterns("cn={0},ou=institution,ou=people")
.userSearchBase("")
.contextSource(contextSource);
}
}
现在,我想创建一个基于令牌的身份验证,以便首次成功登录后,服务器可以通过使用服务器上创建的令牌验证请求标头来简单地验证请求。
由于LDAP身份验证是在后台使用ldapAuthentiationProvider完成的,因此我不确定如何从首次登录中获取用户凭证以及如何发送令牌作为对登录的响应。我是否应该在表单登录过滤器中注入自定义身份验证成功处理程序,以基于用户凭据创建令牌?如果是这样,该怎么做呢?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句