update 优化 多账号体系用户行为监听逻辑
This commit is contained in:
parent
1f1d4e2def
commit
1ae369855b
@ -1,4 +1,4 @@
|
||||
package com.ruoyi.framework.satoken;
|
||||
package com.ruoyi.framework.listener;
|
||||
|
||||
import cn.dev33.satoken.listener.SaTokenListener;
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
@ -8,43 +8,46 @@ import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.core.domain.dto.UserOnlineDTO;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.utils.RedisUtils;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.ServletUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.enums.UserType;
|
||||
import com.ruoyi.common.utils.*;
|
||||
import com.ruoyi.common.utils.ip.AddressUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 自定义侦听器的实现
|
||||
* 用户行为 侦听器的实现
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MySaTokenListener implements SaTokenListener {
|
||||
public class UserActionListener implements SaTokenListener {
|
||||
|
||||
/**
|
||||
* 每次登录时触发
|
||||
*/
|
||||
@Override
|
||||
public void doLogin(String loginType, Object loginId, SaLoginModel loginModel) {
|
||||
UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
|
||||
String ip = ServletUtils.getClientIP();
|
||||
SysUser user = SecurityUtils.getUser();
|
||||
String tokenValue = StpUtil.getTokenValue();
|
||||
UserOnlineDTO userOnlineDTO = new UserOnlineDTO()
|
||||
.setIpaddr(ip)
|
||||
.setLoginLocation(AddressUtils.getRealAddressByIP(ip))
|
||||
.setBrowser(userAgent.getBrowser().getName())
|
||||
.setOs(userAgent.getOs().getName())
|
||||
.setLoginTime(System.currentTimeMillis())
|
||||
.setTokenId(tokenValue)
|
||||
.setUserName(user.getUserName());
|
||||
if (StringUtils.isNotNull(user.getDept())) {
|
||||
userOnlineDTO.setDeptName(user.getDept().getDeptName());
|
||||
UserType userType = LoginUtils.getUserType(loginId);
|
||||
if (userType == UserType.SYS_USER) {
|
||||
UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"));
|
||||
String ip = ServletUtils.getClientIP();
|
||||
SysUser user = SecurityUtils.getUser();
|
||||
String tokenValue = StpUtil.getTokenValue();
|
||||
UserOnlineDTO userOnlineDTO = new UserOnlineDTO()
|
||||
.setIpaddr(ip)
|
||||
.setLoginLocation(AddressUtils.getRealAddressByIP(ip))
|
||||
.setBrowser(userAgent.getBrowser().getName())
|
||||
.setOs(userAgent.getOs().getName())
|
||||
.setLoginTime(System.currentTimeMillis())
|
||||
.setTokenId(tokenValue)
|
||||
.setUserName(user.getUserName());
|
||||
if (StringUtils.isNotNull(user.getDept())) {
|
||||
userOnlineDTO.setDeptName(user.getDept().getDeptName());
|
||||
}
|
||||
RedisUtils.setCacheObject(Constants.ONLINE_TOKEN_KEY + tokenValue, userOnlineDTO);
|
||||
log.info("user doLogin, useId:{}, token:{}", loginId, tokenValue);
|
||||
} else if (userType == UserType.APP_USER) {
|
||||
// app端 自行根据业务编写
|
||||
}
|
||||
RedisUtils.setCacheObject(Constants.ONLINE_TOKEN_KEY + tokenValue, userOnlineDTO);
|
||||
log.info("user doLogin, useId:{}, token:{}", loginId, tokenValue);
|
||||
}
|
||||
|
||||
/**
|
@ -28,7 +28,6 @@ public class SaInterfaceImpl implements StpInterface {
|
||||
Long userId = LoginUtils.getUserId();
|
||||
SysUser user = iSysUserService.getById(userId);
|
||||
Set<String> menuPermission = sysPermissionService.getMenuPermission(user);
|
||||
//采用的是用户里自带的权限,实现一次性访问reids,进行判断是否可以访问
|
||||
return new ArrayList<>(menuPermission);
|
||||
} else if (userType == UserType.APP_USER) {
|
||||
// app端权限返回 自行根据业务编写
|
||||
|
Loading…
x
Reference in New Issue
Block a user