You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2025/03/06 10:02:27 UTC

(struts-examples) 01/01: Adjusts config to be compatible with Struts 7 stronger security

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch fix/permission
in repository https://gitbox.apache.org/repos/asf/struts-examples.git

commit 90b7e6f8de37f59c2869b8f88d4afc9325db10b8
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Thu Mar 6 11:02:13 2025 +0100

    Adjusts config to be compatible with Struts 7 stronger security
---
 .../org/apache/struts/edit/action/EditAction.java  | 85 ++++++++++------------
 control-tags/src/main/resources/struts.xml         |  1 +
 2 files changed, 41 insertions(+), 45 deletions(-)

diff --git a/control-tags/src/main/java/org/apache/struts/edit/action/EditAction.java b/control-tags/src/main/java/org/apache/struts/edit/action/EditAction.java
index 1e527b7..ef6f46c 100755
--- a/control-tags/src/main/java/org/apache/struts/edit/action/EditAction.java
+++ b/control-tags/src/main/java/org/apache/struts/edit/action/EditAction.java
@@ -5,6 +5,7 @@ import org.apache.struts.edit.model.State;
 import org.apache.struts.edit.service.EditService;
 import org.apache.struts.edit.service.EditServiceInMemory;
 import org.apache.struts2.ActionSupport;
+import org.apache.struts2.interceptor.parameter.StrutsParameter;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -18,61 +19,55 @@ import java.util.List;
  */
 public class EditAction extends ActionSupport {
 
-	private static final long serialVersionUID = 1L;
+    private EditService editService = new EditServiceInMemory();
 
-	private EditService editService = new EditServiceInMemory();
+    private Person personBean;
+    private String[] sports = {"football", "baseball", "basketball"};
+    private String[] genders = {"male", "female", "not sure"};
+    private List<State> states;
+    private String[] carModelsAvailable = {"Ford", "Chrysler", "Toyota", "Nissan"};
 
-	private Person personBean;
-	private String [] sports = {"football", "baseball", "basketball" };
-	private String [] genders = {"male", "female", "not sure" };
-	private List<State> states ;
-	private String [] carModelsAvailable = {"Ford","Chrysler","Toyota","Nissan"};
+    public String save() throws Exception {
+        editService.savePerson(getPersonBean());
 
-	public String save() throws Exception {
-	    editService.savePerson( getPersonBean() );
+        return SUCCESS;
+    }
 
-		return SUCCESS;
-	}
+    public String input() throws Exception {
+        setPersonBean(editService.getPerson());
 
-	public String input() throws Exception {
-		setPersonBean( editService.getPerson() );
+        return INPUT;
+    }
 
-		return INPUT;
-	}
+    @StrutsParameter(depth = 2)
+    public Person getPersonBean() {
+        return personBean;
+    }
 
-	public Person getPersonBean() {
-		return personBean;
-	}
+    public void setPersonBean(Person person) {
+        personBean = person;
+    }
 
-	public void setPersonBean(Person person) {
-		personBean = person;
-	}
+    public List<String> getSports() {
+        return Arrays.asList(sports);
+    }
 
-	public List<String> getSports() {
-		return Arrays.asList(sports);
-	}
+    public List<String> getGenders() {
+        return Arrays.asList(genders);
+    }
 
-	public List<String> getGenders() {
-		return Arrays.asList(genders);
-	}
+    public List<State> getStates() {
+        states = new ArrayList<>();
+        states.add(new State("AZ", "Arizona"));
+        states.add(new State("CA", "California"));
+        states.add(new State("FL", "Florida"));
+        states.add(new State("KS", "Kansas"));
+        states.add(new State("NY", "New York"));
 
+        return states;
+    }
 
-
-	public List<State> getStates() {
-
-		states = new ArrayList<>();
-		states.add( new State("AZ", "Arizona") );
-		states.add( new State("CA", "California") );
-		states.add( new State("FL", "Florida") );
-		states.add( new State("KS", "Kansas") );
-		states.add( new State("NY", "New York") );
-
-		return states;
-	}
-
-
-
-	public String [] getCarModelsAvailable() {
-		return carModelsAvailable;
-	}
+    public String[] getCarModelsAvailable() {
+        return carModelsAvailable;
+    }
 }
diff --git a/control-tags/src/main/resources/struts.xml b/control-tags/src/main/resources/struts.xml
index 750b70f..3473cb6 100755
--- a/control-tags/src/main/resources/struts.xml
+++ b/control-tags/src/main/resources/struts.xml
@@ -6,6 +6,7 @@
 
     <constant name="struts.devMode" value="true"/>
     <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
+    <constant name="struts.allowlist.packageNames" value="org.apache.struts.edit.model"/>
 
     <package name="basicstruts2" extends="struts-default">
         <default-action-ref name="index"/>