Skip to content

Commit

Permalink
Extends exclusion list
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Jul 31, 2023
1 parent 2533d31 commit ce40157
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private Set<Class<?>> parseClasses(String commaDelimitedClasses) {
try {
classes.add(Class.forName(className));
} catch (ClassNotFoundException e) {
LOG.warn("Class: {} doesn't exist, ignoring it!", className);
throw new ConfigurationException("Cannot load class for exclusion/exemption configuration: " + className, e);
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/resources/struts-excluded-classes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
java.lang.Thread,
sun.misc.Unsafe,
com.opensymphony.xwork2.ActionContext,
org.apache.commons.collections.BeanMap,
org.apache.commons.beanutils.BeanMap"/>
com.opensymphony.xwork2.ognl.SecurityMemberAccess,
com.opensymphony.xwork2.ognl.OgnlValueStack"/>

<constant name="struts.devMode.excludedClasses"
value="
Expand Down
37 changes: 32 additions & 5 deletions core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.location.LocatableProperties;
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
import java.beans.BeanInfo;
import ognl.InappropriateExpressionException;
import ognl.MethodFailedException;
import ognl.NoSuchPropertyException;
Expand All @@ -48,6 +47,7 @@
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.StrutsException;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.lang.reflect.Method;
import java.text.DateFormat;
Expand Down Expand Up @@ -877,6 +877,33 @@ public void testStringToLong() {
assertEquals(123, foo.getALong());
}

public void testBeanMapExpressions() throws OgnlException {
Foo foo = new Foo();
ognlUtil.setExcludedClasses(
"com.opensymphony.xwork2.ognl.SecurityMemberAccess"
);

Map<String, Object> context = ognlUtil.createDefaultContext(foo);

String expression = "%{\n" +
"(#request.a=#@org.apache.commons.collections.BeanMap@{}) +\n" +
"(#request.a.setBean(#request.get('struts.valueStack')) == true) +\n" +
"(#request.b=#@org.apache.commons.collections.BeanMap@{}) +\n" +
"(#request.b.setBean(#request.get('a').get('context'))) +\n" +
"(#request.c=#@org.apache.commons.collections.BeanMap@{}) +\n" +
"(#request.c.setBean(#request.get('b').get('memberAccess'))) +\n" +
"(#request.get('c').put('excluded'+'PackageNames',#@org.apache.commons.collections.BeanMap@{}.keySet())) +\n" +
"(#request.get('c').put('excludedClasses',#@org.apache.commons.collections.BeanMap@{}.keySet()))\n" +
"}";

ognlUtil.setValue("title", context, foo, expression);

assertEquals(foo.getTitle(), expression);

SecurityMemberAccess sma = (SecurityMemberAccess) ((OgnlContext) context).getMemberAccess();
assertTrue(sma.isClassExcluded(SecurityMemberAccess.class));
}

public void testNullProperties() {
Foo foo = new Foo();
foo.setALong(88);
Expand Down Expand Up @@ -1834,19 +1861,19 @@ public void testOgnlDefaultCacheFactoryCoverage() {
defaultOgnlCacheFactory.setUseLRUCache("false");
ognlCache = defaultOgnlCacheFactory.buildOgnlCache();
assertNotNull("No param build method result null ?", ognlCache);
assertEquals("Eviction limit for cache mismatches limit for factory ?", 12, ognlCache.getEvictionLimit() );
assertEquals("Eviction limit for cache mismatches limit for factory ?", 12, ognlCache.getEvictionLimit());
ognlCache = defaultOgnlCacheFactory.buildOgnlCache(6, 6, 0.75f, false);
assertNotNull("No param build method result null ?", ognlCache);
assertEquals("Eviction limit for cache mismatches limit for factory ?", 6, ognlCache.getEvictionLimit() );
assertEquals("Eviction limit for cache mismatches limit for factory ?", 6, ognlCache.getEvictionLimit());
// LRU cache
defaultOgnlCacheFactory.setCacheMaxSize("30");
defaultOgnlCacheFactory.setUseLRUCache("true");
ognlCache = defaultOgnlCacheFactory.buildOgnlCache();
assertNotNull("No param build method result null ?", ognlCache);
assertEquals("Eviction limit for cache mismatches limit for factory ?", 30, ognlCache.getEvictionLimit() );
assertEquals("Eviction limit for cache mismatches limit for factory ?", 30, ognlCache.getEvictionLimit());
ognlCache = defaultOgnlCacheFactory.buildOgnlCache(15, 15, 0.75f, false);
assertNotNull("No param build method result null ?", ognlCache);
assertEquals("Eviction limit for cache mismatches limit for factory ?", 15, ognlCache.getEvictionLimit() );
assertEquals("Eviction limit for cache mismatches limit for factory ?", 15, ognlCache.getEvictionLimit());
}

/**
Expand Down

0 comments on commit ce40157

Please sign in to comment.