From 47409787a4073a913095434c168aabf595ffbbde Mon Sep 17 00:00:00 2001 From: weihongyang <1075331873@qq.com> Date: Thu, 23 Jun 2022 11:51:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9Esercurity=E7=9A=84Log?= =?UTF-8?q?outHandler=E7=9A=84=E5=AE=9E=E7=8E=B0=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cnbm/admin/handler/LogoutHandlerImpl.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ym-admin/src/main/java/com/cnbm/admin/handler/LogoutHandlerImpl.java diff --git a/ym-admin/src/main/java/com/cnbm/admin/handler/LogoutHandlerImpl.java b/ym-admin/src/main/java/com/cnbm/admin/handler/LogoutHandlerImpl.java new file mode 100644 index 0000000..d41ac20 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/handler/LogoutHandlerImpl.java @@ -0,0 +1,32 @@ +package com.cnbm.admin.handler; + +import com.cnbm.admin.entity.LoginUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.security.core.Authentication; +import org.springframework.security.web.authentication.logout.LogoutHandler; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @Author weihongyang + * @Date 2022/6/23 11:24 AM + * @Version 1.0 + */ +@Component +public class LogoutHandlerImpl implements LogoutHandler { + + @Autowired + private RedisTemplate redisTemplate; + + @Override + public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) { + //获取SecurityContextHolder中的用户id + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + String userid = loginUser.getSysUserEntity().getId().toString(); + //删除redis中的值 + redisTemplate.delete("login:"+userid); + } +}