操作日志自动记录参数.
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package com.orion.ops.module.infra.controller;
|
||||
|
||||
import com.orion.lang.define.wrapper.HttpWrapper;
|
||||
import com.orion.ops.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import com.orion.ops.framework.log.core.annotation.IgnoreLog;
|
||||
import com.orion.ops.framework.log.core.enums.IgnoreLogMode;
|
||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||
import com.orion.ops.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.ops.module.infra.define.operator.AuthenticationOperatorType;
|
||||
import com.orion.ops.module.infra.entity.request.user.UserLoginRequest;
|
||||
import com.orion.ops.module.infra.entity.request.user.UserResetPasswordRequest;
|
||||
import com.orion.ops.module.infra.entity.vo.UserLoginVO;
|
||||
@@ -42,15 +44,16 @@ public class AuthenticationController {
|
||||
@Resource
|
||||
private SystemUserService systemUserService;
|
||||
|
||||
@OperatorLog(AuthenticationOperatorType.LOGIN)
|
||||
@PermitAll
|
||||
@Operation(summary = "登陆")
|
||||
@PostMapping("/login")
|
||||
public UserLoginVO login(@Validated @RequestBody UserLoginRequest request,
|
||||
HttpServletRequest servletRequest) {
|
||||
String token = authenticationService.login(request, servletRequest);
|
||||
return UserLoginVO.builder().token(token).build();
|
||||
return authenticationService.login(request, servletRequest);
|
||||
}
|
||||
|
||||
@OperatorLog(AuthenticationOperatorType.LOGOUT)
|
||||
@PermitAll
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@Operation(summary = "登出")
|
||||
@@ -60,6 +63,7 @@ public class AuthenticationController {
|
||||
return HttpWrapper.ok();
|
||||
}
|
||||
|
||||
@OperatorLog(AuthenticationOperatorType.UPDATE_PASSWORD)
|
||||
@Operation(summary = "修改密码")
|
||||
@PutMapping("/update-password")
|
||||
public HttpWrapper<?> updatePassword(@Validated @RequestBody UserResetPasswordRequest request) {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.orion.ops.module.infra.define.operator;
|
||||
|
||||
import com.orion.ops.framework.biz.operator.log.core.model.OperatorType;
|
||||
|
||||
import static com.orion.ops.framework.biz.operator.log.core.holder.OperatorTypeHolder.set;
|
||||
|
||||
/**
|
||||
* 认证服务 操作日志类型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-10-10 19:06
|
||||
*/
|
||||
public class AuthenticationOperatorType {
|
||||
|
||||
private static final String MODULE = "infra:authentication";
|
||||
|
||||
public static final String LOGIN = "authentication:login";
|
||||
|
||||
public static final String LOGOUT = "authentication:logout";
|
||||
|
||||
public static final String UPDATE_PASSWORD = "authentication:update-password";
|
||||
|
||||
public static void init() {
|
||||
set(new OperatorType(MODULE, LOGIN, "登陆系统"));
|
||||
set(new OperatorType(MODULE, LOGOUT, "登出系统"));
|
||||
set(new OperatorType(MODULE, UPDATE_PASSWORD, "修改密码"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,6 +36,10 @@ public class OperatorLogDO extends BaseDO {
|
||||
@TableField("user_id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "用户名")
|
||||
@TableField("username")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "traceId")
|
||||
@TableField("trace_id")
|
||||
private String traceId;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.orion.ops.module.infra.entity.request.user;
|
||||
|
||||
import com.orion.ops.framework.desensitize.core.annotation.Desensitize;
|
||||
import com.orion.ops.framework.desensitize.core.annotation.DesensitizeObject;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -13,6 +15,7 @@ import javax.validation.constraints.NotEmpty;
|
||||
* @since 2023/7/13 22:16
|
||||
*/
|
||||
@Data
|
||||
@DesensitizeObject
|
||||
@Schema(name = "UserLoginRequest", description = "登陆请求")
|
||||
public class UserLoginRequest {
|
||||
|
||||
@@ -20,6 +23,7 @@ public class UserLoginRequest {
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
@Desensitize(toEmpty = true)
|
||||
@NotEmpty
|
||||
@Schema(description = "密码")
|
||||
private String password;
|
||||
|
||||
@@ -31,6 +31,9 @@ public class OperatorLogVO implements Serializable {
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "traceId")
|
||||
private String traceId;
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.orion.ops.module.infra.runner;
|
||||
|
||||
import com.orion.ops.module.infra.define.operator.AuthenticationOperatorType;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 操作类型 初始化
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/10/10 18:03
|
||||
*/
|
||||
@Component
|
||||
public class InfraOperatorTypeRunner implements CommandLineRunner {
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
AuthenticationOperatorType.init();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.orion.ops.module.infra.service;
|
||||
import com.orion.ops.framework.common.security.LoginUser;
|
||||
import com.orion.ops.module.infra.entity.dto.LoginTokenDTO;
|
||||
import com.orion.ops.module.infra.entity.request.user.UserLoginRequest;
|
||||
import com.orion.ops.module.infra.entity.vo.UserLoginVO;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -30,9 +31,9 @@ public interface AuthenticationService {
|
||||
*
|
||||
* @param request request
|
||||
* @param servletRequest servletRequest
|
||||
* @return token
|
||||
* @return login
|
||||
*/
|
||||
String login(UserLoginRequest request, HttpServletRequest servletRequest);
|
||||
UserLoginVO login(UserLoginRequest request, HttpServletRequest servletRequest);
|
||||
|
||||
/**
|
||||
* 登出
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.orion.lang.define.wrapper.Pair;
|
||||
import com.orion.lang.utils.Exceptions;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.lang.utils.crypto.Signatures;
|
||||
import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.security.LoginUser;
|
||||
@@ -23,6 +24,7 @@ import com.orion.ops.module.infra.entity.domain.SystemRoleDO;
|
||||
import com.orion.ops.module.infra.entity.domain.SystemUserDO;
|
||||
import com.orion.ops.module.infra.entity.dto.LoginTokenDTO;
|
||||
import com.orion.ops.module.infra.entity.request.user.UserLoginRequest;
|
||||
import com.orion.ops.module.infra.entity.vo.UserLoginVO;
|
||||
import com.orion.ops.module.infra.enums.LoginTokenStatusEnum;
|
||||
import com.orion.ops.module.infra.enums.UserStatusEnum;
|
||||
import com.orion.ops.module.infra.service.AuthenticationService;
|
||||
@@ -62,13 +64,15 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
private RedisTemplate<String, String> redisTemplate;
|
||||
|
||||
@Override
|
||||
public String login(UserLoginRequest request, HttpServletRequest servletRequest) {
|
||||
public UserLoginVO login(UserLoginRequest request, HttpServletRequest servletRequest) {
|
||||
// 登陆前检查
|
||||
this.preCheckLogin(request);
|
||||
// 获取登陆用户
|
||||
LambdaQueryWrapper<SystemUserDO> wrapper = systemUserDAO.wrapper()
|
||||
.eq(SystemUserDO::getUsername, request.getUsername());
|
||||
SystemUserDO user = systemUserDAO.of(wrapper).getOne();
|
||||
// 设置日志上下文
|
||||
OperatorLogs.setUser(SystemUserConvert.MAPPER.toLoginUser(user));
|
||||
// 检查密码
|
||||
boolean passwordCorrect = this.checkPassword(request, user);
|
||||
Valid.isTrue(passwordCorrect, ErrorMessage.USERNAME_PASSWORD_ERROR);
|
||||
@@ -90,7 +94,10 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
this.invalidOtherDeviceToken(user.getId(), current, remoteAddr, location);
|
||||
}
|
||||
// 生成 loginToken
|
||||
return this.generatorLoginToken(user, current, remoteAddr, location);
|
||||
String token = this.generatorLoginToken(user, current, remoteAddr, location);
|
||||
return UserLoginVO.builder()
|
||||
.token(token)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -63,7 +63,7 @@ public class SystemUserServiceImpl implements SystemUserService {
|
||||
public Long createSystemUser(SystemUserCreateRequest request) {
|
||||
// 转换
|
||||
SystemUserDO record = SystemUserConvert.MAPPER.to(request);
|
||||
// 查询用户名称是否存在
|
||||
// 查询用户名是否存在
|
||||
this.checkUsernamePresent(record);
|
||||
// 查询花名是否存在
|
||||
this.checkNicknamePresent(record);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<resultMap id="BaseResultMap" type="com.orion.ops.module.infra.entity.domain.OperatorLogDO">
|
||||
<id column="id" property="id"/>
|
||||
<result column="user_id" property="userId"/>
|
||||
<result column="username" property="username"/>
|
||||
<result column="trace_id" property="traceId"/>
|
||||
<result column="address" property="address"/>
|
||||
<result column="location" property="location"/>
|
||||
@@ -25,7 +26,7 @@
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, user_id, trace_id, address, location, user_agent, module, type, log_info, extra, result, error_message, return_value, duration, start_time, end_time, create_time
|
||||
id, user_id, username, trace_id, address, location, user_agent, module, type, log_info, extra, result, error_message, return_value, duration, start_time, end_time, create_time
|
||||
</sql>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user