Search in sources :

Example 71 with CodeSource

use of java.security.CodeSource in project hadoop by apache.

the class FindClass method loadedClass.

/**
   * Log that a class has been loaded, and where from.
   * @param name classname
   * @param clazz class
   */
private void loadedClass(String name, Class clazz) {
    out("Loaded %s as %s", name, clazz);
    CodeSource source = clazz.getProtectionDomain().getCodeSource();
    URL url = source.getLocation();
    out("%s: %s", name, url);
}
Also used : CodeSource(java.security.CodeSource) URL(java.net.URL)

Example 72 with CodeSource

use of java.security.CodeSource in project cachecloud by sohutv.

the class NMONFileFactory method init.

/**
	 * 初始化nmon文件
	 */
private static void init() {
    try {
        String path = System.getProperty(NMON_DIR_PATH);
        if (path == null) {
            String classpath = null;
            try {
                CodeSource codeSource = NMONFileFactory.class.getProtectionDomain().getCodeSource();
                classpath = codeSource.getLocation().getPath();
                if (classpath.startsWith(FILE)) {
                    //like that: file:/opt/app/cachecloud/cachecloud-web-1.0-SNAPSHOT.war!/WEB-INF/classes!/
                    classpath = classpath.substring(FILE.length() + 1);
                }
                if (new File(classpath).isDirectory()) {
                    path = classpath + "../.." + NMON_PATH;
                } else {
                    //like that: /opt/app/cachecloud/cachecloud-web-1.0-SNAPSHOT.war!/WEB-INF/classes!/
                    String[] tmp = classpath.split("!/", 2);
                    path = tmp[0].substring(0, tmp[0].lastIndexOf("/")) + NMON_PATH;
                }
            } catch (Exception e) {
                logger.error(classpath, e);
            }
        }
        File nmonDir = new File(path);
        if (!nmonDir.exists()) {
            logger.error("{} path not exist", nmonDir.getAbsolutePath());
            return;
        }
        //获取操作系统目录
        File[] osDirs = nmonDir.listFiles();
        if (osDirs == null) {
            logger.error("{} not contains OS folders", nmonDir.getAbsolutePath());
            return;
        }
        for (File osDir : osDirs) {
            //获取处理器架构目录
            File[] archFiles = osDir.listFiles();
            if (archFiles == null) {
                logger.info("{} not contains architecture folders", osDir.getName());
                continue;
            }
            for (File archDir : archFiles) {
                //获取nmon文件目录
                File[] nmonFiles = archDir.listFiles();
                if (nmonFiles == null) {
                    logger.info("{} not contains nomon files", archDir.getName());
                    continue;
                }
                for (File nmonFile : nmonFiles) {
                    nmonFileMap.put(osDir.getName() + "_" + archDir.getName() + "_" + nmonFile.getName(), nmonFile);
                }
                logger.info("init {} {} nmon file size=" + nmonFiles.length, osDir.getName(), archDir.getName());
            }
        }
        logger.info("init {} finished, os size={}", nmonDir.getAbsolutePath(), osDirs.length);
    } catch (Exception e) {
        logger.error("init nmon factory", e);
    }
}
Also used : CodeSource(java.security.CodeSource) File(java.io.File)

Example 73 with CodeSource

use of java.security.CodeSource in project neo4j by neo4j.

the class EmbeddedJarLoader method loadJarFromRelativePath.

/**
     * Try to load jar from relative ../lib/ directory for cases when we do not have jars in a class path.
     * @param jar - path to a jar file to load.
     * @return loaded jar file
     * @throws EmbeddedJarNotFoundException if jar not exist or file name can't be represented as URI.
     */
private File loadJarFromRelativePath(String jar) {
    try {
        CodeSource codeSource = getClass().getProtectionDomain().getCodeSource();
        URI uri = codeSource.getLocation().toURI();
        File jarFile = new File(new File(uri).getParent(), jar);
        if (!jarFile.exists()) {
            throw new EmbeddedJarNotFoundException("Jar file '" + jar + "' not found.");
        }
        return jarFile;
    } catch (URISyntaxException e) {
        throw new EmbeddedJarNotFoundException("Jar file '" + jar + "' not found.");
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) CodeSource(java.security.CodeSource) URI(java.net.URI) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 74 with CodeSource

use of java.security.CodeSource in project pinpoint by naver.

the class AgentClassLoaderTest method getProjectLibDir.

private String getProjectLibDir() {
    // not really necessary, but useful for testing protectionDomain
    ProtectionDomain protectionDomain = AgentClassLoader.class.getProtectionDomain();
    CodeSource codeSource = protectionDomain.getCodeSource();
    URL location = codeSource.getLocation();
    logger.debug("lib location:{}", location);
    String path = location.getPath();
    // file:/D:/nhn_source/pinpoint_project/pinpoint-tomcat-profiler/target/classes/
    int dirPath = path.lastIndexOf("target/classes/");
    if (dirPath == -1) {
        throw new RuntimeException("target/classes/ not found");
    }
    String projectDir = path.substring(1, dirPath);
    return projectDir + "src/test/lib";
}
Also used : ProtectionDomain(java.security.ProtectionDomain) CodeSource(java.security.CodeSource) URL(java.net.URL)

Example 75 with CodeSource

use of java.security.CodeSource in project jaggery by wso2.

the class JaggerySecurityDomain method getCodeSource.

@SuppressFBWarnings("PATH_TRAVERSAL_IN")
public CodeSource getCodeSource() throws ScriptException {
    if (codeSource != null) {
        return codeSource;
    }
    URL url = null;
    try {
        String contextPath = servletContext.getRealPath("/");
        if (contextPath == null) {
            url = servletContext.getResource(scriptPath);
        } else {
            if (!contextPath.endsWith(File.separator)) {
                contextPath += File.separator;
            }
            url = new File(contextPath + scriptPath).getCanonicalFile().toURI().toURL();
        }
        codeSource = new CodeSource(url, (Certificate[]) null);
        return codeSource;
    } catch (IOException e) {
        throw new ScriptException(e);
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) IOException(java.io.IOException) CodeSource(java.security.CodeSource) File(java.io.File) URL(java.net.URL) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

CodeSource (java.security.CodeSource)104 URL (java.net.URL)49 ProtectionDomain (java.security.ProtectionDomain)39 File (java.io.File)30 IOException (java.io.IOException)20 Certificate (java.security.cert.Certificate)17 JarFile (java.util.jar.JarFile)13 PermissionCollection (java.security.PermissionCollection)12 URI (java.net.URI)11 URISyntaxException (java.net.URISyntaxException)11 Permissions (java.security.Permissions)11 Policy (java.security.Policy)10 FilePermission (java.io.FilePermission)7 InputStream (java.io.InputStream)6 AccessControlContext (java.security.AccessControlContext)6 MalformedURLException (java.net.MalformedURLException)5 Permission (java.security.Permission)4 JarEntry (java.util.jar.JarEntry)4 GroovyClassLoader (groovy.lang.GroovyClassLoader)3 URLClassLoader (java.net.URLClassLoader)3