Skip to content

Commit

Permalink
Merge branch '1.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Jun 1, 2016
2 parents ac5696e + 3772d9f commit 436b58a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()}.
*
Expand Down Expand Up @@ -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<Boolean> useFastExceptions = new ThreadLocal<Boolean>();

private final JarFile jarFile;

private final Permission permission;

private URL jarFileUrl;

private final JarEntryName jarEntryName;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,6 +51,7 @@
*
* @author Phillip Webb
* @author Martin Lau
* @author Andy Wilkinson
*/
public class JarFileTests {

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down

0 comments on commit 436b58a

Please sign in to comment.