001: /*
002: * $Id: SmtpsConnector.java 10489 2008-01-23 17:53:38Z dfeist $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.transport.email;
012:
013: import org.mule.api.lifecycle.CreateException;
014: import org.mule.api.lifecycle.InitialisationException;
015: import org.mule.api.security.TlsIndirectKeyStore;
016: import org.mule.api.security.TlsIndirectTrustStore;
017: import org.mule.api.security.tls.TlsConfiguration;
018: import org.mule.api.security.tls.TlsPropertiesMapper;
019:
020: import java.io.IOException;
021: import java.util.Properties;
022:
023: import javax.mail.URLName;
024:
025: /** Creates a secure SMTP connection */
026: public class SmtpsConnector extends SmtpConnector implements
027: TlsIndirectTrustStore, TlsIndirectKeyStore {
028:
029: public static final String SMTPS = "smtps";
030: public static final String DEFAULT_SOCKET_FACTORY = SmtpsSocketFactory.class
031: .getName();
032:
033: private String socketFactory = DEFAULT_SOCKET_FACTORY;
034: private String socketFactoryFallback = "false";
035: private TlsConfiguration tls = new TlsConfiguration(
036: TlsConfiguration.DEFAULT_KEYSTORE);
037:
038: public static final int DEFAULT_SMTPS_PORT = 465;
039:
040: public SmtpsConnector() {
041: super (DEFAULT_SMTPS_PORT);
042: }
043:
044: public String getProtocol() {
045: return "smtps";
046: }
047:
048: public String getBaseProtocol() {
049: return "smtp";
050: }
051:
052: protected void doInitialise() throws InitialisationException {
053: try {
054: tls.initialise(true, null);
055: } catch (CreateException e) {
056: throw new InitialisationException(e, this );
057: }
058: }
059:
060: // @Override
061: protected void extendPropertiesForSession(Properties global,
062: Properties local, URLName url) {
063: super .extendPropertiesForSession(global, local, url);
064:
065: local.setProperty("mail." + getProtocol() + ".ssl", "true");
066: local.setProperty("mail." + getProtocol()
067: + ".socketFactory.class", getSocketFactory());
068: local
069: .setProperty("mail." + getProtocol()
070: + ".socketFactory.fallback",
071: getSocketFactoryFallback());
072:
073: new TlsPropertiesMapper(SmtpsSocketFactory.MULE_SMTPS_NAMESPACE)
074: .writeToProperties(global, tls);
075: }
076:
077: public String getSocketFactory() {
078: return socketFactory;
079: }
080:
081: public void setSocketFactory(String sslSocketFactory) {
082: this .socketFactory = sslSocketFactory;
083: }
084:
085: public String getSocketFactoryFallback() {
086: return socketFactoryFallback;
087: }
088:
089: public void setSocketFactoryFallback(String socketFactoryFallback) {
090: this .socketFactoryFallback = socketFactoryFallback;
091: }
092:
093: public String getTrustStore() {
094: return tls.getTrustStore();
095: }
096:
097: public String getTrustStorePassword() {
098: return tls.getTrustStorePassword();
099: }
100:
101: public void setTrustStore(String trustStore) throws IOException {
102: tls.setTrustStore(trustStore);
103: }
104:
105: public void setTrustStorePassword(String trustStorePassword) {
106: tls.setTrustStorePassword(trustStorePassword);
107: }
108:
109: // these were not present before, but could be set implicitly via global proeprties
110: // that is no longer true, so i have added them in here
111:
112: public String getClientKeyStore() {
113: return this .tls.getClientKeyStore();
114: }
115:
116: public String getClientKeyStorePassword() {
117: return this .tls.getClientKeyStorePassword();
118: }
119:
120: public String getClientKeyStoreType() {
121: return this .tls.getClientKeyStoreType();
122: }
123:
124: public void setClientKeyStore(String name) throws IOException {
125: this .tls.setClientKeyStore(name);
126: }
127:
128: public void setClientKeyStorePassword(String clientKeyStorePassword) {
129: this .tls.setClientKeyStorePassword(clientKeyStorePassword);
130: }
131:
132: public void setClientKeyStoreType(String clientKeyStoreType) {
133: this.tls.setClientKeyStoreType(clientKeyStoreType);
134: }
135:
136: }
|