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