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