Repository: oozie Updated Branches: refs/heads/branch-4.2 545b37c18 -> 46402ac45
OOZIE-2240 add configuration to disable email attachment support (egashira via shwethags) Project: http://git-wip-us.apache.org/repos/asf/oozie/repo Commit: http://git-wip-us.apache.org/repos/asf/oozie/commit/46402ac4 Tree: http://git-wip-us.apache.org/repos/asf/oozie/tree/46402ac4 Diff: http://git-wip-us.apache.org/repos/asf/oozie/diff/46402ac4 Branch: refs/heads/branch-4.2 Commit: 46402ac45577fcbe946ab8805ce471f83d1479dd Parents: 545b37c Author: Shwetha GS <[email protected]> Authored: Fri May 22 11:34:57 2015 +0530 Committer: Shwetha GS <[email protected]> Committed: Fri May 22 11:34:57 2015 +0530 ---------------------------------------------------------------------- .../oozie/action/email/EmailActionExecutor.java | 11 +++++- core/src/main/resources/oozie-default.xml | 8 +++++ .../action/email/TestEmailActionExecutor.java | 36 ++++++++++++++------ release-log.txt | 3 +- 4 files changed, 46 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oozie/blob/46402ac4/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java b/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java index 04d49c3..1d260b4 100644 --- a/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java +++ b/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java @@ -52,6 +52,7 @@ import org.apache.oozie.action.ActionExecutor; import org.apache.oozie.action.ActionExecutorException; import org.apache.oozie.action.ActionExecutorException.ErrorType; import org.apache.oozie.client.WorkflowAction; +import org.apache.oozie.service.ConfigurationService; import org.apache.oozie.service.HadoopAccessorException; import org.apache.oozie.service.Services; import org.apache.oozie.service.HadoopAccessorService; @@ -73,6 +74,7 @@ public class EmailActionExecutor extends ActionExecutor { public static final String EMAIL_SMTP_USER = CONF_PREFIX + "smtp.username"; public static final String EMAIL_SMTP_PASS = CONF_PREFIX + "smtp.password"; public static final String EMAIL_SMTP_FROM = CONF_PREFIX + "from.address"; + public static final String EMAIL_ATTACHMENT_ENABLED = CONF_PREFIX + "attachment.enabled"; private final static String TO = "to"; private final static String CC = "cc"; @@ -84,6 +86,10 @@ public class EmailActionExecutor extends ActionExecutor { private final static String DEFAULT_CONTENT_TYPE = "text/plain"; private XLog LOG = XLog.getLog(getClass()); + public static final String EMAIL_ATTACHMENT_ERROR_MSG = + "\n Note: This email is missing configured email attachments " + + "as sending attachments in email action is disabled in the Oozie server. " + + "It could be for security compliance with data protection or other reasons"; public EmailActionExecutor() { super("email"); @@ -210,7 +216,7 @@ public class EmailActionExecutor extends ActionExecutor { message.setSubject(subject); // when there is attachment - if (attachments != null && attachments.length > 0) { + if (attachments != null && attachments.length > 0 && ConfigurationService.getBoolean(EMAIL_ATTACHMENT_ENABLED)) { Multipart multipart = new MimeMultipart(); // Set body text @@ -234,6 +240,9 @@ public class EmailActionExecutor extends ActionExecutor { message.setContent(multipart); } else { + if (attachments != null && attachments.length > 0 && !ConfigurationService.getBoolean(EMAIL_ATTACHMENT_ENABLED)) { + body = body + EMAIL_ATTACHMENT_ERROR_MSG; + } message.setContent(body, contentType); } } http://git-wip-us.apache.org/repos/asf/oozie/blob/46402ac4/core/src/main/resources/oozie-default.xml ---------------------------------------------------------------------- diff --git a/core/src/main/resources/oozie-default.xml b/core/src/main/resources/oozie-default.xml index 8d59182..8960073 100644 --- a/core/src/main/resources/oozie-default.xml +++ b/core/src/main/resources/oozie-default.xml @@ -2535,4 +2535,12 @@ </description> </property> + <property> + <name>oozie.email.attachment.enabled</name> + <value>true</value> + <description> + This value determines whether to support email attachment of a file on HDFS. + Set it false if there is any security concern. + </description> + </property> </configuration> http://git-wip-us.apache.org/repos/asf/oozie/blob/46402ac4/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java b/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java index 1ccd22d..747e3ac 100644 --- a/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java +++ b/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java @@ -35,6 +35,7 @@ import org.apache.oozie.WorkflowActionBean; import org.apache.oozie.WorkflowJobBean; import org.apache.oozie.action.ActionExecutorException; import org.apache.oozie.action.hadoop.ActionExecutorTestCase; +import org.apache.oozie.service.ConfigurationService; import org.apache.oozie.service.Services; import org.apache.oozie.service.WorkflowAppService; import org.apache.oozie.util.XConfiguration; @@ -229,18 +230,21 @@ public class TestEmailActionExecutor extends ActionExecutorTestCase { StringBuilder tag = new StringBuilder(); tag.append(path1.toString()).append(",").append(path2.toString()); assertAttachment(tag.toString(), 2, content1, content2); + + //test case when email attachment support set to false + ConfigurationService.setBoolean(EmailActionExecutor.EMAIL_ATTACHMENT_ENABLED, false); + sendAndReceiveEmail(tag.toString()); + MimeMessage retMeg = server.getReceivedMessages()[1]; + String msgBody = GreenMailUtil.getBody(retMeg); + assertEquals(msgBody.indexOf("This is a test mail"), 0); + assertNotSame(msgBody.indexOf(EmailActionExecutor.EMAIL_ATTACHMENT_ERROR_MSG),-1); + // email content is not multi-part since not attaching files + assertFalse(retMeg.getContent() instanceof Multipart); + assertTrue(retMeg.getContentType().contains("text/plain")); } private void assertAttachment(String attachtag, int attachCount, String content1, String content2) throws Exception { - StringBuilder elem = new StringBuilder(); - elem.append("<email xmlns=\"uri:oozie:email-action:0.2\">"); - elem.append("<to>[email protected]</to>"); - elem.append("<subject>sub</subject>"); - elem.append("<body><body> This is a test mail </body></body>"); - elem.append("<attachment>").append(attachtag).append("</attachment>"); - elem.append("</email>"); - EmailActionExecutor emailContnetType = new EmailActionExecutor(); - emailContnetType.validateAndMail(createAuthContext("email-action"), XmlUtils.parseXml(elem.toString())); + sendAndReceiveEmail(attachtag); MimeMessage retMeg = server.getReceivedMessages()[0]; Multipart retParts = (Multipart) (retMeg.getContent()); int numAttach = 0; @@ -253,12 +257,24 @@ public class TestEmailActionExecutor extends ActionExecutorTestCase { numAttach++; } else { - assertEquals("<body> This is a test mail </body>", retValue); + assertEquals("This is a test mail", retValue); } } assertEquals(attachCount, numAttach); } + private void sendAndReceiveEmail(String attachtag) throws Exception { + StringBuilder elem = new StringBuilder(); + elem.append("<email xmlns=\"uri:oozie:email-action:0.2\">"); + elem.append("<to>[email protected]</to>"); + elem.append("<subject>sub</subject>"); + elem.append("<body>This is a test mail</body>"); + elem.append("<attachment>").append(attachtag).append("</attachment>"); + elem.append("</email>"); + EmailActionExecutor emailExecutor = new EmailActionExecutor(); + emailExecutor.validateAndMail(createAuthContext("email-action"), XmlUtils.parseXml(elem.toString())); + } + @Override protected void tearDown() throws Exception { super.tearDown(); http://git-wip-us.apache.org/repos/asf/oozie/blob/46402ac4/release-log.txt ---------------------------------------------------------------------- diff --git a/release-log.txt b/release-log.txt index 09e4b81..737c768 100644 --- a/release-log.txt +++ b/release-log.txt @@ -1,5 +1,6 @@ --- Oozie 4.2.0 release (unreleased) +-- Oozie 4.2.0 release +OOZIE-2240 add configuration to disable email attachment support (egashira via shwethags) OOZIE-1963 Create a Hive Server 2 example (qwertymaniac via shwethags) OOZIE-1993 Rerun fails during join in certain condition (shwethags) OOZIE-2236 Need to package hive-hcatalog-server-extensions.jar in the hcatalog sharelib (venkatnrangan via bzhang)
