use of java.io.FilePermission in project spring-boot by spring-projects.
the class JarFileTests method createEntryUrl.
@Test
public void createEntryUrl() throws Exception {
URL url = new URL(this.jarFile.getUrl(), "1.dat");
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/1.dat");
JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
assertThat(jarURLConnection.getJarFile()).isSameAs(this.jarFile);
assertThat(jarURLConnection.getJarEntry()).isSameAs(this.jarFile.getJarEntry("1.dat"));
assertThat(jarURLConnection.getContentLength()).isEqualTo(1);
assertThat(jarURLConnection.getContent()).isInstanceOf(InputStream.class);
assertThat(jarURLConnection.getContentType()).isEqualTo("content/unknown");
assertThat(jarURLConnection.getPermission()).isInstanceOf(FilePermission.class);
FilePermission permission = (FilePermission) jarURLConnection.getPermission();
assertThat(permission.getActions()).isEqualTo("read");
assertThat(permission.getName()).isEqualTo(this.rootJarFile.getPath());
}
use of java.io.FilePermission in project spring-boot by spring-projects.
the class JarFileTests method getNestedJarFile.
@Test
public void getNestedJarFile() throws Exception {
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
Enumeration<java.util.jar.JarEntry> entries = nestedJarFile.entries();
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/");
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/MANIFEST.MF");
assertThat(entries.nextElement().getName()).isEqualTo("3.dat");
assertThat(entries.nextElement().getName()).isEqualTo("4.dat");
assertThat(entries.nextElement().getName()).isEqualTo("ä.dat");
assertThat(entries.hasMoreElements()).isFalse();
InputStream inputStream = nestedJarFile.getInputStream(nestedJarFile.getEntry("3.dat"));
assertThat(inputStream.read()).isEqualTo(3);
assertThat(inputStream.read()).isEqualTo(-1);
URL url = nestedJarFile.getUrl();
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/");
JarURLConnection conn = (JarURLConnection) url.openConnection();
assertThat(conn.getJarFile()).isSameAs(nestedJarFile);
assertThat(conn.getJarFileURL().toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar");
assertThat(conn.getInputStream()).isNotNull();
JarInputStream jarInputStream = new JarInputStream(conn.getInputStream());
assertThat(jarInputStream.getNextJarEntry().getName()).isEqualTo("3.dat");
assertThat(jarInputStream.getNextJarEntry().getName()).isEqualTo("4.dat");
assertThat(jarInputStream.getNextJarEntry().getName()).isEqualTo("ä.dat");
jarInputStream.close();
assertThat(conn.getPermission()).isInstanceOf(FilePermission.class);
FilePermission permission = (FilePermission) conn.getPermission();
assertThat(permission.getActions()).isEqualTo("read");
assertThat(permission.getName()).isEqualTo(this.rootJarFile.getPath());
}
use of java.io.FilePermission in project lwjgl by LWJGL.
the class AppletLoader method updateClassPath.
/**
* Edits the ClassPath at runtime to include the jars
* that have just been downloaded and then adds the
* lwjgl natives folder property.
*
* @param path location where applet is stored
* @throws Exception if it fails to add classpath
*/
protected void updateClassPath(final String path) throws Exception {
setState(STATE_UPDATING_CLASSPATH);
percentage = 95;
URL[] urls = new URL[urlList.length];
for (int i = 0; i < urlList.length; i++) {
String file = new File(path, getJarName(urlList[i])).toURI().toString();
// fix JVM bug where ! is not escaped
file = file.replace("!", "%21");
urls[i] = new URL(file);
}
// get AppletLoader certificates
final Certificate[] certs = getCurrentCertificates();
// detect if we are running on a mac and save result as boolean
String osName = System.getProperty("os.name");
final boolean isMacOS = (osName.startsWith("Mac") || osName.startsWith("Darwin"));
// add downloaded jars to the classpath with required permissions
classLoader = new URLClassLoader(urls) {
protected PermissionCollection getPermissions(CodeSource codesource) {
PermissionCollection perms = null;
try {
// no permissions
perms = new Permissions();
// if certificates match the AppletLoader certificates then we should be all set
if (certificatesMatch(certs, codesource.getCertificates())) {
perms.add(new AllPermission());
return perms;
}
String host = getCodeBase().getHost();
if (host != null && (host.length() > 0)) {
// add permission for downloaded jars to access host they were from
perms.add(new SocketPermission(host, "connect,accept"));
} else if ("file".equals(codesource.getLocation().getProtocol())) {
// if running locally add file permission
String path = codesource.getLocation().getFile().replace('/', File.separatorChar);
perms.add(new FilePermission(path, "read"));
}
} catch (Exception e) {
e.printStackTrace();
}
return perms;
}
// allow non lwjgl native to be found from cache directory
protected String findLibrary(String libname) {
String libPath = path + "natives" + File.separator + LWJGLUtil.mapLibraryName(libname);
if (new File(libPath).exists()) {
return libPath;
}
return super.findLibrary(libname);
}
};
debug_sleep(2000);
// unload natives loaded by a previous instance of this lwjgl applet
unloadNatives(path);
// add natives files path to native class path
System.setProperty("org.lwjgl.librarypath", path + "natives");
// Make sure jinput knows about the new path too
System.setProperty("net.java.games.input.librarypath", path + "natives");
// set the library path, useful for non lwjgl natives
System.setProperty("java.library.path", path + "natives");
// mark natives as loaded
natives_loaded = true;
}
use of java.io.FilePermission in project wildfly by wildfly.
the class EEDefaultPermissionsProcessor method deploy.
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ModuleSpecification attachment = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
if (attachment == null) {
return;
}
final List<PermissionFactory> permissions = attachment.getPermissionFactories();
final Enumeration<Permission> e = DEFAULT_PERMISSIONS.elements();
while (e.hasMoreElements()) {
permissions.add(new ImmediatePermissionFactory(e.nextElement()));
}
//make sure they can read the contents of the deployment
ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
try {
File file = root.getRoot().getPhysicalFile();
if (file != null && file.isDirectory()) {
FilePermission permission = new FilePermission(file.getAbsolutePath() + File.separatorChar + "-", "read");
permissions.add(new ImmediatePermissionFactory(permission));
}
} catch (IOException ex) {
throw new DeploymentUnitProcessingException(ex);
}
}
use of java.io.FilePermission in project wildfly by wildfly.
the class RebindTestCase method deploy.
@Deployment
public static Archive<?> deploy() {
String tmpdir = System.getProperty("jboss.home");
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "RebindTestCase.jar");
jar.addClasses(RebindTestCase.class, BindingLookupBean.class);
jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.as.controller, " + "org.jboss.remoting3\n"), "MANIFEST.MF");
jar.addAsManifestResource(createPermissionsXmlAsset(new RemotingPermission("addConnectionProvider"), new RemotingPermission("connect"), new RemotingPermission("createEndpoint"), new RuntimePermission("createXnioWorker"), new FilePermission(tmpdir + "/standalone/tmp/auth/-", "read"), new SocketPermission(TestSuiteEnvironment.getServerAddress(), "connect,resolve")), "permissions.xml");
return jar;
}
Aggregations