|
|
@ -6,11 +6,11 @@ import cn.dev33.satoken.stp.SaLoginModel;
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
import cn.hutool.http.useragent.UserAgent;
|
|
|
|
import cn.hutool.http.useragent.UserAgent;
|
|
|
|
import cn.hutool.http.useragent.UserAgentUtil;
|
|
|
|
import cn.hutool.http.useragent.UserAgentUtil;
|
|
|
|
import com.ruoyi.common.core.constant.CacheNames;
|
|
|
|
import com.ruoyi.common.core.constant.CacheConstants;
|
|
|
|
import com.ruoyi.common.core.enums.UserType;
|
|
|
|
import com.ruoyi.common.core.enums.UserType;
|
|
|
|
import com.ruoyi.common.core.utils.ServletUtils;
|
|
|
|
import com.ruoyi.common.core.utils.ServletUtils;
|
|
|
|
import com.ruoyi.common.core.utils.ip.AddressUtils;
|
|
|
|
import com.ruoyi.common.core.utils.ip.AddressUtils;
|
|
|
|
import com.ruoyi.common.redis.utils.CacheUtils;
|
|
|
|
import com.ruoyi.common.redis.utils.RedisUtils;
|
|
|
|
import com.ruoyi.common.satoken.utils.LoginHelper;
|
|
|
|
import com.ruoyi.common.satoken.utils.LoginHelper;
|
|
|
|
import com.ruoyi.system.api.domain.SysUserOnline;
|
|
|
|
import com.ruoyi.system.api.domain.SysUserOnline;
|
|
|
|
import com.ruoyi.system.api.model.LoginUser;
|
|
|
|
import com.ruoyi.system.api.model.LoginUser;
|
|
|
@ -18,6 +18,8 @@ import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 用户行为 侦听器的实现
|
|
|
|
* 用户行为 侦听器的实现
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -51,12 +53,7 @@ public class UserActionListener implements SaTokenListener {
|
|
|
|
if (ObjectUtil.isNotNull(user.getDeptName())) {
|
|
|
|
if (ObjectUtil.isNotNull(user.getDeptName())) {
|
|
|
|
userOnline.setDeptName(user.getDeptName());
|
|
|
|
userOnline.setDeptName(user.getDeptName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String cacheNames = CacheNames.ONLINE_TOKEN;
|
|
|
|
RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, userOnline, Duration.ofSeconds(tokenConfig.getTimeout()));
|
|
|
|
if (tokenConfig.getTimeout() > 0) {
|
|
|
|
|
|
|
|
// 增加 ttl 过期时间 单位秒
|
|
|
|
|
|
|
|
cacheNames = CacheNames.ONLINE_TOKEN + "#" + tokenConfig.getTimeout() + "s";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CacheUtils.put(cacheNames, tokenValue, userOnline);
|
|
|
|
|
|
|
|
log.info("user doLogin, useId:{}, token:{}", loginId, tokenValue);
|
|
|
|
log.info("user doLogin, useId:{}, token:{}", loginId, tokenValue);
|
|
|
|
} else if (userType == UserType.APP_USER) {
|
|
|
|
} else if (userType == UserType.APP_USER) {
|
|
|
|
// app端 自行根据业务编写
|
|
|
|
// app端 自行根据业务编写
|
|
|
@ -68,7 +65,7 @@ public class UserActionListener implements SaTokenListener {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void doLogout(String loginType, Object loginId, String tokenValue) {
|
|
|
|
public void doLogout(String loginType, Object loginId, String tokenValue) {
|
|
|
|
CacheUtils.evict(CacheNames.ONLINE_TOKEN, tokenValue);
|
|
|
|
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
|
|
|
log.info("user doLogout, useId:{}, token:{}", loginId, tokenValue);
|
|
|
|
log.info("user doLogout, useId:{}, token:{}", loginId, tokenValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -77,7 +74,7 @@ public class UserActionListener implements SaTokenListener {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void doKickout(String loginType, Object loginId, String tokenValue) {
|
|
|
|
public void doKickout(String loginType, Object loginId, String tokenValue) {
|
|
|
|
CacheUtils.evict(CacheNames.ONLINE_TOKEN, tokenValue);
|
|
|
|
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
|
|
|
log.info("user doLogoutByLoginId, useId:{}, token:{}", loginId, tokenValue);
|
|
|
|
log.info("user doLogoutByLoginId, useId:{}, token:{}", loginId, tokenValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -86,7 +83,7 @@ public class UserActionListener implements SaTokenListener {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void doReplaced(String loginType, Object loginId, String tokenValue) {
|
|
|
|
public void doReplaced(String loginType, Object loginId, String tokenValue) {
|
|
|
|
CacheUtils.evict(CacheNames.ONLINE_TOKEN, tokenValue);
|
|
|
|
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
|
|
|
log.info("user doReplaced, useId:{}, token:{}", loginId, tokenValue);
|
|
|
|
log.info("user doReplaced, useId:{}, token:{}", loginId, tokenValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|