java.security.ProtectionDomain#getCodeSource ( )源码实例Demo

下面列出了java.security.ProtectionDomain#getCodeSource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sofa-ark   文件: ClassUtils.java

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();
    }
 
源代码2 项目: jsonde   文件: ProfilerImpl.java

@Override
public void describeRedefinableClass(long classId, Class clazz) {

    DescribeClassMessage describeClassMessage = new DescribeClassMessage(classId, true);

    describeClassMessage.setClassLoaderId(
            classLoaderIdGenerator.getId(clazz.getClassLoader())
    );

    ProtectionDomain protectionDomain = clazz.getProtectionDomain();
    if (null != protectionDomain) {
        CodeSource codeSource = protectionDomain.getCodeSource();
        if (null != codeSource) {
            URL codeLocation = codeSource.getLocation();
            describeClassMessage.setCodeLocation(codeLocation.toExternalForm());
        }
    }

    networkServer.sendMessage(describeClassMessage);

}
 

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;
}
 
源代码4 项目: openjdk-jdk9   文件: JavaAdapterFactory.java

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;
}
 
源代码5 项目: confucius-commons   文件: ClassUtils.java

/**
 * Get {@link Class}'s code source location URL
 *
 * @param type
 * @return If , return <code>null</code>.
 * @throws NullPointerException
 *         If <code>type</code> is <code>null</code> , {@link NullPointerException} will be thrown.
 */
public static URL getCodeSourceLocation(Class<?> type) throws NullPointerException {

    URL codeSourceLocation = null;
    ClassLoader classLoader = type.getClassLoader();

    if (classLoader == null) { // Bootstrap ClassLoader or type is primitive or void
        String path = findClassPath(type);
        if (StringUtils.isNotBlank(path)) {
            try {
                codeSourceLocation = new File(path).toURI().toURL();
            } catch (MalformedURLException ignored) {
                codeSourceLocation = null;
            }
        }
    } else {
        ProtectionDomain protectionDomain = type.getProtectionDomain();
        CodeSource codeSource = protectionDomain == null ? null : protectionDomain.getCodeSource();
        codeSourceLocation = codeSource == null ? null : codeSource.getLocation();
    }
    return codeSourceLocation;
}
 
源代码6 项目: TrackRay   文件: WebApplication.java

protected static Archive createArchive(Class clazz) throws Exception {
	ProtectionDomain protectionDomain = clazz.getProtectionDomain();
	CodeSource codeSource = protectionDomain.getCodeSource();
	URI location = codeSource != null ? codeSource.getLocation().toURI() : null;
	String path = location != null ? location.getSchemeSpecificPart() : null;
	if (path == null) {
		throw new IllegalStateException("Unable to determine code source archive");
	} else {
		File root = new File(path);
		if (!root.exists()) {
			throw new IllegalStateException("Unable to determine code source archive from " + root);
		} else {
			return (Archive)(root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root));
		}
	}
}
 

/**
 * Returns the executable file archive
 * @return executable file archive
 * @throws Exception
 */
protected ExecutableArchive createArchive() throws Exception {
    ProtectionDomain protectionDomain = getClass().getProtectionDomain();
    CodeSource codeSource = protectionDomain.getCodeSource();
    URI location = (codeSource == null ? null : codeSource.getLocation().toURI());
    String path = (location == null ? null : location.getSchemeSpecificPart());
    if (path == null) {
        throw new IllegalStateException("Unable to determine code source archive");
    }
    File root = new File(path);
    if (!root.exists()) {
        throw new IllegalStateException("Unable to determine code source archive from " + root);
    }
    return root.isDirectory() ? new ExecutableArkBizJar(new ExplodedArchive(root))
        : new ExecutableArkBizJar(new JarFileArchive(root), root.toURI().toURL());
}
 
源代码8 项目: dubbo-2.6.5   文件: ReflectUtils.java

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();
}
 
