|
19 | 19 |
|
20 | 20 | package org.elasticsearch.bootstrap; |
21 | 21 |
|
| 22 | +import org.elasticsearch.Build; |
22 | 23 | import org.elasticsearch.SecureSM; |
| 24 | +import org.elasticsearch.Version; |
23 | 25 | import org.elasticsearch.common.SuppressForbidden; |
24 | 26 | import org.elasticsearch.common.io.PathUtils; |
25 | 27 | import org.elasticsearch.common.network.NetworkModule; |
|
43 | 45 | import java.security.Permissions; |
44 | 46 | import java.security.Policy; |
45 | 47 | import java.security.URIParameter; |
| 48 | +import java.util.ArrayList; |
46 | 49 | import java.util.Collections; |
47 | 50 | import java.util.HashMap; |
48 | 51 | import java.util.HashSet; |
49 | 52 | import java.util.LinkedHashSet; |
| 53 | +import java.util.List; |
50 | 54 | import java.util.Map; |
51 | 55 | import java.util.Set; |
52 | 56 |
|
@@ -191,27 +195,39 @@ static Map<String,Policy> getPluginPermissions(Environment environment) throws I |
191 | 195 | @SuppressForbidden(reason = "accesses fully qualified URLs to configure security") |
192 | 196 | static Policy readPolicy(URL policyFile, Set<URL> codebases) { |
193 | 197 | try { |
| 198 | + List<String> propertiesSet = new ArrayList<>(); |
194 | 199 | try { |
195 | 200 | // set codebase properties |
196 | 201 | for (URL url : codebases) { |
197 | 202 | String shortName = PathUtils.get(url.toURI()).getFileName().toString(); |
198 | 203 | if (shortName.endsWith(".jar") == false) { |
199 | 204 | continue; // tests :( |
200 | 205 | } |
201 | | - String previous = System.setProperty("codebase." + shortName, url.toString()); |
| 206 | + String property = "codebase." + shortName; |
| 207 | + if (shortName.startsWith("elasticsearch-rest-client")) { |
| 208 | + // The rest client is currently the only example where we have an elasticsearch built artifact |
| 209 | + // which needs special permissions in policy files when used. This temporary solution is to |
| 210 | + // pass in an extra system property that omits the -version.jar suffix the other properties have. |
| 211 | + // That allows the snapshots to reference snapshot builds of the client, and release builds to |
| 212 | + // referenced release builds of the client, all with the same grant statements. |
| 213 | + final String esVersion = Version.CURRENT + (Build.CURRENT.isSnapshot() ? "-SNAPSHOT" : ""); |
| 214 | + final int index = property.indexOf("-" + esVersion + ".jar"); |
| 215 | + assert index >= 0; |
| 216 | + String restClientAlias = property.substring(0, index); |
| 217 | + propertiesSet.add(restClientAlias); |
| 218 | + System.setProperty(restClientAlias, url.toString()); |
| 219 | + } |
| 220 | + propertiesSet.add(property); |
| 221 | + String previous = System.setProperty(property, url.toString()); |
202 | 222 | if (previous != null) { |
203 | 223 | throw new IllegalStateException("codebase property already set: " + shortName + "->" + previous); |
204 | 224 | } |
205 | 225 | } |
206 | 226 | return Policy.getInstance("JavaPolicy", new URIParameter(policyFile.toURI())); |
207 | 227 | } finally { |
208 | 228 | // clear codebase properties |
209 | | - for (URL url : codebases) { |
210 | | - String shortName = PathUtils.get(url.toURI()).getFileName().toString(); |
211 | | - if (shortName.endsWith(".jar") == false) { |
212 | | - continue; // tests :( |
213 | | - } |
214 | | - System.clearProperty("codebase." + shortName); |
| 229 | + for (String property : propertiesSet) { |
| 230 | + System.clearProperty(property); |
215 | 231 | } |
216 | 232 | } |
217 | 233 | } catch (NoSuchAlgorithmException | URISyntaxException e) { |
|
0 commit comments