配置 LoginInterceptor
@Service
public class LoginInterceptor implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
System.out.println("init");
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(httpServletRequest,httpServletResponse);
}
@Override
public void destroy() {
System.out.println("完成了");
}
在 SecurityConfig里面配置
@Autowired
private LoginInterceptor myFilterSecurityInterceptor;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin().loginPage("/authentication/require")
.loginProcessingUrl("/authentication/form")
.successHandler(myLoginAuthSuccessHandler).and()
.authorizeRequests().antMatchers("/authentication/require",
"/authentication/form",
"/**/*.js",
"/**/*.css",
"/**/*.jpg",
"/**/*.png",
"/**/*.woff2",
"/auth/*",
"/oauth/*",
"/login/**",
"/mylogout",
"/exit"
)
.permitAll()
.anyRequest().authenticated().and().anonymous().disable().exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login?error")).and()
.csrf().disable();
http.addFilterBefore(myFilterSecurityInterceptor, FilterSecurityInterceptor.class);
}
作者:云大牛1994
来源:CSDN
原文:https://blog.csdn.net/qq_4359...
版权声明:本文为博主原创文章,转载请附上博文链接!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。