登录集成插件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

76 lines
3.3 KiB

package com.fr.plugin.decision.integration.filter;
import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.general.http.HttpRequest;
import com.fr.general.http.HttpToolbox;
import com.fr.json.JSONObject;
import com.fr.plugin.decision.integration.config.IntegrateConf;
import com.fr.plugin.decision.integration.utils.CommonUtils;
import com.fr.plugin.decision.integration.utils.LogUtils;
import com.fr.plugin.decision.integration.validation.BILinkValidate;
import com.fr.plugin.decision.integration.validation.DashboardValidate;
import com.fr.plugin.decision.integration.validation.TemplateValidate;
import com.fr.plugin.decision.integration.validation.Validate;
import com.fr.third.fasterxml.jackson.databind.ObjectMapper;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.entity.StringEntity;
import com.fr.web.utils.DefaultRequestParameterCollector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class RequestCheckFilter extends AbstractEmbedRequestFilterProvider {
private Validate[] validates = new Validate[] {TemplateValidate.KEY, BILinkValidate.KEY, DashboardValidate.KEY};
@Override
public void filter(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (!IntegrateConf.getInstance().getParaCheckTurnOn()) return;
for (Validate v : validates) {
if (v.accept(request)) {
HashMap<String, Object> params = v.getCheckParameter(request);
params.putAll(getBaseParams(request));
if (!doCheck(params)) {
LogUtils.debug("request check failed, now will show error page");
CommonUtils.showErrorPage(response, "请登录系统访问报表", "");
}
break;
}
}
}
private HashMap<String, Object> getBaseParams(HttpServletRequest request) {
HashMap<String, Object> requestMap = new HashMap<>();
requestMap.putAll(DefaultRequestParameterCollector.getInstance().getParametersFromParameter(request));
requestMap.put("userId", LoginService.getInstance().getCurrentUserNameFromRequestCookie(request));
return requestMap;
}
private boolean doCheck(Map params) {
try {
HashMap<String, String> headerMap = new HashMap(1);
headerMap.put("Content-Type", "application/json");
HttpEntity entity = new StringEntity(new ObjectMapper().writeValueAsString(params), "utf-8");
LogUtils.debug("request check params:{}", params);
String result = HttpToolbox.executeAndParse(
HttpRequest.custom()
.url(IntegrateConf.getInstance().getParaCheckUrl())
.post(entity)
.headers(headerMap)
.build());
LogUtils.debug("request check result:{}", result);
return new JSONObject(result).getBoolean("data");
} catch (Exception e) {
LogUtils.error(e.getMessage(), e);
return false;
}
}
}