| | |
| | | import com.moon.server.entity.all.*; |
| | | import com.moon.server.entity.sys.ResEntity; |
| | | import com.moon.server.entity.sys.ResLogEntity; |
| | | import com.moon.server.entity.sys.TokenEntity; |
| | | import com.moon.server.entity.sys.UserEntity; |
| | | import com.moon.server.helper.AsyncHelper; |
| | | import com.moon.server.helper.HttpHelper; |
| | |
| | | } |
| | | // 7.检查白名单和IP一致性 |
| | | if (!checkWhiteList(ip, req)) { |
| | | if (!ip.equals(sysService.tokenService.getEntityByToken(token).getIp())) { |
| | | if (!checkIpSource(ip, token)) { |
| | | return WebHelper.writeStr2Page(res, AuthInterceptor.ILLEGAL_TOKEN); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | return whiteList.contains(ip); |
| | | } |
| | | |
| | | /** |
| | | * 检查IP一致性:固定令牌不检查 |
| | | */ |
| | | private boolean checkIpSource(String ip, String token) { |
| | | TokenEntity te = sysService.tokenService.getEntityByToken(token); |
| | | |
| | | return StaticData.I1 == te.getType() || te.getIp().equals(ip); |
| | | } |
| | | |
| | | /** |
| | |
| | | String proxyUrl = entity.getProxy().replace("{token}", token); |
| | | int end = req.getRequestURL().indexOf(proxyUrl) + proxyUrl.length(); |
| | | |
| | | String url = entity.getUrl() + req.getRequestURL().substring(end); |
| | | String url = entity.getUrl().trim() + req.getRequestURL().substring(end); |
| | | // category:0-其他,1-GisServer,2-GeoServer,3-数简 |
| | | if (StaticData.I2 == entity.getCategory()) { |
| | | url = getGeoServerUrl(req, ue, entity, url); |
| | |
| | | } |
| | | |
| | | String str = req.getQueryString(); |
| | | if (!StaticData.GET_CAPABILITIES.equals(req.getParameter(StaticData.REQUEST))) { |
| | | // |
| | | boolean isLower = str.contains(StaticData.SERVICE); |
| | | String layersKey = isLower ? StaticData.LAYERS : StaticData.LAYERS.toUpperCase(); |
| | | String layers = req.getParameter(layersKey); |
| | | String request = req.getParameter(isLower ? StaticData.REQUEST : StaticData.REQUEST.toUpperCase()); |
| | | if (!StaticData.GET_CAPABILITIES.equals(request) && null != layers) { |
| | | int start = str.indexOf(layersKey); |
| | | int end = str.indexOf("&", start); |
| | | layers = filterGeoLayers(ue, layers); |
| | | |
| | | str = str.replace(str.substring(start, end > -1 ? end : str.length()), layersKey + "=" + layers); |
| | | } else { |
| | | List<String> tabs = StaticData.ADMIN.equals(ue.getUid()) ? permsService.selectAllTabs() : permsService.selectTabs(ue.getUid()); |
| | | entity.setTab(null == tabs ? "" : StringHelper.join(tabs, ",")); |
| | | entity.setBak(StaticData.GET_CAPABILITIES); |
| | | } |
| | | |
| | | return url + (url.contains("?") ? "&" : "?") + str; |
| | | } |
| | | |
| | | /** |
| | | * 过滤GeoServer图层 |
| | | */ |
| | | private String filterGeoLayers(UserEntity ue, String layers) { |
| | | List<String> tabs = StaticData.ADMIN.equals(ue.getUid()) ? permsService.selectAllTabs() : permsService.selectTabs(ue.getUid()); |
| | | if (null == tabs || tabs.isEmpty()) { |
| | | return ""; |
| | | } |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | | String[] strs = layers.split(StaticData.COMMA); |
| | | for (String str : strs) { |
| | | if (tabs.contains(str)) { |
| | | sb.append(str).append(","); |
| | | } |
| | | } |
| | | sb.deleteCharAt(sb.length() - 1); |
| | | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 转发请求 |
| | | */ |
| | | private void forward(HttpServletRequest request, HttpServletResponse response, ResEntity entity, String url) throws Exception { |