01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.tomcat.util.net;
18:
19: import java.net.Socket;
20:
21: /* SSLImplementation:
22:
23: Abstract factory and base class for all SSL implementations.
24:
25: @author EKR
26: */
27: abstract public class SSLImplementation {
28: private static org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory
29: .getLog(SSLImplementation.class);
30:
31: // The default implementations in our search path
32: private static final String PureTLSImplementationClass = "org.apache.tomcat.util.net.puretls.PureTLSImplementation";
33: private static final String JSSEImplementationClass = "org.apache.tomcat.util.net.jsse.JSSEImplementation";
34:
35: private static final String[] implementations = {
36: PureTLSImplementationClass, JSSEImplementationClass };
37:
38: public static SSLImplementation getInstance()
39: throws ClassNotFoundException {
40: for (int i = 0; i < implementations.length; i++) {
41: try {
42: SSLImplementation impl = getInstance(implementations[i]);
43: return impl;
44: } catch (Exception e) {
45: if (logger.isTraceEnabled())
46: logger.trace(
47: "Error creating " + implementations[i], e);
48: }
49: }
50:
51: // If we can't instantiate any of these
52: throw new ClassNotFoundException(
53: "Can't find any SSL implementation");
54: }
55:
56: public static SSLImplementation getInstance(String className)
57: throws ClassNotFoundException {
58: if (className == null)
59: return getInstance();
60:
61: try {
62: // Workaround for the J2SE 1.4.x classloading problem (under Solaris).
63: // Class.forName(..) fails without creating class using new.
64: // This is an ugly workaround.
65: if (JSSEImplementationClass.equals(className)) {
66: return new org.apache.tomcat.util.net.jsse.JSSEImplementation();
67: }
68: Class clazz = Class.forName(className);
69: return (SSLImplementation) clazz.newInstance();
70: } catch (Exception e) {
71: if (logger.isDebugEnabled())
72: logger.debug("Error loading SSL Implementation "
73: + className, e);
74: throw new ClassNotFoundException(
75: "Error loading SSL Implementation " + className
76: + " :" + e.toString());
77: }
78: }
79:
80: abstract public String getImplementationName();
81:
82: abstract public ServerSocketFactory getServerSocketFactory();
83:
84: abstract public SSLSupport getSSLSupport(Socket sock);
85: }
|