← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16348: Email settings, encrypting smtp password

 

------------------------------------------------------------
revno: 16348
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-08-08 11:41:58 +0200
message:
  Email settings, encrypting smtp password
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetSMTPSettingsAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetSMTPSettingsAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/META-INF/dhis/beans.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java	2014-07-07 06:44:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/configuration/Configuration.java	2014-08-08 09:41:58 +0000
@@ -82,6 +82,12 @@
     private String remoteServerPassword;
 
     // -------------------------------------------------------------------------
+    // SMTP
+    // -------------------------------------------------------------------------
+    
+    private String smtpPassword;
+    
+    // -------------------------------------------------------------------------
     // Constructor
     // -------------------------------------------------------------------------
 
@@ -219,4 +225,17 @@
     {
         this.remoteServerPassword = remoteServerPassword;
     }
+
+    /**
+     * Do not serialize.
+     */
+    public String getSmtpPassword()
+    {
+        return smtpPassword;
+    }
+    
+    public void setSmtpPassword( String smtpPassword )
+    {
+        this.smtpPassword = smtpPassword;
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java	2014-08-05 10:57:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java	2014-08-08 09:41:58 +0000
@@ -150,8 +150,6 @@
 
     String getEmailUsername();
 
-    String getEmailPassword();
-
     boolean getEmailTls();
     
     String getEmailSender();

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java	2014-08-05 14:21:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/message/EmailMessageSender.java	2014-08-08 09:41:58 +0000
@@ -39,6 +39,7 @@
 import org.apache.commons.mail.Email;
 import org.apache.commons.mail.EmailException;
 import org.apache.commons.mail.SimpleEmail;
+import org.hisp.dhis.configuration.ConfigurationService;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.system.util.DebugUtils;
 import org.hisp.dhis.user.User;
@@ -70,6 +71,13 @@
         this.systemSettingManager = systemSettingManager;
     }
     
+    private ConfigurationService configurationService;
+    
+    public void setConfigurationService( ConfigurationService configurationService )
+    {
+        this.configurationService = configurationService;
+    }
+    
     private UserService userService;
 
     public void setUserService( UserService userService )
@@ -91,7 +99,7 @@
         String hostName = systemSettingManager.getEmailHostName();
         int port = systemSettingManager.getEmailPort();
         String username = systemSettingManager.getEmailUsername();
-        String password = systemSettingManager.getEmailPassword();
+        String password = configurationService.getConfiguration().getSmtpPassword();
         boolean tls = systemSettingManager.getEmailTls();
         String from = systemSettingManager.getEmailSender();
 
@@ -108,6 +116,7 @@
         
         try
         {
+            System.out.println("pw " + password);
             Email email = getEmail( hostName, port, username, password, tls, from );
             email.setSubject( SUBJECT_PREFIX + subject );
             email.setMsg( text );
@@ -124,7 +133,7 @@
                 {
                     email.addBcc( user.getEmail() );
                     
-                    log.info( "Sending email to user: " + user.getUsername() + " with email address: " + user.getEmail() );
+                    log.info( "Sending email to user: " + user.getUsername() + " with email address: " + user.getEmail() + " to host: " + hostName + ":" + port );
                     
                     hasRecipients = true;
                 }
@@ -133,7 +142,7 @@
             if ( hasRecipients )
             {
                 email.send();
-                log.info( "Email sent using host: " + hostName + " with TLS: " + tls );
+                log.info( "Email sent using host: " + hostName + ":" + port + " with TLS: " + tls );
             }
         }
         catch ( EmailException ex )

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java	2014-06-24 19:25:03 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java	2014-08-08 09:41:58 +0000
@@ -146,11 +146,6 @@
         return (Integer) getSystemSetting( KEY_EMAIL_PORT, DEFAULT_EMAIL_PORT );
     }
 
-    public String getEmailPassword()
-    {
-        return StringUtils.trimToNull( (String) getSystemSetting( KEY_EMAIL_PASSWORD ) );
-    }
-
     public String getEmailUsername()
     {
         return StringUtils.trimToNull( (String) getSystemSetting( KEY_EMAIL_USERNAME ) );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2014-08-04 14:27:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2014-08-08 09:41:58 +0000
@@ -643,6 +643,7 @@
 
   <bean id="emailMessageSender" class="org.hisp.dhis.message.EmailMessageSender">
     <property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
+    <property name="configurationService" ref="org.hisp.dhis.configuration.ConfigurationService" />
     <property name="userService" ref="org.hisp.dhis.user.UserService" />
   </bean>
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml	2014-07-07 06:44:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/configuration/hibernate/Configuration.hbm.xml	2014-08-08 09:41:58 +0000
@@ -36,7 +36,9 @@
 	
 	<property name="remoteServerUsername" column="remoteserverusername" />
 	
-	<property name="remoteServerPassword" column="remoteServerPassword" type="encryptedString" />
+	<property name="remoteServerPassword" column="remoteserverpassword" type="encryptedString" />
+	
+	<property name="smtpPassword" column="smptpassword" type="encryptedString" />
 	
   </class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetSMTPSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetSMTPSettingsAction.java	2014-05-20 15:16:46 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetSMTPSettingsAction.java	2014-08-08 09:41:58 +0000
@@ -28,7 +28,10 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.configuration.Configuration;
+import org.hisp.dhis.configuration.ConfigurationService;
 import org.hisp.dhis.setting.SystemSettingManager;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -43,12 +46,11 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
+    @Autowired
     private SystemSettingManager systemSettingManager;
 
-    public void setSystemSettingManager( SystemSettingManager systemSettingManager )
-    {
-        this.systemSettingManager = systemSettingManager;
-    }
+    @Autowired
+    private ConfigurationService configurationService;
 
     // -------------------------------------------------------------------------
     // Output
@@ -102,11 +104,13 @@
 
     public String execute()
     {
+        Configuration config = configurationService.getConfiguration();
+        
         smtpHostName = systemSettingManager.getEmailHostName();
         
         smtpPort = systemSettingManager.getEmailPort();
         
-        smtpPassword = systemSettingManager.getEmailPassword();
+        smtpPassword = config.getSmtpPassword();
         
         smtpUsername = systemSettingManager.getEmailUsername();
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetSMTPSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetSMTPSettingsAction.java	2014-05-20 15:16:46 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetSMTPSettingsAction.java	2014-08-08 09:41:58 +0000
@@ -30,8 +30,11 @@
 
 import static org.hisp.dhis.setting.SystemSettingManager.*;
 
+import org.hisp.dhis.configuration.Configuration;
+import org.hisp.dhis.configuration.ConfigurationService;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.setting.SystemSettingManager;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
 
@@ -46,12 +49,11 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
+    @Autowired
     private SystemSettingManager systemSettingManager;
 
-    public void setSystemSettingManager( SystemSettingManager systemSettingManager )
-    {
-        this.systemSettingManager = systemSettingManager;
-    }
+    @Autowired
+    private ConfigurationService configurationService;
 
     // -------------------------------------------------------------------------
     // Input
@@ -119,12 +121,14 @@
 
     public String execute()
     {
+        Configuration config = configurationService.getConfiguration();
+        
         systemSettingManager.saveSystemSetting( KEY_EMAIL_HOST_NAME, smtpHostName );
 
         systemSettingManager.saveSystemSetting( KEY_EMAIL_PORT, smtpPort );
         
-        systemSettingManager.saveSystemSetting( KEY_EMAIL_PASSWORD, smtpPassword );
-
+        config.setSmtpPassword( smtpPassword );
+        
         systemSettingManager.saveSystemSetting( KEY_EMAIL_USERNAME, smtpUsername );
 
         systemSettingManager.saveSystemSetting( KEY_EMAIL_TLS, smtpTls );
@@ -132,6 +136,8 @@
         systemSettingManager.saveSystemSetting( KEY_EMAIL_SENDER, emailSender );
         
         message = i18n.getString( "settings_updated" );
+        
+        configurationService.setConfiguration( config );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/META-INF/dhis/beans.xml	2014-07-07 16:48:48 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/META-INF/dhis/beans.xml	2014-08-08 09:41:58 +0000
@@ -52,15 +52,11 @@
 
   <bean id="org.hisp.dhis.settings.action.system.GetSMTPSettingsAction"
     class="org.hisp.dhis.settings.action.system.GetSMTPSettingsAction"
-    scope="prototype">
-    <property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
-  </bean>
+    scope="prototype"/>
 
   <bean id="org.hisp.dhis.settings.action.system.SetSMTPSettingsAction"
     class="org.hisp.dhis.settings.action.system.SetSMTPSettingsAction"
-    scope="prototype">
-    <property name="systemSettingManager" ref="org.hisp.dhis.setting.SystemSettingManager" />
-  </bean>
+    scope="prototype"/>
 
   <bean id="org.hisp.dhis.settings.action.system.GetAccessSettingsAction"
     class="org.hisp.dhis.settings.action.system.GetAccessSettingsAction"