feat: sercurity的配置文件新增加LogoutHandler的实现类 在LogoutFilter之前加入jwtAuthenticationTokenFilter

This commit is contained in:
weihongyang 2022-06-23 15:39:49 +08:00
父節點 aab0ea4479
當前提交 093d6ee362

查看文件

@ -1,6 +1,7 @@
package com.cnbm.admin.config;
import com.cnbm.admin.filter.JwtAuthenticationTokenFilter;
import com.cnbm.admin.handler.LogoutHandlerImpl;
import com.cnbm.admin.handler.LogoutSuccessHandlerImpl;
import com.cnbm.admin.service.impl.UserDetailsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
@ -19,6 +20,8 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutFilter;
/**
* @Author weihongyang
* @Date 2022/6/8 1:51 PM
@ -49,6 +52,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private LogoutSuccessHandlerImpl logoutSuccessHandler;
@Autowired
private LogoutHandlerImpl logoutHandler;
@Override
protected void configure(HttpSecurity http) throws Exception {
@ -72,12 +78,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.authenticated()
// 退出登录默认为/logout这里修改接口地址为 /doLogout
.and().logout().logoutUrl("/doLogout")
.addLogoutHandler(logoutHandler)
// 设置退出登录成功处理程序退出成功后返回JSON字符串
.logoutSuccessHandler(logoutSuccessHandler);
//添加过滤器
http.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
http.addFilterBefore(jwtAuthenticationTokenFilter, LogoutFilter.class);
//配置异常处理器
http.exceptionHandling()
//配置认证失败处理器