Added: struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/CreateActionForm.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/CreateActionForm.java?view=auto&rev=151660 ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/CreateActionForm.java (added) +++ struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/CreateActionForm.java Sun Feb 6 17:59:31 2005 @@ -0,0 +1,64 @@ +/* + * Created on Jan 17, 2005 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.apache.struts.chain.commands.servlet; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.ActionServlet; +import org.apache.struts.action.DynaActionForm; +import org.apache.struts.action.DynaActionFormClass; +import org.apache.struts.chain.commands.util.ClassUtils; +import org.apache.struts.chain.contexts.ActionContext; +import org.apache.struts.chain.contexts.ServletActionContext; +import org.apache.struts.config.ActionConfig; +import org.apache.struts.config.FormBeanConfig; +import org.apache.struts.config.ModuleConfig; + +public class CreateActionForm extends + org.apache.struts.chain.commands.AbstractCreateActionForm { + + // ------------------------------------------------------ Instance Variables + private static final Log log = + LogFactory.getLog(CreateActionForm.class); + + + /* Implement servlet-specific details of creating a new form instance. + * @see org.apache.struts.chain.commands.CreateActionForm#createNewFormInstance(org.apache.struts.chain.contexts.ActionContext, org.apache.struts.config.ActionConfig, org.apache.struts.config.FormBeanConfig) + */ + protected ActionForm createNewFormInstance(ActionContext actionCtx, + ActionConfig actionConfig, FormBeanConfig formBeanConfig) + throws Exception { + ActionForm instance; + log.trace("Make a new instance of: " + formBeanConfig); + // Create a new form bean instance + if (formBeanConfig.getDynamic()) { + ModuleConfig moduleConfig = actionCtx.getModuleConfig(); + DynaActionFormClass dynaClass = + DynaActionFormClass.createDynaActionFormClass(formBeanConfig); + instance = (ActionForm) dynaClass.newInstance(); + ((DynaActionForm) instance).initialize + ((ActionMapping) actionConfig); + } else { + instance = (ActionForm) + ClassUtils.getApplicationInstance(formBeanConfig.getType()); + } + + // Configure and cache the new instance + /** @todo Move this dependency on the Servlet API into a subclass and make this one abstract. + * Then again, ActionForm itself depends on the Servlet API. + * */ + ServletActionContext saContext = (ServletActionContext) actionCtx; + ActionServlet servlet = saContext.getActionServlet(); + instance.setServlet(servlet); + actionCtx.setActionForm(instance); + + return instance; + } + +}
Modified: struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ExecuteAction.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ExecuteAction.java?view=diff&r1=151659&r2=151660 ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ExecuteAction.java (original) +++ struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ExecuteAction.java Sun Feb 6 17:59:31 2005 @@ -18,13 +18,13 @@ import org.apache.commons.chain.Context; -import org.apache.commons.chain.web.servlet.ServletWebContext; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.chain.commands.AbstractExecuteAction; import org.apache.struts.config.ActionConfig; import org.apache.struts.config.ForwardConfig; +import org.apache.struts.chain.contexts.ServletActionContext; /** @@ -58,11 +58,11 @@ ActionForm actionForm) throws Exception { - ServletWebContext swcontext = (ServletWebContext) context; + ServletActionContext saContext = (ServletActionContext) context; return (action.execute((ActionMapping) actionConfig, actionForm, - swcontext.getRequest(), - swcontext.getResponse())); + saContext.getRequest(), + saContext.getResponse())); } Modified: struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java?view=diff&r1=151659&r2=151660 ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java (original) +++ struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformForward.java Sun Feb 6 17:59:31 2005 @@ -19,6 +19,7 @@ import javax.servlet.RequestDispatcher; import javax.servlet.http.HttpServletRequest; + import org.apache.commons.chain.Context; import org.apache.commons.chain.web.servlet.ServletWebContext; import org.apache.struts.chain.commands.AbstractPerformForward; Modified: struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformInclude.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformInclude.java?view=diff&r1=151659&r2=151660 ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformInclude.java (original) +++ struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PerformInclude.java Sun Feb 6 17:59:31 2005 @@ -20,7 +20,7 @@ import javax.servlet.RequestDispatcher; import javax.servlet.http.HttpServletRequest; import org.apache.commons.chain.Context; -import org.apache.commons.chain.web.servlet.ServletWebContext; +import org.apache.struts.chain.contexts.ServletActionContext; import org.apache.struts.chain.commands.AbstractPerformInclude; import org.apache.struts.upload.MultipartRequestWrapper; @@ -48,7 +48,7 @@ protected void perform(Context context, String uri) throws Exception { - ServletWebContext swcontext = (ServletWebContext) context; + ServletActionContext swcontext = (ServletActionContext) context; // Get the underlying request in the case of a multipart wrapper HttpServletRequest request = swcontext.getRequest(); Modified: struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PopulateActionForm.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PopulateActionForm.java?view=diff&r1=151659&r2=151660 ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PopulateActionForm.java (original) +++ struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/PopulateActionForm.java Sun Feb 6 17:59:31 2005 @@ -17,16 +17,16 @@ package org.apache.struts.chain.commands.servlet; -import org.apache.commons.chain.Context; -import org.apache.commons.chain.web.servlet.ServletWebContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.struts.Globals; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.chain.commands.AbstractPopulateActionForm; +import org.apache.struts.chain.contexts.ActionContext; +import org.apache.struts.chain.contexts.ServletActionContext; import org.apache.struts.config.ActionConfig; import org.apache.struts.util.RequestUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * <p>Populate the form bean (if any) for this request. Sets the multipart @@ -43,28 +43,26 @@ // ------------------------------------------------------- Protected Methods - protected void populate(Context context, + protected void populate(ActionContext context, ActionConfig actionConfig, ActionForm actionForm) throws Exception { - ServletWebContext swcontext = (ServletWebContext) context; - RequestUtils.populate(actionForm, actionConfig.getPrefix(), actionConfig.getSuffix(), swcontext.getRequest()); + ServletActionContext saContext = (ServletActionContext) context; + RequestUtils.populate(actionForm, actionConfig.getPrefix(), actionConfig.getSuffix(), saContext.getRequest()); } - protected void reset(Context context, + protected void reset(ActionContext context, ActionConfig actionConfig, ActionForm actionForm) { - ServletWebContext swcontext = (ServletWebContext) context; - actionForm.reset((ActionMapping) actionConfig, swcontext.getRequest()); + ServletActionContext saContext = (ServletActionContext) context; + actionForm.reset((ActionMapping) actionConfig, saContext.getRequest()); // Set the multipart class if (actionConfig.getMultipartClass() != null) { - swcontext.getRequestScope().put(Globals.MULTIPART_KEY, + saContext.getRequestScope().put(Globals.MULTIPART_KEY, actionConfig.getMultipartClass()); } } - - } Modified: struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/RequestNoCache.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/RequestNoCache.java?view=diff&r1=151659&r2=151660 ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/RequestNoCache.java (original) +++ struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/RequestNoCache.java Sun Feb 6 17:59:31 2005 @@ -19,8 +19,8 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.chain.Context; -import org.apache.commons.chain.web.servlet.ServletWebContext; import org.apache.struts.chain.commands.AbstractRequestNoCache; +import org.apache.struts.chain.contexts.ServletActionContext; /** @@ -38,8 +38,8 @@ protected void requestNoCache(Context context) { - ServletWebContext swcontext = (ServletWebContext) context; - HttpServletResponse response = swcontext.getResponse(); + ServletActionContext sacontext = (ServletActionContext) context; + HttpServletResponse response = sacontext.getResponse(); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache,no-store,max-age=0"); Modified: struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectAction.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectAction.java?view=diff&r1=151659&r2=151660 ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectAction.java (original) +++ struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectAction.java Sun Feb 6 17:59:31 2005 @@ -19,10 +19,10 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.chain.Context; -import org.apache.commons.chain.web.servlet.ServletWebContext; import org.apache.struts.chain.commands.AbstractSelectAction; import org.apache.struts.chain.Constants; import org.apache.struts.config.ModuleConfig; +import org.apache.struts.chain.contexts.ServletActionContext; /** @@ -40,8 +40,8 @@ protected String getPath(Context context) { - ServletWebContext swcontext = (ServletWebContext) context; - HttpServletRequest request = swcontext.getRequest(); + ServletActionContext saContext = (ServletActionContext) context; + HttpServletRequest request = saContext.getRequest(); String path = null; boolean extension = false; @@ -66,8 +66,7 @@ } // Strip the module prefix and extension (if any) - ModuleConfig moduleConfig = (ModuleConfig) - swcontext.get(getModuleConfigKey()); + ModuleConfig moduleConfig = saContext.getModuleConfig(); String prefix = moduleConfig.getPrefix(); if (!path.startsWith(prefix)) { throw new IllegalArgumentException("Path does not start with '" + Modified: struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectLocale.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectLocale.java?view=diff&r1=151659&r2=151660 ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectLocale.java (original) +++ struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SelectLocale.java Sun Feb 6 17:59:31 2005 @@ -20,9 +20,11 @@ import java.util.Locale; import javax.servlet.http.HttpSession; import org.apache.commons.chain.Context; -import org.apache.commons.chain.web.servlet.ServletWebContext; import org.apache.struts.Globals; import org.apache.struts.chain.commands.AbstractSelectLocale; +import org.apache.struts.chain.contexts.ServletActionContext; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.logging.Log; /** @@ -34,6 +36,8 @@ public class SelectLocale extends AbstractSelectLocale { + private static final Log log = LogFactory.getLog(SelectLocale.class); + // ------------------------------------------------------- Protected Methods @@ -44,17 +48,17 @@ */ protected Locale getLocale(Context context) { - ServletWebContext swcontext = (ServletWebContext) context; + ServletActionContext saContext = (ServletActionContext) context; // Has a Locale already been selected? - HttpSession session = swcontext.getRequest().getSession(); + HttpSession session = saContext.getRequest().getSession(); Locale locale = (Locale) session.getAttribute(Globals.LOCALE_KEY); if (locale != null) { return (locale); } // Select and cache the Locale to be used - locale = swcontext.getRequest().getLocale(); + locale = saContext.getRequest().getLocale(); if (locale == null) { locale = Locale.getDefault(); } Modified: struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SetContentType.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SetContentType.java?view=diff&r1=151659&r2=151660 ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SetContentType.java (original) +++ struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/SetContentType.java Sun Feb 6 17:59:31 2005 @@ -19,8 +19,8 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.chain.Context; -import org.apache.commons.chain.web.servlet.ServletWebContext; import org.apache.struts.chain.commands.AbstractSetContentType; +import org.apache.struts.chain.contexts.ServletActionContext; /** @@ -39,7 +39,7 @@ protected void setContentType(Context context, String contentType) { - ServletWebContext swcontext = (ServletWebContext) context; + ServletActionContext swcontext = (ServletActionContext) context; HttpServletResponse response = swcontext.getResponse(); response.setContentType(contentType); Modified: struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ValidateActionForm.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ValidateActionForm.java?view=diff&r1=151659&r2=151660 ============================================================================== --- struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ValidateActionForm.java (original) +++ struts/core/trunk/src/share/org/apache/struts/chain/commands/servlet/ValidateActionForm.java Sun Feb 6 17:59:31 2005 @@ -18,15 +18,14 @@ import org.apache.commons.chain.Context; -import org.apache.commons.chain.web.servlet.ServletWebContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.chain.commands.AbstractValidateActionForm; +import org.apache.struts.chain.contexts.ServletActionContext; import org.apache.struts.config.ActionConfig; -import org.apache.struts.Globals; /** @@ -63,9 +62,9 @@ ActionConfig actionConfig, ActionForm actionForm) { - ServletWebContext swcontext = (ServletWebContext) context; + ServletActionContext saContext = (ServletActionContext) context; ActionErrors errors = (actionForm.validate((ActionMapping) actionConfig, - swcontext.getRequest())); + saContext.getRequest())); // Special handling for multipart request if (errors != null && !errors.isEmpty()) { @@ -76,13 +75,6 @@ actionForm.getMultipartRequestHandler().rollback(); } } - - // Saving the errors is not part of the contract for this method, - // but the idea of the HttpServletRequest is not present in the - // abstract parent of this class. Put this in now so that it - // at least gets done -- and then see if other developers have - // opinions about whether this is good, bad, or at least acceptable. - swcontext.getRequest().setAttribute(Globals.ERROR_KEY, errors); return errors; Added: struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestAuthorizeAction.java URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestAuthorizeAction.java?view=auto&rev=151660 ============================================================================== --- struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestAuthorizeAction.java (added) +++ struts/core/trunk/src/test/org/apache/struts/chain/commands/servlet/TestAuthorizeAction.java Sun Feb 6 17:59:31 2005 @@ -0,0 +1,108 @@ +package org.apache.struts.chain.commands.servlet; + +import junit.framework.TestCase; + +import org.apache.commons.chain.web.servlet.ServletWebContext; +import org.apache.struts.chain.commands.UnauthorizedActionException; +import org.apache.struts.chain.contexts.ServletActionContext; +import org.apache.struts.config.ActionConfig; +import org.apache.struts.mock.MockActionServlet; +import org.apache.struts.mock.MockHttpServletRequest; +import org.apache.struts.mock.MockHttpServletResponse; +import org.apache.struts.mock.MockPrincipal; +import org.apache.struts.mock.MockServletConfig; +import org.apache.struts.mock.MockServletContext; + +/* JUnitTest case for class: org.apache.struts.chain.commands.servlet.AuthorizeAction */ +public class TestAuthorizeAction extends TestCase { + + MockHttpServletRequest request = null; + MockPrincipal principal = null; + + ServletWebContext swContext = null; + ServletActionContext saContext = null; + AuthorizeAction command = null; + + public TestAuthorizeAction(String _name) { + super(_name); + } + + + /* setUp method for test case */ + protected void setUp() throws Exception { + this.request = new MockHttpServletRequest(); + this.principal = new MockPrincipal("Mr. Macri", new String[]{ "administrator" }); + this.request.setUserPrincipal(principal); + MockServletConfig servletConfig = new MockServletConfig(); + MockServletContext servletContext = new MockServletContext(); + MockActionServlet servlet = new MockActionServlet(servletContext, servletConfig); + servlet.initInternal(); + + this.swContext = new ServletWebContext(servletContext, request, new MockHttpServletResponse()); + this.saContext = new ServletActionContext(swContext); + + this.saContext.setActionServlet(servlet); + this.command = new AuthorizeAction(); + } + + /* tearDown method for test case */ + protected void tearDown() { + } + + public void testAuthorizeOneRole() throws Exception { + ActionConfig config = new ActionConfig(); + config.setPath("/testAuthorizeOneRole"); + config.setRoles("administrator"); + this.saContext.setActionConfig(config); + boolean result = command.execute(saContext); + assertFalse(result); + } + + public void testAuthorizeOneOfManyRoles() throws Exception { + ActionConfig config = new ActionConfig(); + config.setPath("/testAuthorizeOneOfManyRoles"); + config.setRoles("administrator,roustabout,memory"); + this.saContext.setActionConfig(config); + boolean result = command.execute(saContext); + assertFalse(result); + } + + public void testAuthorizeNoRoles() throws Exception { + ActionConfig config = new ActionConfig(); + config.setPath("/testAuthorizeNoRoles"); + this.saContext.setActionConfig(config); + boolean result = command.execute(saContext); + assertFalse(result); + } + + public void testNotAuthorizedOneRole() throws Exception { + ActionConfig config = new ActionConfig(); + config.setPath("/testNotAuthorizedOneRole"); + config.setRoles("roustabout"); + this.saContext.setActionConfig(config); + try { + boolean result = command.execute(saContext); + } + catch (UnauthorizedActionException ex) { + } + } + + public void testNotAuthorizedOneOfManyRoles() throws Exception { + ActionConfig config = new ActionConfig(); + config.setPath("/testNotAuthorizedOneOfManyRoles"); + config.setRoles("roustabout,memory"); + this.saContext.setActionConfig(config); + try { + boolean result = command.execute(saContext); + } + catch (UnauthorizedActionException ex) { + } + } + + + /* Executes the test case */ + public static void main(String[] argv) { + String[] testCaseList = {TestAuthorizeAction.class.getName()}; + junit.textui.TestRunner.main(testCaseList); + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]