WrappedLogSSLSocketFactory.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */


  20. package org.openspcoop2.utils.transport.http;

  21. import java.io.IOException;
  22. import java.io.InputStream;
  23. import java.net.InetAddress;
  24. import java.net.Socket;
  25. import java.net.UnknownHostException;

  26. import javax.net.ssl.SSLSocket;
  27. import javax.net.ssl.SSLSocketFactory;

  28. import org.openspcoop2.utils.LoggerWrapperFactory;
  29. import org.slf4j.Logger;

  30. /**
  31.  * WrappedLogSSLSocketFactory
  32.  *
  33.  * @author Poli Andrea (apoli@link.it)
  34.  * @author $Author$
  35.  * @version $Rev$, $Date$
  36.  */
  37. public class WrappedLogSSLSocketFactory extends SSLSocketFactory {

  38.     private SSLSocketFactory delegate;
  39.     private Logger log;
  40.     private String prefixLog;
  41.     private String clientCertificateConfigurated;

  42.     public WrappedLogSSLSocketFactory(SSLSocketFactory sf0, Logger log, String prefixLog, String clientCertificateConfigurated) {
  43.         this.delegate = sf0;
  44.         this.log = log;
  45.         this.prefixLog = prefixLog;
  46.         if(this.log==null) {
  47.             this.log = LoggerWrapperFactory.getLogger(WrappedLogSSLSocketFactory.class);
  48.         }
  49.         if(this.prefixLog==null) {
  50.             this.prefixLog="";
  51.         }
  52.         this.clientCertificateConfigurated = clientCertificateConfigurated;
  53.     }

  54.     @Override
  55.     public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
  56.         return new WrappedLogSSLSocket((SSLSocket) this.delegate.createSocket(s, host, port, autoClose),
  57.                 this.log, this.prefixLog, this.clientCertificateConfigurated);
  58.     }
  59.    
  60.     @Override
  61.     public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
  62.         return new WrappedLogSSLSocket((SSLSocket) this.delegate.createSocket(host, port),
  63.                 this.log, this.prefixLog, this.clientCertificateConfigurated);
  64.     }

  65.     @Override
  66.     public Socket createSocket(InetAddress address, int port) throws IOException {
  67.         return new WrappedLogSSLSocket((SSLSocket) this.delegate.createSocket(address, port),
  68.                 this.log, this.prefixLog, this.clientCertificateConfigurated);
  69.     }

  70.     @Override
  71.     public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
  72.             throws IOException, UnknownHostException {
  73.         return new WrappedLogSSLSocket((SSLSocket) this.delegate.createSocket(host, port, localHost, localPort),
  74.                 this.log, this.prefixLog, this.clientCertificateConfigurated);
  75.     }

  76.     @Override
  77.     public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
  78.             throws IOException {
  79.         return new WrappedLogSSLSocket((SSLSocket) this.delegate.createSocket(address, port, localAddress, localPort),
  80.                 this.log, this.prefixLog, this.clientCertificateConfigurated);
  81.     }
  82.    
  83.     @Override
  84.     public Socket createSocket(Socket s, InputStream consumed, boolean autoClose) throws IOException {
  85.         return new WrappedLogSSLSocket((SSLSocket) this.delegate.createSocket(s, consumed, autoClose),
  86.                 this.log, this.prefixLog, this.clientCertificateConfigurated);
  87.     }

  88.     @Override
  89.     public Socket createSocket() throws IOException {
  90.         return new WrappedLogSSLSocket((SSLSocket) this.delegate.createSocket(),
  91.                 this.log, this.prefixLog, this.clientCertificateConfigurated);
  92.     }

  93.    
  94.     // METODI NON MODIFICATI
  95.    
  96.     @Override
  97.     public String[] getDefaultCipherSuites() {
  98.         return this.delegate.getDefaultCipherSuites();
  99.     }

  100.     @Override
  101.     public String[] getSupportedCipherSuites() {
  102.         return this.delegate.getSupportedCipherSuites();
  103.     }

  104.     @Override
  105.     public int hashCode() {
  106.         return this.delegate.hashCode();
  107.     }

  108.     @Override
  109.     public boolean equals(Object obj) {
  110.         return this.delegate.equals(obj);
  111.     }

  112.     @Override
  113.     public String toString() {
  114.         return this.delegate.toString();
  115.     }

  116. }