Martin Peřina has uploaded a new change for review.

Change subject: tools: Adds option MAIL_SMTP_ENCRYPTION to notifier
......................................................................

tools: Adds option MAIL_SMTP_ENCRYPTION to notifier

Adds option MAIL_SMTP_ENCRYPTION to allow multiple types of SMTP
encryption to be specified in notifier config. This new option also
replaces old MAIL_ENABLE_SSL option.

Change-Id: I4a914091060c0a86b2710ce20e666d67f28fa401
Signed-off-by: Martin Perina <[email protected]>
---
M 
backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/NotificationProperties.java
M 
backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/sender/mail/JavaMailSender.java
M 
backend/manager/tools/src/test/java/org/ovirt/engine/core/notifier/utils/mail/MailSenderTest.java
M backend/manager/tools/src/test/resources/conf/connection-test-notifier.conf
M backend/manager/tools/src/test/resources/conf/error-notifier.conf
M backend/manager/tools/src/test/resources/conf/notifier-mail-test-plain.conf
M backend/manager/tools/src/test/resources/conf/notifier-mail-test-secured.conf
M backend/manager/tools/src/test/resources/conf/notifier-prop-test.conf
M packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in
9 files changed, 57 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/96/22296/1

diff --git 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/NotificationProperties.java
 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/NotificationProperties.java
index 91d6360..74d9dbd 100644
--- 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/NotificationProperties.java
+++ 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/NotificationProperties.java
@@ -19,10 +19,20 @@
     public static final String MAIL_PORT = "MAIL_PORT";
     public static final String MAIL_USER = "MAIL_USER";
     public static final String MAIL_PASSWORD = "MAIL_PASSWORD";
-    public static final String MAIL_ENABLE_SSL = "MAIL_ENABLE_SSL";
+    public static final String MAIL_SMTP_ENCRYPTION = "MAIL_SMTP_ENCRYPTION";
     public static final String MAIL_FROM = "MAIL_FROM";
     public static final String MAIL_REPLY_TO = "MAIL_REPLY_TO";
     public static final String HTML_MESSAGE_FORMAT = "HTML_MESSAGE_FORMAT";
+
+    /**
+     * No SMTP transport encryption (plain SMTP)
+     */
+    public static final String MAIL_SMTP_ENCRYPTION_NONE = "none";
+
+    /**
+     * SMTP transport encryption using SSL (SMTPS)
+     */
+    public static final String MAIL_SMTP_ENCRYPTION_SSL = "ssl";
 
     /**
      * Service parameters
@@ -102,6 +112,7 @@
 
     /**
      * Validates properties values.
+     *
      * @throws IllegalArgumentException if some properties has invalid values
      */
     public void validate() {
@@ -121,6 +132,16 @@
                                 "Check configuration file, '%s' is missing",
                                 property));
             }
+        }
+
+        if (!isSmtpEncryptionOptionValid()) {
+            throw new IllegalArgumentException(
+                    String.format(
+                        "Check configuration file, '%s' value has to be one 
of: '%s', '%s'.",
+                        NotificationProperties.MAIL_SMTP_ENCRYPTION,
+                        NotificationProperties.MAIL_SMTP_ENCRYPTION_NONE,
+                        NotificationProperties.MAIL_SMTP_ENCRYPTION_SSL
+                    ));
         }
 
         // try to resolve MAIL_SERVER host
@@ -156,7 +177,7 @@
         // validate mail user value
         String emailUser = getProperty(NotificationProperties.MAIL_USER, true);
         if (StringUtils.isEmpty(emailUser)
-                && (getBoolean(NotificationProperties.MAIL_ENABLE_SSL, false)
+                && (isSmtpEncryptionSsl()
                         || 
StringUtils.isNotEmpty(getProperty(NotificationProperties.MAIL_PASSWORD, 
true)))) {
                 throw new IllegalArgumentException(
                         String.format(
@@ -164,4 +185,28 @@
                                 NotificationProperties.MAIL_USER));
         }
     }
