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); + } +}