From 093d6ee362998748afd924c61c68d8e0a75b06c2 Mon Sep 17 00:00:00 2001 From: weihongyang <1075331873@qq.com> Date: Thu, 23 Jun 2022 15:39:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20sercurity=E7=9A=84=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=96=B0=E5=A2=9E=E5=8A=A0LogoutHandler?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E7=8E=B0=E7=B1=BB=20=E5=9C=A8LogoutFilter?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E5=8A=A0=E5=85=A5jwtAuthenticationTokenFilte?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/cnbm/admin/config/SecurityConfig.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java b/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java index 00a8a85..f2dd2e8 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java +++ b/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java @@ -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() //配置认证失败处理器