为了有效规避掉加载结构页面导致的误删页面组件对象,将结构页面排除在清除组件对象的条件外

This commit is contained in:
zhulianghua 2018-08-19 13:27:18 +08:00
parent abf97d7700
commit cf9e131b5c
2 changed files with 455 additions and 134 deletions

View File

@ -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("<html><head><script type=\"text/javascript\">window.location.href=\"" + redirect + "\";</script></head></html>");
}
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(
"<html><head><script type=\"text/javascript\">window.location.href=\""
+ redirect + "\";</script></head></html>");
}
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
+ "]");
}
}

View File

@ -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<Component> comps = new Vector();
/* 19 */ private Vector<Parameter> params = new Vector();
/* */
/* */
/* */
/* */
/* */
/* */ public ComponentSession() {}
/* */
/* */
/* */
/* */
/* */ public Component creatComponent(String sComponentURL, String sTargetWindow, Vector<Parameter> pList)
/* */ {
/* 32 */ Component tcomp = new Component(sComponentURL, sTargetWindow, pList);
/* */
/* 34 */ this.comps.addElement(tcomp);
/* 35 */ return tcomp;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public Component creatComponent(String sComponentURL, String sTargetWindow, HttpServletRequest req)
/* */ throws Exception
/* */ {
/* 49 */ return creatComponent(sComponentURL, sTargetWindow, ParameterUtil.getReqParamList(req, "UTF-8"));
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public Component lookUp(String sClientID)
/* */ {
/* 60 */ for (int i = this.comps.size() - 1; i >= 0; i--) {
/* 61 */ Component tcomp = (Component)this.comps.get(i);
/* 62 */ if (tcomp.getClientID().equals(sClientID))
/* 63 */ return (Component)this.comps.get(i);
/* */ }
/* 65 */ return null;
/* */ }
public boolean checkParentComp(String sClientID)
/* */ {
/* 60 */ for (int i = this.comps.size() - 1; i >= 0; i--) {
/* 61 */ Component tcomp = (Component)this.comps.get(i);
if(tcomp.getCompURL().equals("Blank.jsp")) continue;
/* 62 */ if (tcomp.getParentComponent() != null && tcomp.getParentComponent().getClientID().equals(sClientID))
/* 63 */ return true;
/* */ }
/* 65 */ return false;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public String getComponentsID()
/* */ {
/* 74 */ StringBuffer sbf = new StringBuffer();
/* */
/* 76 */ for (int i = this.comps.size() - 1; i >= 0; i--) {
/* 77 */ Component tcomp = (Component)this.comps.get(i);
/* 78 */ if (i == 0) {
/* 79 */ sbf.append(tcomp.getClientID());
/* 80 */ sbf.append("|");
/* 81 */ sbf.append(tcomp.getCompURL());
/* */ } else {
/* 83 */ sbf.append(i);
/* 84 */ sbf.append("|");
/* 85 */ sbf.append(tcomp.getClientID());
/* 86 */ sbf.append("|");
/* 87 */ sbf.append(tcomp.getCompURL());
if(tcomp.getParentComponent() != null) {
sbf.append("|PComp:");
sbf.append(tcomp.getParentComponent().getClientID());
}
/* 88 */ sbf.append(",");
/* */ }
/* */ }
/* 91 */ return sbf.toString();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public int getSize()
/* */ {
/* 100 */ return this.comps.size();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public int getParamSize()
/* */ {
/* 109 */ return this.params.size();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public Component lookUpAndDestroy(String sClientID)
/* */ {
/* 118 */ for (int i = this.comps.size() - 1; i >= 0; i--) {
/* 119 */ Component tcomp = (Component)this.comps.get(i);
/* */
/* 121 */ if (tcomp.getClientID().equals(sClientID)) {
/* 122 */ Component pComp = tcomp.getParentComponent();
/* 123 */ destroy(i);
/* 124 */ return pComp;
/* */ }
/* */ }
/* 127 */ return null;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public Component lookUpAndDestroyChildByTarget(String sClientID, String sTargetWindow)
/* */ {
/* 136 */ Component pComp = null;
/* 137 */ for (int i = this.comps.size() - 1; i >= 0; i--) {
/* 138 */ Component tcomp = (Component)this.comps.get(i);
/* 139 */ if (tcomp.getClientID().equals(sClientID)) pComp = tcomp;
/* 140 */ Component tpcomp = tcomp.getParentComponent();
/* */
if(tcomp.getCompURL().indexOf("Blank.jsp") != -1 && tpcomp == null) {
destroy(i);
}
/* 142 */ if ((tpcomp != null) && (tpcomp.getClientID().equals(sClientID)) &&
/* 143 */ (tcomp.getTargetWindow().equals(sTargetWindow))) {
/* 144 */ destroy(i);
/* */ }
/* */ }
/* */
/* 148 */ return pComp;
/* */ }
/* */
/* */
/* */
/* */
/* */ public void lookUpAndDestroyChild(String sClientID)
/* */ {
/* 156 */ for (int i = this.comps.size() - 1; i >= 0; i--) {
/* 157 */ Component tcomp = (Component)this.comps.get(i);
/* 158 */ Component tpcomp = tcomp.getParentComponent();
/* */
/* 160 */ if ((tpcomp != null) && (tpcomp.getClientID().equals(sClientID))) {
/* 161 */ destroy(i);
/* 162 */ return;
/* */ }
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ private void destroyChild(Component compParent, int iParentAddress)
/* */ {
/* 174 */ for (int i = this.comps.size() - 1; i >= iParentAddress; i--) {
/* 175 */ Component tcomp = (Component)this.comps.get(i);
/* 176 */ if (tcomp.getParentComponent() == compParent) {
/* 177 */ destroy(i);
/* */ }
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ private void destroy(int iAddress)
/* */ {
/* */ try
/* */ {
/* 190 */ Component tcomp = (Component)this.comps.get(iAddress);
/* */
/* 192 */ destroyChild(tcomp, iAddress);
/* 193 */ tcomp.destroy();
/* 194 */ this.comps.remove(iAddress);
/* */ } catch (Exception e) {
/* 196 */ ARE.getLog().debug("δÕÒµ½ÐèÇåÀíµÄ×é¼þ£¡");
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public void clear()
/* */ {
/* 207 */ int iNewWindow = 0;
/* 208 */ for (int i = this.comps.size() - 1; i >= 0; i--) {
/* 209 */ Component tcomp = (Component)this.comps.get(i);
/* 210 */ if ("_blank".equals(tcomp.getTargetWindow())) {
/* 211 */ iNewWindow++;
/* */
/* 213 */ if (iNewWindow > 5) destroy(i);
/* */ } else {
/* 215 */ destroy(i);
/* */ }
/* */ }
/* */ }
/* */
/* */
/* */ public void setAttribute(String sParaName, String oParaValue)
/* */ throws Exception
/* */ {
/* 224 */ this.params.addElement(new Parameter(sParaName, oParaValue));
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public Object getAttribute(String sParaName)
/* */ throws Exception
/* */ {
/* 234 */ for (int i = this.params.size() - 1; i >= 0; i--) {
/* 235 */ Parameter tmpPara = (Parameter)this.params.get(i);
/* 236 */ if (tmpPara.paraName.equals(sParaName)) {
/* 237 */ return tmpPara.paraValue;
/* */ }
/* */ }
/* 240 */ return null;
/* */ }
/* */
/* */
/* */
/* */ public void removeAttribute(String sParaName)
/* */ throws Exception
/* */ {
/* 248 */ for (int i = this.params.size() - 1; i >= 0; i--) {
/* 249 */ Parameter tmpPara = (Parameter)this.params.get(i);
/* 250 */ if (tmpPara.paraName.equals(sParaName)) {
/* 251 */ this.params.remove(i);
/* 252 */ return;
/* */ }
/* */ }
/* */ }
/* */ }
/* Location: D:\apzl_leasing\WebContent\WEB-INF\lib\awe-3.5_g.jar
* Qualified Name: com.amarsoft.awe.control.model.ComponentSession
* Java Class Version: 6 (50.0)
* JD-Core Version: 0.7.0.1
*/