001: /*
002: * $Id: AbstractTlsRetrieveMailConnector.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: /**
026: * Support for connecting to and receiving email from a secure mailbox (the exact protocol depends on
027: * the subclass).
028: */
029: public abstract class AbstractTlsRetrieveMailConnector extends
030: AbstractRetrieveMailConnector implements TlsIndirectTrustStore,
031: TlsIndirectKeyStore {
032:
033: private String namespace;
034: private String socketFactory;
035: private String socketFactoryFallback = "false";
036: private TlsConfiguration tls = new TlsConfiguration(
037: TlsConfiguration.DEFAULT_KEYSTORE);
038:
039: protected AbstractTlsRetrieveMailConnector(int defaultPort,
040: String namespace, Class defaultSocketFactory) {
041: super (defaultPort);
042: this .namespace = namespace;
043: socketFactory = defaultSocketFactory.getName();
044:
045: // see comment below
046: // this.namespace = TlsConfiguration.JSSE_NAMESPACE;
047: // socketFactory = SSLServerSocketFactory.class.getName();
048: }
049:
050: protected void doInitialise() throws InitialisationException {
051: try {
052: tls.initialise(true, null);
053: } catch (CreateException e) {
054: throw new InitialisationException(e, this );
055: }
056: super .doInitialise();
057: }
058:
059: // @Override
060: protected void extendPropertiesForSession(Properties global,
061: Properties local, URLName url) {
062: super .extendPropertiesForSession(global, local, url);
063:
064: local.setProperty("mail." + getProtocol() + ".ssl", "true");
065: local.setProperty("mail." + getProtocol()
066: + ".socketFactory.class", getSocketFactory());
067: local
068: .setProperty("mail." + getProtocol()
069: + ".socketFactory.fallback",
070: getSocketFactoryFallback());
071:
072: new TlsPropertiesMapper(namespace).writeToProperties(global,
073: tls);
074:
075: // this, instead of the line above, and with the constructor changes,
076: // would have changed to local SSL configuration, if that was possible
077: // (it didn't work)
078: // new TlsPropertiesMapper(namespace).writeToProperties(local, tls);
079: }
080:
081: public String getSocketFactory() {
082: return socketFactory;
083: }
084:
085: public void setSocketFactory(String sslSocketFactory) {
086: this .socketFactory = sslSocketFactory;
087: }
088:
089: public String getSocketFactoryFallback() {
090: return socketFactoryFallback;
091: }
092:
093: public void setSocketFactoryFallback(String socketFactoryFallback) {
094: this .socketFactoryFallback = socketFactoryFallback;
095: }
096:
097: public String getTrustStore() {
098: return tls.getTrustStore();
099: }
100:
101: public String getTrustStorePassword() {
102: return tls.getTrustStorePassword();
103: }
104:
105: public void setTrustStore(String trustStore) throws IOException {
106: tls.setTrustStore(trustStore);
107: }
108:
109: public void setTrustStorePassword(String trustStorePassword) {
110: tls.setTrustStorePassword(trustStorePassword);
111: }
112:
113: // these were not present before, but could be set implicitly via global properties
114: // that is no longer true, so i have added them in here
115:
116: public String getClientKeyStore() {
117: return this .tls.getClientKeyStore();
118: }
119:
120: public String getClientKeyStorePassword() {
121: return this .tls.getClientKeyStorePassword();
122: }
123:
124: public String getClientKeyStoreType() {
125: return this .tls.getClientKeyStoreType();
126: }
127:
128: public void setClientKeyStore(String name) throws IOException {
129: this .tls.setClientKeyStore(name);
130: }
131:
132: public void setClientKeyStorePassword(String clientKeyStorePassword) {
133: this .tls.setClientKeyStorePassword(clientKeyStorePassword);
134: }
135:
136: public void setClientKeyStoreType(String clientKeyStoreType) {
137: this.tls.setClientKeyStoreType(clientKeyStoreType);
138: }
139:
140: }
|