Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AutoDiscoverySecurityProviderFactory |
|
| 3.5;3.5 |
1 | /* | |
2 | * $Id: AutoDiscoverySecurityProviderFactory.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.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 | 0 | public class AutoDiscoverySecurityProviderFactory implements SecurityProviderFactory |
28 | { | |
29 | ||
30 | /** | |
31 | * Default is Sun's JSSE. | |
32 | */ | |
33 | 0 | public static final SecurityProviderInfo DEFAULT_SECURITY_PROVIDER = new SunSecurityProviderInfo(); |
34 | ||
35 | /** | |
36 | * Logger used by this class. | |
37 | */ | |
38 | 0 | protected transient Log logger = LogFactory.getLog(getClass()); |
39 | ||
40 | /** | |
41 | * Security provider properties for IBM JDK. | |
42 | */ | |
43 | 0 | 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 | 0 | 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 | 0 | info = DEFAULT_SECURITY_PROVIDER; |
71 | ||
72 | } | |
73 | ||
74 | // BEA's JRockit uses Sun's JSSE, so defaults are fine | |
75 | ||
76 | 0 | return info; |
77 | } | |
78 | ||
79 | public Provider getProvider() | |
80 | { | |
81 | 0 | SecurityProviderInfo info = getSecurityProviderInfo(); |
82 | ||
83 | 0 | if (logger.isInfoEnabled()) |
84 | { | |
85 | 0 | logger.info("Using " + info.getClass().getName()); |
86 | } | |
87 | ||
88 | try | |
89 | { | |
90 | 0 | return (Provider) ClassUtils.instanciateClass(info.getProviderClass()); |
91 | } | |
92 | 0 | catch (Exception ex) |
93 | { | |
94 | 0 | throw new MuleRuntimeException( |
95 | CoreMessages.failedToInitSecurityProvider(info.getProviderClass()), ex); | |
96 | } | |
97 | } | |
98 | } |