| | |
| | | package com.ruoyi.framework.security.service;
|
| | |
|
| | | import java.util.concurrent.TimeUnit;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.security.core.Authentication;
|
| | | import org.springframework.stereotype.Component;
|
| | | import com.ruoyi.common.constant.CacheConstants;
|
| | | import com.ruoyi.common.constant.Constants;
|
| | | import com.ruoyi.common.exception.user.UserPasswordNotMatchException;
|
| | | import com.ruoyi.common.exception.user.UserPasswordRetryLimitExceedException;
|
| | | import com.ruoyi.common.utils.MessageUtils;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.framework.manager.AsyncManager;
|
| | | import com.ruoyi.framework.manager.factory.AsyncFactory;
|
| | | import com.ruoyi.framework.redis.RedisCache;
|
| | | import com.ruoyi.framework.security.context.AuthenticationContextHolder;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import lombok.RequiredArgsConstructor;
|
| | | import org.springframework.beans.factory.annotation.Value;
|
| | | import org.springframework.security.core.Authentication;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import java.util.concurrent.TimeUnit;
|
| | |
|
| | | /**
|
| | | * 登录密码方法
|
| | |
| | | * @author ruoyi
|
| | | */
|
| | | @Component
|
| | | @RequiredArgsConstructor
|
| | | public class SysPasswordService
|
| | | {
|
| | | @Autowired
|
| | | private RedisCache redisCache;
|
| | | private final RedisCache redisCache;
|
| | |
|
| | | @Value(value = "${user.password.maxRetryCount}")
|
| | | private int maxRetryCount;
|
| | |
| | |
|
| | | if (retryCount >= Integer.valueOf(maxRetryCount).intValue())
|
| | | {
|
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL,
|
| | | MessageUtils.message("user.password.retry.limit.exceed", maxRetryCount, lockTime)));
|
| | | throw new UserPasswordRetryLimitExceedException(maxRetryCount, lockTime);
|
| | | }
|
| | |
|
| | | if (!matches(user, password))
|
| | | {
|
| | | retryCount = retryCount + 1;
|
| | | AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL,
|
| | | MessageUtils.message("user.password.retry.limit.count", retryCount)));
|
| | | redisCache.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES);
|
| | | throw new UserPasswordNotMatchException();
|
| | | }
|