001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.classic.net.server; 015 016import javax.net.ServerSocketFactory; 017import javax.net.ssl.SSLContext; 018 019import ch.qos.logback.core.net.ssl.ConfigurableSSLServerSocketFactory; 020import ch.qos.logback.core.net.ssl.SSLComponent; 021import ch.qos.logback.core.net.ssl.SSLConfiguration; 022import ch.qos.logback.core.net.ssl.SSLParametersConfiguration; 023 024/** 025 * A {@link ServerSocketReceiver} that supports SSL. 026 * 027 * @author Carl Harris 028 */ 029public class SSLServerSocketReceiver extends ServerSocketReceiver implements SSLComponent { 030 031 private SSLConfiguration ssl; 032 private ServerSocketFactory socketFactory; 033 034 /** 035 * {@inheritDoc} 036 */ 037 @Override 038 protected ServerSocketFactory getServerSocketFactory() throws Exception { 039 if (socketFactory == null) { 040 SSLContext sslContext = getSsl().createContext(this); 041 SSLParametersConfiguration parameters = getSsl().getParameters(); 042 parameters.setContext(getContext()); 043 socketFactory = new ConfigurableSSLServerSocketFactory(parameters, sslContext.getServerSocketFactory()); 044 } 045 return socketFactory; 046 } 047 048 /** 049 * Gets the server's SSL configuration. 050 * 051 * @return SSL configuration; if no SSL configuration was provided a default 052 * configuration is returned 053 */ 054 public SSLConfiguration getSsl() { 055 if (ssl == null) { 056 ssl = new SSLConfiguration(); 057 } 058 return ssl; 059 } 060 061 /** 062 * Gets the server's SSL configuration. 063 * 064 * @param ssl the SSL configuration to set. 065 */ 066 public void setSsl(SSLConfiguration ssl) { 067 this.ssl = ssl; 068 } 069 070}