我在WebSecurityConfig類重寫配置方法,春季安全 - httpSecurity.AddFilterBefore IntelliJ IDEA的抱怨
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/auth/**").permitAll()
.anyRequest().authenticated();
httpSecurity
.addFilterBefore(new AuthenticationTokenFilter(), UsernamePasswordAuthenticationFilter.class);
}
的IntelliJ是抱怨addFilterBefore
java.lang.Class<? extends java.servlet.Filter in HttpSecurity cannot be applied
我AuthenticationTokenFilter
public class AuthenticationTokenFilter extends UsernamePasswordAuthenticationFilter {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
}
UsernamePasswordAuthenticationFilter擴展了AbstractAuthen ticationProcessingFilter繼而擴展GenericFilterBean並最終實現Filter。不知道是否應該使用過濾器 請參閱屏幕截圖 - 對於錯誤的MSPaint工作表示歉意。
您的代碼看起來正確。它是否由Maven編譯(或者你有什麼構建系統)?有時候我在Idea中看到一個小故障:它說一些與通用相關的代碼是錯誤的,但它們是正確的。你可以嘗試提取'addFilterBefore()'參數作爲局部變量('Filter Filter = new AuthenticationTokenFilter()','Class <?extends Filter> clazz = UsernamePasswordAuthenticationFilter.class'),然後'addFilterBefore(filter,clazz) ,並且如果它讓Idea變得快樂,則將兩個變量內聯。 –
@RomanPuchkovskiy是的,你是對的,這是一個小故障,我做了你說的,錯誤消失了。如果您可以發佈,我會將其標記爲正確的答案。謝謝 –
轉貼爲答覆 –