-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Cleanup some things after removal of joda-time hack #18959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,11 +45,11 @@ | |
| import java.security.Permissions; | ||
| import java.security.Policy; | ||
| import java.security.URIParameter; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Initializes SecurityManager with necessary permissions. | ||
|
|
@@ -133,19 +133,23 @@ static void configure(Environment environment, boolean filterBadDefaults) throws | |
| @SuppressForbidden(reason = "proper use of URL") | ||
| static Map<String,Policy> getPluginPermissions(Environment environment) throws IOException, NoSuchAlgorithmException { | ||
| Map<String,Policy> map = new HashMap<>(); | ||
| // collect up lists of plugins and modules | ||
| List<Path> pluginsAndModules = new ArrayList<>(); | ||
| // collect up set of plugins and modules by listing directories. | ||
| Set<Path> pluginsAndModules = new LinkedHashSet<>(); // order is already lost, but some filesystems have it | ||
| if (Files.exists(environment.pluginsFile())) { | ||
| try (DirectoryStream<Path> stream = Files.newDirectoryStream(environment.pluginsFile())) { | ||
| for (Path plugin : stream) { | ||
| pluginsAndModules.add(plugin); | ||
| if (pluginsAndModules.add(plugin) == false) { | ||
| throw new IllegalStateException("duplicate plugin: " + plugin); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (Files.exists(environment.modulesFile())) { | ||
| try (DirectoryStream<Path> stream = Files.newDirectoryStream(environment.modulesFile())) { | ||
| for (Path plugin : stream) { | ||
| pluginsAndModules.add(plugin); | ||
| for (Path module : stream) { | ||
| if (pluginsAndModules.add(module) == false) { | ||
| throw new IllegalStateException("duplicate module: " + module); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -155,15 +159,18 @@ static Map<String,Policy> getPluginPermissions(Environment environment) throws I | |
| if (Files.exists(policyFile)) { | ||
| // first get a list of URLs for the plugins' jars: | ||
| // we resolve symlinks so map is keyed on the normalize codebase name | ||
| List<URL> codebases = new ArrayList<>(); | ||
| Set<URL> codebases = new LinkedHashSet<>(); // order is already lost, but some filesystems have it | ||
| try (DirectoryStream<Path> jarStream = Files.newDirectoryStream(plugin, "*.jar")) { | ||
| for (Path jar : jarStream) { | ||
| codebases.add(jar.toRealPath().toUri().toURL()); | ||
| URL url = jar.toRealPath().toUri().toURL(); | ||
| if (codebases.add(url) == false) { | ||
| throw new IllegalStateException("duplicate module/plugin: " + url); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // parse the plugin's policy file into a set of permissions | ||
| Policy policy = readPolicy(policyFile.toUri().toURL(), codebases.toArray(new URL[codebases.size()])); | ||
| Policy policy = readPolicy(policyFile.toUri().toURL(), codebases); | ||
|
|
||
| // consult this policy for each of the plugin's jars: | ||
| for (URL url : codebases) { | ||
|
|
@@ -181,24 +188,33 @@ static Map<String,Policy> getPluginPermissions(Environment environment) throws I | |
| /** | ||
| * Reads and returns the specified {@code policyFile}. | ||
| * <p> | ||
| * Resources (e.g. jar files and directories) listed in {@code codebases} location | ||
| * Jar files listed in {@code codebases} location | ||
| * will be provided to the policy file via a system property of the short name: | ||
| * e.g. <code>${codebase.joda-convert-1.2.jar}</code> would map to full URL. | ||
| */ | ||
| @SuppressForbidden(reason = "accesses fully qualified URLs to configure security") | ||
| static Policy readPolicy(URL policyFile, URL codebases[]) { | ||
| static Policy readPolicy(URL policyFile, Set<URL> codebases) { | ||
| try { | ||
| try { | ||
| // set codebase properties | ||
| for (URL url : codebases) { | ||
| String shortName = PathUtils.get(url.toURI()).getFileName().toString(); | ||
| System.setProperty("codebase." + shortName, url.toString()); | ||
| if (shortName.endsWith(".jar") == false) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we set some system property or so that we can use to at least asssert that we are running tests? I mean it would be nice if somebody tries to sneak in here if we can fail? just a suggestion can also be a followup?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is absolutely nothing I can do here. Otherwise it will break IDEs running these shitty tests, where no sysprop is set :( Thats always been the problem with so much of this stuff! |
||
| continue; // tests :( | ||
| } | ||
| String previous = System.setProperty("codebase." + shortName, url.toString()); | ||
| if (previous != null) { | ||
| throw new IllegalStateException("codebase properly already set: " + shortName + "->" + previous); | ||
| } | ||
| } | ||
| return Policy.getInstance("JavaPolicy", new URIParameter(policyFile.toURI())); | ||
| } finally { | ||
| // clear codebase properties | ||
| for (URL url : codebases) { | ||
| String shortName = PathUtils.get(url.toURI()).getFileName().toString(); | ||
| if (shortName.endsWith(".jar") == false) { | ||
| continue; // tests :( | ||
| } | ||
| System.clearProperty("codebase." + shortName); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is off here?