View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.net.server;
15  
16  import javax.net.ServerSocketFactory;
17  import javax.net.ssl.SSLContext;
18  
19  import ch.qos.logback.core.net.ssl.ConfigurableSSLServerSocketFactory;
20  import ch.qos.logback.core.net.ssl.SSLComponent;
21  import ch.qos.logback.core.net.ssl.SSLConfiguration;
22  import ch.qos.logback.core.net.ssl.SSLParametersConfiguration;
23  
24  /**
25   * 
26   * This is the base class for module specific ServerSocketAppender
27   * implementations.
28   * 
29   * @author Carl Harris
30   */
31  public abstract class SSLServerSocketAppenderBase<E> extends AbstractServerSocketAppender<E> implements SSLComponent {
32  
33      private SSLConfiguration ssl;
34      private ServerSocketFactory socketFactory;
35  
36      @Override
37      protected ServerSocketFactory getServerSocketFactory() {
38          return socketFactory;
39      }
40  
41      /**
42       * {@inheritDoc}
43       */
44      @Override
45      public void start() {
46          try {
47              SSLContext sslContext = getSsl().createContext(this);
48              SSLParametersConfiguration parameters = getSsl().getParameters();
49              parameters.setContext(getContext());
50              socketFactory = new ConfigurableSSLServerSocketFactory(parameters, sslContext.getServerSocketFactory());
51              super.start();
52          } catch (Exception ex) {
53              addError(ex.getMessage(), ex);
54          }
55      }
56  
57      /**
58       * Gets the SSL configuration.
59       * 
60       * @return SSL configuration; if no configuration has been set, a default
61       *         configuration is returned
62       */
63      public SSLConfiguration getSsl() {
64          if (ssl == null) {
65              ssl = new SSLConfiguration();
66          }
67          return ssl;
68      }
69  
70      /**
71       * Sets the SSL configuration.
72       * 
73       * @param ssl the SSL configuration to set
74       */
75      public void setSsl(SSLConfiguration ssl) {
76          this.ssl = ssl;
77      }
78  
79  }