本文整理汇总了Java中java.security.ProtectionDomain.getCodeSource方法的典型用法代码示例。如果您正苦于以下问题:Java ProtectionDomain.getCodeSource方法的具体用法?Java ProtectionDomain.getCodeSource怎么用?Java ProtectionDomain.getCodeSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.ProtectionDomain
的用法示例。
在下文中一共展示了ProtectionDomain.getCodeSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import java.security.ProtectionDomain; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
URL persistenceProviderUrl = FileUtil.getArchiveRoot(PersistenceProvider.class.getProtectionDomain().getCodeSource().getLocation());
ProtectionDomain domain = Resource.class.getProtectionDomain();
System.out.println("Protection domain: " + domain);
CodeSource source = domain.getCodeSource();
System.out.println("Code source: " + source);
if (source != null) {
URL location = source.getLocation();
System.out.println("Location: " + location);
URL resourceUrl = FileUtil.getArchiveRoot(location);
addCompileRoots(Arrays.asList(persistenceProviderUrl, resourceUrl));
} else {
addCompileRoots(Arrays.asList(persistenceProviderUrl));
}
}
示例2: getInstanceAdapterClass
import java.security.ProtectionDomain; //导入方法依赖的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;
}
示例3: getCodeSource
import java.security.ProtectionDomain; //导入方法依赖的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;
}
示例4: getCodeBase
import java.security.ProtectionDomain; //导入方法依赖的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();
}
示例5: getJarURI
import java.security.ProtectionDomain; //导入方法依赖的package包/类
private static URI getJarURI() throws URISyntaxException
{
final ProtectionDomain domain;
final CodeSource source;
final URL url;
final URI uri;
domain = Main.class.getProtectionDomain();
source = domain.getCodeSource();
url = source.getLocation();
uri = url.toURI();
return (uri);
}
示例6: getCodeBase
import java.security.ProtectionDomain; //导入方法依赖的package包/类
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();
}
示例7: implies
import java.security.ProtectionDomain; //导入方法依赖的package包/类
@Override @SuppressForbidden(reason = "fast equals check is desired")
public boolean implies(ProtectionDomain domain, Permission permission) {
CodeSource codeSource = domain.getCodeSource();
// codesource can be null when reducing privileges via doPrivileged()
if (codeSource == null) {
return false;
}
URL location = codeSource.getLocation();
// location can be null... ??? nobody knows
// https://bugs.openjdk.java.net/browse/JDK-8129972
if (location != null) {
// run scripts with limited permissions
if (BootstrapInfo.UNTRUSTED_CODEBASE.equals(location.getFile())) {
return untrusted.implies(domain, permission);
}
// check for an additional plugin permission: plugin policy is
// only consulted for its codesources.
Policy plugin = plugins.get(location.getFile());
if (plugin != null && plugin.implies(domain, permission)) {
return true;
}
}
// Special handling for broken Hadoop code: "let me execute or my classes will not load"
// yeah right, REMOVE THIS when hadoop is fixed
if (permission instanceof FilePermission && "<<ALL FILES>>".equals(permission.getName())) {
for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
if ("org.apache.hadoop.util.Shell".equals(element.getClassName()) &&
"runCommand".equals(element.getMethodName())) {
// we found the horrible method: the hack begins!
// force the hadoop code to back down, by throwing an exception that it catches.
rethrow(new IOException("no hadoop, you cannot do this."));
}
}
}
// otherwise defer to template + dynamic file permissions
return template.implies(domain, permission) || dynamic.implies(permission) || system.implies(domain, permission);
}
示例8: 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());
}
}
示例9: implies
import java.security.ProtectionDomain; //导入方法依赖的package包/类
@Override @SuppressForbidden(reason = "fast equals check is desired")
public boolean implies(ProtectionDomain domain, Permission permission) {
CodeSource codeSource = domain.getCodeSource();
// codesource can be null when reducing privileges via doPrivileged()
if (codeSource == null) {
return false;
}
URL location = codeSource.getLocation();
// location can be null... ??? nobody knows
// https://bugs.openjdk.java.net/browse/JDK-8129972
if (location != null) {
// run scripts with limited permissions
if (BootstrapInfo.UNTRUSTED_CODEBASE.equals(location.getFile())) {
return untrusted.implies(domain, permission);
}
// check for an additional plugin permission: plugin policy is
// only consulted for its codesources.
Policy plugin = plugins.get(location.getFile());
if (plugin != null && plugin.implies(domain, permission)) {
return true;
}
}
// otherwise defer to template + dynamic file permissions
return template.implies(domain, permission) || dynamic.implies(permission) || system.implies(domain, permission);
}
示例10: defineClassSourceLocation
import java.security.ProtectionDomain; //导入方法依赖的package包/类
private String defineClassSourceLocation(ProtectionDomain pd)
{
CodeSource cs = pd.getCodeSource();
String source = null;
if (cs != null && cs.getLocation() != null) {
source = cs.getLocation().toString();
}
return source;
}
示例11: postDefineClass
import java.security.ProtectionDomain; //导入方法依赖的package包/类
private void postDefineClass(Class<?> c, ProtectionDomain pd)
{
if (pd.getCodeSource() != null) {
Certificate certs[] = pd.getCodeSource().getCertificates();
if (certs != null)
setSigners(c, certs);
}
}
示例12: postDefineClass
import java.security.ProtectionDomain; //导入方法依赖的package包/类
private void postDefineClass(Class<?> c, ProtectionDomain pd) {
// define a named package, if not present
getNamedPackage(c.getPackageName(), c.getModule());
if (pd.getCodeSource() != null) {
Certificate certs[] = pd.getCodeSource().getCertificates();
if (certs != null)
setSigners(c, certs);
}
}
示例13: getCodeBase
import java.security.ProtectionDomain; //导入方法依赖的package包/类
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();
}
示例14: getCodeBase
import java.security.ProtectionDomain; //导入方法依赖的package包/类
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;
java.net.URL location = source.getLocation();
if (location == null)
return null;
return location.getFile();
}
示例15: isTestMachineryDomain
import java.security.ProtectionDomain; //导入方法依赖的package包/类
private boolean isTestMachineryDomain(ProtectionDomain domain) {
CodeSource cs = (domain == null) ? null : domain.getCodeSource();
URL loc = (cs == null) ? null : cs.getLocation();
String path = (loc == null) ? null : loc.getPath();
return path != null && TEST_JARS.stream()
.filter(path::endsWith)
.findAny()
.isPresent();
}