Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
rhbz880894 - Externalize email server configuration.
zanata.properties now holds the email server configuration. 
Default values remain as currently (localhost:25, unauthenticated).
  • Loading branch information
carlosmunoz committed Nov 28, 2012
1 parent c9fcfc7 commit b089f21
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 4 deletions.
Expand Up @@ -50,8 +50,8 @@ public class HApplicationConfiguration extends ModelEntityBase
public static String KEY_LOG_DESTINATION_EMAIL = "log.destination.email";
public static String KEY_EMAIL_LOG_EVENTS = "log.email.active";
public static String KEY_EMAIL_LOG_LEVEL = "log.email.level";
public static String KEY_PIWIK_URL = "piwik.url";
public static String KEY_PIWIK_IDSITE = "piwik.idSite";
public static String KEY_PIWIK_URL = "piwik.url";
public static String KEY_PIWIK_IDSITE = "piwik.idSite";
private static final long serialVersionUID = 8652817113098817448L;

private String key;
Expand Down
12 changes: 11 additions & 1 deletion zanata-war/src/etc/zanata.properties
Expand Up @@ -21,4 +21,14 @@ zanata.security.admin.users = user1,user2,user3
# the case on first bootup)
# This parameter will only be used if there is no value defined in the server
# configuration
zanata.email.default.from = no-reply@zanata.org
zanata.email.default.from = no-reply@zanata.org

# Email server settings. If not specified, will default to localhost:25, and no
# authentication
# username, password might be ommitted if the server does not require authentication.
zanata.smtp.host = localhost
zanata.smtp.port = 25
# zanata.smtp.username = myuser
# zanata.smtp.password = mypassword
# zanata.smtp.tls = false
# zanata.smtp.ssl = false
58 changes: 58 additions & 0 deletions zanata-war/src/main/java/org/zanata/ApplicationConfiguration.java
Expand Up @@ -70,6 +70,12 @@ public class ApplicationConfiguration implements Serializable
private static final String KEY_AUTH_POLICY = "zanata.security.auth.policy";
private static final String KEY_ADMIN_USERS = "zanata.security.admin.users";
private static final String KEY_DEFAULT_FROM_ADDRESS = "zanata.email.default.from";
private static final String KEY_EMAIL_HOST = "zanata.smtp.host";
private static final String KEY_EMAIL_PORT = "zanata.smtp.port";
private static final String KEY_EMAIL_USERNAME = "zanata.smtp.username";
private static final String KEY_EMAIL_PASSWORD = "zanata.smtp.password";
private static final String KEY_EMAIL_TLS = "zanata.smtp.tls";
private static final String KEY_EMAIL_SSL = "zanata.smtp.ssl";

private static final String[] allConfigKeys = new String[]
{
Expand Down Expand Up @@ -434,4 +440,56 @@ public String getPiwikIdSite()
{
return configValues.get(HApplicationConfiguration.KEY_PIWIK_IDSITE);
}

public String getEmailServerHost()
{
String host = externalConfig.getProperty(KEY_EMAIL_HOST);

// Default to localhost
if( host == null )
{
host = "localhost";
}
return host;
}

public int getEmailServerPort()
{
String port = externalConfig.getProperty(KEY_EMAIL_PORT);

// Default to 25
if( port == null )
{
port = "25";
}
return Integer.parseInt(port);
}

public String getEmailServerUsername()
{
return externalConfig.getProperty(KEY_EMAIL_USERNAME);
}

public String getEmailServerPassword()
{
return externalConfig.getProperty(KEY_EMAIL_PASSWORD);
}

public boolean useEmailServerTls()
{
if(externalConfig.containsKey(KEY_EMAIL_TLS))
{
return Boolean.parseBoolean( externalConfig.getProperty(KEY_EMAIL_TLS) );
}
return false;
}

public boolean useEmailServerSsl()
{
if(externalConfig.containsKey(KEY_EMAIL_SSL))
{
return Boolean.parseBoolean( externalConfig.getProperty(KEY_EMAIL_SSL) );
}
return false;
}
}
5 changes: 5 additions & 0 deletions zanata-war/src/main/java/org/zanata/ZanataInit.java
Expand Up @@ -144,6 +144,11 @@ public void initZanata() throws Exception
{
checkLuceneLocks(new File(indexBase));
}

// Email server information
log.info("Notification Email Host: " + this.applicationConfiguration.getEmailServerHost() + ":" +
this.applicationConfiguration.getEmailServerPort());

Events.instance().raiseEvent(EVENT_Zanata_Startup);

log.info("Started Zanata...");
Expand Down
@@ -0,0 +1,68 @@
/*
* Copyright 2010, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
* site: http://www.fsf.org.
*/
package org.zanata.seam.mail;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.mail.MailSession;
import org.zanata.ApplicationConfiguration;

/**
* Overrides Seam's default MailSession component to dynamically define properties
* like host, port, etc.
*
* @author Carlos Munoz <a href="mailto:camunoz@redhat.com">camunoz@redhat.com</a>
*/
@Name("org.jboss.seam.mail.mailSession")
@Install(value=true, precedence=Install.APPLICATION, classDependencies = "javax.mail.Session")
@Scope(ScopeType.APPLICATION)
@BypassInterceptors
public class ZanataMailSession extends MailSession
{
public ZanataMailSession()
{
this(null);
}

public ZanataMailSession(String transport)
{
super(transport);
setup();
}

protected void setup()
{
ApplicationConfiguration appConfig =
(ApplicationConfiguration)Component.getInstance(ApplicationConfiguration.class);

// Override default properties
setHost( appConfig.getEmailServerHost() );
setPort( appConfig.getEmailServerPort() );
setUsername( appConfig.getEmailServerUsername() );
setPassword( appConfig.getEmailServerPassword() );
setTls( appConfig.useEmailServerTls() );
setSsl( appConfig.useEmailServerSsl() );
}
}
Expand Up @@ -119,7 +119,8 @@
<component name="zanataJobScheduler" class="org.zanata.job.ZanataJobScheduler"/>

<!-- Mailserver for notification messages -->
<mail:mail-session host="localhost" port="25" ssl="false" tls="false"/>
<!-- From 2.0, email configuration is on zanata.properties -->
<!--<mail:mail-session host="localhost" port="25" ssl="false" tls="false"/>-->

<!-- Maximum size of file uploads
If you are using MySQL, don't forget their magic stuff:
Expand Down

0 comments on commit b089f21

Please sign in to comment.