| | |
| | | package org.springblade.modules.auth.granter; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springblade.common.cache.CacheNames; |
| | | import org.springblade.common.cache.ParamCache; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | |
| | | @AllArgsConstructor |
| | | public class PasswordTokenGranter implements ITokenGranter { |
| | | |
| | | protected static final Logger logger = LoggerFactory.getLogger(CaptchaTokenGranter.class); |
| | | |
| | | public static final String GRANT_TYPE = "password"; |
| | | public static final Integer FAIL_COUNT = 5; |
| | | public static final String FAIL_COUNT_VALUE = "account.failCount"; |
| | |
| | | String tenantId = tokenParameter.getArgs().getStr("tenantId"); |
| | | String username = tokenParameter.getArgs().getStr("username"); |
| | | String password = tokenParameter.getArgs().getStr("password"); |
| | | // 获取登录类型 2:pc 3:app |
| | | String type = tokenParameter.getArgs().getStr("loginType"); |
| | | |
| | | // 判断登录是否锁定 |
| | | int cnt = Func.toInt(bladeRedis.get(CacheNames.tenantKey(tenantId, CacheNames.USER_FAIL_KEY, username)), 0); |
| | | int failCount = Func.toInt(ParamCache.getValue(FAIL_COUNT_VALUE), FAIL_COUNT); |
| | | if (cnt >= failCount) { |
| | | logger.error("用户名或密码错误,用户账号:{},用户名:{},错误次数:{}",tenantId, username, cnt); |
| | | throw new ServiceException(TokenUtil.USER_HAS_TOO_MANY_FAILS); |
| | | } |
| | | |
| | |
| | | if (TokenUtil.judgeTenant(tenant)) { |
| | | throw new ServiceException(TokenUtil.USER_HAS_NO_TENANT_PERMISSION); |
| | | } |
| | | // 获取用户类型 |
| | | String userType = tokenParameter.getArgs().getStr("userType"); |
| | | // 根据不同用户类型调用对应的接口返回数据,用户可自行拓展 |
| | | if (userType.equals(UserEnum.WEB.getName())) { |
| | | userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.WEB); |
| | | } else if (userType.equals(UserEnum.APP.getName())) { |
| | | userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.APP); |
| | | } else { |
| | | userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), UserEnum.OTHER); |
| | | } |
| | | userInfo = userService.userInfo(tenantId, username, DigestUtil.hex(password), Integer.parseInt(type)); |
| | | } |
| | | if (userInfo == null || userInfo.getUser() == null) { |
| | | // 增加错误锁定次数 |