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