Coverage Report - org.mule.transport.email.AbstractTlsRetrieveMailConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractTlsRetrieveMailConnector
77%
30/39
N/A
1.118
 
 1  
 /*
 2  
  * $Id: AbstractTlsRetrieveMailConnector.java 10489 2008-01-23 17:53:38Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transport.email;
 12  
 
 13  
 import org.mule.api.lifecycle.CreateException;
 14  
 import org.mule.api.lifecycle.InitialisationException;
 15  
 import org.mule.api.security.TlsIndirectKeyStore;
 16  
 import org.mule.api.security.TlsIndirectTrustStore;
 17  
 import org.mule.api.security.tls.TlsConfiguration;
 18  
 import org.mule.api.security.tls.TlsPropertiesMapper;
 19  
 
 20  
 import java.io.IOException;
 21  
 import java.util.Properties;
 22  
 
 23  
 import javax.mail.URLName;
 24  
 
 25  
 /**
 26  
  * Support for connecting to and receiving email from a secure mailbox (the exact protocol depends on
 27  
  * the subclass).
 28  
  */
 29  
 public abstract class AbstractTlsRetrieveMailConnector
 30  
         extends AbstractRetrieveMailConnector implements TlsIndirectTrustStore, TlsIndirectKeyStore
 31  
 {
 32  
 
 33  
     private String namespace;
 34  
     private String socketFactory;
 35  56
     private String socketFactoryFallback = "false";
 36  56
     private TlsConfiguration tls = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE);
 37  
 
 38  
     protected AbstractTlsRetrieveMailConnector(int defaultPort, String namespace, Class defaultSocketFactory)
 39  
     {
 40  56
         super(defaultPort);
 41  56
         this.namespace = namespace;
 42  56
         socketFactory = defaultSocketFactory.getName();
 43  
 
 44  
         // see comment below
 45  
 //        this.namespace = TlsConfiguration.JSSE_NAMESPACE;
 46  
 //        socketFactory = SSLServerSocketFactory.class.getName();
 47  56
     }
 48  
 
 49  
     protected void doInitialise() throws InitialisationException
 50  
     {
 51  
         try
 52  
         {
 53  56
             tls.initialise(true, null);
 54  
         }
 55  0
         catch (CreateException e)
 56  
         {
 57  0
             throw new InitialisationException(e, this);
 58  56
         }
 59  56
         super.doInitialise();
 60  56
     }
 61  
 
 62  
     // @Override
 63  
     protected void extendPropertiesForSession(Properties global, Properties local, URLName url)
 64  
     {
 65  8
         super.extendPropertiesForSession(global, local, url);
 66  
 
 67  8
         local.setProperty("mail." + getProtocol() + ".ssl", "true");
 68  8
         local.setProperty("mail." + getProtocol() + ".socketFactory.class", getSocketFactory());
 69  8
         local.setProperty("mail." + getProtocol() + ".socketFactory.fallback", getSocketFactoryFallback());
 70  
 
 71  8
         new TlsPropertiesMapper(namespace).writeToProperties(global, tls);
 72  
 
 73  
         // this, instead of the line above, and with the constructor changes,
 74  
         // would have changed to local SSL configuration, if that was possible
 75  
         // (it didn't work)
 76  
 //        new TlsPropertiesMapper(namespace).writeToProperties(local, tls);
 77  8
     }
 78  
 
 79  
     public String getSocketFactory()
 80  
     {
 81  8
         return socketFactory;
 82  
     }
 83  
 
 84  
     public void setSocketFactory(String sslSocketFactory)
 85  
     {
 86  0
         this.socketFactory = sslSocketFactory;
 87  0
     }
 88  
 
 89  
     public String getSocketFactoryFallback()
 90  
     {
 91  8
         return socketFactoryFallback;
 92  
     }
 93  
 
 94  
     public void setSocketFactoryFallback(String socketFactoryFallback)
 95  
     {
 96  0
         this.socketFactoryFallback = socketFactoryFallback;
 97  0
     }
 98  
 
 99  
     public String getTrustStore()
 100  
     {
 101  4
         return tls.getTrustStore();
 102  
     }
 103  
 
 104  
     public String getTrustStorePassword()
 105  
     {
 106  4
         return tls.getTrustStorePassword();
 107  
     }
 108  
 
 109  
     public void setTrustStore(String trustStore) throws IOException
 110  
     {
 111  56
         tls.setTrustStore(trustStore);
 112  56
     }
 113  
 
 114  
     public void setTrustStorePassword(String trustStorePassword)
 115  
     {
 116  56
         tls.setTrustStorePassword(trustStorePassword);
 117  56
     }
 118  
 
 119  
     // these were not present before, but could be set implicitly via global properties
 120  
     // that is no longer true, so i have added them in here
 121  
 
 122  
     public String getClientKeyStore()
 123  
     {
 124  4
         return this.tls.getClientKeyStore();
 125  
     }
 126  
 
 127  
     public String getClientKeyStorePassword()
 128  
     {
 129  4
         return this.tls.getClientKeyStorePassword();
 130  
     }
 131  
 
 132  
     public String getClientKeyStoreType()
 133  
     {
 134  0
         return this.tls.getClientKeyStoreType();
 135  
     }
 136  
 
 137  
     public void setClientKeyStore(String name) throws IOException
 138  
     {
 139  16
         this.tls.setClientKeyStore(name);
 140  16
     }
 141  
 
 142  
     public void setClientKeyStorePassword(String clientKeyStorePassword)
 143  
     {
 144  16
         this.tls.setClientKeyStorePassword(clientKeyStorePassword);
 145  16
     }
 146  
 
 147  
     public void setClientKeyStoreType(String clientKeyStoreType)
 148  
     {
 149  0
         this.tls.setClientKeyStoreType(clientKeyStoreType);
 150  0
     }
 151  
 
 152  
 }