提交 fe9c54b0 authored 作者: Thomas Mueller's avatar Thomas Mueller

The H2 JDBC client can now be used in an unsigned Applet. The problem was that…

The H2 JDBC client can now be used in an unsigned Applet. The problem was that System.getProperty throws a SecurityException, which is now ignored.
上级 c9fd1f55
...@@ -48,29 +48,11 @@ public class Utils { ...@@ -48,29 +48,11 @@ public class Utils {
private static final int MAX_GC = 8; private static final int MAX_GC = 8;
private static long lastGC; private static long lastGC;
private static final boolean ALLOW_ALL_CLASSES;
private static final HashSet<String> ALLOWED_CLASS_NAMES = New.hashSet();
private static final String[] ALLOWED_CLASS_NAME_PREFIXES;
private static final HashMap<String, byte[]> RESOURCES = New.hashMap(); private static final HashMap<String, byte[]> RESOURCES = New.hashMap();
static { private static boolean allowAllClasses;
String s = SysProperties.ALLOWED_CLASSES; private static HashSet<String> allowedClassNames;
ArrayList<String> prefixes = New.arrayList(); private static String[] allowedClassNamePrefixes;
boolean allowAll = false;
for (String p : StringUtils.arraySplit(s, ',', true)) {
if (p.equals("*")) {
allowAll = true;
} else if (p.endsWith("*")) {
prefixes.add(p.substring(0, p.length() - 1));
} else {
ALLOWED_CLASS_NAMES.add(p);
}
}
ALLOW_ALL_CLASSES = allowAll;
ALLOWED_CLASS_NAME_PREFIXES = new String[prefixes.size()];
prefixes.toArray(ALLOWED_CLASS_NAME_PREFIXES);
}
private Utils() { private Utils() {
// utility class // utility class
...@@ -395,9 +377,29 @@ public class Utils { ...@@ -395,9 +377,29 @@ public class Utils {
* @return the class object * @return the class object
*/ */
public static Class<?> loadUserClass(String className) { public static Class<?> loadUserClass(String className) {
if (!ALLOW_ALL_CLASSES && !ALLOWED_CLASS_NAMES.contains(className)) { if (allowedClassNames == null) {
// initialize the static fields
String s = SysProperties.ALLOWED_CLASSES;
ArrayList<String> prefixes = New.arrayList();
boolean allowAll = false;
HashSet<String> classNames = New.hashSet();
for (String p : StringUtils.arraySplit(s, ',', true)) {
if (p.equals("*")) {
allowAll = true;
} else if (p.endsWith("*")) {
prefixes.add(p.substring(0, p.length() - 1));
} else {
classNames.add(p);
}
}
allowedClassNamePrefixes = new String[prefixes.size()];
prefixes.toArray(allowedClassNamePrefixes);
allowAllClasses = allowAll;
allowedClassNames = classNames;
}
if (!allowAllClasses && !allowedClassNames.contains(className)) {
boolean allowed = false; boolean allowed = false;
for (String s : ALLOWED_CLASS_NAME_PREFIXES) { for (String s : allowedClassNamePrefixes) {
if (className.startsWith(s)) { if (className.startsWith(s)) {
allowed = true; allowed = true;
} }
......
...@@ -34,6 +34,8 @@ public class TestClearReferences extends TestBase { ...@@ -34,6 +34,8 @@ public class TestClearReferences extends TestBase {
"org.h2.util.MathUtils.cachedSecureRandom", "org.h2.util.MathUtils.cachedSecureRandom",
"org.h2.util.NetUtils.cachedLocalAddress", "org.h2.util.NetUtils.cachedLocalAddress",
"org.h2.util.StringUtils.softCache", "org.h2.util.StringUtils.softCache",
"org.h2.util.Utils.allowedClassNames",
"org.h2.util.Utils.allowedClassNamePrefixes",
"org.h2.value.CompareMode.lastUsed", "org.h2.value.CompareMode.lastUsed",
"org.h2.value.Value.softCache", "org.h2.value.Value.softCache",
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论