当前位置: 首页>>代码示例>>Java>>正文


Java SecureClassLoader类代码示例

本文整理汇总了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]));
        }
    };
}
 
开发者ID:eriklarko,项目名称:robopong,代码行数:24,代码来源:ClassFileManager.java

示例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);
        }
    };
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:13,代码来源:SourceCompiler.java

示例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);
    }
  };
}
 
开发者ID:XiaoMi,项目名称:linden,代码行数:13,代码来源:ClassFileManager.java

示例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);
       }
        };
}
 
开发者ID:elimirks,项目名称:JavaJail,代码行数:19,代码来源:RAMClassFileManager.java

示例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);
        }
    };
}
 
开发者ID:josketres,项目名称:builderator,代码行数:11,代码来源:TestCompiler.java

示例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);
        }
    };
}
 
开发者ID:real-logic,项目名称:agrona,代码行数:12,代码来源:ClassFileManager.java

示例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);
        }
    };
}
 
开发者ID:jindrapetrik,项目名称:jpexs-decompiler,代码行数:22,代码来源:ClassFileManager.java

示例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);
        }
    };
}
 
开发者ID:Nocket,项目名称:nocket,代码行数:22,代码来源:ClassFileManager.java

示例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);
    }
  };
}
 
开发者ID:thorntonv,项目名称:mechaverse,代码行数:11,代码来源:JavaCompilerUtil.java

示例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);
		}
	};
}
 
开发者ID:foundation-runtime,项目名称:logging,代码行数:17,代码来源:AbstractFoundationLoggingMarker.java

示例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);
        }
    };
}
 
开发者ID:moilioncircle,项目名称:syntax-parser,代码行数:19,代码来源:ClassFileManager.java

示例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);
			}
		}
	};
}
 
开发者ID:btiernay,项目名称:elasticsearch-lang-java,代码行数:15,代码来源:MemoryJavaFileManager.java

示例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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:44,代码来源:JavaAdapterServices.java

示例14: TestLoader

import java.security.SecureClassLoader; //导入依赖的package包/类
protected TestLoader() throws Exception {
    Constructor<?> ctor = SecureClassLoader.class.getDeclaredConstructor();
    assertFalse(ctor.canAccess(null));
    assertFalse(ctor.trySetAccessible());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:CanAccessTest.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:44,代码来源:JavaAdapterServices.java


注:本文中的java.security.SecureClassLoader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。