Authentication 如何在Spring Security中使用LDAP身份验证创建令牌

Authentication 如何在Spring Security中使用LDAP身份验证创建令牌,authentication,spring-security,ldap,token,Authentication,Spring Security,Ldap,Token,我使用Spring引导和Spring安全性实现了LDAP身份验证。配置非常简单 @Configuration protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter { @Override public void init(AuthenticationManagerBuilder auth) t

我使用Spring引导和Spring安全性实现了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); 
        }
    }
@配置
受保护的静态类AuthenticationConfiguration扩展
GlobalAuthenticationConfigurerAdapter{
@凌驾
public void init(AuthenticationManagerBuilder auth)引发异常{
DefaultSpringSecurityContextSource contextSource=新的DefaultSpringSecurityContextSource(url);
setUserDn(userDn);
setPassword(userPass);
contextSource.setReferral(“follow”);
contextSource.AfterPropertieSet();
LdapAuthenticationProviderConfigurer LdapAuthenticationProviderConfigurer=auth.ldapAuthentication();
ldapAuthenticationProviderConfigurer
.userDnPatterns(“cn={0},ou=机构,ou=人”)
.userSearchBase(“”)
.contextSource(contextSource);
}
}
现在我想创建一个基于令牌的身份验证,这样在第一次成功登录之后,服务器就可以通过使用服务器上创建的令牌验证请求头来验证请求

由于LDAP身份验证是在幕后使用LDAPauthenticationProvider完成的,因此我不确定如何从第一次登录获得用户凭据,以及如何将令牌作为登录响应发送。我是否应该在表单登录筛选器中插入自定义身份验证成功处理程序,以基于用户凭据创建令牌?如果是这样,具体怎么做呢?

您需要