diff --git a/core/src/main/resources/struts-default.xml b/core/src/main/resources/struts-default.xml index a83bcc09c..6fafc5bec 100644 --- a/core/src/main/resources/struts-default.xml +++ b/core/src/main/resources/struts-default.xml @@ -39,14 +39,25 @@ + value=" + java.lang.Object, + java.lang.Runtime, + java.lang.System, + java.lang.Class, + java.lang.ClassLoader, + java.lang.Shutdown, + ognl.OgnlContext, + ognl.MemberAccess, + ognl.ClassResolver, + ognl.TypeConverter, + com.opensymphony.xwork2.ActionContext" /> - + diff --git a/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/SecurityMemberAccessTest.java b/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/SecurityMemberAccessTest.java index 778f9193c..6bc6354df 100644 --- a/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/SecurityMemberAccessTest.java +++ b/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/SecurityMemberAccessTest.java @@ -1,9 +1,11 @@ package com.opensymphony.xwork2.ognl; +import com.opensymphony.xwork2.util.TextParseUtil; import junit.framework.TestCase; import java.lang.reflect.Member; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -306,6 +308,7 @@ public class SecurityMemberAccessTest extends TestCase { public void testAccessPrimitiveInt() throws Exception { // given SecurityMemberAccess sma = new SecurityMemberAccess(false); + sma.setExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("java.lang.,ognl,javax")); String propertyName = "intField"; Member member = FooBar.class.getMethod("get" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1)); @@ -317,6 +320,74 @@ public class SecurityMemberAccessTest extends TestCase { assertTrue(accessible); } + public void testAccessPrimitiveDoubleWithNames() throws Exception { + // given + SecurityMemberAccess sma = new SecurityMemberAccess(false); + sma.setExcludedPackageNames(TextParseUtil.commaDelimitedStringToSet("java.lang.,ognl,javax")); + + + Set> excluded = new HashSet>(); + excluded.add(Object.class); + excluded.add(Runtime.class); + excluded.add(System.class); + excluded.add(Class.class); + excluded.add(ClassLoader.class); + sma.setExcludedClasses(excluded); + + String propertyName = "doubleValue"; + Member member = Double.class.getMethod(propertyName); + + // when + boolean accessible = sma.isAccessible(context, target, member, propertyName); + // then + assertTrue(accessible); + + // given + propertyName = "exit"; + member = System.class.getMethod(propertyName, int.class); + + // when + accessible = sma.isAccessible(context, target, member, propertyName); + + // then + assertFalse(accessible); + + // given + propertyName = "intField"; + member = FooBar.class.getMethod("get" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1)); + + // when + accessible = sma.isAccessible(context, target, member, propertyName); + // then + assertTrue(accessible); + + // given + propertyName = "doubleField"; + member = FooBar.class.getMethod("get" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1)); + + // when + accessible = sma.isAccessible(context, target, member, propertyName); + // then + assertTrue(accessible); + } + + public void testAccessPrimitiveDoubleWithPackageRegExs() throws Exception { + // given + SecurityMemberAccess sma = new SecurityMemberAccess(false); + Set patterns = new HashSet(); + patterns.add(Pattern.compile("^java\\.lang\\..*")); + sma.setExcludedPackageNamePatterns(patterns); + + String propertyName = "doubleValue"; + Member member = Double.class.getMethod(propertyName); + + // when + boolean accessible = sma.isAccessible(context, target, member, propertyName); + + // then + assertTrue(accessible); + } + } class FooBar implements FooBarInterface { @@ -325,6 +396,8 @@ class FooBar implements FooBarInterface { private int intField; + private Double doubleField; + public String getStringField() { return stringField; } @@ -353,6 +426,14 @@ class FooBar implements FooBarInterface { public void setIntField(int intField) { this.intField = intField; } + + public Double getDoubleField() { + return doubleField; + } + + public void setDoubleField(Double doubleField) { + this.doubleField = doubleField; + } } interface FooInterface {