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.ssl;
15  
16  import javax.net.ssl.SSLParameters;
17  import javax.net.ssl.SSLSocket;
18  
19  /**
20   * An {@link SSLConfigurable} wrapper for an {@link SSLSocket}.
21   *
22   * @author Carl Harris
23   * @author Bruno Harbulot
24   */
25  public class SSLConfigurableSocket implements SSLConfigurable {
26  
27      private final SSLSocket delegate;
28  
29      public SSLConfigurableSocket(SSLSocket delegate) {
30          this.delegate = delegate;
31      }
32  
33      public String[] getDefaultProtocols() {
34          return delegate.getEnabledProtocols();
35      }
36  
37      public String[] getSupportedProtocols() {
38          return delegate.getSupportedProtocols();
39      }
40  
41      public void setEnabledProtocols(String[] protocols) {
42          delegate.setEnabledProtocols(protocols);
43      }
44  
45      public String[] getDefaultCipherSuites() {
46          return delegate.getEnabledCipherSuites();
47      }
48  
49      public String[] getSupportedCipherSuites() {
50          return delegate.getSupportedCipherSuites();
51      }
52  
53      public void setEnabledCipherSuites(String[] suites) {
54          delegate.setEnabledCipherSuites(suites);
55      }
56  
57      public void setNeedClientAuth(boolean state) {
58          delegate.setNeedClientAuth(state);
59      }
60  
61      public void setWantClientAuth(boolean state) {
62          delegate.setWantClientAuth(state);
63      }
64  
65      @Override
66      public void setHostnameVerification(boolean hostnameVerification) {
67          if (!hostnameVerification) {
68              return;
69          }
70          SSLParameters sslParameters = delegate.getSSLParameters();
71          sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
72          delegate.setSSLParameters(sslParameters);
73      }
74  
75  }