源代码9 项目: openjdk-8   文件: ClassLoader.java

private String defineClassSourceLocation(ProtectionDomain pd)
{
    CodeSource cs = pd.getCodeSource();
    String source = null;
    if (cs != null && cs.getLocation() != null) {
        source = cs.getLocation().toString();
    }
    return source;
}
 

private void postDefineClass(Class<?> c, ProtectionDomain pd)
{
    if (pd.getCodeSource() != null) {
        Certificate certs[] = pd.getCodeSource().getCertificates();
        if (certs != null)
            setSigners(c, certs);
    }
}
 
源代码11 项目: openjdk-jdk8u   文件: ClassLoader.java

private String defineClassSourceLocation(ProtectionDomain pd)
{
    CodeSource cs = pd.getCodeSource();
    String source = null;
    if (cs != null && cs.getLocation() != null) {
        source = cs.getLocation().toString();
    }
    return source;
}
 
源代码12 项目: TencentKona-8   文件: ClassLoader.java

private void postDefineClass(Class<?> c, ProtectionDomain pd)
{
    if (pd.getCodeSource() != null) {
        Certificate certs[] = pd.getCodeSource().getCertificates();
        if (certs != null)
            setSigners(c, certs);
    }
}
 

private static String getSource(final Class<? extends MCRServletContainerInitializer> clazz) {
    if (clazz == null) {
        return null;
    }
    ProtectionDomain protectionDomain = clazz.getProtectionDomain();
    CodeSource codeSource = protectionDomain.getCodeSource();
    if (codeSource == null) {
        LogManager.getLogger().warn("Cannot get CodeSource.");
        return null;
    }
    URL location = codeSource.getLocation();
    String fileName = location.getFile();
    File sourceFile = new File(fileName);
    return sourceFile.getName();
}
 

public String nameExpected(String className) {
  Class cls = this.getClass();
  ProtectionDomain pr = cls.getProtectionDomain();
  CodeSource cs = pr.getCodeSource();
  URL loc = cs.getLocation();
  String s = loc.toString();
  if(s.startsWith("file:")) {
    s = s.substring(5);
  }
  // in the default asmx ant script, class will be run from something like
  // asmx/output/... so just cut things off at asmx
  s = s.substring(0, s.lastIndexOf("asmx")+4);
  return s+"/test/conform/cases/"+className+".expected";
}
 
源代码15 项目: jeesuite-libs   文件: ReflectUtils.java

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();
}
 
源代码16 项目: pixymeta-android   文件: LangUtils.java

/** Java language specific classes return null cSource */
public static URL getLoadedClassLocation(Class<?> cls) {
	ProtectionDomain pDomain = cls.getProtectionDomain();
	CodeSource cSource = pDomain.getCodeSource();
	URL loc = (cSource==null)?null:cSource.getLocation(); 
	
	return loc; 
}
 
源代码17 项目: Java8CN   文件: ClassLoader.java

private void postDefineClass(Class<?> c, ProtectionDomain pd)
{
    if (pd.getCodeSource() != null) {
        Certificate certs[] = pd.getCodeSource().getCertificates();
        if (certs != null)
            setSigners(c, certs);
    }
}
 
源代码18 项目: jsongood   文件: ReflectUtils.java

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();
}
 
源代码19 项目: JDKSourceCode1.8   文件: ClassLoader.java

private void postDefineClass(Class<?> c, ProtectionDomain pd)
{
    if (pd.getCodeSource() != null) {
        Certificate certs[] = pd.getCodeSource().getCertificates();
        if (certs != null)
            setSigners(c, certs);
    }
}
 

/**
 * Checks whether the given domain is unknown. In that case, restrict everything!
 *
 * @param domain
 *            the domain in question, may be {@code null}
 * @return {@code true} if the domain is unknown; {@code false} otherwise
 *
 */
private static boolean isUnknown(ProtectionDomain domain) {
	return domain == null || domain.getCodeSource() == null;
}