fix 修复 登录错误锁定不区分租户问题
parent
07255f0e7f
commit
9e86a7e094
|
|
@ -14,6 +14,7 @@ import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
import org.dromara.auth.form.RegisterBody;
|
import org.dromara.auth.form.RegisterBody;
|
||||||
import org.dromara.auth.properties.CaptchaProperties;
|
import org.dromara.auth.properties.CaptchaProperties;
|
||||||
import org.dromara.auth.properties.UserPasswordProperties;
|
import org.dromara.auth.properties.UserPasswordProperties;
|
||||||
|
import org.dromara.common.core.constant.CacheConstants;
|
||||||
import org.dromara.common.core.constant.Constants;
|
import org.dromara.common.core.constant.Constants;
|
||||||
import org.dromara.common.core.constant.GlobalConstants;
|
import org.dromara.common.core.constant.GlobalConstants;
|
||||||
import org.dromara.common.core.constant.TenantConstants;
|
import org.dromara.common.core.constant.TenantConstants;
|
||||||
|
|
@ -205,7 +206,7 @@ public class SysLoginService {
|
||||||
* 登录校验
|
* 登录校验
|
||||||
*/
|
*/
|
||||||
public void checkLogin(LoginType loginType, String tenantId, String username, Supplier<Boolean> supplier) {
|
public void checkLogin(LoginType loginType, String tenantId, String username, Supplier<Boolean> supplier) {
|
||||||
String errorKey = GlobalConstants.PWD_ERR_CNT_KEY + username;
|
String errorKey = CacheConstants.PWD_ERR_CNT_KEY + username;
|
||||||
String loginFail = Constants.LOGIN_FAIL;
|
String loginFail = Constants.LOGIN_FAIL;
|
||||||
Integer maxRetryCount = userPasswordProperties.getMaxRetryCount();
|
Integer maxRetryCount = userPasswordProperties.getMaxRetryCount();
|
||||||
Integer lockTime = userPasswordProperties.getLockTime();
|
Integer lockTime = userPasswordProperties.getLockTime();
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import org.dromara.common.core.utils.ValidatorUtils;
|
||||||
import org.dromara.common.json.utils.JsonUtils;
|
import org.dromara.common.json.utils.JsonUtils;
|
||||||
import org.dromara.common.redis.utils.RedisUtils;
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
import org.dromara.common.satoken.utils.LoginHelper;
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
|
import org.dromara.common.tenant.helper.TenantHelper;
|
||||||
import org.dromara.system.api.RemoteUserService;
|
import org.dromara.system.api.RemoteUserService;
|
||||||
import org.dromara.system.api.domain.vo.RemoteClientVo;
|
import org.dromara.system.api.domain.vo.RemoteClientVo;
|
||||||
import org.dromara.system.api.model.LoginUser;
|
import org.dromara.system.api.model.LoginUser;
|
||||||
|
|
@ -46,10 +47,11 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||||
String tenantId = loginBody.getTenantId();
|
String tenantId = loginBody.getTenantId();
|
||||||
String email = loginBody.getEmail();
|
String email = loginBody.getEmail();
|
||||||
String emailCode = loginBody.getEmailCode();
|
String emailCode = loginBody.getEmailCode();
|
||||||
|
LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
|
||||||
// 通过邮箱查找用户
|
LoginUser user = remoteUserService.getUserInfoByEmail(email, tenantId);
|
||||||
LoginUser loginUser = remoteUserService.getUserInfoByEmail(email, tenantId);
|
loginService.checkLogin(LoginType.EMAIL, tenantId, user.getUsername(), () -> !validateEmailCode(tenantId, email, emailCode));
|
||||||
loginService.checkLogin(LoginType.EMAIL, tenantId, loginUser.getUsername(), () -> !validateEmailCode(tenantId, email, emailCode));
|
return user;
|
||||||
|
});
|
||||||
loginUser.setClientKey(client.getClientKey());
|
loginUser.setClientKey(client.getClientKey());
|
||||||
loginUser.setDeviceType(client.getDeviceType());
|
loginUser.setDeviceType(client.getDeviceType());
|
||||||
SaLoginModel model = new SaLoginModel();
|
SaLoginModel model = new SaLoginModel();
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import org.dromara.common.core.utils.ValidatorUtils;
|
||||||
import org.dromara.common.json.utils.JsonUtils;
|
import org.dromara.common.json.utils.JsonUtils;
|
||||||
import org.dromara.common.redis.utils.RedisUtils;
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
import org.dromara.common.satoken.utils.LoginHelper;
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
|
import org.dromara.common.tenant.helper.TenantHelper;
|
||||||
import org.dromara.system.api.RemoteUserService;
|
import org.dromara.system.api.RemoteUserService;
|
||||||
import org.dromara.system.api.domain.vo.RemoteClientVo;
|
import org.dromara.system.api.domain.vo.RemoteClientVo;
|
||||||
import org.dromara.system.api.model.LoginUser;
|
import org.dromara.system.api.model.LoginUser;
|
||||||
|
|
@ -58,9 +59,11 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||||
if (captchaProperties.getEnabled()) {
|
if (captchaProperties.getEnabled()) {
|
||||||
validateCaptcha(tenantId, username, code, uuid);
|
validateCaptcha(tenantId, username, code, uuid);
|
||||||
}
|
}
|
||||||
|
LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
|
||||||
LoginUser loginUser = remoteUserService.getUserInfo(username, tenantId);
|
LoginUser user = remoteUserService.getUserInfo(username, tenantId);
|
||||||
loginService.checkLogin(LoginType.PASSWORD, tenantId, username, () -> !BCrypt.checkpw(password, loginUser.getPassword()));
|
loginService.checkLogin(LoginType.PASSWORD, tenantId, username, () -> !BCrypt.checkpw(password, user.getPassword()));
|
||||||
|
return user;
|
||||||
|
});
|
||||||
loginUser.setClientKey(client.getClientKey());
|
loginUser.setClientKey(client.getClientKey());
|
||||||
loginUser.setDeviceType(client.getDeviceType());
|
loginUser.setDeviceType(client.getDeviceType());
|
||||||
SaLoginModel model = new SaLoginModel();
|
SaLoginModel model = new SaLoginModel();
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import org.dromara.common.core.utils.ValidatorUtils;
|
||||||
import org.dromara.common.json.utils.JsonUtils;
|
import org.dromara.common.json.utils.JsonUtils;
|
||||||
import org.dromara.common.redis.utils.RedisUtils;
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
import org.dromara.common.satoken.utils.LoginHelper;
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
|
import org.dromara.common.tenant.helper.TenantHelper;
|
||||||
import org.dromara.system.api.RemoteUserService;
|
import org.dromara.system.api.RemoteUserService;
|
||||||
import org.dromara.system.api.domain.vo.RemoteClientVo;
|
import org.dromara.system.api.domain.vo.RemoteClientVo;
|
||||||
import org.dromara.system.api.model.LoginUser;
|
import org.dromara.system.api.model.LoginUser;
|
||||||
|
|
@ -46,10 +47,11 @@ public class SmsAuthStrategy implements IAuthStrategy {
|
||||||
String tenantId = loginBody.getTenantId();
|
String tenantId = loginBody.getTenantId();
|
||||||
String phonenumber = loginBody.getPhonenumber();
|
String phonenumber = loginBody.getPhonenumber();
|
||||||
String smsCode = loginBody.getSmsCode();
|
String smsCode = loginBody.getSmsCode();
|
||||||
|
LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
|
||||||
// 通过手机号查找用户
|
LoginUser user = remoteUserService.getUserInfoByPhonenumber(phonenumber, tenantId);
|
||||||
LoginUser loginUser = remoteUserService.getUserInfoByPhonenumber(phonenumber, tenantId);
|
loginService.checkLogin(LoginType.SMS, tenantId, user.getUsername(), () -> !validateSmsCode(tenantId, phonenumber, smsCode));
|
||||||
loginService.checkLogin(LoginType.SMS, tenantId, loginUser.getUsername(), () -> !validateSmsCode(tenantId, phonenumber, smsCode));
|
return user;
|
||||||
|
});
|
||||||
loginUser.setClientKey(client.getClientKey());
|
loginUser.setClientKey(client.getClientKey());
|
||||||
loginUser.setDeviceType(client.getDeviceType());
|
loginUser.setDeviceType(client.getDeviceType());
|
||||||
SaLoginModel model = new SaLoginModel();
|
SaLoginModel model = new SaLoginModel();
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,9 @@ public interface CacheConstants {
|
||||||
*/
|
*/
|
||||||
String SYS_DICT_KEY = "sys_dict:";
|
String SYS_DICT_KEY = "sys_dict:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录账户密码错误次数 redis key
|
||||||
|
*/
|
||||||
|
String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,6 @@ public interface GlobalConstants {
|
||||||
*/
|
*/
|
||||||
String RATE_LIMIT_KEY = GLOBAL_REDIS_KEY + "rate_limit:";
|
String RATE_LIMIT_KEY = GLOBAL_REDIS_KEY + "rate_limit:";
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录账户密码错误次数 redis key
|
|
||||||
*/
|
|
||||||
String PWD_ERR_CNT_KEY = GLOBAL_REDIS_KEY + "pwd_err_cnt:";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 三方认证 redis key
|
* 三方认证 redis key
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,23 @@
|
||||||
package org.dromara.system.controller.monitor;
|
package org.dromara.system.controller.monitor;
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.dromara.common.core.constant.GlobalConstants;
|
import org.dromara.common.core.constant.CacheConstants;
|
||||||
import org.dromara.common.core.domain.R;
|
import org.dromara.common.core.domain.R;
|
||||||
import org.dromara.common.web.core.BaseController;
|
|
||||||
import org.dromara.common.excel.utils.ExcelUtil;
|
import org.dromara.common.excel.utils.ExcelUtil;
|
||||||
import org.dromara.common.log.annotation.Log;
|
import org.dromara.common.log.annotation.Log;
|
||||||
import org.dromara.common.log.enums.BusinessType;
|
import org.dromara.common.log.enums.BusinessType;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
import org.dromara.common.redis.utils.RedisUtils;
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
|
import org.dromara.common.web.core.BaseController;
|
||||||
import org.dromara.system.domain.bo.SysLogininforBo;
|
import org.dromara.system.domain.bo.SysLogininforBo;
|
||||||
import org.dromara.system.domain.vo.SysLogininforVo;
|
import org.dromara.system.domain.vo.SysLogininforVo;
|
||||||
import org.dromara.system.service.ISysLogininforService;
|
import org.dromara.system.service.ISysLogininforService;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -79,7 +79,7 @@ public class SysLogininforController extends BaseController {
|
||||||
@Log(title = "账户解锁", businessType = BusinessType.OTHER)
|
@Log(title = "账户解锁", businessType = BusinessType.OTHER)
|
||||||
@GetMapping("/unlock/{userName}")
|
@GetMapping("/unlock/{userName}")
|
||||||
public R<Void> unlock(@PathVariable("userName") String userName) {
|
public R<Void> unlock(@PathVariable("userName") String userName) {
|
||||||
String loginName = GlobalConstants.PWD_ERR_CNT_KEY + userName;
|
String loginName = CacheConstants.PWD_ERR_CNT_KEY + userName;
|
||||||
if (RedisUtils.hasKey(loginName)) {
|
if (RedisUtils.hasKey(loginName)) {
|
||||||
RedisUtils.deleteObject(loginName);
|
RedisUtils.deleteObject(loginName);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package org.dromara.system.dubbo;
|
package org.dromara.system.dubbo;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.lang.Opt;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
@ -10,6 +11,7 @@ import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.core.exception.user.UserException;
|
import org.dromara.common.core.exception.user.UserException;
|
||||||
import org.dromara.common.core.utils.DateUtils;
|
import org.dromara.common.core.utils.DateUtils;
|
||||||
import org.dromara.common.core.utils.MapstructUtils;
|
import org.dromara.common.core.utils.MapstructUtils;
|
||||||
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.mybatis.helper.DataPermissionHelper;
|
import org.dromara.common.mybatis.helper.DataPermissionHelper;
|
||||||
import org.dromara.common.tenant.helper.TenantHelper;
|
import org.dromara.common.tenant.helper.TenantHelper;
|
||||||
import org.dromara.system.api.RemoteUserService;
|
import org.dromara.system.api.RemoteUserService;
|
||||||
|
|
@ -257,16 +259,11 @@ public class RemoteUserServiceImpl implements RemoteUserService {
|
||||||
loginUser.setUserType(userVo.getUserType());
|
loginUser.setUserType(userVo.getUserType());
|
||||||
loginUser.setMenuPermission(permissionService.getMenuPermission(userVo.getUserId()));
|
loginUser.setMenuPermission(permissionService.getMenuPermission(userVo.getUserId()));
|
||||||
loginUser.setRolePermission(permissionService.getRolePermission(userVo.getUserId()));
|
loginUser.setRolePermission(permissionService.getRolePermission(userVo.getUserId()));
|
||||||
TenantHelper.dynamic(userVo.getTenantId(), () -> {
|
Opt<SysDeptVo> deptOpt = Opt.of(userVo.getDeptId()).map(deptService::selectDeptById);
|
||||||
SysDeptVo dept = null;
|
loginUser.setDeptName(deptOpt.map(SysDeptVo::getDeptName).orElse(StringUtils.EMPTY));
|
||||||
if (ObjectUtil.isNotNull(userVo.getDeptId())) {
|
loginUser.setDeptCategory(deptOpt.map(SysDeptVo::getDeptCategory).orElse(StringUtils.EMPTY));
|
||||||
dept = deptService.selectDeptById(userVo.getDeptId());
|
List<SysRoleVo> roles = roleService.selectRolesByUserId(userVo.getUserId());
|
||||||
}
|
loginUser.setRoles(BeanUtil.copyToList(roles, RoleDTO.class));
|
||||||
loginUser.setDeptName(ObjectUtil.isNull(dept) ? "" : dept.getDeptName());
|
|
||||||
loginUser.setDeptCategory(ObjectUtil.isNull(dept) ? "" : dept.getDeptCategory());
|
|
||||||
List<SysRoleVo> roles = roleService.selectRolesByUserId(userVo.getUserId());
|
|
||||||
loginUser.setRoles(BeanUtil.copyToList(roles, RoleDTO.class));
|
|
||||||
});
|
|
||||||
return loginUser;
|
return loginUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue