Browse Source

open

master
pioneer 2 years ago
commit
78df8db495
  1. 6
      README.md
  2. 7
      conf/bg.xml
  3. BIN
      lib/cas-client-core-3.2.1.jar
  4. BIN
      lib/casclient.jar
  5. 30
      plugin.xml
  6. 60
      src/main/java/com/fr/plugin/jsd9683/Jsd9683PluginLifecycleMonitor.java
  7. 25
      src/main/java/com/fr/plugin/jsd9683/beans/DeleteUserBean.java
  8. 53
      src/main/java/com/fr/plugin/jsd9683/beans/ReportFileBean.java
  9. 45
      src/main/java/com/fr/plugin/jsd9683/conf/Jsd9683ConfigXmlConfigReader.java
  10. 229
      src/main/java/com/fr/plugin/jsd9683/controller/Jsd9683Controller.java
  11. 12
      src/main/java/com/fr/plugin/jsd9683/controller/Jsd9683ControllerProvider.java
  12. 47
      src/main/java/com/fr/plugin/jsd9683/filter/CasFilter.java
  13. 373
      src/main/java/com/fr/plugin/jsd9683/filter/Jsd9683Filter.java
  14. 26
      src/main/java/com/fr/plugin/jsd9683/filter/NoFilter.java
  15. 60
      src/main/java/com/fr/plugin/jsd9683/filter/RequestGlobalFilter.java
  16. 20
      src/main/java/com/fr/plugin/jsd9683/webResourceProvider/Jsd9683WebResourceComponent.java
  17. 17
      src/main/java/com/fr/plugin/jsd9683/webResourceProvider/Jsd9683WebResourceProvider.java
  18. 51
      src/main/java/com/fr/plugin/jsd9683/webResourceProvider/MyTemplateRequestChecker.java
  19. 30
      src/main/resources/com/fr/plugin/jsd9683/jscss/Jsd9683.js
  20. 81
      src/main/resources/com/fr/plugin/jsd9683/jscss/unavaliable.html
  21. 7
      交付/conf/bg.xml

6
README.md

@ -0,0 +1,6 @@
# open-JSD-9412
JSD-9412 cas单点集成\
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\
仅作为开发者学习参考使用!禁止用于任何商业用途!\
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。

7
conf/bg.xml

@ -0,0 +1,7 @@
<root>
<casLoginUrl>http://xxx/login</casLoginUrl>
<casValidateUrl>http://xxxx/proxyValidate</casValidateUrl>
<casClientServerName>x.x.x.x:8080</casClientServerName>
<roleValidateUrl>http://xx/fine_report/report_access_validation</roleValidateUrl>
<isAuthority>true</isAuthority>
</root>

BIN
lib/cas-client-core-3.2.1.jar

Binary file not shown.

BIN
lib/casclient.jar

Binary file not shown.

30
plugin.xml

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.plugin.jsd9683</id>
<name><![CDATA[xx数据中台插件]]></name>
<active>yes</active>
<version>1.0</version>
<env-version>10.0</env-version>
<jartime>2018-07-31</jartime>
<vendor>fr.open</vendor>
<description><![CDATA[]]></description>
<change-notes><![CDATA[
[2018-08-01]修改一点问题。<br/>
[2018-07-31]初始化插件。<br/>
]]></change-notes>
<extra-decision>
<WebResourceProvider class="com.fr.plugin.jsd9683.webResourceProvider.Jsd9683WebResourceProvider"/>
<GlobalRequestFilterProvider class="com.fr.plugin.jsd9683.filter.CasFilter"/>
<GlobalRequestFilterProvider class="com.fr.plugin.jsd9683.filter.Jsd9683Filter"/>
<GlobalRequestFilterProvider class="com.fr.plugin.jsd9683.filter.RequestGlobalFilter"/>
<ControllerRegisterProvider class="com.fr.plugin.jsd9683.controller.Jsd9683ControllerProvider"/>
</extra-decision>
<extra-core>
</extra-core>
<function-recorder class="com.fr.plugin.jsd9683.Jsd9683PluginLifecycleMonitor"/>
<lifecycle-monitor class="com.fr.plugin.jsd9683.Jsd9683PluginLifecycleMonitor"/>
</plugin>

60
src/main/java/com/fr/plugin/jsd9683/Jsd9683PluginLifecycleMonitor.java

@ -0,0 +1,60 @@
package com.fr.plugin.jsd9683;
import com.fr.base.PropertiesUtils;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.jsd9683.conf.Jsd9683ConfigXmlConfigReader;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.stable.xml.XMLTools;
import com.fr.workspace.WorkContext;
import java.io.*;
@EnableMetrics
@FunctionRecorder
public class Jsd9683PluginLifecycleMonitor extends AbstractPluginLifecycleMonitor {
@Override
@Focus(id = "com.fr.plugin.jsd9683", text = "jsd9683", source = Original.PLUGIN)
public void afterRun(PluginContext pluginContext) {
// PreHandlerFactory.getInstance().registerRequestCheckers(new MyTemplateRequestChecker());
FineLoggerFactory.getLogger().info("插件启动:");
//读取webroot下的配置文件
String envPath = WorkContext.getCurrent().getPath();
FineLoggerFactory.getLogger().info("envPath:"+envPath);
String webReport = (new File(envPath)).getParent();
FineLoggerFactory.getLogger().info("webReport:"+webReport);
File envFile = new File(webReport+File.separator+"conf"+File.separator+"bg.xml");
try {
XMLTools.readFileXML(Jsd9683ConfigXmlConfigReader.getInstance(), envFile);
} catch (Exception e) {
e.printStackTrace();
}
FineLoggerFactory.getLogger().info(pluginContext.getID()+" startup.....");
FineLoggerFactory.getLogger().info("插件启动");
FineLoggerFactory.getLogger().info("jsd9683 plugin start ..........................");
// ddd();
}
@Override
public void beforeStop(PluginContext pluginContext) {
FineLoggerFactory.getLogger().info("插件停止");
}
}

25
src/main/java/com/fr/plugin/jsd9683/beans/DeleteUserBean.java

@ -0,0 +1,25 @@
package com.fr.plugin.jsd9683.beans;
public class DeleteUserBean {
private String orgCode;
private String userName;
public void setOrgCode(String orgCode) {
this.orgCode = orgCode;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getOrgCode() {
return orgCode;
}
public String getUserName() {
return userName;
}
}

53
src/main/java/com/fr/plugin/jsd9683/beans/ReportFileBean.java

@ -0,0 +1,53 @@
package com.fr.plugin.jsd9683.beans;
import java.util.ArrayList;
public class ReportFileBean {
private String name;
private String path;
private String previewUrl;
private boolean isDir;
private ArrayList<ReportFileBean> children;
public void setName(String name) {
this.name = name;
}
public void setPath(String path) {
this.path = path;
}
public void setChildren(ArrayList<ReportFileBean> children) {
this.children = children;
}
public String getName() {
return name;
}
public String getPath() {
return path;
}
public String getPreviewUrl() {
return previewUrl;
}
public boolean isDir() {
return isDir;
}
public void setDir(boolean dir) {
isDir = dir;
}
public void setPreviewUrl(String previewUrl) {
this.previewUrl = previewUrl;
}
public ArrayList<ReportFileBean> getChildren() {
return children;
}
}

45
src/main/java/com/fr/plugin/jsd9683/conf/Jsd9683ConfigXmlConfigReader.java

@ -0,0 +1,45 @@
package com.fr.plugin.jsd9683.conf;
import com.fr.stable.StringUtils;
import com.fr.stable.xml.XMLReadable;
import com.fr.stable.xml.XMLableReader;
public class Jsd9683ConfigXmlConfigReader implements XMLReadable {
private static Jsd9683ConfigXmlConfigReader instance;
public static Jsd9683ConfigXmlConfigReader getInstance(){
if(instance == null){
instance = new Jsd9683ConfigXmlConfigReader();
}
return instance;
}
public static String CAS_LOGIN_URL = "";
public static String CAS_VALIDATE_URL = "";
public static String CAS_SERVER_NAME = "";
public static String ROLE_VALIDATE_URL = "";
public static String isAuthority = "true";
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String nodeName = reader.getTagName();
if ("casLoginUrl".equals(nodeName)) {
CAS_LOGIN_URL = StringUtils.trim(reader.getElementValue());
}
if ("casValidateUrl".equals(nodeName)) {
CAS_VALIDATE_URL = StringUtils.trim(reader.getElementValue());
}
if ("casClientServerName".equals(nodeName)) {
CAS_SERVER_NAME = StringUtils.trim(reader.getElementValue());
}
if ("roleValidateUrl".equals(nodeName)) {
ROLE_VALIDATE_URL = StringUtils.trim(reader.getElementValue());
}
if ("isAuthority".equals(nodeName)) {
isAuthority = StringUtils.trim(reader.getElementValue());
}
}
}
}

229
src/main/java/com/fr/plugin/jsd9683/controller/Jsd9683Controller.java

