本文整理汇总了Java中java.security.ProtectionDomain.getClassLoader方法的典型用法代码示例。如果您正苦于以下问题:Java ProtectionDomain.getClassLoader方法的具体用法?Java ProtectionDomain.getClassLoader怎么用?Java ProtectionDomain.getClassLoader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.ProtectionDomain
的用法示例。
在下文中一共展示了ProtectionDomain.getClassLoader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cleanProtectionDomainWhichCameFromModuleClassLoader
import java.security.ProtectionDomain; //导入方法依赖的package包/类
/**
* 清理来自URLClassLoader.acc.ProtectionDomain[]中,来自上一个ModuleClassLoader的ProtectionDomain
* 这样写好蛋疼,而且还有不兼容的风险,从JDK6+都必须要这样清理,但我找不出更好的办法。
* 在重置沙箱时,遇到MgrModule模块无法正确卸载类的情况,主要的原因是在于URLClassLoader.acc.ProtectionDomain[]中包含了上一个ModuleClassLoader的引用
* 所以必须要在这里清理掉,否则随着重置次数的增加,类会越累积越多
*/
private void cleanProtectionDomainWhichCameFromModuleClassLoader() {
// got ProtectionDomain[] from URLClassLoader's acc
final AccessControlContext acc = unCaughtGetClassDeclaredJavaFieldValue(URLClassLoader.class, "acc", this);
final ProtectionDomain[] protectionDomainArray = unCaughtInvokeMethod(
unCaughtGetClassDeclaredJavaMethod(AccessControlContext.class, "getContext"),
acc
);
// remove ProtectionDomain which loader is ModuleClassLoader
final Set<ProtectionDomain> cleanProtectionDomainSet = new LinkedHashSet<ProtectionDomain>();
if (ArrayUtils.isNotEmpty(protectionDomainArray)) {
for (final ProtectionDomain protectionDomain : protectionDomainArray) {
if (protectionDomain.getClassLoader() == null
|| !StringUtils.equals(ModuleClassLoader.class.getName(), protectionDomain.getClassLoader().getClass().getName())) {
cleanProtectionDomainSet.add(protectionDomain);
}
}
}
// rewrite acc
final AccessControlContext newAcc = new AccessControlContext(cleanProtectionDomainSet.toArray(new ProtectionDomain[]{}));
unCaughtSetClassDeclaredJavaFieldValue(URLClassLoader.class, "acc", this, newAcc);
}
示例2: loadJar
import java.security.ProtectionDomain; //导入方法依赖的package包/类
/**
* Loads specified JAR.
*
* @param jarFileInfo
* @throws IOException
*/
private void loadJar(JarFileInfo jarFileInfo) throws IOException {
lstJarFile.add(jarFileInfo);
try {
Enumeration<JarEntry> en = jarFileInfo.jarFile.entries();
final String EXT_JAR = ".jar";
while (en.hasMoreElements()) {
JarEntry je = en.nextElement();
if (je.isDirectory()) {
continue;
}
String s = je.getName().toLowerCase(); // JarEntry name
if (s.lastIndexOf(EXT_JAR) == s.length() - EXT_JAR.length()) {
JarEntryInfo inf = new JarEntryInfo(jarFileInfo, je);
File fileTemp = createTempFile(inf);
logInfo(LogArea.JAR, "Loading inner JAR %s from temp file %s",
inf.jarEntry, getFilename4Log(fileTemp));
// Construct ProtectionDomain for this inner JAR:
URL url = fileTemp.toURI().toURL();
ProtectionDomain pdParent = jarFileInfo.pd;
// 'csParent' is never null: top JAR has it, JCL creates it for child JAR:
CodeSource csParent = pdParent.getCodeSource();
Certificate[] certParent = csParent.getCertificates();
CodeSource csChild = (certParent == null ? new CodeSource(url, csParent.getCodeSigners())
: new CodeSource(url, certParent));
ProtectionDomain pdChild = new ProtectionDomain(csChild,
pdParent.getPermissions(), pdParent.getClassLoader(), pdParent.getPrincipals());
loadJar(new JarFileInfo(
new JarFile(fileTemp), inf.getName(), jarFileInfo, pdChild, fileTemp));
}
}
} catch (JarClassLoaderException e) {
throw new RuntimeException(
"ERROR on loading inner JAR: " + e.getMessageAll());
}
}