mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge branch '1.3.x'
This commit is contained in:
commit
436b58acbf
@ -18,6 +18,7 @@ package org.springframework.boot.loader.jar;
|
||||
|
||||
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.URLConnection;
|
||||
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 @@ class JarURLConnection extends java.net.JarURLConnection {
|
||||
|
||||
private static final String FILE_COLON_DOUBLE_SLASH = "file://";
|
||||
|
||||
private static final String READ_ACTION = "read";
|
||||
|
||||
private static ThreadLocal<Boolean> useFastExceptions = new ThreadLocal<Boolean>();
|
||||
|
||||
private final JarFile jarFile;
|
||||
|
||||
private final Permission permission;
|
||||
|
||||
private URL jarFileUrl;
|
||||
|
||||
private final JarEntryName jarEntryName;
|
||||
@ -84,6 +91,8 @@ class JarURLConnection extends java.net.JarURLConnection {
|
||||
}
|
||||
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 @@ class JarURLConnection extends java.net.JarURLConnection {
|
||||
return this.jarEntryName.getContentType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Permission getPermission() throws IOException {
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
static void setUseFastExceptions(boolean useFastExceptions) {
|
||||
JarURLConnection.useFastExceptions.set(useFastExceptions);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import java.io.File;
|
||||
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 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Martin Lau
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class JarFileTests {
|
||||
|
||||
@ -208,6 +210,10 @@ public class JarFileTests {
|
||||
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 class JarFileTests {
|
||||
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 class JarFileTests {
|
||||
}
|
||||
|
||||
@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();
|
||||
|
Loading…
Reference in New Issue
Block a user