當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。