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