ConnettorePluginApiHelper.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 java.util.ArrayList;
  22. import java.util.Arrays;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.Map.Entry;

  26. import org.openspcoop2.core.commons.Filtri;
  27. import org.openspcoop2.core.commons.Liste;
  28. import org.openspcoop2.core.config.rs.server.model.ConnettoreEnum;
  29. import org.openspcoop2.core.config.rs.server.model.ConnettorePlugin;
  30. import org.openspcoop2.core.config.rs.server.model.OneOfApplicativoServerConnettore;
  31. import org.openspcoop2.core.config.rs.server.model.OneOfConnettoreErogazioneConnettore;
  32. import org.openspcoop2.core.config.rs.server.model.OneOfConnettoreFruizioneConnettore;
  33. import org.openspcoop2.core.constants.CostantiDB;
  34. import org.openspcoop2.core.constants.TipiConnettore;
  35. import org.openspcoop2.core.plugins.Plugin;
  36. import org.openspcoop2.core.plugins.constants.TipoPlugin;
  37. import org.openspcoop2.core.registry.Connettore;
  38. import org.openspcoop2.utils.service.fault.jaxrs.FaultCode;
  39. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  40. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCore;
  41. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriCostanti;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;

  43. /**
  44.  * ConnettorePluginApiHelper
  45.  *
  46.  * @author $Author$
  47.  * @version $Rev$, $Date$
  48.  *
  49.  */
  50. public class ConnettorePluginApiHelper extends AbstractConnettoreApiHelper<ConnettorePlugin> {

  51.     @Override
  52.     protected ConnettorePlugin getConnettore(OneOfConnettoreErogazioneConnettore conn) throws Exception {
  53.         return (ConnettorePlugin) conn;
  54.     }

  55.     @Override
  56.     protected ConnettorePlugin getConnettore(OneOfConnettoreFruizioneConnettore conn) throws Exception {
  57.         return (ConnettorePlugin) conn;
  58.     }

  59.     @Override
  60.     protected ConnettorePlugin getConnettore(OneOfApplicativoServerConnettore conn) throws Exception {
  61.         return (ConnettorePlugin) conn;
  62.     }

  63.     @Override
  64.     public boolean connettoreCheckData(ConnettorePlugin conn, ErogazioniEnv env, boolean erogazione) throws Exception {
  65.         ConsoleSearch ricerca = new ConsoleSearch(true);
  66.         ricerca.addFilter(Liste.CONFIGURAZIONE_PLUGINS_CLASSI,  Filtri.FILTRO_TIPO_PLUGIN_CLASSI, TipoPlugin.CONNETTORE.toString());

  67.         ConfigurazioneCore confCore = new ConfigurazioneCore(env.stationCore);

  68.         List<Plugin> listaTmp = confCore.pluginsClassiList(ricerca);

  69.         if(!listaTmp.stream().anyMatch(p -> p.getTipo().equals(conn.getPlugin()))) {
  70.             throw FaultCode.RICHIESTA_NON_VALIDA.toException("Tipo plugin ["+conn.getPlugin()+"] non trovato");
  71.         }
  72.        
  73.        
  74.         return env.saHelper.endPointCheckData(
  75.                 null,
  76.                 env.tipo_protocollo,
  77.                 erogazione,
  78.                 TipiConnettore.CUSTOM.getNome(),
  79.                 null,
  80.                 null,   // nome
  81.                 null,   // tipo
  82.                 null,   // httpConf.getUsername()
  83.                 null,   // httpConf.getPassword()
  84.                 null,   // this.initcont,
  85.                 null,   // this.urlpgk,
  86.                 null,   // provurl jms,
  87.                 null,   // connfact,
  88.                 null,   // sendas,
  89.                 null,                                                   // this.httpsurl,
  90.                 null,   // httpsConf.getTipologia().toString(),
  91.                 false,      // this.httpshostverify,
  92.                 ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS, // httpsTrustVerifyCert
  93.                 null,   // this.httpspath
  94.                 null,   // this.httpstipo,
  95.                 null,   // this.httpspwd,
  96.                 null,   // this.httpsalgoritmo
  97.                 false,
  98.                 null,
  99.                 "",                                                                     // httpspwdprivatekeytrust,
  100.                 null,   // pathkey
  101.                 null,   // this.httpstipokey
  102.                 null,   // this.httpspwdkey
  103.                 null,   // this.httpspwdprivatekey,  
  104.                 null,   // this.httpsalgoritmokey,
  105.                 null,   // httpsKeyAlias
  106.                 null,   // httpsTrustStoreCRLs
  107.                 null,   // httpsTrustStoreOCSPPolicy
  108.                 null,   // httpsKeyStoreBYOKPolicy
  109.                 conn.getPlugin(),                                                               //  tipoconn (personalizzato)
  110.                 ServletUtils.boolToCheckBoxStatus(false),                                           //autenticazioneHttp,
  111.                 ServletUtils.boolToCheckBoxStatus(false),  
  112.                 null,   // evalnull( () -> proxy.getHostname() ),
  113.                 null,   // evalnull( () -> proxy.getPorta().toString() ),
  114.                 null,   // evalnull( () -> proxy.getUsername() ),
  115.                 null,   // evalnull( () -> proxy.getPassword() ),
  116.                 ServletUtils.boolToCheckBoxStatus(false), //ServletUtils.boolToCheckBoxStatus( tempiRisposta_enabled ),
  117.                 null,   // evalnull( () -> timeoutConf.getConnectionTimeout().toString()),  // this.tempiRisposta_connectionTimeout,
  118.                 null,   // evalnull( () -> timeoutConf.getConnectionReadTimeout().toString()), //null,  // this.tempiRisposta_readTimeout,
  119.                 null,   // evalnull( () -> timeoutConf.getTempoMedioRisposta().toString()), // this.tempiRisposta_tempoMedioRisposta,
  120.                 "no",   // this.opzioniAvanzate,
  121.                 "",     // this.transfer_mode,
  122.                 "",     // this.transfer_mode_chunk_size,
  123.                 "",     // this.redirect_mode,
  124.                 "",     // this.redirect_max_hop,
  125.                 null,   // this.requestOutputFileName,
  126.                 null,   // this.requestOutputFileName_permissions
  127.                 null,   // this.requestOutputFileNameHeaders,
  128.                 null,   // this.requestOutputFileNameHeaders_permissions
  129.                 null,   // this.requestOutputParentDirCreateIfNotExists,
  130.                 null,   // this.requestOutputOverwriteIfExists,
  131.                 null,   // this.responseInputMode,
  132.                 null,   // this.responseInputFileName,
  133.                 null,   // this.responseInputFileNameHeaders,
  134.                 null,   // this.responseInputDeleteAfterRead,
  135.                 null,   // this.responseInputWaitTime,
  136.                 false, // autenticazioneToken
  137.                 null, // tokenPolicy
  138.                 null, // autenticazioneApiKey
  139.                 false, // useOAS3Names
  140.                 false, // useAppId
  141.                 null, // apiKeyHeader
  142.                 null, // apiKey,
  143.                 null, // appIdHeader,
  144.                 null, // appId,
  145.                 null, // listExtendedConnettore
  146.                 false, // erogazioneServizioApplicativoServerEnabled,
  147.                 null // erogazioneServizioApplicativoServer
  148.             );
  149.        
  150.     }

  151.     @Override
  152.     public Connettore fillConnettoreRegistro(org.openspcoop2.core.registry.Connettore regConnettore,
  153.             ErogazioniEnv env,
  154.             ConnettorePlugin conn,
  155.             String oldConnT) throws Exception {
  156.         env.apsHelper.fillConnettore(
  157.                 regConnettore,
  158.                 conn.isDebug() != null && conn.isDebug() ? "true" : "false",                // this.connettoreDebug,
  159.                 TipiConnettore.CUSTOM.getNome(),            // endpointtype
  160.                 oldConnT,                       // oldConnT
  161.                 conn.getPlugin(),                       // tipoConn Personalizzato
  162.                 null, // this.url,
  163.                 null,   // this.nome,
  164.                 null,   // this.tipo,
  165.                 null,
  166.                 null,
  167.                 null,   // this.initcont,
  168.                 null,   // this.urlpgk,
  169.                 null, // this.url,
  170.                 null,   // this.connfact,
  171.                 null,   // this.sendas,
  172.                 null, // this.httpsurl,
  173.                 null,               // this.httpstipologia
  174.                 false,  // this.httpshostverify,
  175.                 ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS, // httpsTrustVerifyCert
  176.                 null,               // this.httpspath
  177.                 null,   // this.httpstipo,
  178.                 null,           // this.httpspwd,
  179.                 null,                   // this.httpsalgoritmo
  180.                 false,
  181.                 null,           // this.httpskeystore,
  182.                 "",                                                                 //  this.httpspwdprivatekeytrust
  183.                 null,               // pathkey
  184.                 null,       // this.httpstipokey
  185.                 null,           // this.httpspwdkey
  186.                 null,               // this.httpspwdprivatekey,  
  187.                 null,               // this.httpsalgoritmokey,
  188.                 null,                   // httpsKeyAlias
  189.                 null,                   // httpsTrustStoreCRLs
  190.                 null,                   // httpsTrustStoreOCSPPolicy
  191.                 null,                   // httpsKeyStoreBYOKPolicy
  192.            
  193.                 ServletUtils.boolToCheckBoxStatus( false ),
  194.                 null,
  195.                 null,
  196.                 null,
  197.                 null,
  198.                
  199.                 ServletUtils.boolToCheckBoxStatus( false ),
  200.                 null,   // this.tempiRisposta_connectionTimeout,
  201.                 null, //null,   // this.tempiRisposta_readTimeout,
  202.                 null,   // this.tempiRisposta_tempoMedioRisposta,
  203.                 "no",   // this.opzioniAvanzate,
  204.                 "",     // this.transfer_mode,
  205.                 "",     // this.transfer_mode_chunk_size,
  206.                 "",     // this.redirect_mode,
  207.                 "",     // this.redirect_max_hop,
  208.                 null,   // this.requestOutputFileName,
  209.                 null,   // this.requestOutputFileName_permissions
  210.                 null,   // this.requestOutputFileNameHeaders,
  211.                 null,   // this.requestOutputFileNameHeaders_permissions
  212.                 null,   // this.requestOutputParentDirCreateIfNotExists,
  213.                 null,   // this.requestOutputOverwriteIfExists,
  214.                 null,   // this.responseInputMode,
  215.                 null,   // this.responseInputFileName,
  216.                 null,   // this.responseInputFileNameHeaders,
  217.                 null,   // this.responseInputDeleteAfterRead,
  218.                 null,   // this.responseInputWaitTime,
  219.                 null,   // tokenPolicy
  220.                 null, null, // apiKeyHeader,  apiKeyValue
  221.                 null, null, // appIdHeader, appIdValue
  222.                 null, // connettoreStatusParams
  223.                 null // listExtendedConnettore
  224.                 );
  225.        
  226.         if(conn.getProprieta() != null) {
  227.             for(org.openspcoop2.core.config.rs.server.model.Proprieta prop: conn.getProprieta()) {
  228.                 org.openspcoop2.core.registry.Property property = new org.openspcoop2.core.registry.Property();
  229.                 property.setNome(prop.getNome());
  230.                 property.setValore(prop.getValore());
  231.                 regConnettore.addProperty(property);
  232.             }
  233.         }      

  234.         return regConnettore;
  235.     }

  236.     @Override
  237.     public org.openspcoop2.core.config.Connettore buildConnettoreConfigurazione(
  238.             org.openspcoop2.core.config.Connettore regConnettore, ErogazioniEnv env, ConnettorePlugin conn,
  239.             String oldConnT) throws Exception {

  240.         env.apsHelper.fillConnettore(
  241.                 regConnettore,
  242.                 conn.isDebug() != null && conn.isDebug() ? "true" : "false",                // this.connettoreDebug,
  243.                         TipiConnettore.CUSTOM.getNome(),            // endpointtype
  244.                         oldConnT,                       // oldConnT
  245.                         conn.getPlugin(),                       // tipoConn Personalizzato
  246.                         null, // this.url,
  247.                         null,   // this.nome,
  248.                         null,   // this.tipo,
  249.                         null,
  250.                         null,
  251.                         null,   // this.initcont,
  252.                         null,   // this.urlpgk,
  253.                         null, // this.url,
  254.                         null,   // this.connfact,
  255.                         null,   // this.sendas,
  256.                         null, // this.httpsurl,
  257.                         null,               // this.httpstipologia
  258.                         false,  // this.httpshostverify,
  259.                         ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS, // httpsTrustVerifyCert
  260.                         null,               // this.httpspath
  261.                         null,   // this.httpstipo,
  262.                         null,           // this.httpspwd,
  263.                         null,                   // this.httpsalgoritmo
  264.                         false,
  265.                         null,           // this.httpskeystore,
  266.                         "",                                                                 //  this.httpspwdprivatekeytrust
  267.                         null,               // pathkey
  268.                         null,       // this.httpstipokey
  269.                         null,           // this.httpspwdkey
  270.                         null,               // this.httpspwdprivatekey,  
  271.                         null,               // this.httpsalgoritmokey,
  272.                         null,                   // httpsKeyAlias
  273.                         null,                   // httpsTrustStoreCRLs
  274.                         null,                   // httpsTrustStoreOCSPPolicy
  275.                         null,                   // httpsKeyStoreBYOKPolicy

  276.                         ServletUtils.boolToCheckBoxStatus( false ),
  277.                         null,
  278.                         null,
  279.                         null,
  280.                         null,

  281.                         ServletUtils.boolToCheckBoxStatus( false ),
  282.                         null,   // this.tempiRisposta_connectionTimeout,
  283.                         null, //null,   // this.tempiRisposta_readTimeout,
  284.                         null,   // this.tempiRisposta_tempoMedioRisposta,
  285.                         "no",   // this.opzioniAvanzate,
  286.                         "",     // this.transfer_mode,
  287.                         "",     // this.transfer_mode_chunk_size,
  288.                         "",     // this.redirect_mode,
  289.                         "",     // this.redirect_max_hop,
  290.                         null,   // this.requestOutputFileName,
  291.                         null,   // this.requestOutputFileName_permissions
  292.                         null,   // this.requestOutputFileNameHeaders,
  293.                         null,   // this.requestOutputFileNameHeaders_permissions
  294.                         null,   // this.requestOutputParentDirCreateIfNotExists,
  295.                         null,   // this.requestOutputOverwriteIfExists,
  296.                         null,   // this.responseInputMode,
  297.                         null,   // this.responseInputFileName,
  298.                         null,   // this.responseInputFileNameHeaders,
  299.                         null,   // this.responseInputDeleteAfterRead,
  300.                         null,   // this.responseInputWaitTime,
  301.                         null,   // tokenPolicy
  302.                         null, null, // apiKeyHeader,  apiKeyValue
  303.                         null, null, // appIdHeader, appIdValue
  304.                         null, // connettoreStatusParams
  305.                         null // listExtendedConnettore
  306.                         );  

  307.        
  308.         if(conn.getProprieta() != null) {
  309.             for(org.openspcoop2.core.config.rs.server.model.Proprieta prop: conn.getProprieta()) {
  310.                 org.openspcoop2.core.config.Property property = new org.openspcoop2.core.config.Property();
  311.                 property.setNome(prop.getNome());
  312.                 property.setValore(prop.getValore());
  313.                 regConnettore.addProperty(property);
  314.             }
  315.         }      

  316.         return regConnettore;
  317.     }

  318.     @Override
  319.     public ConnettorePlugin buildConnettore(Map<String, String> props, String tipo) {
  320.         ConnettorePlugin c = new ConnettorePlugin();
  321.        
  322.         c.setTipo(ConnettoreEnum.PLUGIN);
  323.         c.setDebug(Boolean.parseBoolean(props.get(CostantiDB.CONNETTORE_DEBUG)));
  324.        
  325.         c.setPlugin(tipo);
  326.        
  327.         List<String> propsExclude = Arrays.asList(CostantiDB.CONNETTORE_DEBUG);
  328.        
  329.         List<org.openspcoop2.core.config.rs.server.model.Proprieta> propLst = new ArrayList<>();

  330.         for(Entry<String, String> prop: props.entrySet()) {
  331.             if(!propsExclude.contains(prop.getKey())) {
  332.                 org.openspcoop2.core.config.rs.server.model.Proprieta p = new org.openspcoop2.core.config.rs.server.model.Proprieta();
  333.                 p.setNome(prop.getKey());
  334.                 p.setValore(prop.getValue());
  335.                 propLst.add(p);
  336.             }
  337.         }
  338.        
  339.         c.setProprieta(propLst);
  340.         return c;
  341.     }

  342.     @Override
  343.     public String getUrlConnettore(Map<String, String> props, String tipoConnettore) throws Exception {
  344.         return "[plugin] " + tipoConnettore;
  345.     }

  346. }