mirror of https://github.com/elunez/eladmin
parent
7c5193a93d
commit
e57502b16c
|
@ -48,6 +48,8 @@ public class AuthController {
|
|||
private Long expiration;
|
||||
@Value("${rsa.private_key}")
|
||||
private String privateKey;
|
||||
@Value("${single.login:true}")
|
||||
private Boolean singleLogin;
|
||||
private final SecurityProperties properties;
|
||||
private final RedisUtils redisUtils;
|
||||
private final UserDetailsService userDetailsService;
|
||||
|
@ -97,6 +99,10 @@ public class AuthController {
|
|||
put("token", properties.getTokenStartWith() + token);
|
||||
put("user", jwtUser);
|
||||
}};
|
||||
if(singleLogin){
|
||||
//踢掉之前已经登录的token
|
||||
onlineUserService.checkLoginOnUser(authUser.getUsername(),token);
|
||||
}
|
||||
return ResponseEntity.ok(authInfo);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package me.zhengjie.modules.security.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.zhengjie.modules.security.config.SecurityProperties;
|
||||
import me.zhengjie.modules.security.security.vo.JwtUser;
|
||||
import me.zhengjie.modules.security.security.vo.OnlineUser;
|
||||
|
@ -16,6 +17,7 @@ import java.util.*;
|
|||
* @Date 2019年10月26日21:56:27
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class OnlineUserService {
|
||||
|
||||
private final SecurityProperties properties;
|
||||
|
@ -131,4 +133,30 @@ public class OnlineUserService {
|
|||
public OnlineUser getOne(String key) {
|
||||
return (OnlineUser)redisUtils.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测用户是否在之前已经登录,已经登录踢下线
|
||||
* @param userName
|
||||
*/
|
||||
public void checkLoginOnUser(String userName, String igoreToken){
|
||||
List<OnlineUser> onlineUsers = getAll(userName);
|
||||
if(onlineUsers ==null || onlineUsers.isEmpty()){
|
||||
return;
|
||||
}
|
||||
for(OnlineUser onlineUser:onlineUsers){
|
||||
if(onlineUser.getUserName().equals(userName)){
|
||||
try {
|
||||
String token =EncryptUtils.desDecrypt(onlineUser.getKey());
|
||||
if(StringUtils.isNotBlank(igoreToken)&&!igoreToken.equals(token)){
|
||||
this.kickOut(onlineUser.getKey());
|
||||
}else if(StringUtils.isBlank(igoreToken)){
|
||||
this.kickOut(onlineUser.getKey());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("checkUser is error",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue