Search in sources :

Example 51 with CodeSource

use of java.security.CodeSource in project Payara by payara.

the class EJBSecurityManager method getApplicationCodeSource.

private static CodeSource getApplicationCodeSource(String pcid) throws Exception {
    CodeSource result = null;
    String archiveURI = "file:///" + pcid.replace(' ', '_');
    try {
        java.net.URI uri = null;
        try {
            uri = new java.net.URI(archiveURI);
            if (uri != null) {
                result = new CodeSource(uri.toURL(), (java.security.cert.Certificate[]) null);
            }
        } catch (java.net.URISyntaxException use) {
            // manually create the URL
            _logger.log(Level.SEVERE, "JACC_createurierror", use);
            throw new RuntimeException(use);
        }
    } catch (java.net.MalformedURLException mue) {
        // should never come here.
        _logger.log(Level.SEVERE, "JACC_ejbsm.codesourceerror", mue);
        throw new RuntimeException(mue);
    }
    return result;
}
Also used : CodeSource(java.security.CodeSource)

Example 52 with CodeSource

use of java.security.CodeSource in project Payara by payara.

the class PayaraMicroLauncher method getBootClass.

/**
 * Boot method via Micro.getInstance()
 * @return
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws ClassNotFoundException
 * @throws Exception
 */
public static PayaraMicroBoot getBootClass() throws InstantiationException, IllegalAccessException, ClassNotFoundException, Exception {
    if (bootInstance == null) {
        if (mainBoot) {
            Class<?> mainClass = Thread.currentThread().getContextClassLoader().loadClass("fish.payara.micro.impl.PayaraMicroImpl");
            Method instanceMethod = mainClass.getDeclaredMethod("getInstance");
            bootInstance = (PayaraMicroBoot) instanceMethod.invoke(null);
        } else {
            PayaraMicroLauncher launcher = new PayaraMicroLauncher();
            // set system property for our jar file
            ProtectionDomain protectionDomain = PayaraMicroLauncher.class.getProtectionDomain();
            CodeSource codeSource = protectionDomain.getCodeSource();
            URI location = (codeSource == null ? null : codeSource.getLocation().toURI());
            System.setProperty(MICRO_JAR_PROPERTY, location.toString());
            ClassLoader loader = launcher.createClassLoader(launcher.getClassPathArchives());
            fish.payara.micro.boot.loader.jar.JarFile.registerUrlProtocolHandler();
            Thread.currentThread().setContextClassLoader(loader);
            Class<?> mainClass = Thread.currentThread().getContextClassLoader().loadClass("fish.payara.micro.impl.PayaraMicroImpl");
            Method instanceMethod = mainClass.getDeclaredMethod("getInstance");
            bootInstance = (PayaraMicroBoot) instanceMethod.invoke(null);
        }
    }
    return bootInstance;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) Method(java.lang.reflect.Method) CodeSource(java.security.CodeSource) URI(java.net.URI)

Example 53 with CodeSource

use of java.security.CodeSource in project Payara by payara.

the class PayaraMicroLauncher method main.

/**
 * Boot method via java -jar
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    PayaraMicroLauncher launcher = new PayaraMicroLauncher();
    // set system property for our jar file
    ProtectionDomain protectionDomain = PayaraMicroLauncher.class.getProtectionDomain();
    CodeSource codeSource = protectionDomain.getCodeSource();
    URI location = (codeSource == null ? null : codeSource.getLocation().toURI());
    System.setProperty(MICRO_JAR_PROPERTY, location.toString());
    mainBoot = true;
    launcher.launch(args);
}
Also used : ProtectionDomain(java.security.ProtectionDomain) CodeSource(java.security.CodeSource) URI(java.net.URI)

Example 54 with CodeSource

use of java.security.CodeSource in project Payara by payara.

the class ExplodedURLClassloader method explodeJars.

private void explodeJars() throws IOException {
    // create a runtime jar directory
    File runtimeDir = new File(explodedDir, "runtime");
    runtimeDir.mkdirs();
    if (deleteOnExit) {
        runtimeDir.deleteOnExit();
    }
    // create a lib directory
    File libDir = new File(explodedDir, "lib");
    libDir.mkdirs();
    if (deleteOnExit) {
        libDir.deleteOnExit();
    }
    // sets the system property used in the server.policy file for permissions
    System.setProperty("fish.payara.micro.UnpackDir", explodedDir.getAbsolutePath());
    // Get our jar files
    CodeSource src = ExplodedURLClassloader.class.getProtectionDomain().getCodeSource();
    if (src != null) {
        try {
            // find the root jar
            String[] jars = src.getLocation().toURI().getSchemeSpecificPart().split("!");
            File file = new File(jars[0]);
            JarFile jar = new JarFile(file);
            Enumeration<JarEntry> entries = jar.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                String fileName = null;
                if (entry.getName().startsWith(JAR_DOMAIN_DIR)) {
                    fileName = entry.getName().substring(JAR_DOMAIN_DIR.length());
                } else if (entry.getName().startsWith(LIB_DOMAIN_DIR)) {
                    fileName = entry.getName().substring(LIB_DOMAIN_DIR.length());
                }
                if (fileName != null) {
                    File outputFile = new File(runtimeDir, fileName);
                    if (deleteOnExit) {
                        outputFile.deleteOnExit();
                    }
                    super.addURL(outputFile.getAbsoluteFile().toURI().toURL());
                    if (entry.isDirectory()) {
                        outputFile.mkdirs();
                    } else {
                        // write out the jar file
                        try (InputStream is = jar.getInputStream(entry)) {
                            Files.copy(is, outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                        }
                    }
                }
            }
        } catch (URISyntaxException ex) {
            Logger.getLogger(ExplodedURLClassloader.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : InputStream(java.io.InputStream) URISyntaxException(java.net.URISyntaxException) CodeSource(java.security.CodeSource) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 55 with CodeSource

use of java.security.CodeSource in project Payara by payara.

the class RuntimeDirectory method unpackRuntime.

private void unpackRuntime() throws URISyntaxException, IOException {
    // make a docroot here
    new File(directory, "docroot").mkdirs();
    // create a config dir and unpack
    configDir = new File(directory, "config");
    configDir.mkdirs();
    // Get our configuration files
    CodeSource src = PayaraMicro.class.getProtectionDomain().getCodeSource();
    if (src != null) {
        // find the root jar
        String[] jars = src.getLocation().toURI().getSchemeSpecificPart().split("!");
        File file = new File(jars[0]);
        JarFile jar = new JarFile(file);
        Enumeration<JarEntry> entries = jar.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();
            if (entry.getName().startsWith(JAR_DOMAIN_DIR)) {
                String fileName = entry.getName().substring(JAR_DOMAIN_DIR.length());
                File outputFile = new File(configDir, fileName);
                if (isTempDir) {
                    outputFile.deleteOnExit();
                }
                // only unpack if an existing file is not there
                if (!outputFile.exists()) {
                    if (entry.isDirectory()) {
                        outputFile.mkdirs();
                    } else {
                        // write out the conifugration file
                        try (InputStream is = jar.getInputStream(entry)) {
                            Files.copy(is, outputFile.toPath());
                        }
                    }
                }
            }
        }
    } else {
        throw new IOException("Unable to find the runtime to unpack");
    }
    // sort out the security properties
    configureSecurity();
    JarUtil.extractRars(directory.getAbsolutePath());
    JarUtil.setEnv(directory.getAbsolutePath());
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) CodeSource(java.security.CodeSource) PayaraMicro(fish.payara.micro.PayaraMicro) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File)

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