(struts) branch fix/WW-5468-modeldriven-2 updated: WW-5468 Replace tabs with spaces
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch fix/WW-5468-modeldriven-2 in repository https://gitbox.apache.org/repos/asf/struts.git The following commit(s) were added to refs/heads/fix/WW-5468-modeldriven-2 by this push: new 9a5080d40 WW-5468 Replace tabs with spaces 9a5080d40 is described below commit 9a5080d4036f5c93f74130c67a0bddde3f9e1342 Author: Kusal Kithul-Godage AuthorDate: Sat Oct 12 22:58:00 2024 +1100 WW-5468 Replace tabs with spaces --- .../struts2/rest/RestActionInvocationTest.java | 402 ++--- 1 file changed, 201 insertions(+), 201 deletions(-) diff --git a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java index 6536fd187..c6019c0e0 100644 --- a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java +++ b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java @@ -50,97 +50,97 @@ import static jakarta.servlet.http.HttpServletResponse.SC_NOT_MODIFIED; public class RestActionInvocationTest extends TestCase { - RestActionInvocation restActionInvocation; - MockHttpServletRequest request; - MockHttpServletResponse response; - - @Override - protected void setUp() throws Exception { - super.setUp(); - - restActionInvocation = new RestActionInvocationTester(); - request = new MockHttpServletRequest(); - response = new MockHttpServletResponse(); - ServletActionContext.setRequest(request); - ServletActionContext.setResponse(response); - - } - - /** -* Test the correct action results: null, String, HttpHeaders, Result -* @throws Exception -*/ - public void testSaveResult() throws Exception { - - Object methodResult = "index"; - ActionConfig actionConfig = restActionInvocation.getProxy().getConfig(); - assertEquals("index", restActionInvocation.saveResult(actionConfig, methodResult)); - - setUp(); - methodResult = new DefaultHttpHeaders("show"); - assertEquals("show", restActionInvocation.saveResult(actionConfig, methodResult)); - assertEquals(methodResult, restActionInvocation.httpHeaders); - - setUp(); - methodResult = new HttpHeaderResult(HttpServletResponse.SC_ACCEPTED); - assertEquals(null, restActionInvocation.saveResult(actionConfig, methodResult)); - assertEquals(methodResult, restActionInvocation.createResult()); - - setUp(); - try { - methodResult = new Object(); - restActionInvocation.saveResult(actionConfig, methodResult); - - // ko - assertFalse(true); - - } catch (ConfigurationException c) { - // ok, object not allowed - } - } - - /** -* Test the target selection: exception, error messages, model and null -* @throws Exception -*/ - public void testSelectTarget() throws Exception { - - // Exception - Exception e = new Exception(); - restActionInvocation.getStack().set("exception", e); - restActionInvocation.selectTarget(); - assertEquals(e, restActionInvocation.target); - - // Error messages - setUp(); - String actionMessage = "Error!"; - RestActionSupport action = (RestActionSupport)restActionInvocation.getAction(); - action.addActionError(actionMessage); - Map errors = new HashMap(); - List list = new ArrayList(); - list.add(actionMessage); - errors.put("actionErrors", list); - restActionInvocation.selectTarget(); - assertEquals(errors, restActionInvocation.target); - - // Model with get and no content in post, put, delete - setUp(); - RestAction restAction = (RestAction)restActionInvocation.getAction(); - List model = new ArrayList(); - model.add("Item"); - restAction.model = model; - request.setMethod("GET"); - restActionInvocation.selectTarget(); - assertEquals(model, restActionInvocation.target); - request.setMethod("POST"); - restActionInvocation.selectTarget(); - assertEquals(null, restActionInvocation.target); - request.setMethod("PUT"); - restActionInvocation.selectTarget(); - assertEquals(null, restActionInvocation.target); - request.setMethod("DELETE"); - restActionInvocation.selectTarget(); - assertEquals(null, restActionInvocation.target); +RestActionInvocation restActio
(struts) branch fix/WW-5468-modeldriven-2 created (now 10f47305b)
This is an automated email from the ASF dual-hosted git repository. kusal pushed a change to branch fix/WW-5468-modeldriven-2 in repository https://gitbox.apache.org/repos/asf/struts.git at 10f47305b WW-5468 Remove unneeded annotations This branch includes the following new commits: new a57f51cc2 WW-5468 Reworked fix, exempt ModelDriven Action parameters new 10f47305b WW-5468 Remove unneeded annotations The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
(struts) 01/02: WW-5468 Reworked fix, exempt ModelDriven Action parameters
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch fix/WW-5468-modeldriven-2 in repository https://gitbox.apache.org/repos/asf/struts.git commit a57f51cc2bdd3d3501327c1c9b0798e314918152 Author: Kusal Kithul-Godage AuthorDate: Fri Oct 11 20:55:50 2024 +1100 WW-5468 Reworked fix, exempt ModelDriven Action parameters --- .../java/com/opensymphony/xwork2/ModelDriven.java | 5 +- .../parameter/ParametersInterceptor.java | 88 ++ .../parameter/StrutsParameterAnnotationTest.java | 25 +++--- 3 files changed, 58 insertions(+), 60 deletions(-) diff --git a/core/src/main/java/com/opensymphony/xwork2/ModelDriven.java b/core/src/main/java/com/opensymphony/xwork2/ModelDriven.java index 59641a997..fc7f9a348 100644 --- a/core/src/main/java/com/opensymphony/xwork2/ModelDriven.java +++ b/core/src/main/java/com/opensymphony/xwork2/ModelDriven.java @@ -30,10 +30,13 @@ public interface ModelDriven { /** * Gets the model to be pushed onto the ValueStack instead of the Action itself. + * + * Please be aware that all setters and getters of every depth on the object returned by this method are available + * for user parameter injection! * * @return the model */ -@StrutsParameter +@StrutsParameter(depth = Integer.MAX_VALUE) T getModel(); } diff --git a/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java index 5d1010a0b..67e0d9142 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java @@ -259,19 +259,19 @@ public class ParametersInterceptor extends MethodFilterInterceptor { protected ValueStack toNewStack(ValueStack stack) { ValueStack newStack = valueStackFactory.createValueStack(stack); -if (newStack instanceof ClearableValueStack) { -((ClearableValueStack) newStack).clearContextValues(); +if (newStack instanceof ClearableValueStack clearable) { +clearable.clearContextValues(); newStack.getActionContext().withLocale(stack.getActionContext().getLocale()).withValueStack(stack); } return newStack; } protected void applyMemberAccessProperties(ValueStack stack) { -if (!(stack instanceof MemberAccessValueStack)) { +if (!(stack instanceof MemberAccessValueStack accessValueStack)) { return; } -((MemberAccessValueStack) stack).useAcceptProperties(acceptedPatterns.getAcceptedPatterns()); -((MemberAccessValueStack) stack).useExcludeProperties(excludedPatterns.getExcludedPatterns()); + accessValueStack.useAcceptProperties(acceptedPatterns.getAcceptedPatterns()); + accessValueStack.useExcludeProperties(excludedPatterns.getExcludedPatterns()); } protected Map toAcceptableParameters(HttpParameters parameters, Object action) { @@ -333,7 +333,7 @@ public class ParametersInterceptor extends MethodFilterInterceptor { } protected boolean isAcceptableParameterNameAware(String name, Object action) { -return !(action instanceof ParameterNameAware) || ((ParameterNameAware) action).acceptableParameterName(name); +return !(action instanceof ParameterNameAware nameAware) || nameAware.acceptableParameterName(name); } /** @@ -349,7 +349,15 @@ public class ParametersInterceptor extends MethodFilterInterceptor { } long paramDepth = name.codePoints().mapToObj(c -> (char) c).filter(NESTING_CHARS::contains).count(); -if (!isModelDriven(action) && requireAnnotationsTransitionMode && paramDepth == 0) { + +if (action instanceof ModelDriven && !ActionContext.getContext().getValueStack().peek().equals(action)) { +LOG.debug("Model driven Action detected, exempting from @StrutsParameter annotation requirement and OGNL allowlisting model type"); +// (Exempted by annotation on com.opensymphony.xwork2.ModelDriven#getModel) +return hasValidAnnotatedMember("model", action, paramDepth + 1); +} + +if (requireAnnotationsTransitionMode && paramDepth == 0) { +LOG.debug("Annotation transition mode enabled, exempting non-nested parameter [{}] from @StrutsParameter annotation requirement", name); return true; } @@ -366,39 +374,34 @@ public class ParametersInterceptor extends MethodFilterInterceptor { * save computation by checking this last. */ protected boolean hasValidAnnotatedMember(String rootProperty, Object action, long paramDepth) { -final String property = isModelDriven(action) ? "model" : rootProperty; -LOG.debug("Using [{}] as a root property of [{}]", property, action
(struts) 02/02: WW-5468 Remove unneeded annotations
This is an automated email from the ASF dual-hosted git repository. kusal pushed a commit to branch fix/WW-5468-modeldriven-2 in repository https://gitbox.apache.org/repos/asf/struts.git commit 10f47305b10f2f033d1d8c1c1001e118a1bf2d69 Author: Kusal Kithul-Godage AuthorDate: Sat Oct 12 22:52:53 2024 +1100 WW-5468 Remove unneeded annotations --- core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java| 1 - .../java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java| 1 - .../opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java | 2 +- .../test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java | 2 -- .../com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java | 2 -- .../opensymphony/xwork2/validator/VisitorValidatorModelAction.java | 2 -- .../org/apache/struts/beanvalidation/actions/ModelDrivenAction.java | 5 + .../apache/struts/beanvalidation/actions/ValidateGroupAction.java| 5 + .../test/java/org/apache/struts2/rest/RestActionInvocationTest.java | 2 -- .../src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java | 1 - 10 files changed, 3 insertions(+), 20 deletions(-) diff --git a/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java b/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java index 6ffcad2ff..0e04af38c 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAction.java @@ -44,7 +44,6 @@ public class ModelDrivenAction extends ActionSupport implements ModelDriven { /** * @return the model to be pushed onto the ValueStack after the Action itself */ -@StrutsParameter(depth = 2) @Override public Object getModel() { return model; diff --git a/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java b/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java index 5549b60b1..d52ead805 100644 --- a/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java +++ b/core/src/test/java/com/opensymphony/xwork2/ModelDrivenAnnotationAction.java @@ -44,7 +44,6 @@ public class ModelDrivenAnnotationAction extends ActionSupport implements ModelD /** * @return the model to be pushed onto the ValueStack after the Action itself */ -@StrutsParameter(depth = 2) @Override public Object getModel() { return model; diff --git a/core/src/test/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java b/core/src/test/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java index 65b21c86d..f6513f5f2 100644 --- a/core/src/test/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java +++ b/core/src/test/java/com/opensymphony/xwork2/interceptor/ModelDrivenInterceptorTest.java @@ -178,7 +178,7 @@ public class ModelDrivenInterceptorTest extends XWorkTestCase { } -public class ModelDrivenAction extends ActionSupport implements ModelDriven { +public class ModelDrivenAction extends ActionSupport implements ModelDriven { @Override public Object getModel() { diff --git a/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java b/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java index 0c445860b..b25b83090 100644 --- a/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java +++ b/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAction2.java @@ -19,7 +19,6 @@ package com.opensymphony.xwork2.test; import com.opensymphony.xwork2.ModelDrivenAction; -import org.apache.struts2.interceptor.parameter.StrutsParameter; /** @@ -35,7 +34,6 @@ public class ModelDrivenAction2 extends ModelDrivenAction { /** * @return the model to be pushed onto the ValueStack after the Action itself */ -@StrutsParameter(depth = 3) @Override public Object getModel() { return model; diff --git a/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java b/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java index 7c26dcfab..44aaa7280 100644 --- a/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java +++ b/core/src/test/java/com/opensymphony/xwork2/test/ModelDrivenAnnotationAction2.java @@ -19,7 +19,6 @@ package com.opensymphony.xwork2.test; import com.opensymphony.xwork2.ModelDrivenAnnotationAction; -import org.apache.struts2.interceptor.parameter.StrutsParameter; /** @@ -36,7 +35,6 @@ public class ModelDrivenAnnotationAction2 extends ModelDrivenAnnotationAction { /** * @return the model to be pushed onto the ValueStack after the Action itself */ -@StrutsParameter(depth = 3) @Override public Object getModel() { return model; diff --git a/core/src/test/java/com/opensymphony/xwork2/validator/Vis