Browse Source

feat: [用户登录] 对接域控接口

master
memorylkf 3 weeks ago
parent
commit
9c831217c0
3 changed files with 59 additions and 18 deletions
  1. +26
    -15
      hxhq-auth/src/main/java/com/hxhq/auth/service/SysPasswordService.java
  2. +20
    -0
      hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/service/TokenService.java
  3. +13
    -3
      hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java

+ 26
- 15
hxhq-auth/src/main/java/com/hxhq/auth/service/SysPasswordService.java View File

@ -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)

+ 20
- 0
hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/service/TokenService.java View File

@ -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());
}
}

+ 13
- 3
hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysUserServiceImpl.java View File

@ -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

Loading…
Cancel
Save