本文整理汇总了Java中java.security.SecureClassLoader类的典型用法代码示例。如果您正苦于以下问题:Java SecureClassLoader类的具体用法?Java SecureClassLoader怎么用?Java SecureClassLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SecureClassLoader类属于java.security包,在下文中一共展示了SecureClassLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClassLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
/**
* Will be used by us to get the class loader for our
* compiled class. It creates an anonymous class
* extending the SecureClassLoader which uses the
* byte code created by the compiler and stored in
* the JavaClassObject, and returns the Class for it
*/
@Override
public ClassLoader getClassLoader(Location location) {
return new SecureClassLoader() {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
byte[] b = jclassObject.getBytes();
URL url = null;
try {
url = new URL("file://" + DynaCompTest.PADDLES_CODESOURCE);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
return super.defineClass(name, jclassObject.getBytes(), 0, b.length, new CodeSource(url, new Certificate[0]));
}
};
}
示例2: getClassLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
@Override
public ClassLoader getClassLoader(Location location) {
return new SecureClassLoader() {
@Override
protected Class<?> findClass(String name)
throws ClassNotFoundException {
byte[] bytes = classObject.getBytes();
return super.defineClass(name, bytes, 0,
bytes.length);
}
};
}
示例3: getClassLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
@Override
public ClassLoader getClassLoader(Location location) {
return new SecureClassLoader() {
@Override
protected Class<?> findClass(String name)
throws ClassNotFoundException {
byte[] b = jclassObject.getBytes();
return super.defineClass(name, jclassObject
.getBytes(), 0, b.length);
}
};
}
示例4: getClassLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
/**
* Will be used by us to get the class loader for our
* compiled class. It creates an anonymous class
* extending the SecureClassLoader which uses the
* byte code created by the compiler and stored in
* the RAMClassFile, and returns the Class for it
*/
@Override
public ClassLoader getClassLoader(Location location) {
return new SecureClassLoader() {
@Override
protected Class<?> findClass(String name)
throws ClassNotFoundException {
byte[] b = contents.get(name).getBytes();
return super.defineClass(name, b, 0, b.length);
}
};
}
示例5: getClassLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
@Override
public ClassLoader getClassLoader(Location location) {
return new SecureClassLoader() {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
byte[] b = objects.get(name).getBytes();
return super.defineClass(name, objects.get(name).getBytes(), 0, b.length);
}
};
}
示例6: getClassLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
public ClassLoader getClassLoader(final Location location)
{
return new SecureClassLoader()
{
protected Class<?> findClass(final String name)
{
final byte[] buffer = classObjectByNameMap.get(name).getBytes();
return super.defineClass(name, buffer, 0, buffer.length);
}
};
}
示例7: getClassLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
/**
* Will be used by us to get the class loader for our compiled class. It
* creates an anonymous class extending the SecureClassLoader which uses the
* byte code created by the compiler and stored in the JavaClassObject, and
* returns the Class for it
*
* @param location
* @return
*/
@Override
public ClassLoader getClassLoader(Location location) {
return new SecureClassLoader() {
@Override
protected Class<?> findClass(String name)
throws ClassNotFoundException {
byte[] b = jclassObject.getBytes();
return super.defineClass(name, jclassObject
.getBytes(), 0, b.length);
}
};
}
示例8: getClassLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
/**
* Will be used by us to get the class loader for our compiled class. It
* creates an anonymous class extending the SecureClassLoader which uses the
* byte code created by the compiler and stored in the JavaClassObject, and
* returns the Class for it
*
* @param location the location
* @return the class loader
*/
@Override
public ClassLoader getClassLoader(Location location) {
return new SecureClassLoader() {
@Override
protected Class<?> findClass(String name)
throws ClassNotFoundException {
byte[] b = jclassObject.getBytes();
return super.defineClass(name, jclassObject.getBytes(), 0,
b.length);
}
};
}
示例9: getClassLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
@Override
public ClassLoader getClassLoader(Location location) {
return new SecureClassLoader() {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
byte[] b = jclassObject.getBytes();
return super.defineClass(name, jclassObject.getBytes(), 0, b.length);
}
};
}
示例10: getClassLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
/**
* Will be used by us to get the class loader for our compiled class. It
* creates an anonymous class extending the SecureClassLoader which uses
* the byte code created by the compiler and stored in the
* JavaClassObject, and returns the Class for it
*/
@Override
public ClassLoader getClassLoader(Location location) {
return new SecureClassLoader() {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
byte[] b = jclassObject.getBytes();
return super.defineClass(name, jclassObject.getBytes(), 0, b.length);
}
};
}
示例11: getClassLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
/**
* Will be used by us to get the class loader for our
* compiled class. It creates an anonymous class
* extending the SecureClassLoader which uses the
* byte code created by the compiler and stored in
* the JavaClassObject, and returns the Class for it
*/
@Override
public ClassLoader getClassLoader(Location location) {
return new SecureClassLoader() {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
byte[] b = jclassObject.getBytes();
return super.defineClass(name, jclassObject.getBytes(), 0, b.length);
}
};
}
示例12: getClassLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
@Override
public ClassLoader getClassLoader(Location location) {
return new SecureClassLoader() {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
byte[] b = javaFileObject.getBytes();
if (b != null && b.length > 0) {
return super.defineClass(name, javaFileObject.getBytes(), 0, b.length);
} else {
return super.findClass(name);
}
}
};
}
示例13: createNoPermissionsInvoker
import java.security.SecureClassLoader; //导入依赖的package包/类
private static MethodHandle createNoPermissionsInvoker() {
final String className = "NoPermissionsInvoker";
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null);
final Type objectType = Type.getType(Object.class);
final Type methodHandleType = Type.getType(MethodHandle.class);
final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke",
Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null));
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor(
Type.VOID_TYPE, objectType), false);
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
cw.visitEnd();
final byte[] bytes = cw.toByteArray();
final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
@Override
public ClassLoader run() {
return new SecureClassLoader(null) {
@Override
protected Class<?> findClass(final String name) throws ClassNotFoundException {
if(name.equals(className)) {
return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(
new CodeSource(null, (CodeSigner[])null), new Permissions()));
}
throw new ClassNotFoundException(name);
}
};
}
});
try {
return MethodHandles.lookup().findStatic(Class.forName(className, true, loader), "invoke",
MethodType.methodType(void.class, MethodHandle.class, Object.class));
} catch(final ReflectiveOperationException e) {
throw new AssertionError(e.getMessage(), e);
}
}
示例14: TestLoader
import java.security.SecureClassLoader; //导入依赖的package包/类
protected TestLoader() throws Exception {
Constructor<?> ctor = SecureClassLoader.class.getDeclaredConstructor();
assertFalse(ctor.canAccess(null));
assertFalse(ctor.trySetAccessible());
}
示例15: createNoPermissionsInvoker
import java.security.SecureClassLoader; //导入依赖的package包/类
private static MethodHandle createNoPermissionsInvoker() {
final String className = "NoPermissionsInvoker";
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, className, null, "java/lang/Object", null);
final Type objectType = Type.getType(Object.class);
final Type methodHandleType = Type.getType(MethodHandle.class);
final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "invoke",
Type.getMethodDescriptor(Type.VOID_TYPE, methodHandleType, objectType), null, null));
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.invokevirtual(methodHandleType.getInternalName(), "invokeExact", Type.getMethodDescriptor(
Type.VOID_TYPE, objectType), false);
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
cw.visitEnd();
final byte[] bytes = cw.toByteArray();
final ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
@Override
public ClassLoader run() {
return new SecureClassLoader(null) {
@Override
protected Class<?> findClass(final String name) throws ClassNotFoundException {
if(name.equals(className)) {
return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(
new CodeSource(null, (CodeSigner[])null), new Permissions()));
}
throw new ClassNotFoundException(name);
}
};
}
});
try {
return MethodHandles.publicLookup().findStatic(Class.forName(className, true, loader), "invoke",
MethodType.methodType(void.class, MethodHandle.class, Object.class));
} catch(final ReflectiveOperationException e) {
throw new AssertionError(e.getMessage(), e);
}
}