1 5 package org.jresearch.gossip.tags.userstatus; 6 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpSession ; 9 import javax.servlet.jsp.JspException ; 10 import javax.servlet.jsp.tagext.TagSupport ; 11 12 import org.jresearch.gossip.IConst; 13 import org.jresearch.gossip.am.ban.BanGuard; 14 import org.jresearch.gossip.am.model.IPermissionGuard; 15 import org.jresearch.gossip.am.values.PermissionPoint; 16 import org.jresearch.gossip.exception.SystemException; 17 18 22 public class CheckAccessTag extends TagSupport { 23 24 private String var; 25 26 private String objectId; 27 28 private String operationId; 29 30 33 public String getVar() { 34 return var; 35 } 36 37 41 public void setVar(String var) { 42 this.var = var; 43 } 44 45 48 public String getObjectId() { 49 return objectId; 50 } 51 52 56 public void setObjectId(String objectId) { 57 this.objectId = objectId; 58 } 59 60 63 public String getOperationId() { 64 return operationId; 65 } 66 67 71 public void setOperationId(String operationId) { 72 this.operationId = operationId; 73 } 74 75 80 public int doStartTag() throws JspException { 81 BanGuard guard; 82 try { 83 Boolean isAlloved = haveAccess((HttpServletRequest ) pageContext 84 .getRequest()); 85 if (this.var != null) 86 pageContext.setAttribute(var, isAlloved); 87 if (isAlloved.booleanValue()) { 88 return EVAL_BODY_INCLUDE; 89 } 90 return SKIP_BODY; 91 } catch (SystemException e) { 92 throw new JspException (e); 93 } 94 } 95 96 private Boolean haveAccess(HttpServletRequest request) 97 throws SystemException { 98 HttpSession session = request.getSession(); 99 if (session.getAttribute(IConst.SESSION.PERMISSION_GUARD_KEY) == null) { 100 throw new SystemException("PERMISSION_GUARD not found in session"); 101 } 102 IPermissionGuard guard = (IPermissionGuard) session 103 .getAttribute(IConst.SESSION.PERMISSION_GUARD_KEY); 104 105 PermissionPoint point = new PermissionPoint(Integer 106 .parseInt(this.objectId), Integer.parseInt(this.operationId)); 107 return new Boolean (guard.checkPermission(point)); 108 109 } 110 } | Popular Tags |