SSLSocketFactoryCache.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.security.keystore.cache;

  21. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  22. import org.openspcoop2.security.SecurityException;
  23. import org.openspcoop2.security.keystore.SSLSocketFactory;
  24. import org.openspcoop2.utils.transport.http.SSLConfig;

  25. /**
  26.  * SSLSocketFactoryCache
  27.  *
  28.  * @author Andrea Poli (apoli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. public class SSLSocketFactoryCache extends AbstractKeystoreCache<SSLSocketFactory> {

  33.     @Override
  34.     public SSLSocketFactory createKeystore(String key, Object... params)
  35.             throws SecurityException {
  36.         if(params==null){
  37.             throw new SecurityException("Params is null");
  38.         }
  39.         if(params.length==2){
  40.             if( ! (params[0] instanceof RequestInfo) ){
  41.                 throw new SecurityException("Param[0] must be RequestInfo");
  42.             }
  43.             RequestInfo requestInfo = (RequestInfo) params[0];
  44.             if( ! (params[1] instanceof SSLConfig) ){
  45.                 throw new SecurityException("Param[1] must be SSLConfig");
  46.             }
  47.             SSLConfig sslConfig = (SSLConfig) params[1];
  48.             return new SSLSocketFactory(requestInfo,sslConfig);
  49.         }
  50.         else{
  51.             throw new SecurityException("Params [lenght:"+params.length+"] not supported");
  52.         }
  53.     }

  54.     @Override
  55.     public String getPrefixKey() {
  56.         return "SSLSocketFactory ";
  57.     }
  58. }