Spring安全性要求对标有"匿名"的页面进行身份验证。或" permitAll"

时间:2015-12-14 13:04:11

标签: java spring-security spring-boot

我的应用程序有一个经过身份验证的管理区域。我的问题是它还需要对登录页面进行身份验证(尽管它被标记为&#34;匿名&#34;或者&#34; permitAll&#34; - 我已经尝试了两者)。< / p>

我的配置:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.antMatcher("/admin/**")
        .authorizeRequests()
            .antMatchers("/admin/login.html", "/admin/logout.html").permitAll() //"anonymous()" has same result
            .antMatchers("/admin/**").hasAnyRole("ADMIN", "PUBLISHER")
            .anyRequest().authenticated()
        .and()
            .addFilter(preAuthenticationFilter())
            .addFilter(adminExceptionTranslationFilter())
            .csrf().disable()
            .logout()
                .logoutRequestMatcher(new AntPathRequestMatcher("/admin/logout.html"))
                .logoutSuccessUrl("/index.html")
                .invalidateHttpSession(true);
}

我唯一能想到的可能是罪魁祸首是preAuthenticationFilter扩展了AbstractPreAuthenticatedProcessingFilter类(身份验证是基于智能卡的,并且该类从由...发送的证书中提取凭据浏览器)。我猜这可能是因为它是一种 pre 经过身份验证的过滤器,然后Spring可能会在任何请求之前运行它 - 从而在浏览器中提示身份验证请求(即使访问过的页面&#34; /admin/login.html"不要求身份验证。)

所以我的问题最终是如何实际禁用登录页面的身份验证?据我所知,从文档中可以正确配置antMatcher

1 个答案:

答案 0 :(得分:0)

这是代理问题。有问题的代码是正确的。