使用JWT令牌的LDAP

时间:2017-08-24 13:33:07

标签: spring spring-security

我正在尝试使用 Spring LdapAuthenticationProviderConfigurer进行身份验证,但它仅适用于formLogin()

我像这样配置AuthenticationManagerBuilder

@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
    LdapAuthenticationProviderConfigurer<AuthenticationManagerBuilder> ldapAuthenticationProviderConfigurer = auth
        .ldapAuthentication();
    UserDetailsContextMapper userDetailsContextMapper = userDetailsContextMapper();
    ldapAuthenticationProviderConfigurer.userSearchFilter("(&(sAMAccountName={0}))").userSearchBase("ou=my-ou")
        .contextSource(contextSource).userDetailsContextMapper(userDetailsContextMapper);
    auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}

这是我的contextSource

public DefaultSpringSecurityContextSource contextSource() {
    DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(
        "url");
    contextSource.setBase("base");
    contextSource.setUserDn("userDn");
    contextSource.setPassword("password");
    contextSource.setReferral("follow");
    contextSource.afterPropertiesSet();
    return contextSource;
}

启用后,一切正常:

        .formLogin()
        .loginProcessingUrl("/api/authenticate")

只有在启用此选项时,AuthenticationManagerBuilder才会触发LDAP

我无法使用JWT Token,因为该选项不是必需的。

这是我的JWT HttpSecurity配置:

        .csrf().disable().headers().frameOptions().disable()
        .and()
        .sessionManagement()
        .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .addFilterBefore(corsFilter, UsernamePasswordAuthenticationFilter.class)
        .exceptionHandling()
        .authenticationEntryPoint(http401UnauthorizedEntryPoint())
        .and()
        .authorizeRequests()
        .antMatchers("/api/register").permitAll()
        .antMatchers("/api/activate").permitAll()
        .antMatchers("/api/authenticate").permitAll()
        .antMatchers("/api/account/reset_password/init").permitAll()
        .antMatchers("/api/account/reset_password/finish").permitAll()
        .antMatchers("/api/profile-info").permitAll()
        .antMatchers("/api/**").authenticated()
        .antMatchers("/management/health").permitAll()
        .antMatchers("/management/**").hasAuthority(AuthoritiesConstants.ADMIN)
        .antMatchers("/v2/api-docs/**").permitAll()
        .antMatchers("/swagger-resources/configuration/ui").permitAll()
        .antMatchers("/swagger-ui/index.html").hasAuthority(AuthoritiesConstants.ADMIN)
        .and().apply(securityConfigurerAdapter());

适用于local DB users

当我启用spring security logging并致电/api/authenticate时,登录机制不会通过LDAP

有没有办法手动触发LDAP进程?

我可以在其他地方设置trigger网址吗?

谢谢。

0 个答案:

没有答案