ConnettoreMessageBoxApiHelper.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.Map;

  22. import org.openspcoop2.core.config.Credenziali;
  23. import org.openspcoop2.core.config.InvocazionePorta;
  24. import org.openspcoop2.core.config.ServizioApplicativo;
  25. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  26. import org.openspcoop2.core.config.constants.CredenzialeTipo;
  27. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  28. import org.openspcoop2.core.config.rs.server.model.ConnettoreConfigurazioneHttpBasic;
  29. import org.openspcoop2.core.config.rs.server.model.ConnettoreEnum;
  30. import org.openspcoop2.core.config.rs.server.model.ConnettoreMessageBox;
  31. import org.openspcoop2.core.config.rs.server.model.OneOfApplicativoServerConnettore;
  32. import org.openspcoop2.core.config.rs.server.model.OneOfConnettoreErogazioneConnettore;
  33. import org.openspcoop2.core.config.rs.server.model.OneOfConnettoreFruizioneConnettore;
  34. import org.openspcoop2.core.constants.TipiConnettore;
  35. import org.openspcoop2.core.registry.Connettore;
  36. import org.openspcoop2.utils.service.fault.jaxrs.FaultCode;
  37. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriCostanti;
  38. import org.openspcoop2.web.ctrlstat.servlet.sa.ServiziApplicativiCostanti;
  39. import org.openspcoop2.web.lib.mvc.ServletUtils;

  40. /**
  41.  * ConnettoreMessageBoxApiHelper
  42.  *
  43.  * @author $Author$
  44.  * @version $Rev$, $Date$
  45.  *
  46.  */
  47. public class ConnettoreMessageBoxApiHelper extends AbstractConnettoreApiHelper<ConnettoreMessageBox> {

  48.     @Override
  49.     public boolean connettoreCheckData(ConnettoreMessageBox conn, ErogazioniEnv env, boolean erogazione) throws Exception {
  50.         return true;
  51.     }

  52.     @Override
  53.     protected org.openspcoop2.core.config.Connettore buildConnettoreConfigurazione(ServizioApplicativo sa, ErogazioniEnv env, ConnettoreMessageBox connettore, String oldConnT) throws Exception {
  54.        
  55.         Credenziali credenziali = new Credenziali();
  56.         credenziali.setTipo(CredenzialeTipo.BASIC);
  57.         credenziali.setUser(connettore.getAutenticazioneHttp().getUsername());
  58.         credenziali.setPassword(connettore.getAutenticazioneHttp().getPassword());
  59.         if(sa.getInvocazionePorta() == null) {
  60.             sa.setInvocazionePorta(new InvocazionePorta());
  61.         }
  62.         sa.getInvocazionePorta().addCredenziali(credenziali);
  63.         sa.getInvocazioneServizio().setGetMessage(StatoFunzionalita.ABILITATO);
  64.        
  65.         String protocollo = env.soggettiCore.getProtocolloAssociatoTipoSoggetto(sa.getTipoSoggettoProprietario());

  66.         env.requestWrapper.overrideParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_MESSAGE_BOX, CostantiConfigurazione.ABILITATO.toString());
  67.         env.requestWrapper.overrideParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_USERNAME, connettore.getAutenticazioneHttp().getUsername());
  68.         env.requestWrapper.overrideParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_PASSWORD, connettore.getAutenticazioneHttp().getPassword());
  69.         env.requestWrapper.overrideParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_SBUSTAMENTO_SOAP, CostantiConfigurazione.DISABILITATO.toString());
  70.         env.requestWrapper.overrideParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_SBUSTAMENTO_INFO_PROTOCOLLO_RICHIESTA, CostantiConfigurazione.DISABILITATO.toString());
  71.         env.requestWrapper.overrideParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_ENDPOINT_TYPE, TipiConnettore.DISABILITATO.getNome());

  72.         boolean ok = env.saHelper.servizioApplicativoEndPointCheckData(protocollo, null, sa);
  73.        
  74.         if(!ok) {
  75.             throw FaultCode.RICHIESTA_NON_VALIDA.toException(env.saHelper.getPd().getMessage());
  76.         }
  77.         return super.buildConnettoreConfigurazione(sa, env, connettore, oldConnT);
  78.     }
  79.    
  80.     @Override
  81.     public Connettore fillConnettoreRegistro(org.openspcoop2.core.registry.Connettore regConnettore,
  82.             ErogazioniEnv env,
  83.             ConnettoreMessageBox conn,
  84.             String oldConnT) throws Exception {
  85.         env.apsHelper.fillConnettore(
  86.                 regConnettore,
  87.                 "false",                // this.connettoreDebug,
  88.                 TipiConnettore.DISABILITATO.getNome(),          // endpointtype
  89.                 oldConnT,                       // oldConnT
  90.                 "",                     // tipoConn Personalizzato
  91.                 null, // this.url,
  92.                 null,   // this.nome,
  93.                 null,   // this.tipo,
  94.                 null,
  95.                 null,
  96.                 null,   // this.initcont,
  97.                 null,   // this.urlpgk,
  98.                 null, // this.url,
  99.                 null,   // this.connfact,
  100.                 null,   // this.sendas,
  101.                 null, // this.httpsurl,
  102.                 null,               // this.httpstipologia
  103.                 false,  // this.httpshostverify,
  104.                 ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS, // httpsTrustVerifyCert
  105.                 null,               // this.httpspath
  106.                 null,   // this.httpstipo,
  107.                 null,           // this.httpspwd,
  108.                 null,                   // this.httpsalgoritmo
  109.                 false,
  110.                 null,           // this.httpskeystore,
  111.                 "",                                                                 //  this.httpspwdprivatekeytrust
  112.                 null,               // pathkey
  113.                 null,       // this.httpstipokey
  114.                 null,           // this.httpspwdkey
  115.                 null,               // this.httpspwdprivatekey,  
  116.                 null,               // this.httpsalgoritmokey,
  117.                 null,                   // httpsKeyAlias
  118.                 null,                   // httpsTrustStoreCRLs
  119.                 null,                   // httpsTrustStoreOCSPPolicy
  120.                 null,                   // httpsKeyStoreBYOKPolicy
  121.            
  122.                 ServletUtils.boolToCheckBoxStatus( false ),
  123.                 null,
  124.                 null,
  125.                 null,
  126.                 null,
  127.                
  128.                 ServletUtils.boolToCheckBoxStatus( false ),
  129.                 null,   // this.tempiRisposta_connectionTimeout,
  130.                 null, //null,   // this.tempiRisposta_readTimeout,
  131.                 null,   // this.tempiRisposta_tempoMedioRisposta,
  132.                 "no",   // this.opzioniAvanzate,
  133.                 "",     // this.transfer_mode,
  134.                 "",     // this.transfer_mode_chunk_size,
  135.                 "",     // this.redirect_mode,
  136.                 "",     // this.redirect_max_hop,
  137.                 null,   // this.requestOutputFileName,
  138.                 null,   // this.requestOutputFileName_permissions
  139.                 null,   // this.requestOutputFileNameHeaders,
  140.                 null,   // this.requestOutputFileNameHeaders_permissions
  141.                 null,   // this.requestOutputParentDirCreateIfNotExists,
  142.                 null,   // this.requestOutputOverwriteIfExists,
  143.                 null,   // this.responseInputMode,
  144.                 null,   // this.responseInputFileName,
  145.                 null,   // this.responseInputFileNameHeaders,
  146.                 null,   // this.responseInputDeleteAfterRead,
  147.                 null,   // this.responseInputWaitTime,
  148.                 null,   // tokenPolicy
  149.                 null, null, // apiKeyHeader,  apiKeyValue
  150.                 null, null, // appIdHeader, appIdValue
  151.                
  152.                 null, // connettoreStatusParams
  153.                 null // listExtendedConnettore
  154.                 );      
  155.         return regConnettore;
  156.     }

  157.     @Override
  158.     public org.openspcoop2.core.config.Connettore buildConnettoreConfigurazione(
  159.             org.openspcoop2.core.config.Connettore regConnettore, ErogazioniEnv env, ConnettoreMessageBox conn,
  160.             String oldConnType) throws Exception {

  161.         env.apsHelper.fillConnettore(
  162.                 regConnettore,
  163.                 "false",                // this.connettoreDebug,
  164.                 TipiConnettore.DISABILITATO.getNome(),          // endpointtype
  165.                 oldConnType,                        // oldConnT
  166.                 "",                     // tipoConn Personalizzato
  167.                 null, // this.url,
  168.                 null,   // this.nome,
  169.                 null,   // this.tipo,
  170.                 null,
  171.                 null,
  172.                 null,   // this.initcont,
  173.                 null,   // this.urlpgk,
  174.                 null, // this.url,
  175.                 null,   // this.connfact,
  176.                 null,   // this.sendas,
  177.                 null, // this.httpsurl,
  178.                 null,               // this.httpstipologia
  179.                 false,  // this.httpshostverify,
  180.                 ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS, // httpsTrustVerifyCert
  181.                 null,               // this.httpspath
  182.                 null,   // this.httpstipo,
  183.                 null,           // this.httpspwd,
  184.                 null,                   // this.httpsalgoritmo
  185.                 false,
  186.                 null,           // this.httpskeystore,
  187.                 "",                                                                 //  this.httpspwdprivatekeytrust
  188.                 null,               // pathkey
  189.                 null,       // this.httpstipokey
  190.                 null,           // this.httpspwdkey
  191.                 null,               // this.httpspwdprivatekey,  
  192.                 null,               // this.httpsalgoritmokey,
  193.                 null,                   // httpsKeyAlias
  194.                 null,                   // httpsTrustStoreCRLs
  195.                 null,                   // httpsTrustStoreOCSPPolicy
  196.                 null,                   // httpsKeyStoreBYOKPolicy
  197.            
  198.                 ServletUtils.boolToCheckBoxStatus( false ),
  199.                 null,
  200.                 null,
  201.                 null,
  202.                 null,
  203.                
  204.                 ServletUtils.boolToCheckBoxStatus( false ),
  205.                 null,   // this.tempiRisposta_connectionTimeout,
  206.                 null, //null,   // this.tempiRisposta_readTimeout,
  207.                 null,   // this.tempiRisposta_tempoMedioRisposta,
  208.                 "no",   // this.opzioniAvanzate,
  209.                 "",     // this.transfer_mode,
  210.                 "",     // this.transfer_mode_chunk_size,
  211.                 "",     // this.redirect_mode,
  212.                 "",     // this.redirect_max_hop,
  213.                 null,   // this.requestOutputFileName,
  214.                 null,   // this.requestOutputFileName_permissions
  215.                 null,   // this.requestOutputFileNameHeaders,
  216.                 null,   // this.requestOutputFileNameHeaders_permissions
  217.                 null,   // this.requestOutputParentDirCreateIfNotExists,
  218.                 null,   // this.requestOutputOverwriteIfExists,
  219.                 null,   // this.responseInputMode,
  220.                 null,   // this.responseInputFileName,
  221.                 null,   // this.responseInputFileNameHeaders,
  222.                 null,   // this.responseInputDeleteAfterRead,
  223.                 null,   // this.responseInputWaitTime,
  224.                 null,   // tokenPolicy
  225.                 null, null, // apiKeyHeader,  apiKeyValue
  226.                 null, null, // appIdHeader, appIdValue
  227.                
  228.                 null, // connettoreStatusParams
  229.                 null // listExtendedConnettore
  230.                 );      
  231.         return regConnettore;
  232.     }

  233.     @Override
  234.     protected ConnettoreMessageBox buildConnettore(ServizioApplicativo sa) {
  235.         ConnettoreMessageBox c = new ConnettoreMessageBox();
  236.        
  237.         c.setTipo(ConnettoreEnum.MESSAGE_BOX);
  238.        
  239.         ConnettoreConfigurazioneHttpBasic autenticazioneHttp = new ConnettoreConfigurazioneHttpBasic();
  240.        
  241.         if(sa.getInvocazionePorta().getCredenzialiList().size() > 0) {
  242.             autenticazioneHttp.setUsername(sa.getInvocazionePorta().getCredenziali(0).getUser());
  243.             autenticazioneHttp.setPassword(sa.getInvocazionePorta().getCredenziali(0).getPassword());
  244.         }
  245.        
  246.         c.setAutenticazioneHttp(autenticazioneHttp);
  247.         return c;
  248.     }

  249.     @Override
  250.     public ConnettoreMessageBox buildConnettore(Map<String, String> props, String tipo) {
  251.         //non utilizzabile
  252.         return null; //TODO eccezione
  253.     }

  254.     @Override
  255.     public String getUrlConnettore(Map<String, String> props, String tipoConnettore) throws Exception {
  256.         return "disabilitato [MessageBox]";
  257.     }

  258.     @Override
  259.     protected ConnettoreMessageBox getConnettore(OneOfConnettoreErogazioneConnettore conn) throws Exception {
  260.         return (ConnettoreMessageBox) conn;
  261.     }

  262.     @Override
  263.     protected ConnettoreMessageBox getConnettore(OneOfConnettoreFruizioneConnettore conn) throws Exception {
  264.         return (ConnettoreMessageBox) conn;
  265.     }

  266.     @Override
  267.     protected ConnettoreMessageBox getConnettore(OneOfApplicativoServerConnettore conn) throws Exception {
  268.         return (ConnettoreMessageBox) conn;
  269.     }

  270. }