Java 类java.security.SecureClassLoader 实例源码

项目:robopong    文件:ClassFileManager.java   
/**
 * 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]));
        }
    };
}
项目:ThriftyPaxos    文件:SourceCompiler.java   
@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);
        }
    };
}
项目:linden    文件:ClassFileManager.java   
@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);
    }
  };
}
项目:JavaJail    文件:RAMClassFileManager.java   
/**
 * 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);
       }
        };
}
项目:builderator    文件:TestCompiler.java   
@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);
        }
    };
}
项目:agrona    文件:ClassFileManager.java   
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);
        }
    };
}
项目:jpexs-decompiler    文件:ClassFileManager.java   
/**
 * 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);
        }
    };
}
项目:nocket    文件:ClassFileManager.java   
/**
 * 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);
        }
    };
}
项目:mechaverse    文件:JavaCompilerUtil.java   
@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);
    }
  };
}
项目:logging    文件:AbstractFoundationLoggingMarker.java   
/**
 * 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);
        }
    };
}
项目:java_jail    文件:RAMClassFileManager.java   
/**
 * 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);
       }
        };
}
项目:syntax-parser    文件:ClassFileManager.java   
/**
 * 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);
        }
    };
}
项目:elasticsearch-lang-java    文件:MemoryJavaFileManager.java   
@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);
            }
        }
    };
}
项目:OpenJSharp    文件:JavaAdapterServices.java   
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);
    }
}
项目:openjdk-jdk10    文件:CanAccessTest.java   
protected TestLoader() throws Exception {
    Constructor<?> ctor = SecureClassLoader.class.getDeclaredConstructor();
    assertFalse(ctor.canAccess(null));
    assertFalse(ctor.trySetAccessible());
}
项目:openjdk-jdk10    文件:JavaAdapterServices.java   
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);
    }
}
项目:openjdk9    文件:JavaAdapterServices.java   
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);
    }
}
项目:kaziranga    文件:JavaAdapterServices.java   
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);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:JavaAdapterServices.java   
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);
    }
}
项目:jdk8u_nashorn    文件:JavaAdapterServices.java   
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);
    }
}
项目:infobip-open-jdk-8    文件:JavaAdapterServices.java   
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);
    }
}
项目:OLD-OpenJDK8    文件:JavaAdapterServices.java   
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(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(ReflectiveOperationException e) {
        throw new AssertionError(e.getMessage(), e);
    }
}