|
18 | 18 | */
|
19 | 19 | package org.apache.struts2.ognl;
|
20 | 20 |
|
| 21 | +import ognl.OgnlException; |
| 22 | +import org.apache.commons.lang3.StringUtils; |
| 23 | +import org.apache.logging.log4j.LogManager; |
| 24 | +import org.apache.logging.log4j.core.LogEvent; |
| 25 | +import org.apache.logging.log4j.core.Logger; |
| 26 | +import org.apache.logging.log4j.core.appender.AbstractAppender; |
21 | 27 | import org.apache.struts2.SimpleAction;
|
| 28 | +import org.apache.struts2.StrutsConstants; |
| 29 | +import org.apache.struts2.StrutsException; |
22 | 30 | import org.apache.struts2.TestBean;
|
23 |
| -import org.apache.struts2.text.TextProvider; |
24 | 31 | import org.apache.struts2.XWorkTestCase;
|
25 | 32 | import org.apache.struts2.config.ConfigurationException;
|
| 33 | +import org.apache.struts2.config.DefaultPropertiesProvider; |
26 | 34 | import org.apache.struts2.conversion.impl.ConversionData;
|
27 | 35 | import org.apache.struts2.conversion.impl.XWorkConverter;
|
28 | 36 | import org.apache.struts2.inject.ContainerBuilder;
|
29 | 37 | import org.apache.struts2.ognl.accessor.RootAccessor;
|
30 | 38 | import org.apache.struts2.test.StubConfigurationProvider;
|
31 | 39 | import org.apache.struts2.test.TestBean2;
|
| 40 | +import org.apache.struts2.text.TextProvider; |
32 | 41 | import org.apache.struts2.util.Bar;
|
33 | 42 | import org.apache.struts2.util.BarJunior;
|
34 | 43 | import org.apache.struts2.util.Cat;
|
|
37 | 46 | import org.apache.struts2.util.ValueStackFactory;
|
38 | 47 | import org.apache.struts2.util.location.LocatableProperties;
|
39 | 48 | import org.apache.struts2.util.reflection.ReflectionContextState;
|
40 |
| -import ognl.OgnlException; |
41 |
| -import org.apache.commons.lang3.StringUtils; |
42 |
| -import org.apache.logging.log4j.LogManager; |
43 |
| -import org.apache.logging.log4j.core.LogEvent; |
44 |
| -import org.apache.logging.log4j.core.Logger; |
45 |
| -import org.apache.logging.log4j.core.appender.AbstractAppender; |
46 |
| -import org.apache.struts2.StrutsConstants; |
47 |
| -import org.apache.struts2.StrutsException; |
48 |
| -import org.apache.struts2.config.DefaultPropertiesProvider; |
49 | 49 |
|
50 | 50 | import java.io.ByteArrayInputStream;
|
51 | 51 | import java.io.ByteArrayOutputStream;
|
@@ -1234,6 +1234,33 @@ public void testOgnlValueStackFromOgnlValueStackFactoryAllStaticAccess() throws
|
1234 | 1234 | assertNull("accessed private field (result not null) ?", accessedValue);
|
1235 | 1235 | }
|
1236 | 1236 |
|
| 1237 | + public void testFindValueWithConstructorAndProxyChecks() { |
| 1238 | + loadButSet(Map.of( |
| 1239 | + StrutsConstants.STRUTS_DISALLOW_PROXY_OBJECT_ACCESS, Boolean.TRUE.toString(), |
| 1240 | + StrutsConstants.STRUTS_DISALLOW_PROXY_MEMBER_ACCESS, Boolean.TRUE.toString())); |
| 1241 | + refreshContainerFields(); |
| 1242 | + |
| 1243 | + String value = "test"; |
| 1244 | + String ognlResult = (String) vs.findValue( |
| 1245 | + "new org.apache.struts2.ognl.OgnlValueStackTest$ValueHolder('" + value + "').value", String.class); |
| 1246 | + |
| 1247 | + assertEquals(value, ognlResult); |
| 1248 | + } |
| 1249 | + |
| 1250 | + @SuppressWarnings({"unused", "ClassCanBeRecord"}) |
| 1251 | + public static class ValueHolder { |
| 1252 | + // See testFindValueWithConstructorAndProxyChecks |
| 1253 | + private final String value; |
| 1254 | + |
| 1255 | + public ValueHolder(String value) { |
| 1256 | + this.value = value; |
| 1257 | + } |
| 1258 | + |
| 1259 | + public String getValue() { |
| 1260 | + return value; |
| 1261 | + } |
| 1262 | + } |
| 1263 | + |
1237 | 1264 | static class BadJavaBean {
|
1238 | 1265 | private int count;
|
1239 | 1266 | private int count2;
|
|
0 commit comments