| | |
| | | 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; |
| | |
| | | } |
| | | insertLog(req, ue, resId); |
| | | |
| | | String url = getUrl(req, entity, token, isRest); |
| | | String url = getUrl(req, ue, entity, token, isRest); |
| | | res.setHeader("token", token); |
| | | forward(req, res, entity, url); |
| | | } |
| | |
| | | if (StaticData.ADMIN.equals(ue.getUid())) { |
| | | return true; |
| | | } |
| | | // 7.检查白名单 |
| | | // 7.检查白名单和IP一致性 |
| | | if (!checkWhiteList(ip, req)) { |
| | | // 检查IP一致性 |
| | | if (!checkIpSource(ip, token)) { |
| | | if (!ip.equals(sysService.tokenService.getEntityByToken(token).getIp())) { |
| | | return WebHelper.writeStr2Page(res, AuthInterceptor.ILLEGAL_TOKEN); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 检查IP一致性 |
| | | */ |
| | | private boolean checkIpSource(String ip, String token) { |
| | | TokenEntity te = sysService.tokenService.getEntityByToken(token); |
| | | |
| | | return te.getIp().equals(ip); |
| | | } |
| | | |
| | | /** |
| | | * 检查资源权限 |
| | | */ |
| | | private ResEntity getResEntity(UserEntity ue, int resId) { |
| | |
| | | if (null == rs || rs.isEmpty()) { |
| | | return null; |
| | | } |
| | | |
| | | // List<ResEntity> list = rs.stream().filter(resEntity -> resEntity.getId() == resId).collect(Collectors.toList()) |
| | | for (ResEntity entity : rs) { |
| | | if (resId == entity.getId()) { |
| | |
| | | /** |
| | | * 获取Url |
| | | */ |
| | | private String getUrl(HttpServletRequest req, ResEntity entity, String token, boolean isRest) { |
| | | private String getUrl(HttpServletRequest req, UserEntity ue, ResEntity entity, String token, boolean isRest) { |
| | | String proxyUrl = entity.getProxy().replace("{token}", token); |
| | | int end = req.getRequestURL().indexOf(proxyUrl) + proxyUrl.length(); |
| | | |
| | | String url = entity.getUrl() + req.getRequestURL().substring(end); |
| | | // category:0-其他,1-GisServer,2-GeoServer,3-数简 |
| | | if (StaticData.I2 == entity.getCategory()) { |
| | | url = getGeoServerUrl(req, ue, entity, url); |
| | | } else if (StaticData.I3 == entity.getCategory()) { |
| | | if (null != req.getQueryString()) { |
| | | url = url + (url.contains("?") ? "&" : "?") + req.getQueryString(); |
| | | } |
| | | // category:0-其他,1-GisServer,2-GeoServer,3-数简 |
| | | if (StaticData.I2 == entity.getCategory()) { |
| | | // |
| | | } else if (StaticData.I3 == entity.getCategory()) { |
| | | if (isRest) { |
| | | url = url.replace("/v6/wmts/", "/v6/rest/"); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取GeoServer地址 |
| | | */ |
| | | private String getGeoServerUrl(HttpServletRequest req, UserEntity ue, ResEntity entity, String url) { |
| | | if (null == req.getQueryString()) { |
| | | return url; |
| | | } |
| | | |
| | | String str = req.getQueryString(); |
| | | if (!StaticData.GET_CAPABILITIES.equals(req.getParameter(StaticData.REQUEST))) { |
| | | // |
| | | } |
| | | |
| | | return url + (url.contains("?") ? "&" : "?") + str; |
| | | } |
| | | |
| | | /** |
| | | * 转发请求 |
| | | */ |
| | | private void forward(HttpServletRequest request, HttpServletResponse response, ResEntity entity, String url) throws Exception { |