move OpenJDK.getProtectionDomain into Classes.java

This way, apps can access the CodeSource of a class whether they're
using the OpenJDK class library or the Avian one.
This commit is contained in:
Joel Dice 2014-02-26 13:39:05 -07:00
parent d95a8a9626
commit 0c298eb513
5 changed files with 26 additions and 56 deletions

View File

@ -13,6 +13,13 @@ package avian;
import static avian.Stream.read1;
import static avian.Stream.read2;
import java.net.URL;
import java.net.MalformedURLException;
import java.security.CodeSource;
import java.security.AllPermission;
import java.security.Permissions;
import java.security.ProtectionDomain;
import java.security.cert.Certificate;
import java.lang.reflect.Modifier;
import java.lang.reflect.Method;
import java.lang.reflect.Field;
@ -513,6 +520,22 @@ public class Classes {
public static Method makeMethod(VMMethod m) {
return makeMethod(SystemClassLoader.getClass(m.class_), index(m));
}
public static ProtectionDomain getProtectionDomain(VMClass c) {
CodeSource source = null;
if (c.source != null) {
try {
source = new CodeSource
(new URL(new String(c.source, 0, c.source.length - 1)),
(Certificate[]) null);
} catch (MalformedURLException ignored) { }
}
Permissions p = new Permissions();
p.add(new AllPermission());
return new ProtectionDomain(source, p);
}
public static native Method makeMethod(Class c, int slot);

View File

@ -1,48 +0,0 @@
/* Copyright (c) 2008-2013, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package avian;
import java.net.URL;
import java.net.MalformedURLException;
import java.security.CodeSource;
import java.security.AllPermission;
import java.security.Permissions;
import java.security.ProtectionDomain;
import java.security.cert.Certificate;
public class OpenJDK {
public static ProtectionDomain getProtectionDomain(VMClass c) {
CodeSource source = null;
if (c.source != null) {
try {
source = new CodeSource
(new URL(new String(c.source, 0, c.source.length - 1)),
(Certificate[]) null);
} catch (MalformedURLException ignored) { }
}
Permissions p = new Permissions();
p.add(new AllPermission());
return new ProtectionDomain(source, p);
}
private static byte[] replace(int a, int b, byte[] s, int offset,
int length)
{
byte[] array = new byte[length];
for (int i = 0; i < length; ++i) {
byte c = s[i];
array[i] = (byte) (c == a ? b : c);
}
return array;
}
}

View File

@ -596,8 +596,6 @@ public final class Class <T> implements Type, AnnotatedElement {
}
public ProtectionDomain getProtectionDomain() {
Permissions p = new Permissions();
p.add(new AllPermission());
return new ProtectionDomain(null, p);
return Classes.getProtectionDomain(vmClass);
}
}

View File

@ -1356,10 +1356,7 @@ ifneq ($(classpath),avian)
$(classpath-src)/avian/VMMethod.java \
$(classpath-src)/avian/avianvmresource/Handler.java
ifneq ($(openjdk),)
classpath-sources := $(classpath-sources) \
$(classpath-src)/avian/OpenJDK.java
else
ifeq ($(openjdk),)
classpath-sources := $(classpath-sources) \
$(classpath-src)/sun/reflect/ConstantPool.java \
$(classpath-src)/java/lang/ReflectiveOperationException.java \

View File

@ -4092,7 +4092,7 @@ jvmGetProtectionDomain(Thread* t, uintptr_t* arguments)
jclass c = reinterpret_cast<jclass>(arguments[0]);
object method = resolveMethod
(t, root(t, Machine::BootLoader), "avian/OpenJDK", "getProtectionDomain",
(t, root(t, Machine::BootLoader), "avian/Classes", "getProtectionDomain",
"(Lavian/VMClass;)Ljava/security/ProtectionDomain;");
return reinterpret_cast<uint64_t>