+
+    /**
+     * Returns {@code true}, mail transport encryption type {@link 
MAIL_SMTP_ENCRYPTION} is set to none
+     * {@link MAIL_SMTP_ENCRYPTION_NONE}
+     */
+    public boolean isSmtpEncryptionNone() {
+        return 
MAIL_SMTP_ENCRYPTION_NONE.equals(getProperty(MAIL_SMTP_ENCRYPTION, true));
+    }
+
+    /**
+     * Returns {@code true}, mail transport encryption type {@link 
MAIL_SMTP_ENCRYPTION} is set to SSL
+     * {@link MAIL_SMTP_ENCRYPTION_SSL}
+     */
+    public boolean isSmtpEncryptionSsl() {
+        return 
MAIL_SMTP_ENCRYPTION_SSL.equals(getProperty(MAIL_SMTP_ENCRYPTION, true));
+    }
+
+    /**
+     * Returns {@code true} if mail transport encryption type {@link 
MAIL_SMTP_ENCRYPTION} is correctly specified,
+     * otherwise {@code false}
+     */
+    public boolean isSmtpEncryptionOptionValid() {
+        return isSmtpEncryptionNone() || isSmtpEncryptionSsl();
+    }
 }
diff --git 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/sender/mail/JavaMailSender.java
 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/sender/mail/JavaMailSender.java
index 7139134..6283583 100644
--- 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/sender/mail/JavaMailSender.java
+++ 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/sender/mail/JavaMailSender.java
@@ -40,7 +40,7 @@
         mailSessionProps.put("mail.smtp.host", 
aMailProps.getProperty(NotificationProperties.MAIL_SERVER));
         mailSessionProps.put("mail.smtp.port", 
aMailProps.getProperty(NotificationProperties.MAIL_PORT));
         // enable SSL
-        if (aMailProps.getBoolean(NotificationProperties.MAIL_ENABLE_SSL, 
false)) {
+        if (aMailProps.isSmtpEncryptionSsl()) {
             mailSessionProps.put("mail.smtp.auth", "true");
             mailSessionProps.put("mail.smtp.socketFactory.class", 
"javax.net.ssl.SSLSocketFactory");
             mailSessionProps.put("mail.smtp.socketFactory.fallback", false);
diff --git 
a/backend/manager/tools/src/test/java/org/ovirt/engine/core/notifier/utils/mail/MailSenderTest.java
 
b/backend/manager/tools/src/test/java/org/ovirt/engine/core/notifier/utils/mail/MailSenderTest.java
index f934f69..dbc7617 100644
--- 
a/backend/manager/tools/src/test/java/org/ovirt/engine/core/notifier/utils/mail/MailSenderTest.java
+++ 
b/backend/manager/tools/src/test/java/org/ovirt/engine/core/notifier/utils/mail/MailSenderTest.java
@@ -106,6 +106,7 @@
         prop.put(NotificationProperties.MAIL_SERVER, "smtp.redhat.com");
         prop.put(NotificationProperties.MAIL_USER, "[email protected]");
         prop.put(NotificationProperties.HTML_MESSAGE_FORMAT, "true");
+        prop.put(NotificationProperties.MAIL_SMTP_ENCRYPTION, 
NotificationProperties.MAIL_SMTP_ENCRYPTION_NONE);
 
         return prop;
     }
@@ -117,7 +118,7 @@
         prop.put(NotificationProperties.MAIL_USER, 
"[email protected]");
         prop.put(NotificationProperties.MAIL_PASSWORD, "q1!w2@e3#!");
         prop.put(NotificationProperties.MAIL_FROM, "[email protected]");
-        prop.put(NotificationProperties.MAIL_ENABLE_SSL, "true");
+        prop.put(NotificationProperties.MAIL_SMTP_ENCRYPTION, 
NotificationProperties.MAIL_SMTP_ENCRYPTION_SSL);
         return prop;
     }
 
diff --git 
a/backend/manager/tools/src/test/resources/conf/connection-test-notifier.conf 
b/backend/manager/tools/src/test/resources/conf/connection-test-notifier.conf
index 104f4aa..8bf0b01 100644
--- 
a/backend/manager/tools/src/test/resources/conf/connection-test-notifier.conf
+++ 
b/backend/manager/tools/src/test/resources/conf/connection-test-notifier.conf
@@ -10,7 +10,7 @@
 [email protected]
 #MAIL_PASSWORD=xxxx
 #HTML_MESSAGE_FORMAT=true
