From 128518989f4c87dce09e6168ade11af911147034 Mon Sep 17 00:00:00 2001 From: hongawen <83944980@qq.com> Date: Wed, 13 Jul 2022 20:16:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A1=E8=AE=A1=E6=97=A5=E5=BF=97=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../njcn/auth/controller/AuthController.java | 8 +++- .../auth/exception/AuthExceptionHandler.java | 4 +- .../njcn/auth/service/UserTokenService.java | 16 +++++++- pqs-auth/src/main/resources/bootstrap.yml | 2 +- .../njcn/common/pojo/constant/LogInfo.java | 12 +++--- .../com/njcn/common/pojo/dto/LogInfoDTO.java | 7 +++- .../njcn/web/service/impl/LogServiceImpl.java | 26 +++++-------- .../java/com/njcn/web/utils/RequestUtil.java | 37 +++++++++++++++---- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- pqs-gateway/src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../src/main/resources/bootstrap.yml | 2 +- .../java/com/njcn/system/pojo/po/UserLog.java | 5 +++ .../service/impl/UserLogServiceImpl.java | 6 +-- .../src/main/resources/bootstrap.yml | 2 +- .../user/service/impl/UserServiceImpl.java | 7 ++++ .../src/main/resources/bootstrap.yml | 2 +- 19 files changed, 100 insertions(+), 46 deletions(-) diff --git a/pqs-auth/src/main/java/com/njcn/auth/controller/AuthController.java b/pqs-auth/src/main/java/com/njcn/auth/controller/AuthController.java index 7d7ad38bd..ef1fbc0bf 100644 --- a/pqs-auth/src/main/java/com/njcn/auth/controller/AuthController.java +++ b/pqs-auth/src/main/java/com/njcn/auth/controller/AuthController.java @@ -3,8 +3,11 @@ package com.njcn.auth.controller; import com.nimbusds.jose.jwk.JWKSet; import com.nimbusds.jose.jwk.RSAKey; import com.njcn.auth.service.UserTokenService; +import com.njcn.common.pojo.annotation.OperateInfo; +import com.njcn.common.pojo.constant.OperateType; import com.njcn.common.pojo.constant.SecurityConstants; import com.njcn.common.pojo.dto.UserTokenInfo; +import com.njcn.common.pojo.enums.common.LogEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.utils.HttpResultUtil; @@ -59,7 +62,10 @@ public class AuthController extends BaseController { private final UserTokenService userTokenService; + + @ApiIgnore + @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.AUTHENTICATE) @ApiOperation("登录认证") @ApiImplicitParams({ @ApiImplicitParam(name = SecurityConstants.GRANT_TYPE, defaultValue = "password", value = "授权模式", required = true), @@ -88,7 +94,7 @@ public class AuthController extends BaseController { //用户的登录名&密码校验成功后,判断当前该用户是否可以正常使用系统 userFeignClient.judgeUserStatus(username); //登录成功后,记录token信息,并处理踢人效果 - userTokenService.recordUserInfo(oAuth2AccessToken); + userTokenService.recordUserInfo(oAuth2AccessToken,RequestUtil.getRealIp()); if (!grantType.equalsIgnoreCase(SecurityConstants.PASSWORD)) { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, oAuth2AccessToken, methodDescribe); } else { diff --git a/pqs-auth/src/main/java/com/njcn/auth/exception/AuthExceptionHandler.java b/pqs-auth/src/main/java/com/njcn/auth/exception/AuthExceptionHandler.java index a2ce22e10..f7464fe6e 100644 --- a/pqs-auth/src/main/java/com/njcn/auth/exception/AuthExceptionHandler.java +++ b/pqs-auth/src/main/java/com/njcn/auth/exception/AuthExceptionHandler.java @@ -42,11 +42,13 @@ public class AuthExceptionHandler { @ExceptionHandler(InvalidGrantException.class) public HttpResult handleInvalidGrantException(HttpServletRequest httpServletRequest, InvalidGrantException invalidGrantException) { String loginName = invalidGrantException.getMessage(); - logService.recodeAuthExceptionLog(invalidGrantException, httpServletRequest, UserResponseEnum.LOGIN_WRONG_PWD.getMessage(), loginName); + HttpResult result = userFeignClient.updateUserLoginErrorTimes(loginName); if (result.getData().equals(UserResponseEnum.LOGIN_USER_LOCKED.getMessage())) { + logService.recodeAuthExceptionLog(invalidGrantException, httpServletRequest, UserResponseEnum.LOGIN_USER_LOCKED.getMessage(), loginName); return HttpResultUtil.assembleResult(UserResponseEnum.LOGIN_USER_LOCKED.getCode(), null, UserResponseEnum.LOGIN_USER_LOCKED.getMessage()); } else { + logService.recodeAuthExceptionLog(invalidGrantException, httpServletRequest, UserResponseEnum.LOGIN_WRONG_PWD.getMessage(), loginName); return HttpResultUtil.assembleResult(UserResponseEnum.LOGIN_WRONG_PWD.getCode(), null, UserResponseEnum.LOGIN_WRONG_PWD.getMessage()); } } diff --git a/pqs-auth/src/main/java/com/njcn/auth/service/UserTokenService.java b/pqs-auth/src/main/java/com/njcn/auth/service/UserTokenService.java index 574444894..073fd654e 100644 --- a/pqs-auth/src/main/java/com/njcn/auth/service/UserTokenService.java +++ b/pqs-auth/src/main/java/com/njcn/auth/service/UserTokenService.java @@ -2,11 +2,16 @@ package com.njcn.auth.service; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; +import com.github.tocrhz.mqtt.publisher.MqttPublisher; import com.nimbusds.jose.JWSObject; +import com.njcn.common.config.GeneralInfo; +import com.njcn.common.pojo.constant.OperateType; import com.njcn.common.pojo.constant.SecurityConstants; +import com.njcn.common.pojo.dto.LogInfoDTO; import com.njcn.common.pojo.dto.UserTokenInfo; import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.common.utils.PubUtils; import com.njcn.redis.utils.RedisUtil; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -33,6 +38,10 @@ public class UserTokenService { private final RedisUtil redisUtil; + private final MqttPublisher publisher; + + private final GeneralInfo generalInfo; + /** * 记录用户token信息,并经过处理后达到最新登录的使用者,将之前的token信息置为黑名单,过期状态 @@ -45,7 +54,7 @@ public class UserTokenService { * @param oAuth2AccessToken 认证后的最新token信息 */ @Async("asyncExecutor") - public void recordUserInfo(OAuth2AccessToken oAuth2AccessToken) { + public void recordUserInfo(OAuth2AccessToken oAuth2AccessToken,String ip) { UserTokenInfo userTokenInfo = new UserTokenInfo(); String accessTokenValue = oAuth2AccessToken.getValue(); JWSObject accessJwsObject ; @@ -56,6 +65,7 @@ public class UserTokenService { } JSONObject accessJson = JSONUtil.parseObj(accessJwsObject.getPayload().toString()); String userIndex = accessJson.getStr(SecurityConstants.USER_INDEX_KEY); + String nickName = accessJson.getStr(SecurityConstants.USER_NICKNAME_KEY); //查询是否有在线的当前用户 String onlineUserKey = SecurityConstants.TOKEN_ONLINE_PREFIX + userIndex; Object onlineTokenInfoOld = redisUtil.getObjectByKey(onlineUserKey); @@ -91,6 +101,10 @@ public class UserTokenService { userTokenInfo.setRefreshTokenExpire(refreshLifeTime); //生命周期在refreshToken的基础上,延迟5分钟 redisUtil.saveByKeyWithExpire(onlineUserKey, userTokenInfo, refreshLifeTime.plusMinutes(5L).toEpochSecond(ZoneOffset.of("+8")) - LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"))); + + //记录成功登录后的信息 + LogInfoDTO logInfoDTO = new LogInfoDTO(nickName, ip, "登录认证", OperateType.AUTHENTICATE, 1, "",0, 1, generalInfo.getMicroServiceName(), userIndex); + publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 2, false); } /** diff --git a/pqs-auth/src/main/resources/bootstrap.yml b/pqs-auth/src/main/resources/bootstrap.yml index 888084dbe..a2d7b6b94 100644 --- a/pqs-auth/src/main/resources/bootstrap.yml +++ b/pqs-auth/src/main/resources/bootstrap.yml @@ -51,6 +51,6 @@ mybatis-plus: mqtt: uri: tcp://@middle.server.url@:1883 - client-id: @artifactId@ + client-id: @artifactId@${random.value} username: t_user password: njcnpqs diff --git a/pqs-common/common-core/src/main/java/com/njcn/common/pojo/constant/LogInfo.java b/pqs-common/common-core/src/main/java/com/njcn/common/pojo/constant/LogInfo.java index d94c0ac50..9888ba61a 100644 --- a/pqs-common/common-core/src/main/java/com/njcn/common/pojo/constant/LogInfo.java +++ b/pqs-common/common-core/src/main/java/com/njcn/common/pojo/constant/LogInfo.java @@ -7,16 +7,16 @@ package com.njcn.common.pojo.constant; */ public interface LogInfo { - String UNKNOWN_OPERATE = "未知业务"; + String UNKNOWN_OPERATE = "unknown operate"; - String UNKNOWN_USER = "未知用户"; + String UNKNOWN_USER = "unknown user"; - String UNKNOWN_IP = "未知IP地址"; + String UNKNOWN_IP = "unknown IP"; - String UNKNOWN_CLIENT = "未知客户端"; + String UNKNOWN_CLIENT = "unknown client"; - String UNKNOWN_SERVER = "未知服务"; + String UNKNOWN_SERVER = "unknown sever"; - String UNKNOWN_DEPT = "未知部门"; + String UNKNOWN_DEPT = "unknown department"; } diff --git a/pqs-common/common-core/src/main/java/com/njcn/common/pojo/dto/LogInfoDTO.java b/pqs-common/common-core/src/main/java/com/njcn/common/pojo/dto/LogInfoDTO.java index 96c9c7bdf..61c2746f1 100644 --- a/pqs-common/common-core/src/main/java/com/njcn/common/pojo/dto/LogInfoDTO.java +++ b/pqs-common/common-core/src/main/java/com/njcn/common/pojo/dto/LogInfoDTO.java @@ -34,6 +34,11 @@ public class LogInfoDTO implements Serializable { */ private Integer result; + /** + * 失败原因 + */ + private String failReason; + /** * 严重度 0.普通 1.中等 2.严重 */ @@ -49,6 +54,6 @@ public class LogInfoDTO implements Serializable { /** * 0 未登录; 1 已登录 */ - private Integer isLogin; + private String userIndex; } diff --git a/pqs-common/common-web/src/main/java/com/njcn/web/service/impl/LogServiceImpl.java b/pqs-common/common-web/src/main/java/com/njcn/web/service/impl/LogServiceImpl.java index ed2ca072c..141852fc3 100644 --- a/pqs-common/common-web/src/main/java/com/njcn/web/service/impl/LogServiceImpl.java +++ b/pqs-common/common-web/src/main/java/com/njcn/web/service/impl/LogServiceImpl.java @@ -1,9 +1,5 @@ package com.njcn.web.service.impl; -import cn.hutool.core.text.StrFormatter; -import cn.hutool.core.util.StrUtil; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tocrhz.mqtt.publisher.MqttPublisher; import com.njcn.common.config.GeneralInfo; import com.njcn.common.pojo.constant.LogInfo; @@ -19,14 +15,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.core.MethodParameter; import org.springframework.http.server.ServerHttpRequest; import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.springframework.web.bind.MethodArgumentNotValidException; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; -import java.time.LocalDateTime; -import java.time.ZoneOffset; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -65,20 +58,21 @@ public class LogServiceImpl implements ILogService { public void recodeAdviceLog(ServerHttpRequest request, MethodParameter returnType, HttpResult httpResult, String methodDescribe) { //处理审计日志 String userName; - int isLogin = 0; + String userIndex ; HttpServletRequest httpServletRequest = RequestUtil.getRequest(request); if (UN_LOGIN_METHOD.contains(methodDescribe)) { userName = RequestUtil.getLoginName(httpServletRequest); + userIndex = userName; } else { userName = RequestUtil.getUserNickname(request); - isLogin = 1; + userIndex = RequestUtil.getUserIndex(request); } String result = httpResult.getCode().equalsIgnoreCase(CommonResponseEnum.FAIL.getCode()) ? CommonResponseEnum.FAIL.getMessage() : CommonResponseEnum.SUCCESS.getMessage(); String ip = RequestUtil.getRealIp(request); String type = ReflectCommonUtil.getOperateInfoByMethod(returnType.getMethod()).getOperateType(); String level = ReflectCommonUtil.getOperateInfoByMethod(returnType.getMethod()).getOperateLevel(); String operateType = ReflectCommonUtil.getOperateTypeByMethod(returnType.getMethod()); - LogInfoDTO logInfoDTO = new LogInfoDTO(userName, ip, methodDescribe, operateType, result.equalsIgnoreCase("失败") ? 0 : 1, levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), isLogin); + LogInfoDTO logInfoDTO = new LogInfoDTO(userName, ip, methodDescribe, operateType, result.equalsIgnoreCase("失败") ? 0 : 1, "",levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), userIndex); publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 2, false); } @@ -95,10 +89,12 @@ public class LogServiceImpl implements ILogService { public void recodeBusinessExceptionLog(Exception exception, HttpServletRequest request, String message) { LogInfoDTO tempLogInfo = RequestUtil.initLogInfo(request); //认证前,获取用户信息 - int isLogin = 1; + String userIndex; if (Objects.equals(tempLogInfo.getUserName(), LogInfo.UNKNOWN_USER)) { tempLogInfo.setUserName(RequestUtil.getLoginName(request)); - isLogin = 0; + userIndex = tempLogInfo.getUserName(); + }else{ + userIndex = RequestUtil.getUserIndex(request); } //根据异常获取method方法 Method method = ReflectCommonUtil.getMethod(exception); @@ -106,12 +102,11 @@ public class LogServiceImpl implements ILogService { MethodArgumentNotValidException methodArgumentNotValidException = (MethodArgumentNotValidException) exception; method = methodArgumentNotValidException.getParameter().getMethod(); } - String methodDescribe = StrFormatter.format("{}{}{}", ReflectCommonUtil.getMethodDescribeByMethod(method), StrUtil.C_COMMA, message); String result = CommonResponseEnum.FAIL.getMessage(); String type = ReflectCommonUtil.getOperateInfoByMethod(method).getOperateType(); String level = ReflectCommonUtil.getOperateInfoByMethod(method).getOperateLevel(); String operateType = ReflectCommonUtil.getOperateTypeByMethod(method); - LogInfoDTO logInfoDTO = new LogInfoDTO(tempLogInfo.getUserName(), tempLogInfo.getIp(), methodDescribe, operateType, result.equalsIgnoreCase("失败") ? 0 : 1, levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), isLogin); + LogInfoDTO logInfoDTO = new LogInfoDTO(tempLogInfo.getUserName(), tempLogInfo.getIp(), ReflectCommonUtil.getMethodDescribeByMethod(method), operateType, result.equalsIgnoreCase("失败") ? 0 : 1,message, levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), userIndex); publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 1, false); } @@ -132,13 +127,12 @@ public class LogServiceImpl implements ILogService { MethodArgumentNotValidException methodArgumentNotValidException = (MethodArgumentNotValidException) exception; method = methodArgumentNotValidException.getParameter().getMethod(); } - String methodDescribe = StrFormatter.format("{}{}{}", ReflectCommonUtil.getMethodDescribeByMethod(method), StrUtil.C_COMMA, message); String result = CommonResponseEnum.FAIL.getMessage(); String ip = RequestUtil.getRealIp(request); String type = ReflectCommonUtil.getOperateInfoByMethod(method).getOperateType(); String level = ReflectCommonUtil.getOperateInfoByMethod(method).getOperateLevel(); String operateType = ReflectCommonUtil.getOperateTypeByMethod(method); - LogInfoDTO logInfoDTO = new LogInfoDTO(userName, ip, methodDescribe, operateType, result.equalsIgnoreCase("失败") ? 0 : 1, levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), 0); + LogInfoDTO logInfoDTO = new LogInfoDTO(userName, ip, ReflectCommonUtil.getMethodDescribeByMethod(method), operateType, result.equalsIgnoreCase("失败") ? 0 : 1,message, levelStringToNumber(level), type.equalsIgnoreCase("业务事件") ? 0 : 1, generalInfo.getMicroServiceName(), userName); publisher.send("/userLog", PubUtils.obj2json(logInfoDTO), 1, false); } diff --git a/pqs-common/common-web/src/main/java/com/njcn/web/utils/RequestUtil.java b/pqs-common/common-web/src/main/java/com/njcn/web/utils/RequestUtil.java index c57fa1fb0..e54e0ba63 100644 --- a/pqs-common/common-web/src/main/java/com/njcn/web/utils/RequestUtil.java +++ b/pqs-common/common-web/src/main/java/com/njcn/web/utils/RequestUtil.java @@ -26,6 +26,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.util.Base64; +import java.util.List; import java.util.Objects; /** @@ -70,7 +71,6 @@ public class RequestUtil { String refreshToken = request.getParameter(SecurityConstants.REFRESH_TOKEN_KEY); String payload = StrUtil.toString(JWSObject.parse(refreshToken).getPayload()); cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(payload); - String authenticationMethod = jsonObject.getStr(SecurityConstants.AUTHENTICATION_METHOD); if (StrUtil.isBlank(authenticationMethod)) { authenticationMethod = AuthenticationMethodEnum.USERNAME.getValue(); @@ -86,8 +86,8 @@ public class RequestUtil { */ public static HttpServletRequest getRequest() { RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); - if(Objects.nonNull(requestAttributes)){ - return ((ServletRequestAttributes)requestAttributes).getRequest(); + if (Objects.nonNull(requestAttributes)) { + return ((ServletRequestAttributes) requestAttributes).getRequest(); } return null; } @@ -132,8 +132,8 @@ public class RequestUtil { */ public static JSONObject getJwtPayload() { JSONObject jsonObject = null; - String jwtPayload = getRequest().getHeader(SecurityConstants.JWT_PAYLOAD_KEY); try { + String jwtPayload = getRequest().getHeader(SecurityConstants.JWT_PAYLOAD_KEY); if (StrUtil.isNotBlank(jwtPayload)) { jwtPayload = URLDecoder.decode(jwtPayload, StandardCharsets.UTF_8.toString()); jsonObject = JSONObject.fromObject(jwtPayload); @@ -150,8 +150,8 @@ public class RequestUtil { */ public static JSONObject getJwtPayload(HttpServletRequest request) { JSONObject jsonObject = null; - String jwtPayload = request.getHeader(SecurityConstants.JWT_PAYLOAD_KEY); try { + String jwtPayload = request.getHeader(SecurityConstants.JWT_PAYLOAD_KEY); if (StrUtil.isNotBlank(jwtPayload)) { jwtPayload = URLDecoder.decode(jwtPayload, StandardCharsets.UTF_8.toString()); jsonObject = JSONObject.fromObject(jwtPayload); @@ -170,8 +170,8 @@ public class RequestUtil { JSONObject jsonObject = null; HttpHeaders headers = request.getHeaders(); try { - String jwtPayload = headers.get(SecurityConstants.JWT_PAYLOAD_KEY).get(0); - if (StrUtil.isNotBlank(jwtPayload)) { + if (CollectionUtils.isNotEmpty(headers.get(SecurityConstants.JWT_PAYLOAD_KEY))) { + String jwtPayload = headers.get(SecurityConstants.JWT_PAYLOAD_KEY).get(0); jwtPayload = URLDecoder.decode(jwtPayload, StandardCharsets.UTF_8.toString()); jsonObject = JSONObject.fromObject(jwtPayload); } @@ -182,6 +182,29 @@ public class RequestUtil { return jsonObject; } + /** + * HttpServletRequest获取在网关中存储的用户索引 + */ + public static String getUserIndex(ServerHttpRequest request) { + String userIndex = LogInfo.UNKNOWN_USER; + JSONObject jwtPayload = getJwtPayload(request); + if (Objects.nonNull(jwtPayload)) { + userIndex = jwtPayload.getString(SecurityConstants.USER_INDEX_KEY); + } + return userIndex; + } + + /** + * HttpServletRequest获取在网关中存储的用户索引 + */ + public static String getUserIndex(HttpServletRequest request) { + String userIndex = LogInfo.UNKNOWN_USER; + JSONObject jwtPayload = getJwtPayload(request); + if (Objects.nonNull(jwtPayload)) { + userIndex = jwtPayload.getString(SecurityConstants.USER_INDEX_KEY); + } + return userIndex; + } /** * HttpServletRequest获取在网关中存储的用户索引 diff --git a/pqs-device/device-boot/src/main/resources/bootstrap.yml b/pqs-device/device-boot/src/main/resources/bootstrap.yml index fd22405fb..7ef31fc6e 100644 --- a/pqs-device/device-boot/src/main/resources/bootstrap.yml +++ b/pqs-device/device-boot/src/main/resources/bootstrap.yml @@ -58,7 +58,7 @@ mybatis-plus: mqtt: uri: tcp://@middle.server.url@:1883 - client-id: @artifactId@ + client-id: @artifactId@${random.value} username: t_user password: njcnpqs diff --git a/pqs-energy/energy-boot/src/main/resources/bootstrap.yml b/pqs-energy/energy-boot/src/main/resources/bootstrap.yml index 1eda55f48..aee1454ec 100644 --- a/pqs-energy/energy-boot/src/main/resources/bootstrap.yml +++ b/pqs-energy/energy-boot/src/main/resources/bootstrap.yml @@ -50,6 +50,6 @@ mybatis-plus: mqtt: uri: tcp://@middle.server.url@:1883 - client-id: @artifactId@_cdf + client-id: @artifactId@${random.value} username: t_user password: njcnpqs \ No newline at end of file diff --git a/pqs-event/event-boot/src/main/resources/bootstrap.yml b/pqs-event/event-boot/src/main/resources/bootstrap.yml index c1303615f..8a7f79d91 100644 --- a/pqs-event/event-boot/src/main/resources/bootstrap.yml +++ b/pqs-event/event-boot/src/main/resources/bootstrap.yml @@ -50,7 +50,7 @@ mybatis-plus: mqtt: uri: tcp://@middle.server.url@:1883 - client-id: @artifactId@ + client-id: @artifactId@${random.value} username: t_user password: njcnpqs diff --git a/pqs-gateway/src/main/resources/bootstrap.yml b/pqs-gateway/src/main/resources/bootstrap.yml index c27231d12..2eebcb185 100644 --- a/pqs-gateway/src/main/resources/bootstrap.yml +++ b/pqs-gateway/src/main/resources/bootstrap.yml @@ -135,7 +135,7 @@ whitelist: mqtt: uri: tcp://@middle.server.url@:1883 - client-id: @artifactId@ + client-id: @artifactId@${random.value} username: t_user password: njcnpqs diff --git a/pqs-harmonic/harmonic-boot/src/main/resources/bootstrap.yml b/pqs-harmonic/harmonic-boot/src/main/resources/bootstrap.yml index ae528020e..633c2d63b 100644 --- a/pqs-harmonic/harmonic-boot/src/main/resources/bootstrap.yml +++ b/pqs-harmonic/harmonic-boot/src/main/resources/bootstrap.yml @@ -50,7 +50,7 @@ mybatis-plus: mqtt: uri: tcp://@middle.server.url@:1883 - client-id: @artifactId@ + client-id: @artifactId@${random.value} username: t_user password: njcnpqs diff --git a/pqs-quality/quality-boot/src/main/resources/bootstrap.yml b/pqs-quality/quality-boot/src/main/resources/bootstrap.yml index a79ebe0e3..bddec7bfc 100644 --- a/pqs-quality/quality-boot/src/main/resources/bootstrap.yml +++ b/pqs-quality/quality-boot/src/main/resources/bootstrap.yml @@ -52,6 +52,6 @@ mybatis-plus: mqtt: uri: tcp://@middle.server.url@:1883 - client-id: @artifactId@ + client-id: @artifactId@${random.value} username: t_user password: njcnpqs \ No newline at end of file diff --git a/pqs-system/system-api/src/main/java/com/njcn/system/pojo/po/UserLog.java b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/po/UserLog.java index 8d29b210b..2e27fc5a9 100644 --- a/pqs-system/system-api/src/main/java/com/njcn/system/pojo/po/UserLog.java +++ b/pqs-system/system-api/src/main/java/com/njcn/system/pojo/po/UserLog.java @@ -48,6 +48,11 @@ public class UserLog extends BaseEntity { */ private Integer result; + /** + * 失败原因 + */ + private String failReason; + /** * 严重度 0.普通 1.中等 2.严重 */ diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/UserLogServiceImpl.java b/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/UserLogServiceImpl.java index 14623f8b3..26d213836 100644 --- a/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/UserLogServiceImpl.java +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/UserLogServiceImpl.java @@ -29,10 +29,8 @@ public class UserLogServiceImpl extends ServiceImpl impl public void addUserLog(LogInfoDTO logInfoDTO) { UserLog userLog = new UserLog(); BeanUtil.copyProperties(logInfoDTO, userLog); - if(logInfoDTO.getIsLogin() == 0){ - userLog.setCreateBy(userLog.getUserName()); - userLog.setUpdateBy(userLog.getUserName()); - } + userLog.setCreateBy(logInfoDTO.getUserIndex()); + userLog.setUpdateBy(logInfoDTO.getUserIndex()); userLog.setState(0); this.baseMapper.insert(userLog); } diff --git a/pqs-system/system-boot/src/main/resources/bootstrap.yml b/pqs-system/system-boot/src/main/resources/bootstrap.yml index 2c3017264..d54ff9e2c 100644 --- a/pqs-system/system-boot/src/main/resources/bootstrap.yml +++ b/pqs-system/system-boot/src/main/resources/bootstrap.yml @@ -51,6 +51,6 @@ mybatis-plus: mqtt: uri: tcp://@middle.server.url@:1883 - client-id: @artifactId@ + client-id: @artifactId@${random.value} username: t_user password: njcnpqs \ No newline at end of file diff --git a/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/UserServiceImpl.java b/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/UserServiceImpl.java index 84b8ddde6..e4282a436 100644 --- a/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/UserServiceImpl.java +++ b/pqs-user/user-boot/src/main/java/com/njcn/user/service/impl/UserServiceImpl.java @@ -89,6 +89,13 @@ public class UserServiceImpl extends ServiceImpl implements IU } //超级管理员则不做任何逻辑判断 if (user.getType() == 0) { + //更新用户登录时间,以及错误登录记录的信息归零。 + user.setState(UserState.ENABLE); + user.setLoginErrorTimes(0); + user.setLoginTime(LocalDateTime.now()); + user.setFirstErrorTime(null); + user.setLockTime(null); + this.baseMapper.updateById(user); return; } //根据用户类型获取对应用户策略 diff --git a/pqs-user/user-boot/src/main/resources/bootstrap.yml b/pqs-user/user-boot/src/main/resources/bootstrap.yml index ec5837071..7faaeb066 100644 --- a/pqs-user/user-boot/src/main/resources/bootstrap.yml +++ b/pqs-user/user-boot/src/main/resources/bootstrap.yml @@ -51,6 +51,6 @@ mybatis-plus: mqtt: uri: tcp://@middle.server.url@:1883 - client-id: @artifactId@ + client-id: @artifactId@${random.value} username: t_user password: njcnpqs