【发布时间】:2016-09-07 16:19:30
【问题描述】:
我使用 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 完成的,我不确定如何从第一次登录中获取用户凭据以及如何发送令牌作为对登录的响应。我应该在表单登录过滤器中注入自定义身份验证成功处理程序以根据用户凭据创建令牌吗?如果可以,具体怎么做?
【问题讨论】:
标签: authentication spring-security ldap token