mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
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
This commit is contained in:
+10
-14
@@ -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<String, Object> newParams) {
|
||||
}
|
||||
|
||||
protected void setParameters(Object action, ValueStack stack, final Map<String, Object> parameters) {
|
||||
protected void setParameters(final Object action, ValueStack stack, final Map<String, Object> parameters) {
|
||||
Map<String, Object> params;
|
||||
Map<String, Object> 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<String, Object> entry : acceptableParameters.entrySet()) {
|
||||
|
||||
@@ -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<Pattern> excludeProperties) {
|
||||
securityMemberAccess.setExcludeProperties(excludeProperties);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.opensymphony.xwork2.ognl;
|
||||
|
||||
public interface PropertiesJudge {
|
||||
|
||||
boolean acceptProperty(String propertyName);
|
||||
|
||||
}
|
||||
@@ -33,8 +33,9 @@ import java.util.regex.Pattern;
|
||||
public class SecurityMemberAccess extends DefaultMemberAccess {
|
||||
|
||||
private final boolean allowStaticMethodAccess;
|
||||
Set<Pattern> excludeProperties = Collections.emptySet();
|
||||
Set<Pattern> acceptProperties = Collections.emptySet();
|
||||
private Set<Pattern> excludeProperties = Collections.emptySet();
|
||||
private Set<Pattern> 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<Pattern> acceptedProperties) {
|
||||
this.acceptProperties = acceptedProperties;
|
||||
}
|
||||
|
||||
public void setPropertiesJudge(PropertiesJudge judge) {
|
||||
this.propertiesJudge = judge;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Pattern> excludeProperties);
|
||||
|
||||
void setAcceptProperties(Set<Pattern> acceptedProperties);
|
||||
|
||||
void setPropertiesJudge(PropertiesJudge judge);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user