| | |
| | | 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"; |
| | |
| | | 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); |
| | | } |
| | | |