CeDo
2021-05-12 768c44eb9cddcf58e4d02ec796a3af47ba4a82e3
bugfixed
1个文件已修改
26 ■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/java/com/panzhihua/zuul/filters/JWTAuthenticationTokenFilter.java 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/java/com/panzhihua/zuul/filters/JWTAuthenticationTokenFilter.java
@@ -114,22 +114,22 @@
                    ResultUtil.responseJson(response, R.fail(HttpStatus.UNAUTHORIZED, "token校验失败"));
                    return;
                }
                String username = claims.getSubject();
                String userId = claims.getSubject();
                int type = (Integer) claims.get("type");
                if (ObjectUtils.isEmpty(username)) {
                if (ObjectUtils.isEmpty(userId)) {
                    ResultUtil.responseJson(response, R.fail(HttpStatus.UNAUTHORIZED, "token校验失败"));
                    return;
                }
                List<SimpleGrantedAuthority> authorities = new ArrayList<>();
                List<SimpleGrantedAuthority> authorities1 = new ArrayList<>();
                if (1 == type) {//小程序用户统一角色
                    String roleAppletKey = SecurityConstants.ROLE_APPLETS_USER +username;
                    String roleAppletKey = SecurityConstants.ROLE_APPLETS_USER +userId;
                    if(stringRedisTemplate.hasKey(roleAppletKey)){
                        String roles = valueOperations.get(roleAppletKey);
                        authorities = JSONArray.parseArray(roles, SimpleGrantedAuthority.class);
                    }else {
                        authorities.add(new SimpleGrantedAuthority(SecurityConstants.ROLE_APPLETS));
                        String userKey = UserConstants.LOGIN_USER_INFO + username;
                        String userKey = UserConstants.LOGIN_USER_INFO + userId;
                        Boolean hasKeyLoginUserInfo = stringRedisTemplate.hasKey(userKey);
                        if (hasKeyLoginUserInfo) {
                            String userInfo = valueOperations.get(userKey);
@@ -140,25 +140,27 @@
                            }
                        }else{
                            //查询登陆用户信息
                            R<LoginUserInfoVO> r = userService.getUserInfoByUserId(username);
                            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);
                            //判断用户是否已实名制
                            if (data.getIsRealNamed() != null && data.getIsRealNamed()) {
                                authorities.add(new SimpleGrantedAuthority(SecurityConstants.ROLE_APPLETS_REAL_NAMED));
                            }
                        }
                        valueOperations.set(roleAppletKey, JSONArray.toJSONString(authorities), 24, TimeUnit.HOURS);
                    }
                } else {
                    String key = SecurityConstants.ROLE_USER + username;
                    String key = SecurityConstants.ROLE_USER + userId;
                    Boolean aBoolean = stringRedisTemplate.hasKey(key);
                    if (aBoolean) {
                        String roles = valueOperations.get(key);
                        authorities = JSONArray.parseArray(roles, SimpleGrantedAuthority.class);
                    } else {
                        R<List<String>> r = userService.getUserRoles(username);
                        R<List<String>> r = userService.getUserRoles(userId);
                        List<String> data =(List<String>)r.getData();
                        if (!ObjectUtils.isEmpty(data)) {
                            data.forEach(s -> {
@@ -169,11 +171,11 @@
                        }
                    }
                }
                UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(username, username, authorities);//主要使用权限 账户 密码 不重要
                UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userId, userId, authorities);//主要使用权限 账户 密码 不重要
                SecurityContextHolder.getContext().setAuthentication(authentication);
                safeboxRequestWrapper.addHeader(TokenConstant.TOKEN_LOGOUT,tokenHeader);
                //登录用户的所有信息
                String userKey = UserConstants.LOGIN_USER_INFO + username;
                String userKey = UserConstants.LOGIN_USER_INFO + userId;
                Boolean hasKeyLoginUserInfo = stringRedisTemplate.hasKey(userKey);
                if(hasKeyLoginUserInfo){
                    String userInfo = valueOperations.get(userKey);
@@ -181,7 +183,7 @@
                    String hexStr = AES.parseByte2HexStr(encrypt);
                    safeboxRequestWrapper.addHeader(TokenConstant.TOKEN_USERINFO, hexStr);
                }else{
                    R<LoginUserInfoVO> r = userService.getUserInfoByUserId(username);
                    R<LoginUserInfoVO> r = userService.getUserInfoByUserId(userId);
                    if (!R.isOk(r)) {
                        ResultUtil.responseJson(response, R.fail(HttpStatus.ERROR, "登录用户信息查询失败"));
                        return;