KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > umo > security > provider > AutoDiscoverySecurityProviderFactory


1 /*
2  * $Id: AutoDiscoverySecurityProviderFactory.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.umo.security.provider;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.MuleRuntimeException;
16 import org.mule.config.i18n.CoreMessageConstants;
17 import org.mule.config.i18n.Message;
18 import org.mule.util.ClassUtils;
19 import org.mule.util.SystemUtils;
20
21 import java.security.Provider JavaDoc;
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  * @author <a HREF="mailto:aperepel@gmail.com">Andrew Perepelytsya</a>
28  */

29 public class AutoDiscoverySecurityProviderFactory implements SecurityProviderFactory
30 {
31
32     /**
33      * Default is Sun's JSSE.
34      */

35     public static final SecurityProviderInfo DEFAULT_SECURITY_PROVIDER = new SunSecurityProviderInfo();
36
37     /**
38      * Logger used by this class.
39      */

40     protected transient Log logger = LogFactory.getLog(getClass());
41
42     /**
43      * Security provider properties for IBM JDK.
44      */

45     private static final SecurityProviderInfo IBM_SECURITY_PROVIDER = new IBMSecurityProviderInfo();
46
47     /**
48      * Security provider properties for IBM JDK 1.4.2 and higher.
49      */

50     // private static final SecurityProviderInfo IBM_SECURITY_PROVIDER_2 = new
51
// IBMSecurityProvider2Info();
52

53     public SecurityProviderInfo getSecurityProviderInfo()
54     {
55         SecurityProviderInfo info;
56
57         if (SystemUtils.isIbmJDK())
58         {
59             // TODO test IBM JDK 1.4.2 more thoroughly and decide if
60
// it's worth including this newer provider support.
61
// switch to IBM's security provider
62
// if (SystemUtils.isJavaVersionAtLeast(142)) {
63
// IBM JSSE2
64
// info = IBM_SECURITY_PROVIDER_2;
65
// } else {
66
// older IBM JSSE
67
info = IBM_SECURITY_PROVIDER;
68             // }
69
}
70         else
71         {
72             info = DEFAULT_SECURITY_PROVIDER;
73
74         }
75
76         // BEA's JRockit uses Sun's JSSE, so defaults are fine
77

78         return info;
79     }
80
81     public Provider JavaDoc getProvider()
82     {
83         SecurityProviderInfo info = getSecurityProviderInfo();
84
85         if (logger.isInfoEnabled())
86         {
87             logger.info("Using " + info.getClass().getName());
88         }
89
90         try
91         {
92             return (Provider JavaDoc)ClassUtils.instanciateClass(info.getProviderClass(), null);
93         }
94         catch (Exception JavaDoc ex)
95         {
96             throw new MuleRuntimeException(new Message("core",
97                 CoreMessageConstants.FAILED_TO_INITIALIZE_SECURITY_PROVIDER, info.getProviderClass()), ex);
98         }
99     }
100 }
101
Popular Tags