diff --git a/src/com/amarsoft/awe/control/RedirectorServlet.java b/src/com/amarsoft/awe/control/RedirectorServlet.java index ef44b97f1..baba89648 100644 --- a/src/com/amarsoft/awe/control/RedirectorServlet.java +++ b/src/com/amarsoft/awe/control/RedirectorServlet.java @@ -15,149 +15,188 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -public class RedirectorServlet extends HttpServlet -{ - private static final long serialVersionUID = 1L; - private String encoding = null; - private String redType = "server"; +public class RedirectorServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + private String encoding = null; + private String redType = "server"; - public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { - doGet(req, resp); - } - - public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { - HttpSession session = req.getSession(false); - - if (session == null) { - ARE.getLog().info("[RED]TimeOut[NoSession] Page=[" + req.getParameter("ComponentURL") + "]"); - resp.sendRedirect(req.getContextPath() + "/Frame/page/sys/SessionExpire.jsp"); - return; - } - - synchronized (this) {//为避免缓存连接时因处理快慢的问题导致连接编号被覆盖的问题,将此对象加锁 - RuntimeContext CurARC = (RuntimeContext)session.getAttribute("CurARC"); - if (CurARC == null) { - ARE.getLog().info("[RED]TimeOut[" + session.getId() + ":" + session.getCreationTime() + ":" + session.getLastAccessedTime() + "] Page=[" + req.getParameter("ComponentURL") + "]"); - resp.sendRedirect(req.getContextPath() + "/Frame/page/sys/SessionExpire.jsp"); - return; - } - - resp.setContentType("text/html; charset=GBK"); - if ((req.getCharacterEncoding() == null) && (this.encoding != null)) { - req.setCharacterEncoding(this.encoding); - } - Configure CurConfig = Configure.getInstance(session.getServletContext()); - if (CurConfig == null) { - throw new ServletException("读取配置文件错误!请检查配置文件。"); - } - String sComponentURL = req.getParameter("ComponentURL"); - try - { - if (!isPathRight(sComponentURL, CurARC)) { - ARE.getLog().debug("[RED] NoRightInfo Page=[" + sComponentURL + "][" + CurARC.getUser().getUserID() + "][" + CurARC.getUser().getUserName() + "]"); - CurARC.setErrInfo("你没有执行该页面[" + sComponentURL + "]的权限!"); - resp.sendRedirect(req.getContextPath() + "/Frame/page/sys/NoRightInfo.jsp"); - return; - } - - ComponentSession CurCompSession = CurARC.getCompSession(); - Component pDestroyedComp = null; - - String sOpenerClientID = req.getParameter("OpenerClientID"); - String sToDestroyAllComponent = req.getParameter("ToDestroyAllComponent"); - String sTargetWindow = req.getParameter("TargetWindow"); - if ((sTargetWindow == null) || (("".equals(sTargetWindow)) && ("undefined".equals(sTargetWindow)))) { - sTargetWindow = "_blank"; - } - - if (("Y".equals(sToDestroyAllComponent)) || (sOpenerClientID == null) || ("_top".equals(sTargetWindow))) { - CurCompSession.clear(); - } - else { - String sToDestroyClientID = req.getParameter("ToDestroyClientID"); - if ((sToDestroyClientID != null) && (!sToDestroyClientID.equals("")) && (!sToDestroyClientID.equals("undefined"))) { - pDestroyedComp = CurCompSession.lookUpAndDestroy(sToDestroyClientID); - } - } - - Component pCurComp = null; - if (sOpenerClientID != null) - { - pCurComp = CurCompSession.lookUpAndDestroyChildByTarget(sOpenerClientID, sTargetWindow); - } - - Component CurComp = CurCompSession.creatComponent(sComponentURL, sTargetWindow, req); - if (pCurComp == null) pCurComp = pDestroyedComp; - if (pCurComp != null) CurComp.setParentComponent(pCurComp); - - String sToInheritObj = req.getParameter("ToInheritObj"); - if ((pCurComp != null) && (sToInheritObj != null) && (sToInheritObj.equalsIgnoreCase("y"))) { - String sObjectType = CurComp.getParentComponent().getAttribute("CompObjectType"); - if (sObjectType != null) { - CurComp.setAttribute("CompObjectType", sObjectType); - } - String sObjectNo = CurComp.getParentComponent().getAttribute("CompObjectNo"); - if (sObjectNo != null) { - CurComp.setAttribute("CompObjectNo", sObjectNo); - } - String sRightType = CurComp.getParentComponent().getAttribute("RightType"); - if (sRightType != null) { - CurComp.setAttribute("RightType", sRightType); - } - - } - - session.setAttribute("CurARC", CurARC); - String redirect = req.getContextPath() + "/" + "ao" + "?" + "ao" + "ID=" + CurComp.getClientID(); - redirectPage(resp, redirect); - return; } catch (Exception e) { - ARE.getLog().error("Redirector[" + sComponentURL + "] Error", e); - resp.getWriter().print("[" + sComponentURL + "]" + e.getMessage()); - } - finally { - } + public void doPost(HttpServletRequest req, HttpServletResponse resp) + throws IOException, ServletException { + doGet(req, resp); } - } - private void redirectPage(HttpServletResponse resp, String redirect) throws IOException { - if ("server".equals(this.redType)) { - resp.sendRedirect(redirect); - } - else - resp.getWriter().print("
"); - } + public void doGet(HttpServletRequest req, HttpServletResponse resp) + throws IOException, ServletException { + HttpSession session = req.getSession(false); - public boolean isPathRight(String path, RuntimeContext CurARC) - throws Exception - { - if ((path == null) || ("".equals(path))) return false; + if (session == null) { + ARE.getLog().info( + "[RED]TimeOut[NoSession] Page=[" + + req.getParameter("ComponentURL") + "]"); + resp.sendRedirect(req.getContextPath() + + "/Frame/page/sys/SessionExpire.jsp"); + return; + } - ArrayList urlList = (ArrayList)CurARC.getObject("UserUrlList"); + RuntimeContext CurARC = (RuntimeContext) session.getAttribute("CurARC"); + if (CurARC == null) { + ARE.getLog().info( + "[RED]TimeOut[" + session.getId() + ":" + + session.getCreationTime() + ":" + + session.getLastAccessedTime() + "] Page=[" + + req.getParameter("ComponentURL") + "]"); + resp.sendRedirect(req.getContextPath() + + "/Frame/page/sys/SessionExpire.jsp"); + return; + } - if ((urlList == null) || (urlList.size() < 1)) { - urlList = RoleManager.getUserUrlList(CurARC.getUser()); - ARE.getLog().debug("[RED] URLTable Size=[" + urlList.size() + "] User=[" + CurARC.getUser().getUserID() + "][" + CurARC.getUser().getUserName() + "]"); - CurARC.setObject("UserUrlList", urlList); - } + resp.setContentType("text/html; charset=GBK"); + if ((req.getCharacterEncoding() == null) && (this.encoding != null)) { + req.setCharacterEncoding(this.encoding); + } + Configure CurConfig = Configure + .getInstance(session.getServletContext()); + if (CurConfig == null) { + throw new ServletException("读取配置文件错误!请检查配置文件。"); + } + String sComponentURL = req.getParameter("ComponentURL"); + try { + if (!isPathRight(sComponentURL, CurARC)) { + ARE.getLog().debug( + "[RED] NoRightInfo Page=[" + sComponentURL + "][" + + CurARC.getUser().getUserID() + "][" + + CurARC.getUser().getUserName() + "]"); + CurARC.setErrInfo("你没有执行该页面[" + sComponentURL + "]的权限!"); + resp.sendRedirect(req.getContextPath() + + "/Frame/page/sys/NoRightInfo.jsp"); + return; + } - if (!AWEHrefCache.getHrefList().matchHref(path)) - { - return true; - } + ComponentSession CurCompSession = CurARC.getCompSession(); + Component pDestroyedComp = null; - return urlList.contains(path); - } + String sOpenerClientID = req.getParameter("OpenerClientID"); + String sToDestroyAllComponent = req + .getParameter("ToDestroyAllComponent"); + String sTargetWindow = req.getParameter("TargetWindow"); + if ((sTargetWindow == null) + || (("".equals(sTargetWindow)) && ("undefined" + .equals(sTargetWindow)))) { + sTargetWindow = "_blank"; + } - public void init() - throws ServletException - { - super.init(); - this.encoding = getInitParameter("encoding"); - if ((this.encoding == null) || ("".equals(this.encoding))) this.encoding = null; + if (("Y".equals(sToDestroyAllComponent)) + || (sOpenerClientID == null) + || ("_top".equals(sTargetWindow))) { + CurCompSession.clear(); + } else { + String sToDestroyClientID = req + .getParameter("ToDestroyClientID"); + if ((sToDestroyClientID != null) + && (!sToDestroyClientID.equals("")) + && (!sToDestroyClientID.equals("undefined"))) { + pDestroyedComp = CurCompSession + .lookUpAndDestroy(sToDestroyClientID); + } + } - this.redType = getInitParameter("RedirectType"); - if ((this.redType == null) || ("".equals(this.redType))) this.redType = "server"; + Component pCurComp = null; + + // 为了有效规避掉加载结构页面导致的误删页面组件对象,将结构页面排除在清除组件对象的条件外 by zhulh 2018/08/19 + if (sOpenerClientID != null + && (sComponentURL.indexOf("Blank.jsp") == -1 || ( + sComponentURL.indexOf("Blank.jsp") != -1 && + !CurCompSession.checkParentComp(sOpenerClientID)))) { + pCurComp = CurCompSession.lookUpAndDestroyChildByTarget( + sOpenerClientID, sTargetWindow); + } - ARE.getLog().info("[RED] RedirectorServlet InitParameter : encoding[" + this.encoding + "] RedirectType[" + this.redType + "]"); - } + Component CurComp = CurCompSession.creatComponent(sComponentURL, + sTargetWindow, req); + if (pCurComp == null) + pCurComp = pDestroyedComp; + if (pCurComp != null) + CurComp.setParentComponent(pCurComp); + + String sToInheritObj = req.getParameter("ToInheritObj"); + if ((pCurComp != null) && (sToInheritObj != null) + && (sToInheritObj.equalsIgnoreCase("y"))) { + String sObjectType = CurComp.getParentComponent().getAttribute( + "CompObjectType"); + if (sObjectType != null) { + CurComp.setAttribute("CompObjectType", sObjectType); + } + String sObjectNo = CurComp.getParentComponent().getAttribute( + "CompObjectNo"); + if (sObjectNo != null) { + CurComp.setAttribute("CompObjectNo", sObjectNo); + } + String sRightType = CurComp.getParentComponent().getAttribute( + "RightType"); + if (sRightType != null) { + CurComp.setAttribute("RightType", sRightType); + } + + } + + session.setAttribute("CurARC", CurARC); + String redirect = req.getContextPath() + "/" + "ao" + "?" + "ao" + + "ID=" + CurComp.getClientID(); + redirectPage(resp, redirect); + return; + } catch (Exception e) { + ARE.getLog().error("Redirector[" + sComponentURL + "] Error", e); + resp.getWriter().print("[" + sComponentURL + "]" + e.getMessage()); + } finally { + } + } + + private void redirectPage(HttpServletResponse resp, String redirect) + throws IOException { + if ("server".equals(this.redType)) { + resp.sendRedirect(redirect); + } else + resp.getWriter().print( + ""); + } + + public boolean isPathRight(String path, RuntimeContext CurARC) + throws Exception { + if ((path == null) || ("".equals(path))) + return false; + + ArrayList urlList = (ArrayList) CurARC.getObject("UserUrlList"); + + if ((urlList == null) || (urlList.size() < 1)) { + urlList = RoleManager.getUserUrlList(CurARC.getUser()); + ARE.getLog().debug( + "[RED] URLTable Size=[" + urlList.size() + "] User=[" + + CurARC.getUser().getUserID() + "][" + + CurARC.getUser().getUserName() + "]"); + CurARC.setObject("UserUrlList", urlList); + } + + if (!AWEHrefCache.getHrefList().matchHref(path)) { + return true; + } + + return urlList.contains(path); + } + + public void init() throws ServletException { + super.init(); + this.encoding = getInitParameter("encoding"); + if ((this.encoding == null) || ("".equals(this.encoding))) + this.encoding = null; + + this.redType = getInitParameter("RedirectType"); + if ((this.redType == null) || ("".equals(this.redType))) + this.redType = "server"; + + ARE.getLog().info( + "[RED] RedirectorServlet InitParameter : encoding[" + + this.encoding + "] RedirectType[" + this.redType + + "]"); + } } \ No newline at end of file diff --git a/src/com/amarsoft/awe/control/model/ComponentSession.java b/src/com/amarsoft/awe/control/model/ComponentSession.java new file mode 100644 index 000000000..4c283bcdc --- /dev/null +++ b/src/com/amarsoft/awe/control/model/ComponentSession.java @@ -0,0 +1,282 @@ +/* */ package com.amarsoft.awe.control.model; +/* */ +/* */ import com.amarsoft.are.ARE; +/* */ import com.amarsoft.are.log.Log; +/* */ import java.io.Serializable; +/* */ import java.util.Vector; +/* */ import javax.servlet.http.HttpServletRequest; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class ComponentSession +/* */ implements Serializable +/* */ { +/* */ private static final long serialVersionUID = 1L; +/* 18 */ private Vector