1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     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
18package javax.net.ssl;
19
20import java.security.NoSuchAlgorithmException;
21import java.security.Security;
22import javax.net.ServerSocketFactory;
23
24/**
25 * The factory for SSL server sockets.
26 */
27public abstract class SSLServerSocketFactory extends ServerSocketFactory {
28    // TODO EXPORT CONTROL
29
30    // The default SSL socket factory
31    private static ServerSocketFactory defaultServerSocketFactory;
32
33    private static String defaultName;
34
35    /**
36     * Returns the default {@code SSLServerSocketFactory} instance. The default
37     * implementation is defined by the security property
38     * "ssl.ServerSocketFactory.provider".
39     *
40     * @return the default {@code SSLServerSocketFactory} instance.
41     */
42    public static synchronized ServerSocketFactory getDefault() {
43        if (defaultServerSocketFactory != null) {
44            return defaultServerSocketFactory;
45        }
46        if (defaultName == null) {
47            defaultName = Security.getProperty("ssl.ServerSocketFactory.provider");
48            if (defaultName != null) {
49                ClassLoader cl = Thread.currentThread().getContextClassLoader();
50                if (cl == null) {
51                    cl = ClassLoader.getSystemClassLoader();
52                }
53                try {
54                    final Class<?> ssfc = Class.forName(defaultName, true, cl);
55                    defaultServerSocketFactory = (ServerSocketFactory) ssfc.newInstance();
56                } catch (Exception e) {
57                }
58            }
59        }
60        if (defaultServerSocketFactory == null) {
61            SSLContext context;
62            try {
63                context = SSLContext.getDefault();
64            } catch (NoSuchAlgorithmException e) {
65                context = null;
66            }
67            if (context != null) {
68                defaultServerSocketFactory = context.getServerSocketFactory();
69            }
70        }
71        if (defaultServerSocketFactory == null) {
72            // Use internal dummy implementation
73            defaultServerSocketFactory = new DefaultSSLServerSocketFactory(
74                    "No ServerSocketFactory installed");
75        }
76        return defaultServerSocketFactory;
77    }
78
79    /**
80     * Creates a new {@code SSLServerSocketFactory} instance.
81     */
82    protected SSLServerSocketFactory() {
83    }
84
85    /**
86     * Returns the names of the cipher suites that are enabled by default.
87     *
88     * @return the names of the cipher suites that are enabled by default
89     */
90    public abstract String[] getDefaultCipherSuites();
91
92    /**
93     * Returns the list of supported cipher suites that could be enabled for an
94     * SSL connection created by this factory.
95     *
96     * @return the list of supported cipher suites
97     */
98    public abstract String[] getSupportedCipherSuites();
99}
100