當前位置: 首頁>>代碼示例>>Java>>正文


Java CodeSource類代碼示例

本文整理匯總了Java中java.security.CodeSource的典型用法代碼示例。如果您正苦於以下問題:Java CodeSource類的具體用法?Java CodeSource怎麽用?Java CodeSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CodeSource類屬於java.security包,在下文中一共展示了CodeSource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getClasspathForClass

import java.security.CodeSource; //導入依賴的package包/類
public static File getClasspathForClass(Class<?> targetClass) {
    URI location;
    try {
        CodeSource codeSource = targetClass.getProtectionDomain().getCodeSource();
        if (codeSource != null && codeSource.getLocation() != null) {
            location = codeSource.getLocation().toURI();
            if (location.getScheme().equals("file")) {
                return new File(location);
            }
        }
        if (targetClass.getClassLoader() != null) {
            String resourceName = targetClass.getName().replace('.', '/') + ".class";
            URL resource = targetClass.getClassLoader().getResource(resourceName);
            if (resource != null) {
                return getClasspathForResource(resource, resourceName);
            }
        }
        throw new GradleException(String.format("Cannot determine classpath for class %s.", targetClass.getName()));
    } catch (URISyntaxException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:23,代碼來源:ClasspathUtil.java

示例2: getJavacApiJarClasspath

import java.security.CodeSource; //導入依賴的package包/類
private static ClassPath getJavacApiJarClasspath() {
    Reference<ClassPath> r = javacApiClasspath;
    ClassPath res = r.get();
    if (res != null) {
        return res;
    }
    if (r == NONE) {
        return null;
    }
    CodeSource codeSource = Modifier.class.getProtectionDomain().getCodeSource();
    URL javacApiJar = codeSource != null ? codeSource.getLocation() : null;
    if (javacApiJar != null) {
        Logger.getLogger(DeclarativeHintsParser.class.getName()).log(Level.FINE, "javacApiJar={0}", javacApiJar);
        File aj = FileUtil.archiveOrDirForURL(javacApiJar);
        if (aj != null) {
            res = ClassPathSupport.createClassPath(FileUtil.urlForArchiveOrDir(aj));
            javacApiClasspath = new WeakReference<>(res);
            return res;
        }
    }
    javacApiClasspath = NONE;
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:DeclarativeHintsParser.java

示例3: getCodeBase

import java.security.CodeSource; //導入依賴的package包/類
/**
 * 得到類所在地址,可以是文件,也可以是jar包
 *
 * @param cls
 *         the cls
 * @return the code base
 */
public static String getCodeBase(Class<?> cls) {

    if (cls == null)
        return null;
    ProtectionDomain domain = cls.getProtectionDomain();
    if (domain == null)
        return null;
    CodeSource source = domain.getCodeSource();
    if (source == null)
        return null;
    URL location = source.getLocation();
    if (location == null)
        return null;
    return location.getFile();
}
 
開發者ID:tiglabs,項目名稱:jsf-sdk,代碼行數:23,代碼來源:ReflectUtils.java

示例4: getInstanceAdapterClass

import java.security.CodeSource; //導入依賴的package包/類
private StaticClass getInstanceAdapterClass(final ProtectionDomain protectionDomain) {
    CodeSource codeSource = protectionDomain.getCodeSource();
    if(codeSource == null) {
        codeSource = MINIMAL_PERMISSION_DOMAIN.getCodeSource();
    }
    StaticClass instanceAdapterClass = instanceAdapters.get(codeSource);
    if(instanceAdapterClass != null) {
        return instanceAdapterClass;
    }
    // Any "unknown source" code source will default to no permission domain.
    final ProtectionDomain effectiveDomain = codeSource.equals(MINIMAL_PERMISSION_DOMAIN.getCodeSource()) ?
            MINIMAL_PERMISSION_DOMAIN : protectionDomain;

    instanceAdapterClass = instanceAdapterGenerator.generateClass(commonLoader, effectiveDomain);
    final StaticClass existing = instanceAdapters.putIfAbsent(codeSource, instanceAdapterClass);
    return existing == null ? instanceAdapterClass : existing;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:JavaAdapterFactory.java

示例5: getContext

import java.security.CodeSource; //導入依賴的package包/類
private static AccessControlContext getContext(File[] dirs)
    throws IOException
{
    PathPermissions perms =
        new PathPermissions(dirs);

    ProtectionDomain domain = new ProtectionDomain(
        new CodeSource(perms.getCodeBase(),
            (java.security.cert.Certificate[]) null),
        perms);

    AccessControlContext acc =
        new AccessControlContext(new ProtectionDomain[] { domain });

    return acc;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:Launcher.java

示例6: getPermissions

import java.security.CodeSource; //導入依賴的package包/類
/**
 * Get the Permissions for a CodeSource.  If this instance
 * of WebappClassLoaderBase is for a web application context,
 * add read FilePermission or JndiPermissions for the base
 * directory (if unpacked),
 * the context URL, and jar file resources.
 *
 * @param codeSource where the code was loaded from
 * @return PermissionCollection for CodeSource
 */
@Override
protected PermissionCollection getPermissions(CodeSource codeSource) {

    String codeUrl = codeSource.getLocation().toString();
    PermissionCollection pc;
    if ((pc = loaderPC.get(codeUrl)) == null) {
        pc = super.getPermissions(codeSource);
        if (pc != null) {
            Iterator<Permission> perms = permissionList.iterator();
            while (perms.hasNext()) {
                Permission p = perms.next();
                pc.add(p);
            }
            loaderPC.put(codeUrl,pc);
        }
    }
    return (pc);

}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:30,代碼來源:WebappClassLoaderBase.java

示例7: checkCerts

import java.security.CodeSource; //導入依賴的package包/類
private void checkCerts(String name, CodeSource cs) {
    int i = name.lastIndexOf('.');
    String pname = (i == -1) ? "" : name.substring(0, i);

    Certificate[] certs = null;
    if (cs != null) {
        certs = cs.getCertificates();
    }
    Certificate[] pcerts = null;
    if (parallelLockMap == null) {
        synchronized (this) {
            pcerts = package2certs.get(pname);
            if (pcerts == null) {
                package2certs.put(pname, (certs == null? nocerts:certs));
            }
        }
    } else {
        pcerts = ((ConcurrentHashMap<String, Certificate[]>)package2certs).
            putIfAbsent(pname, (certs == null? nocerts:certs));
    }
    if (pcerts != null && !compareCerts(pcerts, certs)) {
        throw new SecurityException("class \""+ name +
             "\"'s signer information does not match signer information of other classes in the same package");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:ClassLoader.java

示例8: check

import java.security.CodeSource; //導入依賴的package包/類
@Override
public boolean check(Permission permission) {
	if (!Globals.IS_SECURITY_ENABLED) {
		return true;
	}
	Policy currentPolicy = Policy.getPolicy();
	if (currentPolicy != null) {
		ResourceEntry entry = findResourceInternal("/", "/", false);
		if (entry != null) {
			CodeSource cs = new CodeSource(entry.codeBase, (java.security.cert.Certificate[]) null);
			PermissionCollection pc = currentPolicy.getPermissions(cs);
			if (pc.implies(permission)) {
				return true;
			}
		}
	}
	return false;
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:19,代碼來源:WebappClassLoaderBase.java

示例9: getPermissions

import java.security.CodeSource; //導入依賴的package包/類
/**
 * Get the Permissions for a CodeSource. If this instance of
 * WebappClassLoaderBase is for a web application context, add read
 * FilePermission or JndiPermissions for the base directory (if unpacked),
 * the context URL, and jar file resources.
 *
 * @param codeSource
 *            where the code was loaded from
 * @return PermissionCollection for CodeSource
 */
@Override
protected PermissionCollection getPermissions(CodeSource codeSource) {

	String codeUrl = codeSource.getLocation().toString();
	PermissionCollection pc;
	if ((pc = loaderPC.get(codeUrl)) == null) {
		pc = super.getPermissions(codeSource);
		if (pc != null) {
			Iterator<Permission> perms = permissionList.iterator();
			while (perms.hasNext()) {
				Permission p = perms.next();
				pc.add(p);
			}
			loaderPC.put(codeUrl, pc);
		}
	}
	return (pc);

}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:30,代碼來源:WebappClassLoaderBase.java

示例10: getPermissions

import java.security.CodeSource; //導入依賴的package包/類
/**
 * Get the Permissions for a CodeSource.  If this instance
 * of WebappClassLoader is for a web application context,
 * add read FilePermission or JndiPermissions for the base
 * directory (if unpacked),
 * the context URL, and jar file resources.
 *
 * @param codeSource where the code was loaded from
 * @return PermissionCollection for CodeSource
 */
protected PermissionCollection getPermissions(CodeSource codeSource) {

    String codeUrl = codeSource.getLocation().toString();
    PermissionCollection pc;
    if ((pc = (PermissionCollection)loaderPC.get(codeUrl)) == null) {
        pc = super.getPermissions(codeSource);
        if (pc != null) {
            Iterator perms = permissionList.iterator();
            while (perms.hasNext()) {
                Permission p = (Permission)perms.next();
                pc.add(p);
            }
            loaderPC.put(codeUrl,pc);
        }
    }
    return (pc);

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:29,代碼來源:WebappClassLoader.java

示例11: getApplicationDirectory

import java.security.CodeSource; //導入依賴的package包/類
public static String getApplicationDirectory()
{
    String jarDir = null;

    try
    {
        CodeSource codeSource = MiscUtils.class.getProtectionDomain().getCodeSource();
        File jarFile = new File(URLDecoder.decode(codeSource.getLocation().toURI().getPath(), "UTF-8"));
        jarDir = jarFile.getParentFile().getPath();
    } catch (URISyntaxException | UnsupportedEncodingException ex)
    {
        ex.printStackTrace();
    }

    return jarDir + "/";
}
 
開發者ID:SamaGames,項目名稱:Hydroangeas,代碼行數:17,代碼來源:MiscUtils.java

示例12: getBaseLocatoin

import java.security.CodeSource; //導入依賴的package包/類
public static URL getBaseLocatoin(Class clazz) {
    if (clazz == null) {
        return null;
    }
    CodeSource codeSource = clazz.getProtectionDomain().getCodeSource();
    if (codeSource != null) {
        URL locationURL = codeSource.getLocation();
        String location = locationURL.toString();
        int i = location.indexOf("!/");
        if (i == -1) {
            return locationURL;
        } else {
            try {
                return new URL(location.substring(0, i));
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        }
    } else {
        return null;
    }
}
 
開發者ID:hellojavaer,項目名稱:fatjar,代碼行數:23,代碼來源:FatJarClassLoaderUtils.java

示例13: getCodeSource

import java.security.CodeSource; //導入依賴的package包/類
/**
 * Get the code source file or class path of the Class passed in.
 *
 * @param clazz
 *            Class to find.
 * @return Jar file name or class path.
 */
public static String getCodeSource(Class<?> clazz) {
    ProtectionDomain protectionDomain = clazz.getProtectionDomain();
    if (protectionDomain == null || protectionDomain.getCodeSource() == null) {
        return null;
    }

    CodeSource codeSource = clazz.getProtectionDomain().getCodeSource();
    URL location = codeSource.getLocation();
    if (location == null) {
        return null;
    }

    String path = codeSource.getLocation().toExternalForm();

    if (path.endsWith(".jar") && path.contains("/")) {
        return path.substring(path.lastIndexOf('/') + 1);
    }
    return path;
}
 
開發者ID:venus-boot,項目名稱:saluki,代碼行數:27,代碼來源:ClassUtils.java

示例14: getCodeSources

import java.security.CodeSource; //導入依賴的package包/類
CodeSource[] getCodeSources(URL url) {
    ensureInitialization();
    if (jv != null) {
        return jv.getCodeSources(this, url);
    }

    /*
     * JAR file has no signed content. Is there a non-signing
     * code source?
     */
    Enumeration<String> unsigned = unsignedEntryNames();
    if (unsigned.hasMoreElements()) {
        return new CodeSource[]{JarVerifier.getUnsignedCS(url)};
    } else {
        return null;
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:JarFile.java

示例15: getPluginPermissions

import java.security.CodeSource; //導入依賴的package包/類
@Test
public void getPluginPermissions() throws Exception {
    CodeSource cs = mock(CodeSource.class);
    ProtectionDomain domain = new ProtectionDomain(cs, null, new PluginClassLoader(new URL[0]), null);

    SandboxSecurityPolicy policy = new SandboxSecurityPolicy();

    PermissionCollection permissions = policy.getPermissions(domain);
    Assert.assertFalse(permissions.elements().hasMoreElements());

}
 
開發者ID:MatteoJoliveau,項目名稱:PlugFace,代碼行數:12,代碼來源:SandboxSecurityPolicyTest.java


注:本文中的java.security.CodeSource類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。