1 17 package org.apache.forrest.forrestbot.webapp.action; 18 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpServletResponse ; 21 22 import org.apache.forrest.forrestbot.webapp.Config; 23 import org.apache.forrest.forrestbot.webapp.Constants; 24 import org.apache.log4j.Logger; 25 import org.apache.struts.action.Action; 26 import org.apache.struts.action.ActionError; 27 import org.apache.struts.action.ActionErrors; 28 import org.apache.struts.action.ActionForm; 29 import org.apache.struts.action.ActionForward; 30 import org.apache.struts.action.ActionMapping; 31 32 public class BaseAction extends Action { 33 private static Logger log = Logger.getLogger(BaseAction.class); 34 35 public BaseAction() { 36 super(); 37 Config.getInstance(); } 39 40 public ActionForward execute( 41 ActionMapping mapping, 42 ActionForm form, 43 HttpServletRequest request, 44 HttpServletResponse response) 45 throws Exception { 46 super.execute(mapping, form, request, response); 47 48 51 request.setAttribute("Constants", Constants.getConstantFieldsAsMap()); 52 53 response.setHeader("Pragma", "no-cache"); 54 55 return mapping.findForward(Constants.FORWARD_NAME_SUCCESS); 56 } 57 58 protected boolean checkAuthorized(HttpServletRequest request, HttpServletResponse response, boolean setErrors) { 59 Object attr = request.getSession(true).getAttribute("auth"); 60 if (attr != null && ((Boolean )attr).booleanValue()) { 61 return true; 62 } else { 63 if (setErrors) { 64 ActionErrors errors = new ActionErrors(); 65 errors.add("authorize", new ActionError("error.authorization")); 66 saveErrors(request, errors); 67 } 68 return false; 69 } 70 } 71 72 protected boolean checkAuthorized(HttpServletRequest request, HttpServletResponse response) { 73 return checkAuthorized(request, response, true); 74 } 75 76 } 77 | Popular Tags |