Coverage Report - org.mule.transport.email.SmtpsConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
SmtpsConnector
0%
0/40
N/A
0
 
 1  
 /*
 2  
  * $Id: SmtpsConnector.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.MuleContext;
 14  
 import org.mule.api.lifecycle.CreateException;
 15  
 import org.mule.api.lifecycle.InitialisationException;
 16  
 import org.mule.api.security.TlsIndirectKeyStore;
 17  
 import org.mule.api.security.TlsIndirectTrustStore;
 18  
 import org.mule.api.security.tls.TlsConfiguration;
 19  
 import org.mule.api.security.tls.TlsPropertiesMapper;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.util.Properties;
 23  
 
 24  
 import javax.mail.URLName;
 25  
 
 26  
 /** Creates a secure SMTP connection */
 27  
 public class SmtpsConnector extends SmtpConnector implements TlsIndirectTrustStore, TlsIndirectKeyStore
 28  
 {
 29  
 
 30  
     public static final String SMTPS = "smtps";
 31  0
     public static final String DEFAULT_SOCKET_FACTORY = SmtpsSocketFactory.class.getName();
 32  
 
 33  0
     private String socketFactory = DEFAULT_SOCKET_FACTORY;
 34  0
     private String socketFactoryFallback = "false";
 35  0
     private TlsConfiguration tls = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE);
 36  
 
 37  
     public static final int DEFAULT_SMTPS_PORT = 465;
 38  
 
 39  
 
 40  
     public SmtpsConnector(MuleContext context)
 41  
     {
 42  0
         super(DEFAULT_SMTPS_PORT, context);
 43  0
     }
 44  
 
 45  
     public String getProtocol()
 46  
     {
 47  0
         return "smtps";
 48  
     }
 49  
 
 50  
     public String getBaseProtocol()
 51  
     {
 52  0
         return "smtp";
 53  
     }
 54  
 
 55  
     protected void doInitialise() throws InitialisationException
 56  
     {
 57  
         try
 58  
         {
 59  0
             tls.initialise(true, null);
 60  
         }
 61  0
         catch (CreateException e)
 62  
         {
 63  0
             throw new InitialisationException(e, this);
 64  0
         }
 65  0
     }
 66  
 
 67  
     @Override
 68  
     protected void extendPropertiesForSession(Properties global, Properties local, URLName url)
 69  
     {
 70  0
         super.extendPropertiesForSession(global, local, url);
 71  
 
 72  0
         local.setProperty("mail." + getProtocol() + ".ssl", "true");
 73  0
         local.setProperty("mail." + getProtocol() + ".socketFactory.class", getSocketFactory());
 74  0
         local.setProperty("mail." + getProtocol() + ".socketFactory.fallback", getSocketFactoryFallback());
 75  
 
 76  0
         new TlsPropertiesMapper(SmtpsSocketFactory.MULE_SMTPS_NAMESPACE).writeToProperties(global, tls);
 77  0
     }
 78  
 
 79  
     public String getSocketFactory()
 80  
     {
 81  0
         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  0
         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  0
         return tls.getTrustStore();
 102  
     }
 103  
 
 104  
     public String getTrustStorePassword()
 105  
     {
 106  0
         return tls.getTrustStorePassword();
 107  
     }
 108  
 
 109  
     public void setTrustStore(String trustStore) throws IOException
 110  
     {
 111  0
         tls.setTrustStore(trustStore);
 112  0
     }
 113  
 
 114  
     public void setTrustStorePassword(String trustStorePassword)
 115  
     {
 116  0
         tls.setTrustStorePassword(trustStorePassword);
 117  0
     }
 118  
 
 119  
     // these were not present before, but could be set implicitly via global proeprties
 120  
     // that is no longer true, so i have added them in here
 121  
 
 122  
     public String getClientKeyStore()
 123  
     {
 124  0
         return this.tls.getClientKeyStore();
 125  
     }
 126  
 
 127  
     public String getClientKeyStorePassword()
 128  
     {
 129  0
         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  0
         this.tls.setClientKeyStore(name);
 140  0
     }
 141  
 
 142  
     public void setClientKeyStorePassword(String clientKeyStorePassword)
 143  
     {
 144  0
         this.tls.setClientKeyStorePassword(clientKeyStorePassword);
 145  0
     }
 146  
 
 147  
     public void setClientKeyStoreType(String clientKeyStoreType)
 148  
     {
 149  0
         this.tls.setClientKeyStoreType(clientKeyStoreType);
 150  0
     }
 151  
 
 152  
 }