From 9c831217c0d22a4535df9cab4c156608f4f3f260 Mon Sep 17 00:00:00 2001 From: memorylkf <312904636@qq.com> Date: Thu, 26 Mar 2026 11:25:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20[=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95]?= =?UTF-8?q?=20=E5=AF=B9=E6=8E=A5=E5=9F=9F=E6=8E=A7=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hxhq/auth/service/SysPasswordService.java | 41 ++++++++++++++-------- .../hxhq/common/security/service/TokenService.java | 20 +++++++++++ .../system/service/impl/SysUserServiceImpl.java | 16 +++++++-- 3 files changed, 59 insertions(+), 18 deletions(-) diff --git a/hxhq-auth/src/main/java/com/hxhq/auth/service/SysPasswordService.java b/hxhq-auth/src/main/java/com/hxhq/auth/service/SysPasswordService.java index 42daebd..90695cb 100644 --- a/hxhq-auth/src/main/java/com/hxhq/auth/service/SysPasswordService.java +++ b/hxhq-auth/src/main/java/com/hxhq/auth/service/SysPasswordService.java @@ -1,7 +1,10 @@ package com.hxhq.auth.service; import java.util.concurrent.TimeUnit; + +import com.hxhq.common.security.service.TokenService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import com.hxhq.common.core.constant.CacheConstants; import com.hxhq.common.core.constant.Constants; @@ -27,6 +30,11 @@ public class SysPasswordService @Autowired private SysRecordLogService recordLogService; + @Autowired + private TokenService tokenService; + + @Value("${spring.profiles.active:dev}") + private String activeProfile; /** * 登录账户密码错误次数缓存键名 @@ -41,14 +49,14 @@ public class SysPasswordService public void validate(SysUser user, String password) { - String username = user.getUserName(); - - Integer retryCount = redisService.getCacheObject(getCacheKey(username)); - - if (retryCount == null) - { - retryCount = 0; - } +// String username = user.getUserName(); +// +// Integer retryCount = redisService.getCacheObject(getCacheKey(username)); +// +// if (retryCount == null) +// { +// retryCount = 0; +// } // if (retryCount >= Integer.valueOf(maxRetryCount).intValue()) // { @@ -59,20 +67,23 @@ public class SysPasswordService if (!matches(user, password)) { - retryCount = retryCount + 1; +// retryCount = retryCount + 1; // recordLogService.recordLogininfor(username,user.getNickName(), Constants.LOGIN_FAIL, String.format("密码输入错误%s次", retryCount)); - redisService.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES); +// redisService.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES); throw new ServiceException("用户不存在/密码错误"); } - else - { - clearLoginRecordCache(username); - } +// else +// { +// clearLoginRecordCache(username); +// } } public boolean matches(SysUser user, String rawPassword) { - return SecurityUtils.matchesPassword(rawPassword, user.getPassword()); + if ("dev".equals(activeProfile)){ + return SecurityUtils.matchesPassword(rawPassword, user.getPassword()); + } + return tokenService.checkPassword(user.getUserName(),rawPassword); } public void clearLoginRecordCache(String loginName) diff --git a/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/service/TokenService.java b/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/service/TokenService.java index f0b2925..8c3d7da 100644 --- a/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/service/TokenService.java +++ b/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/service/TokenService.java @@ -5,7 +5,10 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpServletRequest; +import com.hxhq.common.core.exception.ServiceException; +import com.hxhq.common.core.web.domain.AjaxResult; import com.hxhq.common.security.utils.SecurityUtils; +import com.hxhq.system.api.RemoteIntegrationService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,6 +37,9 @@ public class TokenService @Autowired private RedisService redisService; + @Autowired + private RemoteIntegrationService remoteIntegrationService; + protected static final long MILLIS_SECOND = 1000; protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; @@ -194,4 +200,18 @@ public class TokenService { return CacheConstants.LOGIN_USERID_KEY + userId; } + + /** + * 调用域控检查用户名密码是否正确 + * @param userName + * @param password + * @return + */ + public Boolean checkPassword(String userName,String password){ + AjaxResult result = remoteIntegrationService.validate(userName,password); + if(result.isSuccess()){ + return true; + } + throw new ServiceException(result.get("msg").toString()); + } } \ No newline at end of file diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java index e2c7931..4901719 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java @@ -13,6 +13,7 @@ import com.hxhq.business.form.common.SignForm; import com.hxhq.business.service.IRoleChangeService; import com.hxhq.business.service.ISystemLogService; import com.hxhq.business.utils.ObjectCompareUtil; +import com.hxhq.common.security.service.TokenService; import com.hxhq.system.api.domain.SysDept; import com.hxhq.system.domain.SysMenu; import com.hxhq.system.domain.SysPost; @@ -25,6 +26,7 @@ import com.hxhq.system.service.ISysUserService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -82,6 +84,11 @@ public class SysUserServiceImpl implements ISysUserService @Autowired private IRoleChangeService roleChangeService; + @Autowired + private TokenService tokenService; + @Value("${spring.profiles.active:dev}") + private String activeProfile; + /** * 根据条件分页查询用户列表 @@ -633,10 +640,13 @@ public class SysUserServiceImpl implements ISysUserService @Override public Boolean checkPassword(SysUser user, String password, Boolean needName) { - if(SecurityUtils.matchesPassword(password,user.getPassword())){ - return true; + if ("dev".equals(activeProfile)){ + if(SecurityUtils.matchesPassword(password,user.getPassword())){ + return true; + } + throw new ServiceException((needName?user.getNickName():"")+"密码错误"); } - throw new ServiceException((needName?user.getNickName():"")+"密码错误"); + return tokenService.checkPassword(user.getUserName(),password); } @Override