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;
}
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;
}
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);
}
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);
}
}
}
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());
}
Aggregations