From bb14a46e456ee3a89ae385559726667acd8af37e Mon Sep 17 00:00:00 2001 From: liusheng <337615773@qq.com> Date: 星期三, 05 三月 2025 19:51:37 +0800 Subject: [PATCH] 代码提交 --- ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java | 42 +++++++++++++++--------------------------- 1 files changed, 15 insertions(+), 27 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java index 6ad91b0..f8f43c2 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java @@ -1,6 +1,7 @@ package com.ruoyi.framework.web.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; @@ -19,12 +20,11 @@ /** * 鐧诲綍瀵嗙爜鏂规硶 - * + * * @author ruoyi */ @Component -public class SysPasswordService -{ +public class SysPasswordService { @Autowired private RedisCache redisCache; @@ -36,58 +36,46 @@ /** * 鐧诲綍璐︽埛瀵嗙爜閿欒娆℃暟缂撳瓨閿悕 - * + * * @param username 鐢ㄦ埛鍚� * @return 缂撳瓨閿甼ey */ - private String getCacheKey(String username) - { + private String getCacheKey(String username) { return CacheConstants.PWD_ERR_CNT_KEY + username; } - public void validate(SysUser user) - { + public void validate(SysUser user) { Authentication usernamePasswordAuthenticationToken = AuthenticationContextHolder.getContext(); String username = usernamePasswordAuthenticationToken.getName(); String password = usernamePasswordAuthenticationToken.getCredentials().toString(); Integer retryCount = redisCache.getCacheObject(getCacheKey(username)); - if (retryCount == null) - { + if (retryCount == null) { retryCount = 0; } - if (retryCount >= Integer.valueOf(maxRetryCount).intValue()) - { - AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, - MessageUtils.message("user.password.retry.limit.exceed", maxRetryCount, lockTime))); + 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)) - { + if (!matches(user, password)) { retryCount = retryCount + 1; - AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, - MessageUtils.message("user.password.retry.limit.count", retryCount))); + 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(); - } - else - { + } else { clearLoginRecordCache(username); } } - public boolean matches(SysUser user, String rawPassword) - { + public boolean matches(SysUser user, String rawPassword) { return SecurityUtils.matchesPassword(rawPassword, user.getPassword()); } - public void clearLoginRecordCache(String loginName) - { - if (redisCache.hasKey(getCacheKey(loginName))) - { + public void clearLoginRecordCache(String loginName) { + if (redisCache.hasKey(getCacheKey(loginName))) { redisCache.deleteObject(getCacheKey(loginName)); } } -- Gitblit v1.9.3