Coverage Report - org.mule.api.security.provider.AutoDiscoverySecurityProviderFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
AutoDiscoverySecurityProviderFactory
0%
0/14
0%
0/4
3.5
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.api.security.provider;
 8  
 
 9  
 import org.mule.api.MuleRuntimeException;
 10  
 import org.mule.config.i18n.CoreMessages;
 11  
 import org.mule.util.ClassUtils;
 12  
 import org.mule.util.SystemUtils;
 13  
 
 14  
 import java.security.Provider;
 15  
 
 16  
 import org.apache.commons.logging.Log;
 17  
 import org.apache.commons.logging.LogFactory;
 18  
 
 19  
 /**
 20  
  * Automatically discovers the JDK we are running on and returns a corresponding
 21  
  * {@link SecurityProviderInfo}. <p/> Implementations of this class are thread-safe.
 22  
  */
 23  0
 public class AutoDiscoverySecurityProviderFactory implements SecurityProviderFactory
 24  
 {
 25  
 
 26  
     /**
 27  
      * Default is Sun's JSSE.
 28  
      */
 29  0
     public static final SecurityProviderInfo DEFAULT_SECURITY_PROVIDER = new SunSecurityProviderInfo();
 30  
 
 31  
     /**
 32  
      * Logger used by this class.
 33  
      */
 34  0
     protected transient Log logger = LogFactory.getLog(getClass());
 35  
 
 36  
     /**
 37  
      * Security provider properties for IBM JDK.
 38  
      */
 39  0
     private static final SecurityProviderInfo IBM_SECURITY_PROVIDER = new IBMSecurityProviderInfo();
 40  
 
 41  
     /**
 42  
      * Security provider properties for IBM JDK 1.4.2 and higher.
 43  
      */
 44  
     // private static final SecurityProviderInfo IBM_SECURITY_PROVIDER_2 = new
 45  
     // IBMSecurityProvider2Info();
 46  
 
 47  
     public SecurityProviderInfo getSecurityProviderInfo()
 48  
     {
 49  
         SecurityProviderInfo info;
 50  
 
 51  0
         if (SystemUtils.isIbmJDK())
 52  
         {
 53  
             // TODO test IBM JDK 1.4.2 more thoroughly and decide if
 54  
             // it's worth including this newer provider support.
 55  
             // switch to IBM's security provider
 56  
             // if (SystemUtils.isJavaVersionAtLeast(142)) {
 57  
             // IBM JSSE2
 58  
             // info = IBM_SECURITY_PROVIDER_2;
 59  
             // } else {
 60  
             // older IBM JSSE
 61  0
             info = IBM_SECURITY_PROVIDER;
 62  
             // }
 63  
         }
 64  
         else
 65  
         {
 66  0
             info = DEFAULT_SECURITY_PROVIDER;
 67  
 
 68  
         }
 69  
 
 70  
         // BEA's JRockit uses Sun's JSSE, so defaults are fine
 71  
 
 72  0
         return info;
 73  
     }
 74  
 
 75  
     public Provider getProvider()
 76  
     {
 77  0
         SecurityProviderInfo info = getSecurityProviderInfo();
 78  
 
 79  0
         if (logger.isInfoEnabled())
 80  
         {
 81  0
             logger.info("Using " + info.getClass().getName());
 82  
         }
 83  
 
 84  
         try
 85  
         {
 86  0
             return (Provider) ClassUtils.instanciateClass(info.getProviderClass());
 87  
         }
 88  0
         catch (Exception ex)
 89  
         {
 90  0
             throw new MuleRuntimeException(
 91  
                 CoreMessages.failedToInitSecurityProvider(info.getProviderClass()), ex);
 92  
         }
 93  
     }
 94  
 }