diff --git a/elasticsearch/license/base/build.gradle b/elasticsearch/license/base/build.gradle index 6263d20cd4e..c76fb7c7579 100644 --- a/elasticsearch/license/base/build.gradle +++ b/elasticsearch/license/base/build.gradle @@ -5,6 +5,8 @@ dependencies { testCompile "org.elasticsearch.test:framework:${version}" } +compactProfile = 'full' + dependencyLicenses.enabled = false jar { diff --git a/elasticsearch/x-pack/build.gradle b/elasticsearch/x-pack/build.gradle index a9e223f3f74..07ec70d1a1a 100644 --- a/elasticsearch/x-pack/build.gradle +++ b/elasticsearch/x-pack/build.gradle @@ -35,6 +35,10 @@ dependencies { compile 'com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer:r239' compile 'com.google.guava:guava:16.0.1' // needed by watcher for the html sanitizer and shield tests for jimfs compile 'com.sun.mail:javax.mail:1.5.3' + // HACK: java 9 removed javax.activation from the default modules, so instead of trying to add modules, which would have + // to be conditionalized for java 8/9, we pull in the classes directly + compile 'javax.activation:activation:1.1' + testCompile 'org.subethamail:subethasmtp:3.1.7' // needed for subethasmtp, has @GuardedBy annotation testCompile 'com.google.code.findbugs:jsr305:3.0.1' diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/AbstractExporterTemplateTestCase.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/AbstractExporterTemplateTestCase.java index 2986a0f28e3..3cbf9fbbfc9 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/AbstractExporterTemplateTestCase.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/AbstractExporterTemplateTestCase.java @@ -121,7 +121,8 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa assertNotNull(exporters); // Wait for exporting bulks to be ready to export - assertBusy(() -> assertThat(exporters.openBulk(), notNullValue())); + Runnable busy = () -> assertThat(exporters.openBulk(), notNullValue()); + assertBusy(busy); exporters.export(collector.collect()); } diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporterTemplateTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporterTemplateTests.java index c9dd36c7716..dae09e0131f 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporterTemplateTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/http/HttpExporterTemplateTests.java @@ -93,7 +93,8 @@ public class HttpExporterTemplateTests extends AbstractExporterTemplateTestCase @Override protected void awaitIndexExists(String index) throws Exception { - assertBusy(() -> assertThat("could not find index " + index, dispatcher.hasIndex(index), is(true)), 10, TimeUnit.SECONDS); + Runnable busy = () -> assertThat("could not find index " + index, dispatcher.hasIndex(index), is(true)); + assertBusy(busy, 10, TimeUnit.SECONDS); } class MockServerDispatcher extends Dispatcher { diff --git a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/file/tool/UsersToolTests.java b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/file/tool/UsersToolTests.java index 8e18018dac6..44a1c2730a8 100644 --- a/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/file/tool/UsersToolTests.java +++ b/elasticsearch/x-pack/shield/src/test/java/org/elasticsearch/shield/authc/file/tool/UsersToolTests.java @@ -92,6 +92,7 @@ public class UsersToolTests extends CommandTestCase { public static void closeJimfs() throws IOException { if (jimfs != null) { jimfs.close(); + jimfs = null; } } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index 19b705fa770..2dbaebfbff1 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -37,6 +37,8 @@ import org.elasticsearch.xpack.common.secret.SecretModule; import org.elasticsearch.xpack.extensions.XPackExtension; import org.elasticsearch.xpack.extensions.XPackExtensionsService; import org.elasticsearch.xpack.notification.Notification; +import org.elasticsearch.xpack.notification.email.Account; +import org.elasticsearch.xpack.notification.email.support.BodyPartSource; import org.elasticsearch.xpack.rest.action.RestXPackInfoAction; import org.elasticsearch.xpack.common.text.TextTemplateModule; import org.elasticsearch.xpack.rest.action.RestXPackUsageAction; @@ -84,6 +86,9 @@ public class XPackPlugin extends Plugin { throw bogus; // some other bug } } + // some classes need to have their own clinit blocks + BodyPartSource.init(); + Account.init(); } protected final Settings settings; diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Account.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Account.java index 28ab5a27e3e..fed92a3408a 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Account.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/Account.java @@ -32,13 +32,6 @@ public class Account { static final String SMTP_PROTOCOL = "smtp"; static { - // required as java doesn't always find the correct mailcap to properly handle mime types - final MailcapCommandMap mailcap = (MailcapCommandMap) CommandMap.getDefaultCommandMap(); - mailcap.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html"); - mailcap.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml"); - mailcap.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain"); - mailcap.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed"); - mailcap.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822"); SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission(new SpecialPermission()); @@ -46,12 +39,22 @@ public class Account { AccessController.doPrivileged(new PrivilegedAction() { @Override public Void run() { + // required as java doesn't always find the correct mailcap to properly handle mime types + final MailcapCommandMap mailcap = (MailcapCommandMap) CommandMap.getDefaultCommandMap(); + mailcap.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html"); + mailcap.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml"); + mailcap.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain"); + mailcap.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed"); + mailcap.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822"); CommandMap.setDefaultCommandMap(mailcap); return null; } }); } + // exists only to allow ensuring class is initialized + public static void init() {} + static final Settings DEFAULT_SMTP_TIMEOUT_SETTINGS = Settings.builder() .put("connection_timeout", TimeValue.timeValueMinutes(2)) .put("write_timeout", TimeValue.timeValueMinutes(2)) diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/support/BodyPartSource.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/support/BodyPartSource.java index 40e4582ae64..f7376888feb 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/support/BodyPartSource.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/support/BodyPartSource.java @@ -5,18 +5,30 @@ */ package org.elasticsearch.xpack.notification.email.support; +import org.elasticsearch.SpecialPermission; import org.elasticsearch.common.xcontent.ToXContent; +import javax.activation.CommandMap; import javax.activation.FileTypeMap; import javax.mail.MessagingException; import javax.mail.internet.MimeBodyPart; +import java.security.AccessController; +import java.security.PrivilegedAction; /** * */ public abstract class BodyPartSource implements ToXContent { - protected static FileTypeMap fileTypeMap = FileTypeMap.getDefaultFileTypeMap(); + protected static FileTypeMap fileTypeMap; + static { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkPermission(new SpecialPermission()); + } + fileTypeMap = AccessController.doPrivileged( + (PrivilegedAction)() -> FileTypeMap.getDefaultFileTypeMap()); + } protected final String id; protected final String name; @@ -46,4 +58,7 @@ public abstract class BodyPartSource implements ToXContent { public abstract MimeBodyPart bodyPart() throws MessagingException; + // exists only to allow ensuring class is initialized + public static void init() {} + } diff --git a/elasticsearch/x-pack/src/main/plugin-metadata/plugin-security.policy b/elasticsearch/x-pack/src/main/plugin-metadata/plugin-security.policy index 881e64e9da4..d3e821f4858 100644 --- a/elasticsearch/x-pack/src/main/plugin-metadata/plugin-security.policy +++ b/elasticsearch/x-pack/src/main/plugin-metadata/plugin-security.policy @@ -11,6 +11,8 @@ grant { // to load the class with the application class loader permission java.lang.RuntimePermission "setContextClassLoader"; permission java.lang.RuntimePermission "getClassLoader"; + // TODO: remove use of this jar as soon as possible!!!! + permission java.lang.RuntimePermission "accessClassInPackage.com.sun.activation.registries"; // bouncy castle permission java.security.SecurityPermission "putProviderProperty.BC"; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java index 1500c2f6dc2..fd358684e60 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java @@ -6,6 +6,9 @@ package org.elasticsearch.xpack.watcher.history; import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.common.logging.ESLoggerFactory; +import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.search.aggregations.Aggregations; import org.elasticsearch.search.aggregations.bucket.terms.Terms; @@ -15,6 +18,9 @@ import org.elasticsearch.xpack.watcher.execution.ExecutionState; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse; import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; @@ -32,14 +38,17 @@ import static org.hamcrest.Matchers.notNullValue; * not analyzed so they can be used in aggregations */ public class HistoryTemplateEmailMappingsTests extends AbstractWatcherIntegrationTestCase { + private static final ESLogger logger = Loggers.getLogger(HistoryTemplateEmailMappingsTests.class); static final String USERNAME = "_user"; static final String PASSWORD = "_passwd"; - private EmailServer server; + private static EmailServer server; - @After - public void cleanup() throws Exception { - server.stop(); + @AfterClass + public static void cleanup() throws Exception { + if (server != null) { + server.stop(); + } } @Override @@ -52,12 +61,16 @@ public class HistoryTemplateEmailMappingsTests extends AbstractWatcherIntegratio return false; // remove shield noise from this test } - @Override - protected Settings nodeSettings(int nodeOrdinal) { + @BeforeClass + public static void setupEmailServer() { if(server == null) { //Need to construct the Email Server here as this happens before init() server = EmailServer.localhost("2500-2600", USERNAME, PASSWORD, logger); } + } + + @Override + protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal))