Coverage Report - org.mule.transport.email.SmtpsConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
SmtpsConnector
78%
31/40
N/A
1.105
 
 1  
 /*
 2  
  * $Id: SmtpsConnector.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  
 /** Creates a secure SMTP connection */
 26  
 public class SmtpsConnector extends SmtpConnector implements TlsIndirectTrustStore, TlsIndirectKeyStore
 27  
 {
 28  
 
 29  
     public static final String SMTPS = "smtps";
 30  2
     public static final String DEFAULT_SOCKET_FACTORY = SmtpsSocketFactory.class.getName();
 31  
 
 32  30
     private String socketFactory = DEFAULT_SOCKET_FACTORY;
 33  30
     private String socketFactoryFallback = "false";
 34  30
     private TlsConfiguration tls = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE);
 35  
 
 36  
     public static final int DEFAULT_SMTPS_PORT = 465;
 37  
 
 38  
 
 39  
     public SmtpsConnector()
 40  
     {
 41  30
         super(DEFAULT_SMTPS_PORT);
 42  30
     }
 43  
 
 44  
     public String getProtocol()
 45  
     {
 46  84
         return "smtps";
 47  
     }
 48  
 
 49  
     public String getBaseProtocol()
 50  
     {
 51  16
         return "smtp";
 52  
     }
 53  
 
 54  
     protected void doInitialise() throws InitialisationException
 55  
     {
 56  
         try
 57  
         {
 58  30
             tls.initialise(true, null);
 59  
         }
 60  0
         catch (CreateException e)
 61  
         {
 62  0
             throw new InitialisationException(e, this);
 63  30
         }
 64  30
     }
 65  
 
 66  
     // @Override
 67  
     protected void extendPropertiesForSession(Properties global, Properties local, URLName url)
 68  
     {
 69  4
         super.extendPropertiesForSession(global, local, url);
 70  
 
 71  4
         local.setProperty("mail." + getProtocol() + ".ssl", "true");
 72  4
         local.setProperty("mail." + getProtocol() + ".socketFactory.class", getSocketFactory());
 73  4
         local.setProperty("mail." + getProtocol() + ".socketFactory.fallback", getSocketFactoryFallback());
 74  
 
 75  4
         new TlsPropertiesMapper(SmtpsSocketFactory.MULE_SMTPS_NAMESPACE).writeToProperties(global, tls);
 76  4
     }
 77  
 
 78  
     public String getSocketFactory()
 79  
     {
 80  4
         return socketFactory;
 81  
     }
 82  
 
 83  
     public void setSocketFactory(String sslSocketFactory)
 84  
     {
 85  0
         this.socketFactory = sslSocketFactory;
 86  0
     }
 87  
 
 88  
     public String getSocketFactoryFallback()
 89  
     {
 90  4
         return socketFactoryFallback;
 91  
     }
 92  
 
 93  
     public void setSocketFactoryFallback(String socketFactoryFallback)
 94  
     {
 95  0
         this.socketFactoryFallback = socketFactoryFallback;
 96  0
     }
 97  
 
 98  
     public String getTrustStore()
 99  
     {
 100  2
         return tls.getTrustStore();
 101  
     }
 102  
 
 103  
     public String getTrustStorePassword()
 104  
     {
 105  2
         return tls.getTrustStorePassword();
 106  
     }
 107  
 
 108  
     public void setTrustStore(String trustStore) throws IOException
 109  
     {
 110  30
         tls.setTrustStore(trustStore);
 111  30
     }
 112  
 
 113  
     public void setTrustStorePassword(String trustStorePassword)
 114  
     {
 115  30
         tls.setTrustStorePassword(trustStorePassword);
 116  30
     }
 117  
 
 118  
     // these were not present before, but could be set implicitly via global proeprties
 119  
     // that is no longer true, so i have added them in here
 120  
 
 121  
     public String getClientKeyStore()
 122  
     {
 123  2
         return this.tls.getClientKeyStore();
 124  
     }
 125  
 
 126  
     public String getClientKeyStorePassword()
 127  
     {
 128  2
         return this.tls.getClientKeyStorePassword();
 129  
     }
 130  
 
 131  
     public String getClientKeyStoreType()
 132  
     {
 133  0
         return this.tls.getClientKeyStoreType();
 134  
     }
 135  
 
 136  
     public void setClientKeyStore(String name) throws IOException
 137  
     {
 138  8
         this.tls.setClientKeyStore(name);
 139  8
     }
 140  
 
 141  
     public void setClientKeyStorePassword(String clientKeyStorePassword)
 142  
     {
 143  8
         this.tls.setClientKeyStorePassword(clientKeyStorePassword);
 144  8
     }
 145  
 
 146  
     public void setClientKeyStoreType(String clientKeyStoreType)
 147  
     {
 148  0
         this.tls.setClientKeyStoreType(clientKeyStoreType);
 149  0
     }
 150  
 
 151  
 }