-#MAIL_ENABLE_SSL=true
+#MAIL_SMTP_ENCRYPTION=none
 #MAIL_USE_DEFAULT_CREDENTIALS=false
 
 # Days to keep history in the event_notification_history table
diff --git a/backend/manager/tools/src/test/resources/conf/error-notifier.conf 
b/backend/manager/tools/src/test/resources/conf/error-notifier.conf
index c18ab02..872fcf5 100644
--- a/backend/manager/tools/src/test/resources/conf/error-notifier.conf
+++ b/backend/manager/tools/src/test/resources/conf/error-notifier.conf
@@ -10,7 +10,7 @@
 [email protected]
 #MAIL_PASSWORD=xxxx
 #HTML_MESSAGE_FORMAT=true
-#MAIL_ENABLE_SSL=true
+#MAIL_SMTP_ENCRYPTION=none
 #MAIL_USE_DEFAULT_CREDENTIALS=false
 
 # Engine server monitor settings
diff --git 
a/backend/manager/tools/src/test/resources/conf/notifier-mail-test-plain.conf 
b/backend/manager/tools/src/test/resources/conf/notifier-mail-test-plain.conf
index 91ae87c..6b6e2b2 100644
--- 
a/backend/manager/tools/src/test/resources/conf/notifier-mail-test-plain.conf
+++ 
b/backend/manager/tools/src/test/resources/conf/notifier-mail-test-plain.conf
@@ -15,3 +15,4 @@
 MAIL_PORT=25
 [email protected]
 HTML_MESSAGE_FORMAT=true
+MAIL_SMTP_ENCRYPTION=none
diff --git 
a/backend/manager/tools/src/test/resources/conf/notifier-mail-test-secured.conf 
b/backend/manager/tools/src/test/resources/conf/notifier-mail-test-secured.conf
index 1e0d854..34d234a 100644
--- 
a/backend/manager/tools/src/test/resources/conf/notifier-mail-test-secured.conf
+++ 
b/backend/manager/tools/src/test/resources/conf/notifier-mail-test-secured.conf
@@ -16,4 +16,4 @@
 [email protected]
 MAIL_PASSWORD="q1!w2@e3#!"
 [email protected]
-MAIL_ENABLE_SSL=true
+MAIL_SMTP_ENCRYPTION=ssl
diff --git 
a/backend/manager/tools/src/test/resources/conf/notifier-prop-test.conf 
b/backend/manager/tools/src/test/resources/conf/notifier-prop-test.conf
index f5a1765..19221da 100644
--- a/backend/manager/tools/src/test/resources/conf/notifier-prop-test.conf
+++ b/backend/manager/tools/src/test/resources/conf/notifier-prop-test.conf
@@ -5,7 +5,7 @@
 [email protected]
 #MAIL_PASSWORD=xxxx
 #HTML_MESSAGE_FORMAT=true
-#MAIL_ENABLE_SSL=true
+#MAIL_SMTP_ENCRYPTION=none
 #MAIL_USE_DEFAULT_CREDENTIALS=false
 
 # Engine server monitor settings
diff --git 
a/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in 
b/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in
index 21ba7ad..3fba4d2 100644
--- a/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in
+++ b/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in
@@ -57,8 +57,8 @@
 SENSITIVE_KEYS="${SENSITIVE_KEYS},MAIL_PASSWORD"
 MAIL_PASSWORD=
 
-# Indicates whether SSL should be used to communicate with mail server.
-MAIL_ENABLE_SSL=false
+# Indicates type of encryption (none or ssl) should be used to communicate 
with mail server.
+MAIL_SMTP_ENCRYPTION=none
 
 # If set to true, sends a message in HTML format.
 HTML_MESSAGE_FORMAT=false


-- 
To view, visit http://gerrit.ovirt.org/22296
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a914091060c0a86b2710ce20e666d67f28fa401
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Martin Peřina <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to