Spring boot 为什么通过DSL的HttpSecurity配置与显式配置的工作方式不同?

Spring boot 为什么通过DSL的HttpSecurity配置与显式配置的工作方式不同?,spring-boot,spring-security,dsl,Spring Boot,Spring Security,Dsl,我费劲地编写了一个DSL来为我的自定义身份验证机制配置HttpSecurity,但我应用于它的大多数配置在应用程序运行时似乎都不起作用,而当我在webapp中手动配置它时,一切都很好 首先是手动配置,它导致myEntryPoint触发,查询authenticationProvider,将筛选器添加到链中,并将myRememberServices添加到该筛选器中。一切正常 public class WebSecurityConfig extends WebSecurityConfigurerAda

我费劲地编写了一个DSL来为我的自定义身份验证机制配置
HttpSecurity
,但我应用于它的大多数配置在应用程序运行时似乎都不起作用,而当我在webapp中手动配置它时,一切都很好

首先是手动配置,它导致my
EntryPoint
触发,查询
authenticationProvider
,将筛选器添加到链中,并将my
RememberServices
添加到该筛选器中。一切正常

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
          .antMatchers("/auth/callback").permitAll()
          .anyRequest().authenticated()
          .and()
        .authenticationProvider(authProvider)
        .rememberMe()
          .rememberMeServices(rememberMeServices)
          .and()
        .exceptionHandling()
          .authenticationEntryPoint(entryPoint)
          .and()
        .addFilterAfter(filter, UsernamePasswordAuthenticationFilter.class);
    /* The following code is basically what gets run when the DSL is in use
    http
        .apply(new EPIdentityDsl())
          // lots of setters called here, removed for clarity
          .and()
        .authorizeRequests().anyRequest().authenticated();
    */
  }

}
然而,DSL中的代码看起来是这样的,当使用它时,
authenticationEntryPoint
永远不会触发。
rememberMeServices
确实得到了配置,看起来过滤器被正确地添加到了链中,但我只是得到了403响应的错误页面,而没有看到
entryPoint
重定向

public class EPIdentityDsl extends AbstractHttpConfigurer<EPIdentityDsl, HttpSecurity> {
  @Override
  public void init(HttpSecurity http) throws Exception {
    // any method that adds/removes another configurer
    // must be done in the init method
    log.debug("dsl init");
    http
        .exceptionHandling()
          .and()
        .rememberMe();
  }

  @Override
  public void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
          .antMatchers(filterProcessesUrl).permitAll()
          .and()
        .authenticationProvider(authProvider)
        .exceptionHandling()
          .authenticationEntryPoint(entryPoint)
          .and()
        .rememberMe()
          .rememberMeServices(rememberMeServices)
          .and()
        .addFilterAfter(filter, UsernamePasswordAuthenticationFilter.class);

  }
}
公共类EPIdentityDsl扩展了AbstractHttpConfigurer{
@凌驾
public void init(HttpSecurity http)引发异常{
//添加/删除其他配置程序的任何方法
//必须在init方法中执行
log.debug(“dsl init”);
http
.例外处理()
.及()
.rememberMe();
}
@凌驾
public void configure(HttpSecurity http)引发异常{
http.authorizeRequests()
.antMatchers(FilterProcessURL).permitAll()
.及()
.authenticationProvider(authProvider)
.例外处理()
.authenticationEntryPoint(入口点)
.及()
.rememberMe()
.记忆服务(记忆服务)
.及()
.addFilterAfter(过滤器,用户名PasswordAuthenticationFilter.class);
}
}

很明显,我在文档中遗漏了一些微妙的交互,导致我基于DSL的
entryPoint
配置丢失。知道为什么吗?如果让我猜的话,可能是我在指定路径的方式上做错了什么,但我无法找到答案。

我也遇到了类似的问题。我通过将入口点移动到init解决了这个问题:)我的dsl设置了身份验证入口点,但在运行时没有使用它…遇到了同样的问题:(