我的应用程序有一个经过身份验证的管理区域。我的问题是,它还需要对登录页面进行身份验证(尽管它被标记为"匿名"或"permitAll"——我已经尝试过了)。
我的配置:
@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可能会在任何请求之前运行它,从而在浏览器中提示身份验证请求(即使访问的页面"/admin/login.html"不需要身份验证)。
因此,我的问题最终是如何实际禁用登录页面的身份验证?据我从文档中所知,antMatcher
的配置是正确的。
这是一个代理问题。有问题的代码是正确的。