当前位置: 首页>>代码示例>>Java>>正文


Java ProtectionDomain.getCodeSource方法代码示例

本文整理汇总了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));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:PersistenceTestCase.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:JavaAdapterFactory.java

示例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;
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:27,代码来源:ClassUtils.java

示例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();
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:23,代码来源:ReflectUtils.java

示例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);
}
 
开发者ID:Ptrk25,项目名称:CDN-FX-2.2,代码行数:15,代码来源:Tools.java

示例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();
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:15,代码来源:ReflectUtils.java

示例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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:41,代码来源:ESPolicy.java

示例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());
    }
}
 
开发者ID:Energyxxer,项目名称:Vanilla-Injection,代码行数:42,代码来源:JarClassLoader.java

示例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);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:28,代码来源:ESPolicy.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:ClassLoader.java

示例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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:ClassLoader.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ClassLoader.java

示例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();
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:11,代码来源:ReflectUtils.java

示例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();
}
 
开发者ID:zhangxin23,项目名称:zookeeper-sandbox,代码行数:15,代码来源:ReflectUtils.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:JAXPPolicyManager.java


注:本文中的java.security.ProtectionDomain.getCodeSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。