diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java index fcefabb025bc..0e26e6a2efbc 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java @@ -18,6 +18,7 @@ import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; +import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; @@ -27,6 +28,8 @@ import java.net.URLEncoder; import java.net.URLStreamHandler; +import java.security.Permission; + /** * {@link java.net.JarURLConnection} used to support {@link JarFile#getUrl()}. * @@ -61,10 +64,14 @@ protected URLConnection openConnection(URL u) throws IOException { private static final String FILE_COLON_DOUBLE_SLASH = "file://"; + private static final String READ_ACTION = "read"; + private static ThreadLocal useFastExceptions = new ThreadLocal(); private final JarFile jarFile; + private final Permission permission; + private URL jarFileUrl; private final JarEntryName jarEntryName; @@ -84,6 +91,8 @@ protected JarURLConnection(URL url, JarFile jarFile) throws IOException { } this.jarFile = jarFile; this.jarEntryName = getJarEntryName(spec); + this.permission = new FilePermission(jarFile.getRootJarFile().getFile().getPath(), + READ_ACTION); } private String getNormalizedFile(URL url) { @@ -210,6 +219,11 @@ public String getContentType() { return this.jarEntryName.getContentType(); } + @Override + public Permission getPermission() throws IOException { + return this.permission; + } + static void setUseFastExceptions(boolean useFastExceptions) { JarURLConnection.useFastExceptions.set(useFastExceptions); } diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java index 73fe6eeefbca..d238656d3083 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java @@ -20,6 +20,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -50,6 +51,7 @@ * * @author Phillip Webb * @author Martin Lau + * @author Andy Wilkinson */ public class JarFileTests { @@ -208,6 +210,10 @@ public void createEntryUrl() throws Exception { 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()); } @Test @@ -261,6 +267,10 @@ public void getNestedJarFile() throws Exception { assertThat(conn.getJarFile()).isSameAs(nestedJarFile); assertThat(conn.getJarFileURL().toString()) .isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar"); + assertThat(conn.getPermission()).isInstanceOf(FilePermission.class); + FilePermission permission = (FilePermission) conn.getPermission(); + assertThat(permission.getActions()).isEqualTo("read"); + assertThat(permission.getName()).isEqualTo(this.rootJarFile.getPath()); } @Test @@ -284,7 +294,7 @@ public void getNestedJarDirectory() throws Exception { } @Test - public void getNestJarEntryUrl() throws Exception { + public void getNestedJarEntryUrl() throws Exception { JarFile nestedJarFile = this.jarFile .getNestedJarFile(this.jarFile.getEntry("nested.jar")); URL url = nestedJarFile.getJarEntry("3.dat").getUrl();