ConnettoreHTTPApiHelper.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.core.config.rs.server.api.impl.erogazioni;

  21. import static org.openspcoop2.utils.service.beans.utils.BaseHelper.evalnull;

  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.Properties;

  25. import org.apache.commons.lang3.StringUtils;
  26. import org.openspcoop2.core.config.rs.server.api.impl.Enums;
  27. import org.openspcoop2.core.config.rs.server.model.ConnettoreConfigurazioneApiKey;
  28. import org.openspcoop2.core.config.rs.server.model.ConnettoreConfigurazioneHttpBasic;
  29. import org.openspcoop2.core.config.rs.server.model.ConnettoreConfigurazioneHttps;
  30. import org.openspcoop2.core.config.rs.server.model.ConnettoreConfigurazioneHttpsClient;
  31. import org.openspcoop2.core.config.rs.server.model.ConnettoreConfigurazioneHttpsServer;
  32. import org.openspcoop2.core.config.rs.server.model.ConnettoreConfigurazioneProxy;
  33. import org.openspcoop2.core.config.rs.server.model.ConnettoreConfigurazioneTimeout;
  34. import org.openspcoop2.core.config.rs.server.model.ConnettoreEnum;
  35. import org.openspcoop2.core.config.rs.server.model.ConnettoreHttp;
  36. import org.openspcoop2.core.config.rs.server.model.KeystoreEnum;
  37. import org.openspcoop2.core.config.rs.server.model.OneOfApplicativoServerConnettore;
  38. import org.openspcoop2.core.config.rs.server.model.OneOfConnettoreErogazioneConnettore;
  39. import org.openspcoop2.core.config.rs.server.model.OneOfConnettoreFruizioneConnettore;
  40. import org.openspcoop2.core.config.rs.server.model.SslTipologiaEnum;
  41. import org.openspcoop2.core.constants.CostantiDB;
  42. import org.openspcoop2.core.constants.TipiConnettore;
  43. import org.openspcoop2.core.registry.Connettore;
  44. import org.openspcoop2.utils.certificate.hsm.HSMUtils;
  45. import org.openspcoop2.utils.service.beans.utils.BaseHelper;
  46. import org.openspcoop2.utils.service.fault.jaxrs.FaultCode;
  47. import org.openspcoop2.web.ctrlstat.costanti.ConnettoreServletType;
  48. import org.openspcoop2.web.ctrlstat.plugins.ExtendedConnettore;
  49. import org.openspcoop2.web.ctrlstat.plugins.servlet.ServletExtendedConnettoreUtils;
  50. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriCostanti;
  51. import org.openspcoop2.web.lib.mvc.Costanti;
  52. import org.openspcoop2.web.lib.mvc.ServletUtils;

  53. /**
  54.  * ConnettoreHTTPApiHelper
  55.  *
  56.  * @author $Author$
  57.  * @version $Rev$, $Date$
  58.  *
  59.  */
  60. public class ConnettoreHTTPApiHelper extends AbstractConnettoreApiHelper<ConnettoreHttp> {

  61.     @Override
  62.     protected boolean connettoreCheckData(ConnettoreHttp conn, ErogazioniEnv env, boolean erogazione) throws Exception {
  63.        
  64.        
  65.         final boolean http_stato  = conn.getAutenticazioneHttp() != null;
  66.         final boolean proxy_enabled = conn.getProxy() != null;
  67.         final boolean tempiRisposta_enabled = conn.getTempiRisposta() != null;
  68.        
  69.         final ConnettoreConfigurazioneApiKey httpApiKey = conn.getAutenticazioneApikey();
  70.         boolean apiKey = (httpApiKey!=null && httpApiKey.getApiKey()!=null && StringUtils.isNotEmpty(httpApiKey.getApiKey()));
  71.         final ConnettoreConfigurazioneHttps httpsConf    = conn.getAutenticazioneHttps();
  72.         final ConnettoreConfigurazioneHttpBasic httpConf     = conn.getAutenticazioneHttp();

  73.         final String endpointtype = httpsConf != null ? TipiConnettore.HTTPS.getNome() : TipiConnettore.HTTP.getNome();
  74.        
  75.         final Properties parametersPOST = null;
  76.         org.openspcoop2.core.registry.Connettore conTmp = null;
  77.         List<ExtendedConnettore> listExtendedConnettore =
  78.                 ServletExtendedConnettoreUtils.getExtendedConnettore(conTmp, ConnettoreServletType.ACCORDO_SERVIZIO_PARTE_SPECIFICA_ADD, env.apsHelper,
  79.                             parametersPOST, false, endpointtype);

  80.         final ConnettoreConfigurazioneHttpsClient httpsClient = httpsConf!=null ? evalnull( httpsConf::getClient ) : null;
  81.         final ConnettoreConfigurazioneHttpsServer httpsServer = httpsConf!=null ? evalnull( httpsConf::getServer ) : null;
  82.         final ConnettoreConfigurazioneProxy       proxy       = conn.getProxy();
  83.         final ConnettoreConfigurazioneTimeout     timeoutConf = conn.getTempiRisposta();
  84.         final String tokenPolicy = conn.getTokenPolicy();
  85.         final boolean autenticazioneToken = tokenPolicy!=null;
  86.        
  87.         final boolean httpsstato = httpsClient != null; // Questo รจ per l'autenticazione client.
  88.          
  89.         String httpskeystore = ErogazioniCheckNotNull.getHttpskeystore(httpsClient);
  90.                        
  91.         return env.saHelper.endPointCheckData(
  92.                 null,
  93.                 env.tipo_protocollo,
  94.                 erogazione,
  95.                 endpointtype,
  96.                 conn.getEndpoint(),
  97.                 null,   // nome
  98.                 null,   // tipo
  99.                 httpConf!=null ? evalnull( httpConf::getUsername ) : null,
  100.                 httpConf!=null ? evalnull( httpConf::getPassword ) : null,
  101.                 null,   // this.initcont,
  102.                 null,   // this.urlpgk,
  103.                 null,   // provurl jms,
  104.                 null,   // connfact,
  105.                 null,   // sendas,
  106.                 conn.getEndpoint(),                                                     // this.httpsurl,
  107.                 evalnull( () -> httpsConf.getTipologia().toString() ),              // this.httpstipologia
  108.                 BaseHelper.evalorElse( () -> httpsConf.isHostnameVerifier().booleanValue(), false ),    // this.httpshostverify,
  109.                 (httpsConf!=null ? !httpsConf.isTrustAllServerCerts() : ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS), // httpsTrustVerifyCert
  110.                 httpsServer!=null ? evalnull( httpsServer::getTruststorePath ) : null,              // this.httpspath
  111.                 evalnull( () -> getTruststoreType(httpsServer) ),   // this.httpstipo,
  112.                 httpsServer!=null ? evalnull( httpsServer::getTruststorePassword ) : null,          // this.httpspwd,
  113.                 httpsServer!=null ? evalnull( httpsServer::getAlgoritmo ) : null,                   // this.httpsalgoritmo
  114.                 httpsstato,
  115.                 httpskeystore,
  116.                 "",                                                                     // httpspwdprivatekeytrust,
  117.                 httpsClient!=null ? evalnull( httpsClient::getKeystorePath ) : null,                // pathkey
  118.                 evalnull( () -> getKeystoreType(httpsClient) ),         // this.httpstipokey
  119.                 httpsClient!=null ? evalnull( httpsClient::getKeystorePassword ) : null,            // this.httpspwdkey
  120.                 httpsClient!=null ? evalnull( httpsClient::getKeyPassword ) : null,             // this.httpspwdprivatekey,  
  121.                 httpsClient!=null ? evalnull( httpsClient::getAlgoritmo ) : null,               // this.httpsalgoritmokey,
  122.                 httpsClient!=null ? evalnull( httpsClient::getKeyAlias ) : null,                    // httpsKeyAlias
  123.                 httpsServer!=null ? evalnull( httpsServer::getTruststoreCrl ) : null,                   // httpsTrustStoreCRLs
  124.                 httpsServer!=null ? evalnull( httpsServer::getTruststoreOcspPolicy) : null,                 // httpsTrustStoreOCSPPolicy
  125.                 httpsClient!=null ? evalnull( httpsClient::getKeystoreByokPolicy) : null,               // httpsKeyStoreBYOKPolicy
  126.                 null,                                                               //  tipoconn (personalizzato)
  127.                 ServletUtils.boolToCheckBoxStatus( http_stato ),                                            //autenticazioneHttp,
  128.                 ServletUtils.boolToCheckBoxStatus( proxy_enabled ),
  129.                 proxy!=null ? evalnull( proxy::getHostname ) : null,
  130.                 evalnull( () -> proxy.getPorta().toString() ),
  131.                 proxy!=null ? evalnull( proxy::getUsername ) : null,
  132.                 proxy!=null ? evalnull( proxy::getPassword ) : null,
  133.                 ServletUtils.boolToCheckBoxStatus( tempiRisposta_enabled ),
  134.                 evalnull( () -> timeoutConf.getConnectionTimeout().toString()), // this.tempiRisposta_connectionTimeout,
  135.                 evalnull( () -> timeoutConf.getConnectionReadTimeout().toString()), //null, // this.tempiRisposta_readTimeout,
  136.                 evalnull( () -> timeoutConf.getTempoMedioRisposta().toString()),    // this.tempiRisposta_tempoMedioRisposta,
  137.                 "no",   // this.opzioniAvanzate,
  138.                 "",     // this.transfer_mode,
  139.                 "",     // this.transfer_mode_chunk_size,
  140.                 "",     // this.redirect_mode,
  141.                 "",     // this.redirect_max_hop,
  142.                 null,   // this.requestOutputFileName,
  143.                 null,   // this.requestOutputFileName_permissions
  144.                 null,   // this.requestOutputFileNameHeaders,
  145.                 null,   // this.requestOutputFileNameHeaders_permissions
  146.                 null,   // this.requestOutputParentDirCreateIfNotExists,
  147.                 null,   // this.requestOutputOverwriteIfExists,
  148.                 null,   // this.responseInputMode,
  149.                 null,   // this.responseInputFileName,
  150.                 null,   // this.responseInputFileNameHeaders,
  151.                 null,   // this.responseInputDeleteAfterRead,
  152.                 null,   // this.responseInputWaitTime,
  153.                 autenticazioneToken,
  154.                 tokenPolicy,
  155.                
  156.                 apiKey ? Costanti.CHECK_BOX_ENABLED : Costanti.CHECK_BOX_DISABLED, // autenticazioneApiKey
  157.                 apiKey &&
  158.                         env.erogazioniHelper.isAutenticazioneApiKeyUseOAS3Names(
  159.                                 evalnull(httpApiKey::getApiKeyHeader),
  160.                                 evalnull(httpApiKey::getAppIdHeader)
  161.                 ), // useOAS3Names
  162.                 apiKey &&
  163.                     env.erogazioniHelper.isAutenticazioneApiKeyUseAppId(
  164.                             evalnull(httpApiKey::getAppId)
  165.                 ), // useAppId
  166.                 httpApiKey!=null ? evalnull( httpApiKey::getApiKeyHeader ) : null, // apiKeyHeader
  167.                 httpApiKey!=null ? evalnull( httpApiKey::getApiKey ) : null, // apiKeyValue
  168.                 httpApiKey!=null ? evalnull( httpApiKey::getAppIdHeader ) : null, // appIdHeader
  169.                 httpApiKey!=null ? evalnull( httpApiKey::getAppId ) : null, // appIdValue              
  170.                
  171.                 listExtendedConnettore,
  172.                 false, // erogazioneServizioApplicativoServerEnabled,
  173.                 null // rogazioneServizioApplicativoServer
  174.             );
  175.     }

  176.     @Override
  177.     protected Connettore fillConnettoreRegistro(org.openspcoop2.core.registry.Connettore regConnettore, ErogazioniEnv env, ConnettoreHttp conn, String oldConnT) throws Exception {
  178.        
  179.         final boolean proxy_enabled = conn.getProxy() != null;
  180.         final boolean tempiRisposta_enabled = conn.getTempiRisposta() != null;
  181.        
  182.         final ConnettoreConfigurazioneApiKey httpApiKey = conn.getAutenticazioneApikey();
  183.         final ConnettoreConfigurazioneHttps httpsConf    = conn.getAutenticazioneHttps();
  184.         final ConnettoreConfigurazioneHttpBasic httpConf     = conn.getAutenticazioneHttp();

  185.         final String endpointtype = httpsConf != null ? TipiConnettore.HTTPS.getNome() : TipiConnettore.HTTP.getNome();
  186.        
  187.         final Properties parametersPOST = null;
  188.         org.openspcoop2.core.registry.Connettore conTmp = null;
  189.         List<ExtendedConnettore> listExtendedConnettore =
  190.                 ServletExtendedConnettoreUtils.getExtendedConnettore(conTmp, ConnettoreServletType.ACCORDO_SERVIZIO_PARTE_SPECIFICA_ADD, env.apsHelper,
  191.                             parametersPOST, false, endpointtype);

  192.         final ConnettoreConfigurazioneHttpsClient httpsClient = httpsConf!=null ? evalnull( httpsConf::getClient ) : null;
  193.         final ConnettoreConfigurazioneHttpsServer httpsServer = httpsConf!=null ? evalnull( httpsConf::getServer ) : null;
  194.         final ConnettoreConfigurazioneProxy       proxy       = conn.getProxy();
  195.         final ConnettoreConfigurazioneTimeout     timeoutConf = conn.getTempiRisposta();
  196.         final String tokenPolicy = conn.getTokenPolicy();
  197.        
  198.         final boolean httpsstato = httpsClient != null; // Questo รจ per l'autenticazione client.
  199.          
  200.         String httpskeystore = ErogazioniCheckNotNull.getHttpskeystore(httpsClient);
  201.                        
  202.          
  203.         env.apsHelper.fillConnettore(
  204.                 regConnettore,
  205.                 conn.isDebug() != null && conn.isDebug() ? "true" : "false",                // this.connettoreDebug,
  206.                 endpointtype,           // endpointtype
  207.                 oldConnT,                       // oldConnT
  208.                 "",                     // tipoConn Personalizzato
  209.                 conn.getEndpoint(),     // this.url,
  210.                 null,   // this.nome,
  211.                 null,   // this.tipo,
  212.                 httpConf!=null ? evalnull( httpConf::getUsername ) : null,
  213.                 httpConf!=null ? evalnull( httpConf::getPassword ) : null,
  214.                 null,   // this.initcont,
  215.                 null,   // this.urlpgk,
  216.                 conn.getEndpoint(), // this.url,
  217.                 null,   // this.connfact,
  218.                 null,   // this.sendas,
  219.                 conn.getEndpoint(),                                                     // this.httpsurl,
  220.                 evalnull( () -> httpsConf.getTipologia().toString() ),              // this.httpstipologia
  221.                 BaseHelper.evalorElse( () -> httpsConf.isHostnameVerifier().booleanValue(), false ),    // this.httpshostverify,
  222.                 (httpsConf!=null ? !httpsConf.isTrustAllServerCerts() : ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS), // httpsTrustVerifyCert
  223.                 httpsServer!=null ? evalnull( httpsServer::getTruststorePath ) : null,              // this.httpspath
  224.                 evalnull( () -> getTruststoreType(httpsServer) ),   // this.httpstipo,
  225.                 httpsServer!=null ? evalnull( httpsServer::getTruststorePassword ) : null,          // this.httpspwd,
  226.                 httpsServer!=null ? evalnull( httpsServer::getAlgoritmo ) : null,                   // this.httpsalgoritmo
  227.                 httpsstato,
  228.                 httpskeystore,          // this.httpskeystore,
  229.                 "",                                                                 //  this.httpspwdprivatekeytrust
  230.                 httpsClient!=null ? evalnull( httpsClient::getKeystorePath ) : null,                // pathkey
  231.                 evalnull( () -> getKeystoreType(httpsClient) ),         // this.httpstipokey
  232.                 httpsClient!=null ? evalnull( httpsClient::getKeystorePassword ) : null,            // this.httpspwdkey
  233.                 httpsClient!=null ? evalnull( httpsClient::getKeyPassword ) : null,             // this.httpspwdprivatekey,  
  234.                 httpsClient!=null ? evalnull( httpsClient::getAlgoritmo ) : null,               // this.httpsalgoritmokey,
  235.                 httpsClient!=null ? evalnull( httpsClient::getKeyAlias ) : null,                    // httpsKeyAlias
  236.                 httpsServer!=null ? evalnull( httpsServer::getTruststoreCrl ) : null,                   // httpsTrustStoreCRLs
  237.                 httpsServer!=null ? evalnull( httpsServer::getTruststoreOcspPolicy) : null,             // httpsTrustStoreOCSPPolicy
  238.                 httpsClient!=null ? evalnull( httpsClient::getKeystoreByokPolicy) : null,               // httpsKeyStoreBYOKPolicy
  239.            
  240.                 ServletUtils.boolToCheckBoxStatus( proxy_enabled ),
  241.                 proxy!=null ? evalnull( proxy::getHostname ) : null,
  242.                 evalnull( () -> proxy.getPorta().toString() ),
  243.                 proxy!=null ? evalnull( proxy::getUsername ) : null,
  244.                 proxy!=null ? evalnull( proxy::getPassword ) : null,
  245.                
  246.                 ServletUtils.boolToCheckBoxStatus( tempiRisposta_enabled ),
  247.                 evalnull( () -> timeoutConf.getConnectionTimeout().toString()), // this.tempiRisposta_connectionTimeout,
  248.                 evalnull( () -> timeoutConf.getConnectionReadTimeout().toString()), //null, // this.tempiRisposta_readTimeout,
  249.                 evalnull( () -> timeoutConf.getTempoMedioRisposta().toString()),    // this.tempiRisposta_tempoMedioRisposta,
  250.                 "no",   // this.opzioniAvanzate,
  251.                 "",     // this.transfer_mode,
  252.                 "",     // this.transfer_mode_chunk_size,
  253.                 "",     // this.redirect_mode,
  254.                 "",     // this.redirect_max_hop,
  255.                 null,   // this.requestOutputFileName,
  256.                 null,   // this.requestOutputFileName_permissions
  257.                 null,   // this.requestOutputFileNameHeaders,
  258.                 null,   // this.requestOutputFileNameHeaders_permissions
  259.                 null,   // this.requestOutputParentDirCreateIfNotExists,
  260.                 null,   // this.requestOutputOverwriteIfExists,
  261.                 null,   // this.responseInputMode,
  262.                 null,   // this.responseInputFileName,
  263.                 null,   // this.responseInputFileNameHeaders,
  264.                 null,   // this.responseInputDeleteAfterRead,
  265.                 null,   // this.responseInputWaitTime,
  266.                 tokenPolicy,
  267.                
  268.                 httpApiKey!=null ? evalnull( httpApiKey::getApiKeyHeader ) : null, // apiKeyHeader
  269.                 httpApiKey!=null ? evalnull( httpApiKey::getApiKey ) : null, // apiKeyValue
  270.                 httpApiKey!=null ? evalnull( httpApiKey::getAppIdHeader ) : null, // appIdHeader
  271.                 httpApiKey!=null ? evalnull( httpApiKey::getAppId ) : null, // appIdValue  
  272.                
  273.                 null, // connettoreStatusParams
  274.                 listExtendedConnettore);            
  275.        
  276.         return regConnettore;
  277.     }

  278.     @Override
  279.     protected org.openspcoop2.core.config.Connettore buildConnettoreConfigurazione(
  280.             org.openspcoop2.core.config.Connettore regConnettore, ErogazioniEnv env, ConnettoreHttp conn,
  281.             String oldConnT) throws Exception {
  282.        
  283.         final boolean proxy_enabled = conn.getProxy() != null;
  284.         final boolean tempiRisposta_enabled = conn.getTempiRisposta() != null;
  285.        
  286.         final ConnettoreConfigurazioneApiKey httpApiKey = conn.getAutenticazioneApikey();
  287.         final ConnettoreConfigurazioneHttps httpsConf    = conn.getAutenticazioneHttps();
  288.         final ConnettoreConfigurazioneHttpBasic httpConf     = conn.getAutenticazioneHttp();

  289.         final String endpointtype = httpsConf != null ? TipiConnettore.HTTPS.getNome() : TipiConnettore.HTTP.getNome();
  290.        
  291.         final Properties parametersPOST = null;
  292.         org.openspcoop2.core.registry.Connettore conTmp = null;
  293.         List<ExtendedConnettore> listExtendedConnettore =
  294.                 ServletExtendedConnettoreUtils.getExtendedConnettore(conTmp, ConnettoreServletType.ACCORDO_SERVIZIO_PARTE_SPECIFICA_ADD, env.apsHelper,
  295.                             parametersPOST, false, endpointtype);

  296.         final ConnettoreConfigurazioneHttpsClient httpsClient = httpsConf!=null ? evalnull( httpsConf::getClient ) : null;
  297.         final ConnettoreConfigurazioneHttpsServer httpsServer = httpsConf!=null ? evalnull( httpsConf::getServer ) : null;
  298.         final ConnettoreConfigurazioneProxy       proxy       = conn.getProxy();
  299.         final ConnettoreConfigurazioneTimeout     timeoutConf = conn.getTempiRisposta();
  300.         final String tokenPolicy = conn.getTokenPolicy();
  301.        
  302.         final boolean httpsstato = httpsClient != null; // Questo รจ per l'autenticazione client.
  303.          
  304.         String httpskeystore = ErogazioniCheckNotNull.getHttpskeystore(httpsClient);
  305.                        
  306.                  
  307.         env.apsHelper.fillConnettore(
  308.                 regConnettore,
  309.                 conn.isDebug() != null && conn.isDebug() ? "true" : "false",                // this.connettoreDebug,
  310.                 endpointtype,           // endpointtype
  311.                 oldConnT,           // oldConnT
  312.                 "",                     // tipoConn Personalizzato
  313.                 conn.getEndpoint(),     // this.url,
  314.                 null,   // this.nome,
  315.                 null,   // this.tipo,
  316.                 httpConf!=null ? evalnull( httpConf::getUsername ) : null,
  317.                 httpConf!=null ? evalnull( httpConf::getPassword ) : null,
  318.                 null,   // this.initcont,
  319.                 null,   // this.urlpgk,
  320.                 conn.getEndpoint(), // this.url,
  321.                 null,   // this.connfact,
  322.                 null,   // this.sendas,
  323.                 conn.getEndpoint(),                                                     // this.httpsurl,
  324.                 evalnull( () -> httpsConf.getTipologia().toString() ),              // this.httpstipologia
  325.                 BaseHelper.evalorElse( () -> httpsConf.isHostnameVerifier().booleanValue(), false ),    // this.httpshostverify,
  326.                 (httpsConf!=null ? !httpsConf.isTrustAllServerCerts() : ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS), // httpsTrustVerifyCert
  327.                 httpsServer!=null ? evalnull( httpsServer::getTruststorePath ) : null,              // this.httpspath
  328.                 evalnull( () -> getTruststoreType(httpsServer) ),   // this.httpstipo,
  329.                 httpsServer!=null ? evalnull( httpsServer::getTruststorePassword ) : null,          // this.httpspwd,
  330.                 httpsServer!=null ? evalnull( httpsServer::getAlgoritmo ) : null,                   // this.httpsalgoritmo
  331.                 httpsstato,
  332.                 httpskeystore,          // this.httpskeystore,
  333.                 "",                                                                 //  this.httpspwdprivatekeytrust
  334.                 httpsClient!=null ? evalnull( httpsClient::getKeystorePath ) : null,                // pathkey
  335.                 evalnull( () -> getKeystoreType(httpsClient) ),         // this.httpstipokey
  336.                 httpsClient!=null ? evalnull( httpsClient::getKeystorePassword ) : null,            // this.httpspwdkey
  337.                 httpsClient!=null ? evalnull( httpsClient::getKeyPassword ) : null,             // this.httpspwdprivatekey,  
  338.                 httpsClient!=null ? evalnull( httpsClient::getAlgoritmo ) : null,               // this.httpsalgoritmokey,
  339.                 httpsClient!=null ? evalnull( httpsClient::getKeyAlias ) : null,                    // httpsKeyAlias
  340.                 httpsServer!=null ? evalnull( httpsServer::getTruststoreCrl ) : null,                   // httpsTrustStoreCRLs
  341.                 httpsServer!=null ? evalnull( httpsServer::getTruststoreOcspPolicy) : null,             // httpsTrustStoreOCSPPolicy
  342.                 httpsClient!=null ? evalnull( httpsClient::getKeystoreByokPolicy) : null,               // httpsKeyStoreBYOKPolicy
  343.            
  344.                 ServletUtils.boolToCheckBoxStatus( proxy_enabled ),
  345.                 proxy!=null ? evalnull( proxy::getHostname ) : null,
  346.                 evalnull( () -> proxy.getPorta().toString() ),
  347.                 proxy!=null ? evalnull( proxy::getUsername ) : null,
  348.                 proxy!=null ? evalnull( proxy::getPassword ) : null,
  349.                
  350.                 ServletUtils.boolToCheckBoxStatus( tempiRisposta_enabled ),
  351.                 evalnull( () -> timeoutConf.getConnectionTimeout().toString()), // this.tempiRisposta_connectionTimeout,
  352.                 evalnull( () -> timeoutConf.getConnectionReadTimeout().toString()), //null, // this.tempiRisposta_readTimeout,
  353.                 evalnull( () -> timeoutConf.getTempoMedioRisposta().toString()),    // this.tempiRisposta_tempoMedioRisposta,
  354.                 "no",   // this.opzioniAvanzate,
  355.                 "",     // this.transfer_mode,
  356.                 "",     // this.transfer_mode_chunk_size,
  357.                 "",     // this.redirect_mode,
  358.                 "",     // this.redirect_max_hop,
  359.                 null,   // this.requestOutputFileName,
  360.                 null,   // this.requestOutputFileName_permissions
  361.                 null,   // this.requestOutputFileNameHeaders,
  362.                 null,   // this.requestOutputFileNameHeaders_permissions
  363.                 null,   // this.requestOutputParentDirCreateIfNotExists,
  364.                 null,   // this.requestOutputOverwriteIfExists,
  365.                 null,   // this.responseInputMode,
  366.                 null,   // this.responseInputFileName,
  367.                 null,   // this.responseInputFileNameHeaders,
  368.                 null,   // this.responseInputDeleteAfterRead,
  369.                 null,   // this.responseInputWaitTime,
  370.                 tokenPolicy,
  371.                
  372.                 httpApiKey!=null ? evalnull( httpApiKey::getApiKeyHeader ) : null, // apiKeyHeader
  373.                 httpApiKey!=null ? evalnull( httpApiKey::getApiKey ) : null, // apiKeyValue
  374.                 httpApiKey!=null ? evalnull( httpApiKey::getAppIdHeader ) : null, // appIdHeader
  375.                 httpApiKey!=null ? evalnull( httpApiKey::getAppId ) : null, // appIdValue  
  376.                
  377.                 null, // connettoreStatusParams
  378.                 listExtendedConnettore);
  379.         return regConnettore;
  380.     }

  381.     @Override
  382.     public ConnettoreHttp buildConnettore(Map<String, String> props, String tipo) {
  383.         ConnettoreHttp c = new ConnettoreHttp();
  384.         c.setTipo(ConnettoreEnum.HTTP);
  385.         c.setEndpoint(props.get(CostantiDB.CONNETTORE_HTTP_LOCATION));
  386.         c.setDebug(Boolean.parseBoolean(props.get(CostantiDB.CONNETTORE_DEBUG)));
  387.        
  388.         ConnettoreConfigurazioneHttpBasic http = new ConnettoreConfigurazioneHttpBasic();
  389.         http.setPassword(evalnull( () -> props.get(CostantiDB.CONNETTORE_PWD).trim()));
  390.         http.setUsername(evalnull( () -> props.get(CostantiDB.CONNETTORE_USER).trim()));
  391.         if ( !StringUtils.isAllEmpty(http.getPassword(), http.getUsername()) ) {
  392.             c.setAutenticazioneHttp(http);
  393.         }
  394.    
  395.         String apiKey = props.get(CostantiDB.CONNETTORE_APIKEY);
  396.         if(apiKey!=null && StringUtils.isNotEmpty(apiKey.trim())) {
  397.             ConnettoreConfigurazioneApiKey apiKeyConf = new ConnettoreConfigurazioneApiKey();
  398.             apiKeyConf.setApiKey(apiKey.trim());
  399.             apiKeyConf.setApiKeyHeader(evalnull( () -> props.get(CostantiDB.CONNETTORE_APIKEY_HEADER).trim()));
  400.             apiKeyConf.setAppId(evalnull( () -> props.get(CostantiDB.CONNETTORE_APIKEY_APPID).trim()));
  401.             apiKeyConf.setAppIdHeader(evalnull( () -> props.get(CostantiDB.CONNETTORE_APIKEY_APPID_HEADER).trim()));
  402.             c.setAutenticazioneApikey(apiKeyConf);
  403.         }
  404.        
  405.         ConnettoreConfigurazioneHttps https = new ConnettoreConfigurazioneHttps();
  406.         https.setHostnameVerifier( props.get(CostantiDB.CONNETTORE_HTTPS_HOSTNAME_VERIFIER) != null
  407.                 ? Boolean.valueOf(props.get(CostantiDB.CONNETTORE_HTTPS_HOSTNAME_VERIFIER))
  408.                 : null
  409.             );
  410.         https.setTipologia(
  411.                 evalnull( () -> Enums.fromValue(SslTipologiaEnum.class, props.get(CostantiDB.CONNETTORE_HTTPS_SSL_TYPE)))
  412.             );
  413.        
  414.         https.setTrustAllServerCerts( props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_ALL_CERTS) != null
  415.                 ? Boolean.valueOf(props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_ALL_CERTS))
  416.                 : null
  417.             );
  418.        
  419.         if(https.isTrustAllServerCerts()==null || !https.isTrustAllServerCerts()) {
  420.             ConnettoreConfigurazioneHttpsServer httpsServer = new ConnettoreConfigurazioneHttpsServer();
  421.            
  422.             httpsServer.setAlgoritmo( evalnull( () ->
  423.                 props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_MANAGEMENT_ALGORITM))
  424.                 );
  425.             httpsServer.setTruststorePassword(
  426.                     evalnull( () -> props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_PASSWORD))
  427.                 );
  428.             httpsServer.setTruststorePath(
  429.                     evalnull( () -> props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_LOCATION))
  430.                 );
  431.            
  432.             String trustStoreType = props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_TYPE);
  433.             if(trustStoreType!=null) {
  434.                 if(HSMUtils.isKeystoreHSM(trustStoreType)) {
  435.                     httpsServer.setTruststoreTipo(KeystoreEnum.PKCS11);
  436.                     httpsServer.setPcks11Tipo(trustStoreType);
  437.                 }
  438.                 else {
  439.                     httpsServer.setTruststoreTipo(Enums.fromValue(KeystoreEnum.class,trustStoreType));
  440.                 }
  441.             }
  442.            
  443.             httpsServer.setTruststoreCrl(
  444.                     evalnull( () -> props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_CRLS))
  445.                 );
  446.            
  447.             httpsServer.setTruststoreOcspPolicy(
  448.                     evalnull( () -> props.get(CostantiDB.CONNETTORE_HTTPS_TRUST_STORE_OCSP_POLICY))
  449.                 );
  450.            
  451.             if(httpsServer.getAlgoritmo()!=null || httpsServer.getTruststorePassword()!=null ||
  452.                     httpsServer.getTruststorePath()!=null || httpsServer.getTruststoreTipo()!=null ||
  453.                     httpsServer.getTruststoreCrl()!=null) {
  454.                 https.setServer(httpsServer);
  455.             }
  456.         }
  457.        
  458.         ConnettoreConfigurazioneHttpsClient httpsClient = new ConnettoreConfigurazioneHttpsClient();
  459.        
  460.         httpsClient.setAlgoritmo(
  461.                 evalnull( () -> props.get(CostantiDB.CONNETTORE_HTTPS_KEY_MANAGEMENT_ALGORITM))
  462.             );
  463.         httpsClient.setKeystorePassword(
  464.                 evalnull( () -> props.get(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_PASSWORD))
  465.             );
  466.         httpsClient.setKeystorePath(
  467.                 evalnull( () -> props.get(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_LOCATION))
  468.             );
  469.         String keyStoreType = props.get(CostantiDB.CONNETTORE_HTTPS_KEY_STORE_TYPE);
  470.         if(keyStoreType!=null) {
  471.             if(HSMUtils.isKeystoreHSM(keyStoreType)) {
  472.                 httpsClient.setKeystoreTipo(KeystoreEnum.PKCS11);
  473.                 httpsClient.setPcks11Tipo(keyStoreType);
  474.             }
  475.             else {
  476.                 httpsClient.setKeystoreTipo(Enums.fromValue(KeystoreEnum.class,keyStoreType));
  477.             }
  478.         }
  479.        
  480.         httpsClient.setKeyPassword(
  481.                 evalnull( () -> props.get(CostantiDB.CONNETTORE_HTTPS_KEY_PASSWORD))
  482.             );
  483.         httpsClient.setKeyAlias(
  484.                 evalnull( () -> props.get(CostantiDB.CONNETTORE_HTTPS_KEY_ALIAS))
  485.             );
  486.        
  487.         if(httpsClient.getAlgoritmo()!=null ||
  488.                 httpsClient.getKeystorePassword()!=null || httpsClient.getKeystorePath()!=null || httpsClient.getKeystoreTipo()!=null ||
  489.                 httpsClient.getKeyPassword()!=null ||  httpsClient.getKeyAlias()!=null) {
  490.             https.setClient(httpsClient);
  491.         }
  492.        
  493.         if ( https.getTipologia() != null ) {
  494.             c.setAutenticazioneHttps(https);
  495.         }
  496.        
  497.         String proxyType = evalnull( () -> props.get(CostantiDB.CONNETTORE_PROXY_TYPE).trim() );
  498.         if ( !StringUtils.isEmpty(proxyType)) {
  499.             ConnettoreConfigurazioneProxy proxy = new ConnettoreConfigurazioneProxy();
  500.             c.setProxy(proxy);
  501.            
  502.             proxy.setHostname(
  503.                     evalnull( () -> props.get(CostantiDB.CONNETTORE_PROXY_HOSTNAME).trim())
  504.                 );
  505.             proxy.setPassword(
  506.                     evalnull( () -> props.get(CostantiDB.CONNETTORE_PROXY_PASSWORD).trim())
  507.                 );
  508.             proxy.setPorta(
  509.                     evalnull( () -> Integer.valueOf(props.get(CostantiDB.CONNETTORE_PROXY_PORT)))
  510.                 );
  511.             proxy.setUsername(
  512.                     evalnull( () -> props.get(CostantiDB.CONNETTORE_PROXY_USERNAME).trim())
  513.                 );
  514.         }
  515.        
  516.         ConnettoreConfigurazioneTimeout tempiRisposta = new ConnettoreConfigurazioneTimeout();      
  517.         tempiRisposta.setConnectionReadTimeout(
  518.                 evalnull( () -> Integer.valueOf(props.get(CostantiDB.CONNETTORE_READ_CONNECTION_TIMEOUT)))
  519.             );
  520.         tempiRisposta.setConnectionTimeout(
  521.                 evalnull( () -> Integer.valueOf(props.get(CostantiDB.CONNETTORE_CONNECTION_TIMEOUT)))
  522.             );
  523.         tempiRisposta.setTempoMedioRisposta(
  524.                 evalnull( () -> Integer.valueOf(props.get(CostantiDB.CONNETTORE_TEMPO_MEDIO_RISPOSTA)))
  525.             );
  526.        
  527.         if ( tempiRisposta.getConnectionReadTimeout() != null || tempiRisposta.getConnectionTimeout() != null || tempiRisposta.getTempoMedioRisposta() != null) {
  528.             c.setTempiRisposta(tempiRisposta);
  529.         }
  530.        
  531.         c.setTokenPolicy(
  532.                 evalnull( () -> props.get(CostantiDB.CONNETTORE_TOKEN_POLICY).trim())
  533.             );
  534.        
  535.         return c;
  536.     }

  537.     @Override
  538.     public String getUrlConnettore(Map<String, String> properties, String tipoConnettore) throws Exception {
  539.         return properties.get(CostantiDB.CONNETTORE_HTTP_LOCATION);
  540.     }

  541.     @Override
  542.     protected ConnettoreHttp getConnettore(OneOfConnettoreErogazioneConnettore conn) throws Exception {
  543.         return (ConnettoreHttp) conn;
  544.     }

  545.     @Override
  546.     protected ConnettoreHttp getConnettore(OneOfConnettoreFruizioneConnettore conn) throws Exception {
  547.         return (ConnettoreHttp) conn;
  548.     }

  549.     @Override
  550.     protected ConnettoreHttp getConnettore(OneOfApplicativoServerConnettore conn) throws Exception {
  551.         return (ConnettoreHttp) conn;
  552.     }

  553.     public static String getKeystoreType(ConnettoreConfigurazioneHttpsClient httpsClient) {
  554.         if(httpsClient.getKeystoreTipo()!=null) {
  555.             if(KeystoreEnum.PKCS11.equals( httpsClient.getKeystoreTipo())) {
  556.                 if(httpsClient.getPcks11Tipo()==null) {
  557.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("Tipo keystore pks11 non indicato");
  558.                 }
  559.                 return httpsClient.getPcks11Tipo();
  560.             }
  561.             else {
  562.                 return httpsClient.getKeystoreTipo().toString();
  563.             }
  564.         }
  565.         return null;
  566.     }
  567.    
  568.     public static String getTruststoreType(ConnettoreConfigurazioneHttpsServer httpsServer) {
  569.         if(httpsServer.getTruststoreTipo()!=null) {
  570.             if(KeystoreEnum.PKCS11.equals( httpsServer.getTruststoreTipo())) {
  571.                 if(httpsServer.getPcks11Tipo()==null) {
  572.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("Tipo keystore pks11 non indicato");
  573.                 }
  574.                 return httpsServer.getPcks11Tipo();
  575.             }
  576.             else {
  577.                 return httpsServer.getTruststoreTipo().toString();
  578.             }
  579.         }
  580.         return null;
  581.     }
  582. }