From b37f92c1f5bea036b13af38d82a0fa9ca690eb3b Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期三, 26 二月 2025 01:27:18 +0800 Subject: [PATCH] 三个身边 --- springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/java/com/panzhihua/zuul/filters/JWTAuthenticationTokenFilter.java | 65 ++++++++++++++++++++++++++++++++ 1 files changed, 64 insertions(+), 1 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/java/com/panzhihua/zuul/filters/JWTAuthenticationTokenFilter.java b/springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/java/com/panzhihua/zuul/filters/JWTAuthenticationTokenFilter.java index a0197ba..2e421c5 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/java/com/panzhihua/zuul/filters/JWTAuthenticationTokenFilter.java +++ b/springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/java/com/panzhihua/zuul/filters/JWTAuthenticationTokenFilter.java @@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import com.panzhihua.common.model.vos.sangeshenbian.SystemUserVo; import com.panzhihua.common.model.vos.user.SysAppConfigVO; import com.panzhihua.common.utlis.*; import org.springframework.context.ApplicationContext; @@ -187,7 +188,69 @@ } valueOperations.set(roleAppletKey, JSONArray.toJSONString(authorities), 24, TimeUnit.HOURS); } - } else { + // 登录用户的所有信息 + String userKey = UserConstants.LOGIN_USER_INFO + userId; + Boolean hasKeyLoginUserInfo = stringRedisTemplate.hasKey(userKey); + if (hasKeyLoginUserInfo) { + String userInfo = valueOperations.get(userKey); + byte[] encrypt = AES.encrypt(userInfo, Constants.AES_KEY); + String hexStr = AES.parseByte2HexStr(encrypt); + safeboxRequestWrapper.addHeader(TokenConstant.TOKEN_USERINFO, hexStr); + } else { + R<LoginUserInfoVO> r = userService.getUserInfoByUserId(userId); + if (!R.isOk(r)) { + ResultUtil.responseJson(response, R.fail(HttpStatus.ERROR, "登录用户信息查询失败")); + return; + } + LoginUserInfoVO data = r.getData(); + String userInfo = JSONObject.toJSONString(data); + valueOperations.set(userKey, userInfo, 24, TimeUnit.HOURS); + byte[] encrypt = AES.encrypt(userInfo, Constants.AES_KEY); + String hexStr = AES.parseByte2HexStr(encrypt); + safeboxRequestWrapper.addHeader(TokenConstant.TOKEN_USERINFO, hexStr); + } + } else if(21 == type){ + //三个身边 + String key = SecurityConstants.ROLE_USER + "sangeshenbian:" + userId; + Boolean aBoolean = stringRedisTemplate.hasKey(key); + R<SystemUserVo> r = systemUserService.getUserById(userId); + if (aBoolean) { + String roles = valueOperations.get(key); + authorities = JSONArray.parseArray(roles, SimpleGrantedAuthority.class); + } else { + SystemUserVo data = r.getData(); + if (!ObjectUtils.isEmpty(data)) { + authorities.add(new SimpleGrantedAuthority(data.getSystemRoleId().toString())); + valueOperations.set(key, JSONArray.toJSONString(authorities), 24, TimeUnit.HOURS); + } + } + + UsernamePasswordAuthenticationToken authentication = + new UsernamePasswordAuthenticationToken(userId, userId, authorities);// 主要使用权限 账户 密码 不重要 + SecurityContextHolder.getContext().setAuthentication(authentication); + safeboxRequestWrapper.addHeader(TokenConstant.TOKEN_LOGOUT, tokenHeader); + // 登录用户的所有信息 + String userKey = UserConstants.LOGIN_USER_INFO + "sangeshenbian:" + userId; + Boolean hasKeyLoginUserInfo = stringRedisTemplate.hasKey(userKey); + if (hasKeyLoginUserInfo) { + String userInfo = valueOperations.get(userKey); + byte[] encrypt = AES.encrypt(userInfo, Constants.AES_KEY); + String hexStr = AES.parseByte2HexStr(encrypt); + safeboxRequestWrapper.addHeader(TokenConstant.TOKEN_USERINFO, hexStr); + } else { + if (!R.isOk(r)) { + ResultUtil.responseJson(response, R.fail(HttpStatus.ERROR, "登录用户信息查询失败")); + return; + } + SystemUserVo data = r.getData(); + String userInfo = JSONObject.toJSONString(data); + valueOperations.set(userKey, userInfo, 24, TimeUnit.HOURS); + byte[] encrypt = AES.encrypt(userInfo, Constants.AES_KEY); + String hexStr = AES.parseByte2HexStr(encrypt); + safeboxRequestWrapper.addHeader(TokenConstant.TOKEN_USERINFO, hexStr); + } + + }else { String key = SecurityConstants.ROLE_USER + userId; Boolean aBoolean = stringRedisTemplate.hasKey(key); if (aBoolean) { -- Gitblit v1.7.1