| | |
| | | package com.panzhihua.zuul.filters; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.panzhihua.common.constants.HttpStatus; |
| | | import com.panzhihua.common.constants.SecurityConstants; |
| | | import com.panzhihua.common.constants.TokenConstant; |
| | | import com.panzhihua.common.constants.UserConstants; |
| | | import com.panzhihua.common.model.vos.LoginUserInfoVO; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.service.user.UserService; |
| | | import com.panzhihua.common.utlis.JWTTokenUtil; |
| | |
| | | } |
| | | UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(username, username, authorities);//主要使用权限 账户 密码 不重要 |
| | | SecurityContextHolder.getContext().setAuthentication(authentication); |
| | | safeboxRequestWrapper.addHeader(UserConstants.USER_ID,username); |
| | | safeboxRequestWrapper.addHeader(TokenConstant.TOKEN_LOGOUT,tokenHeader); |
| | | //登录用户的所有信息 |
| | | String userKey = UserConstants.LOGIN_USER_INFO + username; |
| | | Boolean hasKeyLoginUserInfo = stringRedisTemplate.hasKey(userKey); |
| | | if(hasKeyLoginUserInfo){ |
| | | String userInfo = valueOperations.get(userKey); |
| | | safeboxRequestWrapper.addHeader(UserConstants.LOGIN_USER_INFO,userInfo); |
| | | }else{ |
| | | R<LoginUserInfoVO> userInfoByUserId = userService.getUserInfoByUserId(username); |
| | | LoginUserInfoVO data = userInfoByUserId.getData(); |
| | | String userInfo = JSONObject.toJSONString(data); |
| | | valueOperations.set(userKey,userInfo,24,TimeUnit.HOURS); |
| | | safeboxRequestWrapper.addHeader(UserConstants.LOGIN_USER_INFO,userInfo); |
| | | } |
| | | |
| | | } else { |
| | | ResultUtil.responseJson(response, R.fail(HttpStatus.UNAUTHORIZED, "token校验失败")); |