001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexander Y. Kleymenov
020: * @version $Revision$
021: */package org.apache.harmony.xnet.provider.jsse;
022:
023: import org.apache.harmony.xnet.provider.jsse.SSLParameters;
024:
025: import java.io.IOException;
026: import java.net.InetAddress;
027: import java.net.ServerSocket;
028: import java.security.KeyManagementException;
029: import javax.net.ssl.SSLServerSocketFactory;
030:
031: /**
032: * Implementation of SSLServerSocketFactory.
033: */
034: public class SSLServerSocketFactoryImpl extends SSLServerSocketFactory {
035:
036: private SSLParameters sslParameters;
037: private IOException instantiationException;
038:
039: /**
040: * Constructor.
041: */
042: public SSLServerSocketFactoryImpl() {
043: super ();
044: try {
045: this .sslParameters = SSLParameters.getDefault();
046: this .sslParameters.setUseClientMode(false);
047: } catch (KeyManagementException e) {
048: instantiationException = new IOException(
049: "Delayed instantiation exception:");
050: instantiationException.initCause(e);
051: }
052: }
053:
054: /**
055: * Constructor.
056: */
057: protected SSLServerSocketFactoryImpl(SSLParameters sslParameters) {
058: super ();
059: this .sslParameters = (SSLParameters) sslParameters.clone();
060: this .sslParameters.setUseClientMode(false);
061: }
062:
063: /**
064: * @see javax.net.ssl.SSLServerSocketFactory#getDefaultCipherSuites()
065: */
066: public String[] getDefaultCipherSuites() {
067: if (instantiationException != null) {
068: return new String[0];
069: }
070: return sslParameters.getEnabledCipherSuites();
071: }
072:
073: /**
074: * @see javax.net.ssl.SSLServerSocketFactory#getSupportedCipherSuites()
075: */
076: public String[] getSupportedCipherSuites() {
077: if (instantiationException != null) {
078: return new String[0];
079: }
080: return CipherSuite.getSupportedCipherSuiteNames();
081: }
082:
083: /**
084: * @see javax.net.ServerSocketFactory#createServerSocket()
085: */
086: public ServerSocket createServerSocket() throws IOException {
087: if (instantiationException != null) {
088: throw instantiationException;
089: }
090: return new SSLServerSocketImpl((SSLParameters) sslParameters
091: .clone());
092: }
093:
094: /**
095: * @see javax.net.ServerSocketFactory#createServerSocket(int)
096: */
097: public ServerSocket createServerSocket(int port) throws IOException {
098: if (instantiationException != null) {
099: throw instantiationException;
100: }
101: return new SSLServerSocketImpl(port,
102: (SSLParameters) sslParameters.clone());
103: }
104:
105: /**
106: * @see javax.net.ServerSocketFactory#createServerSocket(int,int)
107: */
108: public ServerSocket createServerSocket(int port, int backlog)
109: throws IOException {
110: if (instantiationException != null) {
111: throw instantiationException;
112: }
113: return new SSLServerSocketImpl(port, backlog,
114: (SSLParameters) sslParameters.clone());
115: }
116:
117: /**
118: * @see javax.net.ServerSocketFactory#createServerSocket(int,int,InetAddress)
119: */
120: public ServerSocket createServerSocket(int port, int backlog,
121: InetAddress iAddress) throws IOException {
122: if (instantiationException != null) {
123: throw instantiationException;
124: }
125: return new SSLServerSocketImpl(port, backlog, iAddress,
126: (SSLParameters) sslParameters.clone());
127: }
128: }
|