diff --git a/mhd-auth/src/main/java/com/mhd/auth/system/service/SysPasswordService.java b/mhd-auth/src/main/java/com/mhd/auth/system/service/SysPasswordService.java index eded6927d..9c3d126e6 100644 --- a/mhd-auth/src/main/java/com/mhd/auth/system/service/SysPasswordService.java +++ b/mhd-auth/src/main/java/com/mhd/auth/system/service/SysPasswordService.java @@ -28,6 +28,7 @@ import com.mhd.common.redis.service.RedisService; import com.mhd.common.security.utils.password.PasswordUtil; import com.mhd.system.api.RemoteLogService; import com.mhd.system.api.domain.SysLogininforPo; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -39,6 +40,7 @@ import javax.annotation.Resource; * @description: 登录密码方法 * @date 2023/12/26 15:33 **/ +@Slf4j @Component public class SysPasswordService { @@ -76,29 +78,31 @@ public class SysPasswordService if (retryCount == null) { retryCount = 0; } - //TODO 从三方配置表中取值 - SysDepartInterfaceInfoDTO sysDepartInterfaceInfoDTO = new SysDepartInterfaceInfoDTO(); - sysDepartInterfaceInfoDTO.setTopOrganizationId(userPo.getTopOrganizationId()); - sysDepartInterfaceInfoDTO.setInterfaceType("login"); - sysDepartInterfaceInfoDTO.setInterfaceTypeKey("maxRetryCount"); - List sysDepartInterfaceInfoPos = thirdPartyServiceFeign.queryListByFeign(sysDepartInterfaceInfoDTO); - if (sysDepartInterfaceInfoPos.isEmpty()){ - String errMsg = "缺少登录信息配置,请联系管理员"; - recordLogininfor(userPo, Constants.LOGIN_FAIL, errMsg, 1); - throw new ServiceException(errMsg); + //TODO 从三方配置表中取值(失败时用默认值,保证登录错误提示可用) + int maxRetryCount = 5; // 默认:密码错5次锁定 + long lockTime = 30L; // 默认:锁定30分钟 + try { + SysDepartInterfaceInfoDTO dto = new SysDepartInterfaceInfoDTO(); + dto.setTopOrganizationId(userPo.getTopOrganizationId()); + dto.setInterfaceType("login"); + dto.setInterfaceTypeKey("maxRetryCount"); + List pos = thirdPartyServiceFeign.queryListByFeign(dto); + if (pos != null && !pos.isEmpty()) { + maxRetryCount = Integer.parseInt(pos.get(0).getInterfaceTypeValue()); + } else { + log.warn("组织[{}]缺少登录配置 login/maxRetryCount,使用默认值{}", userPo.getTopOrganizationId(), maxRetryCount); + } + dto.setInterfaceTypeKey("lockTime"); + pos = thirdPartyServiceFeign.queryListByFeign(dto); + if (pos != null && !pos.isEmpty()) { + lockTime = Long.parseLong(pos.get(0).getInterfaceTypeValue()); + } else { + log.warn("组织[{}]缺少登录配置 login/lockTime,使用默认值{}", userPo.getTopOrganizationId(), lockTime); + } + } catch (Exception e) { + log.warn("读取登录配置失败,使用默认重试策略", e); } - SysDepartInterfaceInfoPo sysDepartInterfaceInfoPo = sysDepartInterfaceInfoPos.get(0); - Integer maxRetryCount = Integer.valueOf(sysDepartInterfaceInfoPo.getInterfaceTypeValue()); - sysDepartInterfaceInfoDTO.setInterfaceTypeKey("lockTime"); - sysDepartInterfaceInfoPos = thirdPartyServiceFeign.queryListByFeign(sysDepartInterfaceInfoDTO); - if (sysDepartInterfaceInfoPos.isEmpty()){ - String errMsg = "缺少登录信息配置,请联系管理员"; - recordLogininfor(userPo, Constants.LOGIN_FAIL, errMsg, 1); - throw new ServiceException(errMsg); - } - sysDepartInterfaceInfoPo = sysDepartInterfaceInfoPos.get(0); - Long lockTime = Long.valueOf(sysDepartInterfaceInfoPo.getInterfaceTypeValue()); - if (retryCount >= maxRetryCount){ + if (retryCount >= maxRetryCount) { String errMsg = String.format("密码输入错误%s次,帐户锁定%s分钟", maxRetryCount, lockTime); recordLogininfor(userPo, Constants.LOGIN_FAIL, errMsg, 1); throw new ServiceException(errMsg); diff --git a/mhd-common/mhd-common-security/src/main/java/com/mhd/common/security/handler/GlobalExceptionHandler.java b/mhd-common/mhd-common-security/src/main/java/com/mhd/common/security/handler/GlobalExceptionHandler.java index e166429f3..56ca86d91 100644 --- a/mhd-common/mhd-common-security/src/main/java/com/mhd/common/security/handler/GlobalExceptionHandler.java +++ b/mhd-common/mhd-common-security/src/main/java/com/mhd/common/security/handler/GlobalExceptionHandler.java @@ -88,7 +88,8 @@ public class GlobalExceptionHandler { String requestURI = request.getRequestURI(); log.error("请求地址'{}',发生未知异常.", requestURI, e); - return AjaxResult.error(e.getMessage()); + String msg = StringUtils.isEmpty(e.getMessage()) ? "系统繁忙,请稍后重试" : e.getMessage(); + return AjaxResult.error(msg); } /** @@ -99,7 +100,8 @@ public class GlobalExceptionHandler { String requestURI = request.getRequestURI(); log.error("请求地址'{}',发生系统异常.", requestURI, e); - return AjaxResult.error(e.getMessage()); + String msg = StringUtils.isEmpty(e.getMessage()) ? "系统繁忙,请稍后重试" : e.getMessage(); + return AjaxResult.error(msg); } /**