簡體   English   中英

Spring安全性要求對標記為“匿名”或“ permitAll”的頁面進行身份驗證

[英]Spring security requires authentication for pages marked with “anonymous” or “permitAll”

我的應用程序具有經過身份驗證的管理區域。 我的問題是,它還要求登錄頁面進行身份驗證(盡管它被標記為“匿名”或“ 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類(身份驗證基於智能卡,該類從瀏覽器發送的證書中提取證書)。 我猜可能是因為它是一種預先身份驗證的過濾器,所以也許Spring在任何請求之前都會運行它-從而在瀏覽器中提示身份驗證請求(即使所訪問的頁面“ /admin/login.html”不需要身份驗證)。

因此,我的問題最終是實際上如何禁用登錄頁面的身份驗證? 據我從文檔中antMatcherantMatcher的配置正確。

這是一個代理問題。 有問題的代碼是正確的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM