commit 78df8db495c85eb36bbeaac81f069737c69e05b9 Author: pioneer Date: Fri Aug 5 16:03:14 2022 +0800 open diff --git a/README.md b/README.md new file mode 100644 index 0000000..4d5f92c --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# open-JSD-9412 + +JSD-9412 cas单点集成\ +免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ +仅作为开发者学习参考使用!禁止用于任何商业用途!\ +为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 \ No newline at end of file diff --git a/conf/bg.xml b/conf/bg.xml new file mode 100644 index 0000000..8dbe357 --- /dev/null +++ b/conf/bg.xml @@ -0,0 +1,7 @@ + + http://xxx/login + http://xxxx/proxyValidate + x.x.x.x:8080 + http://xx/fine_report/report_access_validation + true + diff --git a/lib/cas-client-core-3.2.1.jar b/lib/cas-client-core-3.2.1.jar new file mode 100644 index 0000000..c97b6b1 Binary files /dev/null and b/lib/cas-client-core-3.2.1.jar differ diff --git a/lib/casclient.jar b/lib/casclient.jar new file mode 100644 index 0000000..02737cd Binary files /dev/null and b/lib/casclient.jar differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..7c2f71b --- /dev/null +++ b/plugin.xml @@ -0,0 +1,30 @@ + + com.fr.plugin.jsd9683 + + yes + 1.0 + 10.0 + 2018-07-31 + fr.open + + + [2018-07-31]初始化插件。
+ ]]>
+ + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/src/main/java/com/fr/plugin/jsd9683/Jsd9683PluginLifecycleMonitor.java b/src/main/java/com/fr/plugin/jsd9683/Jsd9683PluginLifecycleMonitor.java new file mode 100644 index 0000000..29722b9 --- /dev/null +++ b/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("插件停止"); + } +} diff --git a/src/main/java/com/fr/plugin/jsd9683/beans/DeleteUserBean.java b/src/main/java/com/fr/plugin/jsd9683/beans/DeleteUserBean.java new file mode 100644 index 0000000..d28df76 --- /dev/null +++ b/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; + } + + +} diff --git a/src/main/java/com/fr/plugin/jsd9683/beans/ReportFileBean.java b/src/main/java/com/fr/plugin/jsd9683/beans/ReportFileBean.java new file mode 100644 index 0000000..d92eb96 --- /dev/null +++ b/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 children; + + public void setName(String name) { + this.name = name; + } + + public void setPath(String path) { + this.path = path; + } + + public void setChildren(ArrayList 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 getChildren() { + return children; + } +} diff --git a/src/main/java/com/fr/plugin/jsd9683/conf/Jsd9683ConfigXmlConfigReader.java b/src/main/java/com/fr/plugin/jsd9683/conf/Jsd9683ConfigXmlConfigReader.java new file mode 100644 index 0000000..6f1e358 --- /dev/null +++ b/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()); + + } + + } + } +} diff --git a/src/main/java/com/fr/plugin/jsd9683/controller/Jsd9683Controller.java b/src/main/java/com/fr/plugin/jsd9683/controller/Jsd9683Controller.java new file mode 100644 index 0000000..f8752cc --- /dev/null +++ b/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 allFiles = new ArrayList<>(); + ArrayList 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 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 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); + } + } + + } + +} diff --git a/src/main/java/com/fr/plugin/jsd9683/controller/Jsd9683ControllerProvider.java b/src/main/java/com/fr/plugin/jsd9683/controller/Jsd9683ControllerProvider.java new file mode 100644 index 0000000..6ca39fb --- /dev/null +++ b/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 + }; + } +} \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/jsd9683/filter/CasFilter.java b/src/main/java/com/fr/plugin/jsd9683/filter/CasFilter.java new file mode 100644 index 0000000..487f0b6 --- /dev/null +++ b/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 initializationParameters() { + HashMap 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; + } +} diff --git a/src/main/java/com/fr/plugin/jsd9683/filter/Jsd9683Filter.java b/src/main/java/com/fr/plugin/jsd9683/filter/Jsd9683Filter.java new file mode 100644 index 0000000..02b8e80 --- /dev/null +++ b/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 = ""; + String endTag = ""; + int beginIndex = result.indexOf(beginTag) + beginTag.length(); + int endIndex = result.indexOf(endTag); + String userName = result.substring(beginIndex, endIndex); + + beginTag = ""; + endTag = ""; + beginIndex = result.indexOf(beginTag) + beginTag.length(); + endIndex = result.indexOf(endTag); + String sid = result.substring(beginIndex, endIndex); + + beginTag = ""; + endTag = ""; + 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 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; + } + +} diff --git a/src/main/java/com/fr/plugin/jsd9683/filter/NoFilter.java b/src/main/java/com/fr/plugin/jsd9683/filter/NoFilter.java new file mode 100644 index 0000000..ac6ed5b --- /dev/null +++ b/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() { + + } +} diff --git a/src/main/java/com/fr/plugin/jsd9683/filter/RequestGlobalFilter.java b/src/main/java/com/fr/plugin/jsd9683/filter/RequestGlobalFilter.java new file mode 100644 index 0000000..3be5ef1 --- /dev/null +++ b/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(); + } + } + } +} diff --git a/src/main/java/com/fr/plugin/jsd9683/webResourceProvider/Jsd9683WebResourceComponent.java b/src/main/java/com/fr/plugin/jsd9683/webResourceProvider/Jsd9683WebResourceComponent.java new file mode 100644 index 0000000..f512e9c --- /dev/null +++ b/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"); + } + +} diff --git a/src/main/java/com/fr/plugin/jsd9683/webResourceProvider/Jsd9683WebResourceProvider.java b/src/main/java/com/fr/plugin/jsd9683/webResourceProvider/Jsd9683WebResourceProvider.java new file mode 100644 index 0000000..3726782 --- /dev/null +++ b/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; + } +} diff --git a/src/main/java/com/fr/plugin/jsd9683/webResourceProvider/MyTemplateRequestChecker.java b/src/main/java/com/fr/plugin/jsd9683/webResourceProvider/MyTemplateRequestChecker.java new file mode 100644 index 0000000..5e099c9 --- /dev/null +++ b/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; + } +} diff --git a/src/main/resources/com/fr/plugin/jsd9683/jscss/Jsd9683.js b/src/main/resources/com/fr/plugin/jsd9683/jscss/Jsd9683.js new file mode 100644 index 0000000..dac038f --- /dev/null +++ b/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; + })(); \ No newline at end of file diff --git a/src/main/resources/com/fr/plugin/jsd9683/jscss/unavaliable.html b/src/main/resources/com/fr/plugin/jsd9683/jscss/unavaliable.html new file mode 100644 index 0000000..de6a562 --- /dev/null +++ b/src/main/resources/com/fr/plugin/jsd9683/jscss/unavaliable.html @@ -0,0 +1,81 @@ + + + + + + + + + + +
+
+ +
+
非常抱歉,无法查看该页面
+
您没有权限访问该报表页面
+
如果您确实需要访问该页面,请联系平台管理员
+
+ + + + \ No newline at end of file diff --git a/交付/conf/bg.xml b/交付/conf/bg.xml new file mode 100644 index 0000000..8dbe357 --- /dev/null +++ b/交付/conf/bg.xml @@ -0,0 +1,7 @@ + + http://xxx/login + http://xxxx/proxyValidate + x.x.x.x:8080 + http://xx/fine_report/report_access_validation + true +