mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-03 19:16:07 +00:00
update 更新 SysLogininfor 登录日志, SysUserOnline 在线用户字段 (客户端, 设备类型), 修改相关方法 ;
update 更新 sql ;
This commit is contained in:
@@ -34,6 +34,16 @@ public class SysUserOnline implements Serializable {
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 客户端
|
||||
*/
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 登录IP地址
|
||||
*/
|
||||
|
@@ -37,6 +37,16 @@ public class RemoteLogininforBo implements Serializable {
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 客户端
|
||||
*/
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 登录IP地址
|
||||
*/
|
||||
|
@@ -115,6 +115,16 @@ public class LoginUser implements Serializable {
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 客户端
|
||||
*/
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 获取登录id
|
||||
*/
|
||||
|
@@ -50,6 +50,8 @@ public class UserActionListener implements SaTokenListener {
|
||||
userOnline.setLoginTime(System.currentTimeMillis());
|
||||
userOnline.setTokenId(tokenValue);
|
||||
userOnline.setUserName(user.getUsername());
|
||||
userOnline.setClientKey(user.getClientKey());
|
||||
userOnline.setDeviceType(user.getDeviceType());
|
||||
if (ObjectUtil.isNotNull(user.getDeptName())) {
|
||||
userOnline.setDeptName(user.getDeptName());
|
||||
}
|
||||
|
@@ -54,6 +54,8 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||
// 通过邮箱查找用户
|
||||
LoginUser loginUser = remoteUserService.getUserInfoByEmail(email, tenantId);
|
||||
loginService.checkLogin(LoginType.EMAIL, tenantId, loginUser.getUsername(), () -> !validateEmailCode(tenantId, email, emailCode));
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginModel model = new SaLoginModel();
|
||||
model.setDevice(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
|
@@ -65,6 +65,8 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
|
||||
LoginUser loginUser = remoteUserService.getUserInfo(username, tenantId);
|
||||
loginService.checkLogin(LoginType.PASSWORD, tenantId, username, () -> !BCrypt.checkpw(password, loginUser.getPassword()));
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginModel model = new SaLoginModel();
|
||||
model.setDevice(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
|
@@ -54,6 +54,8 @@ public class SmsAuthStrategy implements IAuthStrategy {
|
||||
// 通过手机号查找用户
|
||||
LoginUser loginUser = remoteUserService.getUserInfoByPhonenumber(phonenumber, tenantId);
|
||||
loginService.checkLogin(LoginType.SMS, tenantId, loginUser.getUsername(), () -> !validateSmsCode(tenantId, phonenumber, smsCode));
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginModel model = new SaLoginModel();
|
||||
model.setDevice(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
|
@@ -91,6 +91,8 @@ public class SocialAuthStrategy implements IAuthStrategy {
|
||||
}
|
||||
|
||||
LoginUser loginUser = remoteUserService.getUserInfo(socialVo.getUserId(), tenantId);
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
SaLoginModel model = new SaLoginModel();
|
||||
model.setDevice(client.getDeviceType());
|
||||
// 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置
|
||||
|
@@ -48,6 +48,8 @@ public class XcxAuthStrategy implements IAuthStrategy {
|
||||
// 校验 appid + appsrcret + xcxCode 调用登录凭证校验接口 获取 session_key 与 openid
|
||||
String openid = "";
|
||||
XcxLoginUser loginUser = remoteUserService.getUserInfoByOpenid(openid);
|
||||
loginUser.setClientKey(client.getClientKey());
|
||||
loginUser.setDeviceType(client.getDeviceType());
|
||||
|
||||
SaLoginModel model = new SaLoginModel();
|
||||
model.setDevice(client.getDeviceType());
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package org.dromara.common.log.event;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@@ -10,9 +11,12 @@ import org.dromara.common.core.constant.Constants;
|
||||
import org.dromara.common.core.utils.ServletUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.utils.ip.AddressUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.system.api.RemoteClientService;
|
||||
import org.dromara.system.api.RemoteLogService;
|
||||
import org.dromara.system.api.domain.bo.RemoteLogininforBo;
|
||||
import org.dromara.system.api.domain.bo.RemoteOperLogBo;
|
||||
import org.dromara.system.api.domain.vo.RemoteClientVo;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -28,6 +32,8 @@ public class LogEventListener {
|
||||
|
||||
@DubboReference
|
||||
private RemoteLogService remoteLogService;
|
||||
@DubboReference
|
||||
private RemoteClientService remoteClientService;
|
||||
|
||||
/**
|
||||
* 保存系统日志记录
|
||||
@@ -45,6 +51,12 @@ public class LogEventListener {
|
||||
HttpServletRequest request = logininforEvent.getRequest();
|
||||
final UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
||||
final String ip = ServletUtils.getClientIP(request);
|
||||
// 客户端信息
|
||||
String clientid = request.getHeader(LoginHelper.CLIENT_KEY);
|
||||
RemoteClientVo clientVo = null;
|
||||
if (StringUtils.isNotBlank(clientid)) {
|
||||
clientVo = remoteClientService.queryByClientId(clientid);
|
||||
}
|
||||
|
||||
String address = AddressUtils.getRealAddressByIP(ip);
|
||||
StringBuilder s = new StringBuilder();
|
||||
@@ -63,6 +75,10 @@ public class LogEventListener {
|
||||
RemoteLogininforBo logininfor = new RemoteLogininforBo();
|
||||
logininfor.setTenantId(logininforEvent.getTenantId());
|
||||
logininfor.setUserName(logininforEvent.getUsername());
|
||||
if (ObjectUtil.isNotNull(clientVo)) {
|
||||
logininfor.setClientKey(clientVo.getClientKey());
|
||||
logininfor.setDeviceType(clientVo.getDeviceType());
|
||||
}
|
||||
logininfor.setIpaddr(ip);
|
||||
logininfor.setLoginLocation(address);
|
||||
logininfor.setBrowser(browser);
|
||||
|
@@ -37,6 +37,16 @@ public class SysLogininfor implements Serializable {
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 客户端
|
||||
*/
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 登录状态 0成功 1失败
|
||||
*/
|
||||
|
@@ -33,6 +33,16 @@ public class SysLogininforBo {
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 客户端
|
||||
*/
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 登录IP地址
|
||||
*/
|
||||
|
@@ -45,6 +45,19 @@ public class SysLogininforVo implements Serializable {
|
||||
@ExcelProperty(value = "用户账号")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 客户端
|
||||
*/
|
||||
@ExcelProperty(value = "客户端")
|
||||
private String clientKey;
|
||||
|
||||
/**
|
||||
* 设备类型
|
||||
*/
|
||||
@ExcelProperty(value = "设备类型", converter = ExcelDictConvert.class)
|
||||
@ExcelDictFormat(dictType = "sys_device_type")
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 登录状态(0成功 1失败)
|
||||
*/
|
||||
|
@@ -926,6 +926,8 @@ create table sys_logininfor (
|
||||
info_id number(20) not null,
|
||||
tenant_id varchar2(20) default '000000',
|
||||
user_name varchar2(50) default '',
|
||||
client_key varchar2(32) default '',
|
||||
device_type varchar2(32) default '',
|
||||
ipaddr varchar2(128) default '',
|
||||
login_location varchar2(255) default '',
|
||||
browser varchar2(50) default '',
|
||||
@@ -943,6 +945,8 @@ comment on table sys_logininfor is '系统访问记录';
|
||||
comment on column sys_logininfor.info_id is '访问ID';
|
||||
comment on column sys_logininfor.tenant_id is '租户编号';
|
||||
comment on column sys_logininfor.user_name is '登录账号';
|
||||
comment on column sys_logininfor.client_key is '客户端';
|
||||
comment on column sys_logininfor.device_type is '设备类型';
|
||||
comment on column sys_logininfor.ipaddr is '登录IP地址';
|
||||
comment on column sys_logininfor.login_location is '登录地点';
|
||||
comment on column sys_logininfor.browser is '浏览器类型';
|
||||
|
@@ -945,6 +945,8 @@ create table if not exists sys_logininfor
|
||||
info_id int8,
|
||||
tenant_id varchar(20) default '000000'::varchar,
|
||||
user_name varchar(50) default ''::varchar,
|
||||
client_key varchar(32) default ''::varchar,
|
||||
device_type varchar(32) default ''::varchar,
|
||||
ipaddr varchar(128) default ''::varchar,
|
||||
login_location varchar(255) default ''::varchar,
|
||||
browser varchar(50) default ''::varchar,
|
||||
@@ -962,6 +964,8 @@ comment on table sys_logininfor is '系统访问记录';
|
||||
comment on column sys_logininfor.info_id is '访问ID';
|
||||
comment on column sys_logininfor.tenant_id is '租户编号';
|
||||
comment on column sys_logininfor.user_name is '用户账号';
|
||||
comment on column sys_logininfor.client_key is '客户端';
|
||||
comment on column sys_logininfor.device_type is '设备类型';
|
||||
comment on column sys_logininfor.ipaddr is '登录IP地址';
|
||||
comment on column sys_logininfor.login_location is '登录地点';
|
||||
comment on column sys_logininfor.browser is '浏览器类型';
|
||||
|
@@ -695,6 +695,8 @@ create table sys_logininfor (
|
||||
info_id bigint(20) not null comment '访问ID',
|
||||
tenant_id varchar(20) default '000000' comment '租户编号',
|
||||
user_name varchar(50) default '' comment '用户账号',
|
||||
client_key varchar(32) default '' comment '客户端',
|
||||
device_type varchar(32) default '' comment '设备类型',
|
||||
ipaddr varchar(128) default '' comment '登录IP地址',
|
||||
login_location varchar(255) default '' comment '登录地点',
|
||||
browser varchar(50) default '' comment '浏览器类型',
|
||||
|
5
sql/update/oracle/update_2.1-2.1.1.sql
Normal file
5
sql/update/oracle/update_2.1-2.1.1.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE sys_logininfor ADD (client_key VARCHAR(32) DEFAULT '');
|
||||
COMMENT ON COLUMN sys_logininfor.client_key IS '客户端';
|
||||
|
||||
ALTER TABLE sys_logininfor ADD (device_type VARCHAR(32) DEFAULT '');
|
||||
COMMENT ON COLUMN sys_logininfor.device_type IS '设备类型';
|
5
sql/update/postgres/update_2.1-2.1.1.sql
Normal file
5
sql/update/postgres/update_2.1-2.1.1.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE sys_logininfor ADD client_key varchar(32) default ''::varchar;
|
||||
COMMENT ON COLUMN sys_logininfor.client_key IS '客户端';
|
||||
|
||||
ALTER TABLE sys_logininfor ADD device_type varchar(32) default ''::varchar;
|
||||
COMMENT ON COLUMN sys_logininfor.device_type IS '设备类型';
|
3
sql/update/update_2.1-2.1.1.sql
Normal file
3
sql/update/update_2.1-2.1.1.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE sys_logininfor
|
||||
ADD COLUMN client_key VARCHAR(32) NULL DEFAULT NULL COMMENT '客户端' AFTER `user_type`,
|
||||
ADD COLUMN device_type VARCHAR(32) NULL DEFAULT NULL COMMENT '设备类型' AFTER `client_key`;
|
Reference in New Issue
Block a user