feat: 新增sercurity的LogoutHandler的实现类
Esse commit está contido em:
pai
7fe617df56
commit
47409787a4
32
ym-admin/src/main/java/com/cnbm/admin/handler/LogoutHandlerImpl.java
Arquivo normal
32
ym-admin/src/main/java/com/cnbm/admin/handler/LogoutHandlerImpl.java
Arquivo normal
@ -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);
|
||||
}
|
||||
}
|
Carregando…
Referência em uma nova issue
Block a user