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