@ -0,0 +1,229 @@
package com.fr.plugin.jsd9683.controller;
import com.fr.decision.authority.data.User;
import com.fr.decision.webservice.CrossDomainResponse;
import com.fr.decision.webservice.Response;
import com.fr.decision.webservice.annotation.LoginStatusChecker;
import com.fr.decision.webservice.bean.user.UserUpdateBean;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.jsd9683.beans.DeleteUserBean;
import com.fr.plugin.jsd9683.beans.ReportFileBean;
import com.fr.stable.StringUtils;
import com.fr.third.springframework.stereotype.Controller;
import com.fr.third.springframework.web.bind.annotation.*;
import com.fr.web.JSONReportUtils;
import com.fr.web.controller.decision.api.auth.LoginResource;
import com.fr.workspace.WorkContext;
import org.apache.catalina.filters.CorsFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
@Controller
@LoginStatusChecker(
required = false
)
public class Jsd9683Controller {
@RequestMapping(
value = {"/bg/deleteUserByOrgCodeAndName"},
method = {RequestMethod.POST}
)
@ResponseBody
public Response deleteUserByName(HttpServletRequest req, HttpServletResponse res, @RequestBody DeleteUserBean deleteUserBean ) throws Exception {
FineLoggerFactory.getLogger().info("delete user by post................");
String X_Access_Token = req.getHeader("X-Access-Token");
FineLoggerFactory.getLogger().info("X-Access-Token:"+X_Access_Token);
Response response = deleteUserByUserNameAndOrgCode(deleteUserBean.getUserName(),deleteUserBean.getOrgCode());
return response;
}
@RequestMapping(
value = {"/bg/deleteUserByOrgCodeAndName1"},
method = {RequestMethod.GET}
)
@ResponseBody
public Response deleteUserByNameByGet(HttpServletRequest req, HttpServletResponse res, @RequestParam("userName") String userName,@RequestParam("orgCode") String orgCode) throws Exception {
FineLoggerFactory.getLogger().info("delete user by get................");
res.setHeader("Access-Control-Allow-Origin", "*");
String X_Access_Token = req.getHeader("X-Access-Token");
FineLoggerFactory.getLogger().info("X-Access-Token:"+X_Access_Token);
Response response = deleteUserByUserNameAndOrgCode(userName,orgCode);
// return CrossDomainResponse.create().callbackFuncName(callback).parameter("result", "ok").parameter("status", "success").createCrossDomainResponse();
return response;
}
@RequestMapping(
value = {"/bg/deleteUserByOrgCodeAndName2"},
method = {RequestMethod.GET}
)
@ResponseBody
public String deleteUserByNameByJSONP(HttpServletRequest req, HttpServletResponse res, @RequestParam("userName") String userName,@RequestParam("orgCode") String orgCode,@RequestParam(value = "callback",required = false,defaultValue = "callback") String callback) throws Exception {
FineLoggerFactory.getLogger().info("delete user by jsonp................");
String X_Access_Token = req.getHeader("X-Access-Token");
//获取不到,JSONP不支持在header中加入自定义属性
FineLoggerFactory.getLogger().info("X-Access-Token:"+X_Access_Token);
FineLoggerFactory.getLogger().info("==== deleteUserByName userName:"+userName);
FineLoggerFactory.getLogger().info("==== deleteUserByName orgCode:"+orgCode);
String fineUserName = orgCode + "_" +userName;
User user = UserService.getInstance().getUserByUserName(fineUserName);
if(user == null){
return (new CrossDomainResponse()).callbackFuncName(callback).parameter("status", "fail").parameter("errorCode", "0001").parameter("errorMsg", "user is not exist").createCrossDomainResponse();
}
UserUpdateBean deleteBean = new UserUpdateBean();
String[] removeIds = new String[1];
removeIds[0] = user.getId();
deleteBean.setRemoveUserIds(removeIds);//删除登录用户
UserService.getInstance().deleteUsers(deleteBean);
return CrossDomainResponse.create().callbackFuncName(callback).parameter("message", "ok").parameter("status", "success").createCrossDomainResponse();
}
private Response deleteUserByUserNameAndOrgCode(String userName,String orgCode) throws Exception {
FineLoggerFactory.getLogger().info("==== deleteUserByName userName:"+userName);
FineLoggerFactory.getLogger().info("==== deleteUserByName orgCode:"+orgCode);
String fineUserName = orgCode + "_" +userName;
User user = UserService.getInstance().getUserByUserName(fineUserName);
if(user == null){
return Response.error("0001","user is not exist");
// return (new CrossDomainResponse()).callbackFuncName(callback).parameter("status", "fail").parameter("errorCode", "0001").parameter("errorMsg", "user is not exist").createCrossDomainResponse();
}
UserUpdateBean deleteBean = new UserUpdateBean();
String[] removeIds = new String[1];
removeIds[0] = user.getId();
deleteBean.setRemoveUserIds(removeIds);//删除登录用户
UserService.getInstance().deleteUsers(deleteBean);
return Response.ok("ok");
}
//@RequestParam(value = "callback",required = false,defaultValue = "callback") String callback
@RequestMapping(
value = {"/bg/getReportDirList"},
method = {RequestMethod.GET}
)
@ResponseBody
public Response getReportDirList(HttpServletRequest req, HttpServletResponse res, @RequestParam("name") String name) throws Exception {
String envPath = WorkContext.getCurrent().getPath();
FineLoggerFactory.getLogger().info("envPath:" + envPath);
String webReport = (new File(envPath)).getParent();
FineLoggerFactory.getLogger().info("webReport:" + webReport);
String basePath = webReport + File.separator + "WEB-INF" + File.separator + "reportlets" + File.separator;
File reportDir = new File(basePath);
ArrayList<ReportFileBean> allFiles = new ArrayList<>();
ArrayList<ReportFileBean> allReportFile = new ArrayList<>();
if (reportDir.exists()) {
try {
iterateDir(reportDir, allReportFile, basePath, name);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
ReportFileBean root = new ReportFileBean();
root.setDir(true);
root.setPreviewUrl("");
root.setChildren(new ArrayList<>());
root.setPath("");
root.setName("root");
if (allReportFile.size() > 0) {
for (ReportFileBean node : allReportFile) {
String path = node.getPath();
FineLoggerFactory.getLogger().info("==== path:" + path);
if (path.indexOf(File.separator) == -1 ) { //根目录的文件
root.getChildren().add(node);
} else {
String[] pathStrings = path.split("\\"+File.separator);
ReportFileBean childNode = new ReportFileBean();
ReportFileBean parent = null;
String currentPath = "";
for (int i = 0; i < pathStrings.length; i++) {
String fileName = pathStrings[i];
currentPath+= (File.separator+fileName);
if (fileName.indexOf(".cpt") != -1 || fileName.indexOf(".frm") != -1) {
parent = getChildNode(parent.getChildren(), fileName);
parent.setDir(false);
parent.setPath(path);
parent.setPreviewUrl(node.getPreviewUrl());
} else {
if (i == 0) {
parent = getChildNode(root.getChildren(), fileName);
parent.setDir(true);
parent.setPath(currentPath);
parent.setPreviewUrl("");
} else {
parent = getChildNode(parent.getChildren(), fileName);
parent.setDir(true);
parent.setPath(currentPath);
parent.setPreviewUrl("");
}
}
}
}
}
}
//String result = JSONReportUtils.objToJSONString(root);
// FineLoggerFactory.getLogger().info("==== result:" + result);
// return CrossDomainResponse.create().callbackFuncName(callback).parameter("result",result).createCrossDomainResponse();
return Response.ok(root);
}
private ReportFileBean getChildNode(ArrayList<ReportFileBean> clildren,String name){
for(ReportFileBean node : clildren){
if(node.getName().equals(name)){
return node;
}
}
ReportFileBean child = new ReportFileBean();
clildren.add(child);
child.setName(name);
child.setChildren(new ArrayList<>());
return child;
}
private void iterateDir(File parent,ArrayList<ReportFileBean> allReportFile,String basePath,String paramName) throws UnsupportedEncodingException {
File[] childrens = parent.listFiles();
if(childrens != null && childrens.length > 0){
for(File f:childrens){
String reportName = f.getName();
ReportFileBean bean = new ReportFileBean();
bean.setChildren(new ArrayList<>());
boolean isAdd = true;
if(StringUtils.isNotEmpty(paramName)){
if(reportName.indexOf(paramName) == -1){
isAdd = false;
}
}
if(isAdd){
bean.setName(reportName);
String abPath = f.getAbsolutePath();
String rePath = abPath.replace(basePath,"");
bean.setPath(rePath);
bean.setDir(f.isDirectory());
if(bean.isDir() == false){
allReportFile.add(bean);
bean.setPreviewUrl("webroot/decision//view/report?viewlet="+ java.net.URLEncoder.encode(rePath, "UTF-8"));
}
}
iterateDir(f,allReportFile,basePath,paramName);
}
}
}
}

12
src/main/java/com/fr/plugin/jsd9683/controller/Jsd9683ControllerProvider.java

@ -0,0 +1,12 @@
package com.fr.plugin.jsd9683.controller;
import com.fr.decision.fun.impl.AbstractControllerRegisterProvider;
public class Jsd9683ControllerProvider extends AbstractControllerRegisterProvider {
@Override
public Class<?>[] getControllers() {
return new Class[]{
Jsd9683Controller.class
};
}
}

47
src/main/java/com/fr/plugin/jsd9683/filter/CasFilter.java

@ -0,0 +1,47 @@
package com.fr.plugin.jsd9683.filter;
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.jsd9683.conf.Jsd9683ConfigXmlConfigReader;
import edu.yale.its.tp.cas.client.filter.CASFilter;
import java.util.HashMap;
import java.util.Map;
public class CasFilter extends AbstractGlobalRequestFilterProvider {
@Override
public String filterName() {
return "casFilter11";
}
@Override
public String[] urlPatterns() {
return new String[]{
"/decision/view/*",
};
}
public String externalFilterClassName() {
FineLoggerFactory.getLogger().info("isAuthority:"+Jsd9683ConfigXmlConfigReader.isAuthority);
if(Jsd9683ConfigXmlConfigReader.isAuthority.equals("true")){
FineLoggerFactory.getLogger().info("registe com.fr.plugin.jsd9683.servletfilter.CasServeltFilter.................");
return "edu.yale.its.tp.cas.client.filter.CASFilter";
}
else{
FineLoggerFactory.getLogger().info("registe com.fr.plugin.jsd9683.filter.NoFilter.................");
return "com.fr.plugin.jsd9683.filter.NoFilter";
}
// return "com.fr.plugin.jsd9683.servletfilter.CasServeltFilter";
}
public Map<String, String> initializationParameters() {
HashMap<String,String> paramMap = new HashMap<>();
paramMap.put("edu.yale.its.tp.cas.client.filter.validateUrl", Jsd9683ConfigXmlConfigReader.CAS_VALIDATE_URL);
paramMap.put("edu.yale.its.tp.cas.client.filter.loginUrl",Jsd9683ConfigXmlConfigReader.CAS_LOGIN_URL);
paramMap.put("edu.yale.its.tp.cas.client.filter.serverName",Jsd9683ConfigXmlConfigReader.CAS_SERVER_NAME);
FineLoggerFactory.getLogger().info("init casFilter参数.................");
return paramMap;
}
}

373
src/main/java/com/fr/plugin/jsd9683/filter/Jsd9683Filter.java

@ -0,0 +1,373 @@
package com.fr.plugin.jsd9683.filter;
import com.fr.data.NetworkHelper;
import com.fr.decision.authority.data.User;
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider;
import com.fr.decision.mobile.terminal.TerminalHandler;
import com.fr.decision.webservice.bean.user.UserBean;
import com.fr.decision.webservice.utils.DecisionServiceConstants;
import com.fr.decision.webservice.utils.WebServiceUtils;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.general.ComparatorUtils;
import com.fr.json.JSONObject;
import com.fr.json.JSONParser;
import com.fr.locale.InterProviderFactory;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.jsd9683.conf.Jsd9683ConfigXmlConfigReader;
import com.fr.security.JwtUtils;
import com.fr.security.encryption.transmission.impl.AESTransmissionEncryption;
import com.fr.stable.StringUtils;
import com.fr.stable.web.Device;
import com.fr.stable.web.SessionProvider;
import com.fr.third.alibaba.druid.support.json.JSONUtils;
import com.fr.util.TemplateParser;
import com.fr.web.core.SessionPoolManager;
import com.fr.web.core.WidgetSessionIDInfor;
import javax.net.ssl.HttpsURLConnection;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.security.cert.CertificateException;
import java.util.Map;
import javax.net.ssl.*;
import com.fr.web.utils.WebUtils;
import org.jasig.cas.client.validation.Assertion;
public class Jsd9683Filter extends AbstractGlobalRequestFilterProvider {
@Override
public String filterName() {
return "Jsd9683Filter";
}
@Override
public String[] urlPatterns() {
return new String[]{
"/decision/view/report/*",
};
}
@Override
public void doFilter(HttpServletRequest request, HttpServletResponse res, FilterChain filterChain) {
String uri = request.getRequestURI();
String reqUrl = request.getRequestURL().toString();
String ticket = WebUtils.getHTTPRequestParameter(request, "ticket");
FineLoggerFactory.getLogger().info("Jsd9683Filter ===============================req coming:" + uri);
FineLoggerFactory.getLogger().info("===============================req coming:" + reqUrl);
FineLoggerFactory.getLogger().info("===============================[ticket]:" + ticket);
if (StringUtils.isNotEmpty(ticket)) {
FineLoggerFactory.getLogger().info("===============================只有ticket有值才处理" );
String queryString = request.getQueryString();
String http = "http";
if (reqUrl.indexOf("https") != -1) {
http = "https";
}
reqUrl = reqUrl.replace(uri, "");
if (reqUrl.indexOf(":") == -1) {
reqUrl = reqUrl + ":" + request.getLocalPort() + uri + "?" + queryString;
} else {
reqUrl = reqUrl + uri + "?" + queryString;
}
// if(reqUrl.indexOf("?ticket") != -1){
// reqUrl = reqUrl.replace("?ticket","&ticket");
// }
String proxyValidate = Jsd9683ConfigXmlConfigReader.CAS_VALIDATE_URL + "?service=" + reqUrl;
FineLoggerFactory.getLogger().info("================ sendRedirect url:" + proxyValidate);
String result = doHttpReq(proxyValidate, "GET");
FineLoggerFactory.getLogger().info("sendRedirect url result is :" + result);
if (result.indexOf("authenticationSuccess") != -1) {
String beginTag = "<cas:user>";
String endTag = "</cas:user>";
int beginIndex = result.indexOf(beginTag) + beginTag.length();
int endIndex = result.indexOf(endTag);
String userName = result.substring(beginIndex, endIndex);
beginTag = "<cas:sid>";
endTag = "</cas:sid>";
beginIndex = result.indexOf(beginTag) + beginTag.length();
endIndex = result.indexOf(endTag);
String sid = result.substring(beginIndex, endIndex);
beginTag = "<cas:orgCode>";
endTag = "</cas:orgCode>";
beginIndex = result.indexOf(beginTag) + beginTag.length();
endIndex = result.indexOf(endTag);
String orgCode = result.substring(beginIndex, endIndex);
FineLoggerFactory.getLogger().info("================ userName:" + userName + ",sid:" + sid + ",orgCode:" + orgCode);
String fineUserName = orgCode + "_" + userName;
String templateId = getTemplateId(request);
FineLoggerFactory.getLogger().info("templateId:" + templateId);
if (StringUtils.isNotEmpty(templateId)) {
String parentSessionId = getParentSeeesionFromSession(request);
FineLoggerFactory.getLogger().info("parentSessionId:" + parentSessionId);
if (StringUtils.isNotEmpty(parentSessionId)) {
FineLoggerFactory.getLogger().info("child link template....");
//ReportSessionIDInfor,FormSessionIDInfor
templateId = "";
WidgetSessionIDInfor objSession = SessionPoolManager.getSessionIDInfor(parentSessionId, WidgetSessionIDInfor.class);
if (objSession != null) {
String parentPath = objSession.getRelativePath();
FineLoggerFactory.getLogger().info("child link template is ok....:" + parentPath);
templateId = parentPath;
}
}
FineLoggerFactory.getLogger().info("templateId:" + templateId);
if (StringUtils.isNotEmpty(templateId)) {
//去远程看有权限没,y有就继续走,
FineLoggerFactory.getLogger().info("===========role validatee url:" + Jsd9683ConfigXmlConfigReader.ROLE_VALIDATE_URL);
JSONObject jsonObj = new JSONObject();
jsonObj.put("org_code", orgCode);
jsonObj.put("account", userName);
jsonObj.put("report_code", templateId);
jsonObj.put("root_report_code", templateId);
jsonObj.put("params", new JSONObject());
String jsonData = jsonObj.toString();
FineLoggerFactory.getLogger().info("===========role validatee param:" + jsonData);
String roleResult = doPostHttpReq(Jsd9683ConfigXmlConfigReader.ROLE_VALIDATE_URL, jsonData);
FineLoggerFactory.getLogger().info("===========role validatee roleResult:" + roleResult);
if (roleResult.indexOf("true") != -1) {
try {
User user = UserService.getInstance().getUserByUserName(fineUserName);
if (user == null) {
UserBean userBean = new UserBean();
userBean.setRealName(fineUserName);
userBean.setUsername(fineUserName);
userBean.setPassword(AESTransmissionEncryption.getInstance().encrypt("123456"));
userBean.setEmail("");
userBean.setMobile("");
userBean.setRoleIds(new String[]{});
userBean.setCreationType(0);
userBean.setEnable(true);
userBean.setDepartmentPostIds(new ArrayList<>());
userBean.setExtraAttribute(new HashMap<>());
UserService.getInstance().addUser(userBean);
FineLoggerFactory.getLogger().info("add user:" + fineUserName);
}
} catch (Exception e) {
e.printStackTrace();
}
HttpSession session = request.getSession(true);
try {
FineLoggerFactory.getLogger().info("begin login...");
login(request, res, session, fineUserName);
} catch (Exception e) {
e.printStackTrace();
}
try {
filterChain.doFilter(request, res);
} catch (IOException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
}
} else {
FineLoggerFactory.getLogger().info("无权限访问");
try {
FineLoggerFactory.getLogger().info("到无权限界面去了");
PrintWriter printWriter = null;
printWriter = WebUtils.createPrintWriter(res);
Map<String, Object> map = new HashMap<>();
map.put("result", InterProviderFactory.getProvider().getLocText("Fine-Engine_Error_Page_Result"));
map.put("reason", "您没有权限访问该报表页面");
map.put("solution", InterProviderFactory.getProvider().getLocText("Fine-Engine_Please_Contact_Platform_Admin"));
String page = WebServiceUtils.parseWebPageResourceSafe("com/fr/plugin/jsd9683/jscss/unavaliable.html", map);
printWriter.write(page);
printWriter.flush();
printWriter.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
} else {
try {
FineLoggerFactory.getLogger().info("===================== error:go on");
filterChain.doFilter(request, res);
} catch (IOException e) {
FineLoggerFactory.getLogger().info("===================== error:" + e.toString());
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
FineLoggerFactory.getLogger().info("===================== error:" + e.toString());
}
}
}
} else {
try {
FineLoggerFactory.getLogger().info("===================== normal:go on");
filterChain.doFilter(request, res);
} catch (IOException e) {
FineLoggerFactory.getLogger().info("===================== error:" + e.toString());
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
FineLoggerFactory.getLogger().info("===================== error:" + e.toString());
}
}
}
private String doHttpReq(String reqUrl, String methord) {
HttpURLConnection con = null;
BufferedReader buffer = null;
StringBuffer resultBuffer = null;
String result = "";
try {
URL url = new URL(reqUrl);
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod(methord);
//con.setRequestProperty("Content-Type", "application/json;charset=GBK");
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
int responseCode = con.getResponseCode();
FineLoggerFactory.getLogger().info("sendRedirect responseCode:" + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream inputStream = con.getInputStream();
resultBuffer = new StringBuffer();
String line;
buffer = new BufferedReader(new InputStreamReader(inputStream, "GBK"));
while ((line = buffer.readLine()) != null) {
resultBuffer.append(line);
}
result = resultBuffer.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
private String doPostHttpReq(String reqUrl, String jsonData) {
HttpURLConnection con = null;
BufferedReader buffer = null;
StringBuffer resultBuffer = null;
String result = "";
try {
URL url = new URL(reqUrl);
// 得到连接对象
con = (HttpURLConnection) url.openConnection();
// 设置请求类型
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json;charset=utf-8");
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
con.connect();
String body = jsonData;
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(con.getOutputStream(), "UTF-8"));
writer.write(body);
writer.close();
int responseCode = con.getResponseCode();
FineLoggerFactory.getLogger().info("sendRedirect responseCode:" + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream inputStream = con.getInputStream();
resultBuffer = new StringBuffer();
String line;
buffer = new BufferedReader(new InputStreamReader(inputStream, "GBK"));
while ((line = buffer.readLine()) != null) {
resultBuffer.append(line);
}
result = resultBuffer.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
private void login(HttpServletRequest req, HttpServletResponse res, HttpSession session, String username) throws Exception {
// String token = LoginService.getInstance().login(req, res, username);
// req.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, token);
// FineLoggerFactory.getLogger().info("fr FrFilter is over with username is ###" + username);
}
private static String getParentSeeesionFromSession(HttpServletRequest request) {
return NetworkHelper.getHTTPRequestParameter(request, "parentSeeesion");
}
public String getTemplateId(HttpServletRequest request) {
return TemplateParser.analyzeTemplateID(request);
}
private static String getHyperLinkTemplateIdFromSession(HttpServletRequest request) {
SessionProvider session = getSessionFromRequest(request);
return session != null ? session.getRelativePath() : "";
}
private static SessionProvider getSessionFromRequest(HttpServletRequest request) {
try {
String sessionId = NetworkHelper.getHTTPRequestParameter(request, "sessionID");
if (StringUtils.isNotEmpty(sessionId)) {
return SessionPoolManager.getSessionIDInfor(sessionId, SessionProvider.class);
}
} catch (Exception var2) {
FineLoggerFactory.getLogger().error(var2.getMessage(), var2);
}
return null;
}
}

26
src/main/java/com/fr/plugin/jsd9683/filter/NoFilter.java

@ -0,0 +1,26 @@
package com.fr.plugin.jsd9683.filter;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.jsd9683.conf.Jsd9683ConfigXmlConfigReader;
import javax.servlet.*;
import java.io.IOException;
public class NoFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
FineLoggerFactory.getLogger().info("============= NoFilter init.。。。。。。。。。。。。。。 ");
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
FineLoggerFactory.getLogger().info("============= NoFilter go go go ");
filterChain.doFilter(servletRequest,servletResponse);
}
@Override
public void destroy() {
}
}

60
src/main/java/com/fr/plugin/jsd9683/filter/RequestGlobalFilter.java

@ -0,0 +1,60 @@
package com.fr.plugin.jsd9683.filter;
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class RequestGlobalFilter extends AbstractGlobalRequestFilterProvider {
@Override
public String filterName() {
return "RequestGlobalFilter";
}
@Override
public String[] urlPatterns() {
return new String[]{
"/decision/*",
};
}
@Override
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) {
FineLoggerFactory.getLogger().info("===============================RequestGlobalFilter:" );
String origin = req.getHeader("Origin");
FineLoggerFactory.getLogger().info("===============================origin:" +origin);
if (StringUtils.isNotEmpty(origin)) {
res.addHeader("Access-Control-Allow-Origin", origin);
String headers = req.getHeader("Access-Control-Request-Headers");
FineLoggerFactory.getLogger().info("===============================headers:" +headers);
if (StringUtils.isNotEmpty(headers))
res.addHeader("Access-Control-Allow-Headers", headers);
res.addHeader("Access-Control-Allow-Methods", "*");
res.addHeader("Access-Control-Max-Age", "3600");
}
String methodName = req.getMethod();
FineLoggerFactory.getLogger().info("===============================methodName:" +methodName);
if (methodName.equals("OPTIONS")) {
res.setStatus(HttpServletResponse.SC_OK);
FineLoggerFactory.getLogger().info("options set status ok");
}
else{
try {
FineLoggerFactory.getLogger().info(" ok go on");
filterChain.doFilter(req,res);
} catch (IOException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
}
}
}
}

20
src/main/java/com/fr/plugin/jsd9683/webResourceProvider/Jsd9683WebResourceComponent.java

@ -0,0 +1,20 @@
package com.fr.plugin.jsd9683.webResourceProvider;
import com.fr.decision.webservice.interceptor.handler.ReportTemplateRequestChecker;
import com.fr.decision.webservice.utils.DecisionServiceConstants;
import com.fr.web.struct.Component;
import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath;
public class Jsd9683WebResourceComponent extends Component {
public static Jsd9683WebResourceComponent KEY = new Jsd9683WebResourceComponent();
@Override
public ScriptPath script(RequestClient req) {
return ScriptPath.build("/com/fr/plugin/jsd9683/jscss/Jsd9683.js");
}
}

17
src/main/java/com/fr/plugin/jsd9683/webResourceProvider/Jsd9683WebResourceProvider.java

@ -0,0 +1,17 @@
package com.fr.plugin.jsd9683.webResourceProvider;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.report.web.ReportMainComponent;
import com.fr.web.struct.Atom;
public class Jsd9683WebResourceProvider extends AbstractWebResourceProvider {
@Override
public Atom attach() {
return ReportMainComponent.KEY;
}
public Atom client() {
return Jsd9683WebResourceComponent.KEY;
}
}

51
src/main/java/com/fr/plugin/jsd9683/webResourceProvider/MyTemplateRequestChecker.java

@ -0,0 +1,51 @@
package com.fr.plugin.jsd9683.webResourceProvider;
import com.fr.data.NetworkHelper;
import com.fr.decision.webservice.interceptor.DecisionInterceptor;
import com.fr.decision.webservice.interceptor.handler.TemplateRequestChecker;
import com.fr.decision.webservice.utils.DecisionServiceConstants;
import com.fr.log.FineLoggerFactory;
import com.fr.third.springframework.web.method.HandlerMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MyTemplateRequestChecker extends TemplateRequestChecker {
@Override
public String getTemplateId(HttpServletRequest httpServletRequest, HandlerMethod handlerMethod) {
return null;
}
@Override
public boolean detectTemplateNeedAuthenticate(HttpServletRequest httpServletRequest, String s) {
return false;
}
@Override
public boolean detectTemplateRoleAuthority(HttpServletRequest httpServletRequest, String s, String s1) {
return false;
}
@Override
public boolean doesUserHaveAnyHyperlinkTempAuth(String s, String s1) throws Exception {
return false;
}
@Override
public boolean acceptRequest(HttpServletRequest httpServletRequest, HandlerMethod handlerMethod) {
return true;
}
@Override
public boolean checkRequest(HttpServletRequest request, HttpServletResponse httpServletResponse, HandlerMethod handlerMethod) throws Exception {
String hyperlinkUUIDKey = NetworkHelper.getHTTPRequestParameter(request, DecisionServiceConstants.FINE_AUTH_TOKEN_NAME_HYPERLINK);
FineLoggerFactory.getLogger().info("hyperlinkUUIDKey:" + hyperlinkUUIDKey);
return true;
}
@Override
public int toInteger() {
return 0;
}
}

30
src/main/resources/com/fr/plugin/jsd9683/jscss/Jsd9683.js

@ -0,0 +1,30 @@
; (function () {
console.log("加载插件jsd9683...")
function getReportSessionID() {
if (FR && FR.SessionMgr && $.isFunction(FR.SessionMgr.getSessionID)) {
return FR.SessionMgr.getSessionID();
}
return "";
}
var doHyperlinkByGet4Reportlet = FR.doHyperlinkByGet4Reportlet
var newDoHyperlinkByGet4Reportlet = function(url, para, target, feature, title) {
console.log("hack newDoHyperlinkByGet4Reportlet")
var url = url.url+'&parentSeeesion='+getReportSessionID();
console.log("跳转url:"+url)
doHyperlinkByGet4Reportlet.apply(FR,[url,para,target,feature,title]);
}
FR.doHyperlinkByGet4Reportlet = newDoHyperlinkByGet4Reportlet;
var doHyperlinkByPost = FR.doHyperlinkByPost
var newDoHyperlinkByPost = function(url, para, target, feature, title) {
console.log("hack newDoHyperlinkByGet4Reportlet")
var url = url.url+'&parentSeeesion='+getReportSessionID();
console.log("跳转url:"+url)
doHyperlinkByPost.apply(FR,[url,para,target,feature,title]);
}
FR.doHyperlinkByPost = newDoHyperlinkByPost;
})();

81
src/main/resources/com/fr/plugin/jsd9683/jscss/unavaliable.html

@ -0,0 +1,81 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
body {
background-color: #ffffff;
}
.main {
position: absolute;
top: 25%;
left: 10%;
right: 10%;
margin: auto;
}
.main div {
text-align: center;
}
#header-content {
min-width: 40%;
min-height: 40%;
max-width: 100%;
max-height: 100%;
}
.simple-message {
font-weight: 500;
width: 100%;
font-size: 28px;
color: #3685f2;
text-align: center;
margin-top: 20px;
line-height: 40px;
}
.detail-message {
font-size: 16px;
color: #ff4949;
margin: 15px auto;
line-height: 24px;
}
.solution {
font-size: 16px;
color: #ff4949;
line-height: 24px;
}
.login {
color: #3685f2;
text-decoration: none;
line-height: 24px;
float: right;
height: 24px;
font-size: 12px;
margin-right: 40px;
margin-top: 40px;
}
</style>
<script type="text/javascript" src="${fineServletURL}/file?path=com.fr.decision.web.i18n.NormalTextGenerator&type=class&parser=plain"></script>
</head>
<body>
<!--<a href="${fineServletURL}/login${origin}" class="login">${switchAccount}</a>-->
<div class="main" >
<div>
</div>
<div class="simple-message" id="simple-message">非常抱歉,无法查看该页面</div>
<div class="detail-message" id="detail-message">您没有权限访问该报表页面</div>
<div class="solution" id="solution">如果您确实需要访问该页面,请联系平台管理员</div>
</div>
<script>
</script>
</body>
</html>

7
交付/conf/bg.xml

@ -0,0 +1,7 @@
<root>
<casLoginUrl>http://xxx/login</casLoginUrl>
<casValidateUrl>http://xxxx/proxyValidate</casValidateUrl>
<casClientServerName>x.x.x.x:8080</casClientServerName>
<roleValidateUrl>http://xx/fine_report/report_access_validation</roleValidateUrl>
<isAuthority>true</isAuthority>
</root>
Loading…
Cancel
Save