| | |
| | | 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; |
| | |
| | | } |
| | | 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) { |