From f6a07e63e62e13e72cc4ee3a034398b4b30abe03 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Tue, 28 May 2013 20:14:15 +0000 Subject: [PATCH] WW-4083 Extends support of ParametersNameAware to pass the same behaviour to OgnlValueStack git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1487092 13f79535-47bb-0310-9956-ffa450edef68 --- .../interceptor/ParametersInterceptor.java | 24 ++++++++----------- .../xwork2/ognl/OgnlValueStack.java | 10 ++++---- .../xwork2/ognl/PropertiesJudge.java | 7 ++++++ .../xwork2/ognl/SecurityMemberAccess.java | 11 ++++++--- .../xwork2/util/MemberAccessValueStack.java | 6 +++++ 5 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 xwork-core/src/main/java/com/opensymphony/xwork2/ognl/PropertiesJudge.java diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java b/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java index de99148d1..795a82880 100644 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/interceptor/ParametersInterceptor.java @@ -22,23 +22,13 @@ import com.opensymphony.xwork2.XWorkConstants; import com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler; import com.opensymphony.xwork2.conversion.impl.XWorkConverter; import com.opensymphony.xwork2.inject.Inject; -import com.opensymphony.xwork2.util.ArrayUtils; -import com.opensymphony.xwork2.util.ClearableValueStack; -import com.opensymphony.xwork2.util.LocalizedTextUtil; -import com.opensymphony.xwork2.util.MemberAccessValueStack; -import com.opensymphony.xwork2.util.ValueStack; -import com.opensymphony.xwork2.util.ValueStackFactory; +import com.opensymphony.xwork2.ognl.PropertiesJudge; +import com.opensymphony.xwork2.util.*; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; import com.opensymphony.xwork2.util.reflection.ReflectionContextState; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -272,7 +262,7 @@ public class ParametersInterceptor extends MethodFilterInterceptor { protected void addParametersToContext(ActionContext ac, Map newParams) { } - protected void setParameters(Object action, ValueStack stack, final Map parameters) { + protected void setParameters(final Object action, ValueStack stack, final Map parameters) { Map params; Map acceptableParameters; if (ordered) { @@ -313,6 +303,12 @@ public class ParametersInterceptor extends MethodFilterInterceptor { MemberAccessValueStack accessValueStack = (MemberAccessValueStack) newStack; accessValueStack.setAcceptProperties(acceptParams); accessValueStack.setExcludeProperties(excludeParams); + if (action instanceof ParameterNameAware) + accessValueStack.setPropertiesJudge(new PropertiesJudge() { + public boolean acceptProperty(String propertyName) { + return ((ParameterNameAware) action).acceptableParameterName(propertyName); + } + }); } for (Map.Entry entry : acceptableParameters.entrySet()) { diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java index aafccc2cb..10082293b 100644 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java @@ -31,11 +31,7 @@ import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; import com.opensymphony.xwork2.util.logging.LoggerUtils; import com.opensymphony.xwork2.util.reflection.ReflectionContextState; -import ognl.NoSuchPropertyException; -import ognl.Ognl; -import ognl.OgnlContext; -import ognl.OgnlException; -import ognl.PropertyAccessor; +import ognl.*; import java.io.Serializable; import java.util.HashMap; @@ -463,6 +459,10 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS securityMemberAccess.setAcceptProperties(acceptedProperties); } + public void setPropertiesJudge(PropertiesJudge judge) { + securityMemberAccess.setPropertiesJudge(judge); + } + public void setExcludeProperties(Set excludeProperties) { securityMemberAccess.setExcludeProperties(excludeProperties); } diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/PropertiesJudge.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/PropertiesJudge.java new file mode 100644 index 000000000..ed27c0f42 --- /dev/null +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/PropertiesJudge.java @@ -0,0 +1,7 @@ +package com.opensymphony.xwork2.ognl; + +public interface PropertiesJudge { + + boolean acceptProperty(String propertyName); + +} diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java index 0056bfe3a..8b27df2a1 100644 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/SecurityMemberAccess.java @@ -33,8 +33,9 @@ import java.util.regex.Pattern; public class SecurityMemberAccess extends DefaultMemberAccess { private final boolean allowStaticMethodAccess; - Set excludeProperties = Collections.emptySet(); - Set acceptProperties = Collections.emptySet(); + private Set excludeProperties = Collections.emptySet(); + private Set acceptProperties = Collections.emptySet(); + private PropertiesJudge propertiesJudge; public SecurityMemberAccess(boolean method) { super(false); @@ -79,7 +80,7 @@ public class SecurityMemberAccess extends DefaultMemberAccess { return true; } - if (isAccepted(name) && !isExcluded(name)) { + if ((isAccepted(name) && !isExcluded(name)) || (propertiesJudge != null && propertiesJudge.acceptProperty(name))) { return true; } return false; @@ -121,4 +122,8 @@ public class SecurityMemberAccess extends DefaultMemberAccess { public void setAcceptProperties(Set acceptedProperties) { this.acceptProperties = acceptedProperties; } + + public void setPropertiesJudge(PropertiesJudge judge) { + this.propertiesJudge = judge; + } } diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/util/MemberAccessValueStack.java b/xwork-core/src/main/java/com/opensymphony/xwork2/util/MemberAccessValueStack.java index 369676fa6..210d67ff9 100644 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/util/MemberAccessValueStack.java +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/util/MemberAccessValueStack.java @@ -1,5 +1,7 @@ package com.opensymphony.xwork2.util; +import com.opensymphony.xwork2.ognl.PropertiesJudge; + import java.util.Set; import java.util.regex.Pattern; @@ -8,7 +10,11 @@ import java.util.regex.Pattern; * to properties using regular expressions */ public interface MemberAccessValueStack { + void setExcludeProperties(Set excludeProperties); void setAcceptProperties(Set acceptedProperties); + + void setPropertiesJudge(PropertiesJudge judge); + }