[英]Spring Security with filters permitAll not working
我有此安全配置:
@Override
public void configure(HttpSecurity http) throws Exception {
http
.addFilterBefore(
new JwtLoginFilter("/login", authenticationManager()),
UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(
new JwtAuthenticationFilter(),
UsernamePasswordAuthenticationFilter.class);
http.csrf().disable()
.authorizeRequests().antMatchers("/", "/register").permitAll()
.and()
.authorizeRequests().anyRequest().authenticated();
}
這兩個過濾器正在執行身份驗證工作:loginFilter檢查帖子正文中的憑據,然后將cookie添加到響應中。 authenticationFilter檢查身份驗證cookie。
但是,allowAll不允許根路由和“ / register”路由通過(aka。仍通過authenticationFilter,我認為allowAll會讓這些路由通過過濾器)
怎么了?
permitAll()不會忽略過濾器。 在處理完所有篩選器之后,無論請求的安全性上下文中是否存在身份驗證 ,它都只會授予訪問權限。
您應該檢查過濾器以及它們使用的任何AuthenticationProvider實現,以確保它們不會拋出未檢查/未捕獲的異常或明確發送對失敗的身份驗證的響應,從而不會破壞Spring Security的執行流程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.