From d8d0fd16af2f88cc7623b01493338c1f53b64e74 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期四, 16 十一月 2023 08:51:13 +0800 Subject: [PATCH] 提交代码 --- Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/service/BladeUserDetailsServiceImpl.java | 29 ++++++++++++++++++----------- 1 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/service/BladeUserDetailsServiceImpl.java b/Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/service/BladeUserDetailsServiceImpl.java index 4bd2fd2..18730fb 100644 --- a/Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/service/BladeUserDetailsServiceImpl.java +++ b/Source/UBCS/ubcs-auth/src/main/java/com/vci/ubcs/auth/service/BladeUserDetailsServiceImpl.java @@ -31,6 +31,7 @@ import org.springblade.core.jwt.JwtUtil; import org.springblade.core.jwt.props.JwtProperties; import org.springblade.core.redis.cache.BladeRedis; +import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.support.Kv; import org.springblade.core.tool.utils.*; @@ -39,11 +40,13 @@ import com.vci.ubcs.system.entity.Tenant; import com.vci.ubcs.system.feign.ISysClient; import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.security.oauth2.common.exceptions.InvalidGrantException; import org.springframework.security.oauth2.common.exceptions.UserDeniedAuthorizationException; import org.springframework.stereotype.Service; @@ -62,9 +65,9 @@ public class BladeUserDetailsServiceImpl implements UserDetailsService { /** - * 鍏佽閿欒娆℃暟 + * 榛樿鍏佽閿欒娆℃暟 */ - //public static final Integer FAIL_COUNT = 5; + public static final Integer FAIL_COUNT = 5; public static final String FAIL_COUNT_VALUE = "account.failCount"; /** @@ -77,7 +80,6 @@ private final BladeRedis bladeRedis; private final JwtProperties jwtProperties; - /** * 瓒呯骇绠$悊鍛樹俊鎭� @@ -125,24 +127,25 @@ // 鍒ゆ柇鐧诲綍鏄惁閿佸畾 int count = getFailCount(tenantId, username); //涓洪槻姝㈠彇鍊间负绌烘姤閿欑殑鎯呭喌锛屽綋涓虹┖鐨勬椂鍊欑粰榛樿鍙负5娆′究閿佸畾鐢ㄦ埛鐧诲綍锛屼絾鏄竴鑸緢闅惧嚭鐜拌繖绉嶆儏鍐碉紝鍥犱负鎴慺eign閲岄潰鏄粰浜嗛粯璁ゅ瘑鐮佺瓥鐣ユ煡璇㈢殑 - int failCountValue = Func.isEmpty(strategy) ? 5:Func.toInt(strategy.getLockingNum()); - + int failCountValue = Func.isEmpty(strategy) ? FAIL_COUNT:Func.toInt(strategy.getLockingNum()); int failCount = Func.toInt(ParamCache.getValue(FAIL_COUNT_VALUE), failCountValue); if (count >= failCount) { throw new UserDeniedAuthorizationException(TokenUtil.USER_HAS_TOO_MANY_FAILS); } - //瓒呯骇绠$悊鍛橀厤缃枃浠堕厤缃处鍙峰瘑鐮侊紝瀹炵幇鐧诲綍, 榛樿绉熸埛id涓�000000 - if(tenantId.equals(this.tenantId)){ + + //瓒呯骇绠$悊鍛橀厤缃枃浠堕厤缃处鍙峰瘑鐮侊紝瀹炵幇鐧诲綍, 榛樿绉熸埛id鍜岃秴绠′负閰嶇疆鍑烘潵鐨� + if(tenantId.equals(this.tenantId) && userName.equals(username)){ if (!this.userName.equals(username) && !password.equalsIgnoreCase(this.password)) { setFailCount(tenantId, username, count,strategy.getLockingTime()); throw new UsernameNotFoundException(TokenUtil.USER_NOT_FOUND); } //濡傛灉ip姣斿鍚巊et鎶涘嚭寮傚父No value present灏辩洿鎺ユ姏寮傚父缁撴潫鐧诲綍 if(ipEnable){ - Log.debug("褰撳墠璁块棶IP锛�"+getIpAddress(request)); + // Log.debug("褰撳墠璁块棶IP锛�"+getIpAddress(request)); + Log.debug("褰撳墠璁块棶IP锛�"+WebUtil.getIP(request)); try { - ips.stream().filter(s -> s.equals(getIpAddress(request))).findFirst().get(); + ips.stream().filter(s -> s.equals(WebUtil.getIP(request))).findFirst().get(); } catch (Exception e){ throw new UserDeniedAuthorizationException(TokenUtil.IP_NOT_FOND); } @@ -193,6 +196,10 @@ setFailCount(tenantId, username, count,strategy.getLockingTime()); throw new UsernameNotFoundException(TokenUtil.USER_NOT_FOUND); } + // 鐢ㄦ埛鐘舵�佷负1鏃惰鏄庤鐢ㄦ埛琚攣瀹� + if(user.getUserStatus() == 1){ + throw new InvalidGrantException(TokenUtil.USER_LOCK); + } String hex = DigestUtil.hex(password); // 鐢ㄦ埛瀛樺湪浣嗗瘑鐮侀敊璇�,瓒呰繃娆℃暟鍒欓攣瀹氳处鍙� if (grantType != null && !grantType.equals(TokenUtil.REFRESH_TOKEN_KEY) && !user.getPassword().equals(hex)) { @@ -220,8 +227,8 @@ //濉厖鐢ㄦ埛淇℃伅鍒扮敤鎴蜂俊鎭墿灞曠被 BladeUserDetails bladeUserDetails = new BladeUserDetails(user.getId(), user.getTenantId(), StringPool.EMPTY, user.getName(), user.getRealName(), user.getDeptId(), user.getPostId(), user.getRoleId(), Func.join(userInfo.getRoles()), Func.toStr(user.getAvatar(), TokenUtil.DEFAULT_AVATAR), - username, AuthConstant.ENCRYPT + user.getPassword(), userInfo.getDetail(), true, true, true, true, - AuthorityUtils.commaSeparatedStringToAuthorityList(Func.join(result.getData().getRoles())),user.getStrategyUpdateStatus()); + username, AuthConstant.ENCRYPT + user.getPassword(), userInfo.getDetail(),user.getSecretGrade(), true, true, true, true, + AuthorityUtils.commaSeparatedStringToAuthorityList(Func.join(result.getData().getRoles())),user.getStrategyUpdateStatus(),tenant.getData().getTenantName(),user.getDeptName(),user.getEmail()); return bladeUserDetails; } else { throw new UsernameNotFoundException(result.getMsg()); -- Gitblit v1.9.3