5
我在彈簧引導應用程序中配置了以下代碼。我的第二個過濾器是B,在我提出請求時不會調用。未啓用Spring安全篩選器
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity webSecurity) throws Exception {
webSecurity.ignoring().antMatchers(HttpMethod.GET, "/health");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http.addFilterBefore(new A(), BasicAuthenticationFilter.class);
http.addFilterAfter(new B(), new A().getClass());
}
}
import org.springframework.web.filter.GenericFilterBean;
public class A extends GenericFilterBean {
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
throws IOException, ServletException {
System.out.println("filter A");
}
}
import org.springframework.web.filter.GenericFilterBean;
public class B extends GenericFilterBean {
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
throws IOException, ServletException {
System.out.println("filter B");
}
}
編輯:
public class A extends GenericFilterBean {
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {
System.out.println("filter A Before");
arg2.doFilter(arg0,arg1);
System.out.println("filter A After");
}
}
您能否擴展一下。你會得到什麼錯誤信息?你已經嘗試過什麼來解決你的問題? – kebs
以及沒有錯誤..只是不調用過濾器B. – Harshana
Ofcourse不,也不會永遠......您的'doFilter'方法停止請求處理。你應該調用'filterchain.doFilter(request,response);'繼續處理。你正在打破正確的處理。 –