VaultUpdateConfigUtilities.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.pdd.config.vault.cli;

  21. import java.lang.reflect.InvocationTargetException;
  22. import java.sql.Connection;
  23. import java.sql.DriverManager;
  24. import java.sql.PreparedStatement;
  25. import java.sql.ResultSet;
  26. import java.sql.SQLException;
  27. import java.util.ArrayList;
  28. import java.util.List;

  29. import org.apache.commons.lang.StringUtils;
  30. import org.openspcoop2.core.byok.BYOKUtilities;
  31. import org.openspcoop2.core.byok.BYOKWrappedValue;
  32. import org.openspcoop2.core.commons.CoreException;
  33. import org.openspcoop2.core.commons.DBUtils;
  34. import org.openspcoop2.core.constants.CostantiConnettori;
  35. import org.openspcoop2.core.constants.CostantiDB;
  36. import org.openspcoop2.core.constants.CostantiProprieta;
  37. import org.openspcoop2.core.constants.ProprietariProtocolProperty;
  38. import org.openspcoop2.core.id.IDSoggetto;
  39. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  40. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  41. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  42. import org.openspcoop2.pdd.core.byok.DriverBYOK;
  43. import org.openspcoop2.utils.TipiDatabase;
  44. import org.openspcoop2.utils.UtilsException;
  45. import org.openspcoop2.utils.io.Base64Utilities;
  46. import org.openspcoop2.utils.jdbc.IJDBCAdapter;
  47. import org.openspcoop2.utils.jdbc.JDBCAdapterFactory;
  48. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  49. import org.openspcoop2.utils.resources.FileSystemUtilities;
  50. import org.openspcoop2.utils.sql.ISQLQueryObject;
  51. import org.openspcoop2.utils.sql.LikeConfig;
  52. import org.openspcoop2.utils.sql.SQLObjectFactory;
  53. import org.openspcoop2.utils.sql.SQLQueryObjectException;

  54. /**
  55. * VaultUpdateConfigUtilities
  56. *
  57. * @author Poli Andrea (apoli@link.it)
  58. * @author $Author$
  59. * @version $Rev$, $Date$
  60. */
  61. public class VaultUpdateConfigUtilities {
  62.    
  63.     private VaultUpdateConfig config;
  64.    
  65.     private DriverBYOK inDriverBYOK = null;
  66.     private DriverBYOK outDriverBYOK = null;
  67.    
  68.     private String tipoDatabase;
  69.     private String driver;
  70.     private String username;
  71.     private String password;
  72.     private String connectionURL;
  73.    
  74.     private static final String LOG_ORIG_SKIPPED = "\t!skyp! wrapped with other policy:";
  75.     private static final String LOG_ORIG_SKIPPED_NO_WRAPPED = "\t!skyp! no wrapped value:";
  76.     private static final String LOG_ORIG_SKIPPED_ALREADY_WRAPPED = "\t!skyp! already wrapped value:";
  77.     private static final String LOG_ORIG_SKIPPED_WITH_POLICY = "\t!skyp! wrapped with policy:";
  78.     private static final String LOG_ORIG = "\torig:";
  79.     private static final String LOG_NEW = "\tnew:";
  80.     private static final String LOG_ROW_UPDATE = "\trow-update:";
  81.    
  82.     private static final String CONDITION_WHERE_ID = "id = ?";
  83.     private static final String CONDITION_JOIN_ID = ".id = ";
  84.    
  85.     private static final String ALIAS_PLAIN_VALUE = "plainValue";
  86.     private static final String ALIAS_ENC_VALUE = "encValue";
  87.    
  88.     public VaultUpdateConfigUtilities(VaultUpdateConfig config) {
  89.         this.config = config;
  90.     }

  91.     public void process() throws CoreException {

  92.         try {
  93.        
  94.             VaultTools.logCoreDebug("Inizializzazione connessione database in corso...");
  95.            
  96.             VaultDatabaseProperties databaseProperties = VaultDatabaseProperties.getInstance();
  97.             this.tipoDatabase = databaseProperties.getTipoDatabase();
  98.             this.driver = databaseProperties.getDriver();
  99.             this.username = databaseProperties.getUsername();
  100.             this.password = databaseProperties.getPassword();
  101.             this.connectionURL = databaseProperties.getConnectionUrl();
  102.    
  103.             VaultTools.logCoreDebug("Inizializzazione connessione database terminata");
  104.            
  105.            
  106.            
  107.             VaultTools.logCoreDebug("Inizializzazione driver ...");
  108.            
  109.             if(this.config.isInSecurityMode()) {
  110.                 this.inDriverBYOK = new DriverBYOK(VaultTools.getLogCore(), this.config.getInId(), this.config.getInId());
  111.             }
  112.             if(this.config.isOutSecurityMode()) {
  113.                 this.outDriverBYOK = new DriverBYOK(VaultTools.getLogCore(), this.config.getOutId(), this.config.getOutId());
  114.             }

  115.             VaultTools.logCoreDebug("Inizializzazione driver terminata");
  116.            
  117.             StringBuilder output = null;
  118.             if(this.config.getReportPath()!=null) {
  119.                 output = new StringBuilder();
  120.             }
  121.            
  122.             processConnettori(output);
  123.            
  124.             processServiziApplicativi(output);
  125.            
  126.             processSecurity(output);
  127.            
  128.             processGenericProperties(output);
  129.            
  130.             processProtocolProperties(output);
  131.            
  132.             processProperties(output); // lasciare in fondo in modo da non gestire nuovamente le proprietà di sicurezza
  133.            
  134.             if(this.config.getReportPath()!=null && output!=null) {
  135.                 FileSystemUtilities.writeFile(this.config.getReportPath(), output.toString().getBytes());
  136.             }
  137.            
  138.         }
  139.         catch(Exception t) {
  140.             VaultTools.logCoreError(t.getMessage(),t);
  141.             throw new CoreException(t.getMessage(),t);
  142.         }

  143.     }
  144.     private void processConnettori(StringBuilder output) throws CoreException {
  145.         VaultTools.logCoreDebug("Conversione connettori ...");
  146.        
  147.         if(output!=null) {
  148.             if(output.length()>0) {
  149.                 output.append("\n\n");
  150.             }
  151.             output.append("=== Connettori ===\n\n");
  152.         }
  153.                
  154.         updateConnettori("password", "enc_password", output);
  155.         updateConnettori("proxy_password", "enc_proxy_password", output);
  156.         updateConnettori("api_key", null, output);
  157.        
  158.         if(output!=null) {
  159.             output.append("\n\n");
  160.             output.append("=== Connettori Custom ===\n\n");
  161.         }
  162.        
  163.         for (String nomeProprieta : CostantiConnettori.getConfidentials()) {
  164.             updateConnettoriCustom(nomeProprieta, output);
  165.         }
  166.        
  167.         VaultTools.logCoreDebug("Conversione connettori terminata");
  168.     }
  169.     private void processServiziApplicativi(StringBuilder output) throws CoreException {
  170.         VaultTools.logCoreDebug("Conversione applicativi ...");
  171.        
  172.         if(output!=null) {
  173.             if(output.length()>0) {
  174.                 output.append("\n\n");
  175.             }
  176.             output.append("=== Applicativi ===\n\n");
  177.         }
  178.                
  179.         updateServiziApplicativi("passwordrisp", "enc_passwordrisp", output);
  180.         updateServiziApplicativi("passwordinv", "enc_passwordinv", output);
  181.        
  182.         VaultTools.logCoreDebug("Conversione applicativi terminata");
  183.     }
  184.     private void processSecurity(StringBuilder output) throws CoreException {
  185.         VaultTools.logCoreDebug("Conversione message security ...");
  186.        
  187.         List<String> messageSecurityIds = CostantiProprieta.getMessageSecurityIds();
  188.        
  189.         processSecurityFruizioni(messageSecurityIds, output);
  190.         processSecurityErogazioni(messageSecurityIds, output);
  191.        
  192.         VaultTools.logCoreDebug("Conversione message security terminata");
  193.     }
  194.     private void processSecurityFruizioni(List<String> messageSecurityIds, StringBuilder output) throws CoreException {
  195.         if(output!=null) {
  196.             if(output.length()>0) {
  197.                 output.append("\n\n");
  198.             }
  199.             output.append("=== Message Security (Fruizioni request-flow) ===\n\n");
  200.         }
  201.        
  202.         processSecurity(
  203.                 messageSecurityIds, output,
  204.                 CostantiDB.PORTE_DELEGATE, CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST,
  205.                 CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_COLUMN_NOME, CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_COLUMN_VALORE, CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_COLUMN_ENC_VALUE);
  206.                
  207.         if(output!=null) {
  208.             output.append("\n\n");
  209.             output.append("=== Message Security (Fruizioni response-flow) ===\n\n");
  210.         }
  211.        
  212.         processSecurity(
  213.                 messageSecurityIds, output,
  214.                 CostantiDB.PORTE_DELEGATE, CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE,
  215.                 CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_COLUMN_NOME, CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_COLUMN_VALORE, CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_COLUMN_ENC_VALUE);

  216.     }
  217.     private void processSecurityErogazioni(List<String> messageSecurityIds, StringBuilder output) throws CoreException {
  218.         if(output!=null) {
  219.             output.append("\n\n");
  220.             output.append("=== Message Security (Erogazioni request-flow) ===\n\n");
  221.         }
  222.        
  223.         processSecurity(
  224.                 messageSecurityIds, output,
  225.                 CostantiDB.PORTE_APPLICATIVE, CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST,
  226.                 CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST_COLUMN_NOME, CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST_COLUMN_VALORE, CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST_COLUMN_ENC_VALUE);
  227.        
  228.         if(output!=null) {
  229.             output.append("\n\n");
  230.             output.append("=== Message Security (Erogazioni response-flow) ===\n\n");
  231.         }
  232.        
  233.         processSecurity(
  234.                 messageSecurityIds, output,
  235.                 CostantiDB.PORTE_APPLICATIVE, CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE,
  236.                 CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_COLUMN_NOME, CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_COLUMN_VALORE, CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_COLUMN_ENC_VALUE);
  237.        
  238.     }
  239.     private void processSecurity(List<String> messageSecurityIds, StringBuilder output,
  240.             String tabellaPadre, String tabella,
  241.             String nomeColonnaNomeProprieta, String nomeColonnaPlain, String nomeColonnaCodificata) throws CoreException {
  242.         if(messageSecurityIds!=null && !messageSecurityIds.isEmpty()) {
  243.             List<String> lnomiProp = new ArrayList<>();  
  244.             for (String id : messageSecurityIds) {
  245.                 List<String> l =  CostantiProprieta.getMessageSecurityProperties(id);
  246.                 for (String nomeProprieta : l) {
  247.                     if(!lnomiProp.contains(nomeProprieta)) {
  248.                         lnomiProp.add(nomeProprieta);
  249.                     }
  250.                 }
  251.             }
  252.            
  253.             for (String nomeProprieta : lnomiProp) {
  254.                 updateMessageSecurity(tabellaPadre, tabella,
  255.                         nomeColonnaNomeProprieta, nomeColonnaPlain, nomeColonnaCodificata,
  256.                         nomeProprieta, output);
  257.             }
  258.         }
  259.     }
  260.     private void processGenericProperties(StringBuilder output) throws CoreException {
  261.         VaultTools.logCoreDebug("Conversione generic properties ...");
  262.        
  263.         if(output!=null) {
  264.             if(output.length()>0) {
  265.                 output.append("\n\n");
  266.             }
  267.             output.append("=== TokenPolicy Validazione ===\n\n");
  268.         }
  269.        
  270.         for (String nomeProprieta : CostantiProprieta.getTokenValidationProperties()) {
  271.             updateGenericProperties(CostantiProprieta.TOKEN_VALIDATION_ID, nomeProprieta, output);
  272.         }
  273.        
  274.         if(output!=null) {
  275.             output.append("\n\n");
  276.             output.append("=== TokenPolicy Negoziazione ===\n\n");
  277.         }
  278.        
  279.         for (String nomeProprieta : CostantiProprieta.getTokenRetrieveProperties()) {
  280.             updateGenericProperties(CostantiProprieta.TOKEN_NEGOZIAZIONE_ID, nomeProprieta, output);
  281.         }
  282.        
  283.         if(output!=null) {
  284.             output.append("\n\n");
  285.             output.append("=== Attribute Authority ===\n\n");
  286.         }
  287.        
  288.         for (String nomeProprieta : CostantiProprieta.getAttributeAuthorityProperties()) {
  289.             updateGenericProperties(CostantiProprieta.ATTRIBUTE_AUTHORITY_ID, nomeProprieta, output);
  290.         }
  291.        
  292.         VaultTools.logCoreDebug("Conversione generic properties terminata");
  293.     }
  294.     private void processProtocolProperties(StringBuilder output) throws CoreException {
  295.         VaultTools.logCoreDebug("Conversione protocol properties ...");
  296.        
  297.         if(output!=null) {
  298.             if(output.length()>0) {
  299.                 output.append("\n\n");
  300.             }
  301.             output.append("=== ProtocolProperties ===\n\n");
  302.         }
  303.        
  304.         // DBProtocolPropertiesUtils.getProtocolPropertiesConfidentials()
  305.         // Non uso questo metodo poichè viene inizializzato dalla ModI Factory e nel vault non viene usato alcun protocollo
  306.        
  307.         updateProtocolProperties(CostantiDB.MODIPA_KEYSTORE_PASSWORD, false, output);
  308.         updateProtocolProperties(CostantiDB.MODIPA_KEY_PASSWORD, false, output);
  309.         updateProtocolProperties(CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_TRUSTSTORE_PASSWORD, false, output);
  310.         updateProtocolProperties(CostantiDB.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SSL_TRUSTSTORE_PASSWORD, false, output);
  311.        
  312.         updateProtocolProperties(CostantiDB.MODIPA_KEYSTORE_ARCHIVE, true, output);
  313.        
  314.         VaultTools.logCoreDebug("Conversione protocol properties terminata");
  315.     }
  316.     private void processProperties(StringBuilder output) throws CoreException {
  317.         VaultTools.logCoreDebug("Conversione properties ...");
  318.        
  319.         if(output!=null) {
  320.             if(output.length()>0) {
  321.                 output.append("\n\n");
  322.             }
  323.             output.append("=== Soggetti properties ===\n\n");
  324.         }
  325.                
  326.         updateProperties(CostantiDB.SOGGETTI_PROPS, CostantiDB.SOGGETTI_PROPS_COLUMN_NAME, CostantiDB.SOGGETTI_PROPS_COLUMN_VALUE, CostantiDB.SOGGETTI_PROPS_COLUMN_ENC_VALUE, output,
  327.                 false, false);
  328.        
  329.         if(output!=null) {
  330.             output.append("\n\n");
  331.             output.append("=== Applicativi properties ===\n\n");
  332.         }
  333.        
  334.         updateProperties(CostantiDB.SERVIZI_APPLICATIVI_PROPS, CostantiDB.SERVIZI_APPLICATIVI_PROPS_COLUMN_NOME, CostantiDB.SERVIZI_APPLICATIVI_PROPS_COLUMN_VALUE, CostantiDB.SERVIZI_APPLICATIVI_PROPS_COLUMN_ENC_VALUE, output,
  335.                 false, false);
  336.        
  337.         if(output!=null) {
  338.             output.append("\n\n");
  339.             output.append("=== Configurazione properties ===\n\n");
  340.         }
  341.        
  342.         updateProperties(CostantiDB.SYSTEM_PROPERTIES_PDD, CostantiDB.SYSTEM_PROPERTIES_PDD_COLUMN_NOME, CostantiDB.SYSTEM_PROPERTIES_PDD_COLUMN_VALUE, CostantiDB.SYSTEM_PROPERTIES_PDD_COLUMN_ENC_VALUE, output,
  343.                 false, false);
  344.        
  345.        
  346.         processErogazioniProperties(output);
  347.        
  348.         processFruizioniProperties(output);

  349.         VaultTools.logCoreDebug("Conversione properties terminata");
  350.     }
  351.     private void processErogazioniProperties(StringBuilder output) throws CoreException {
  352.         if(output!=null) {
  353.             output.append("\n\n");
  354.             output.append("=== Erogazioni message security request properties ===\n\n");
  355.         }
  356.        
  357.         updateProperties(CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST, CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST_COLUMN_NOME,
  358.                 CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST_COLUMN_VALORE, CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST_COLUMN_ENC_VALUE, output,
  359.                 true, false);
  360.        
  361.         if(output!=null) {
  362.             output.append("\n\n");
  363.             output.append("=== Erogazioni message security response properties ===\n\n");
  364.         }
  365.        
  366.         updateProperties(CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE, CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_COLUMN_NOME,
  367.                 CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_COLUMN_VALORE, CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_COLUMN_ENC_VALUE, output,
  368.                 false, true);
  369.        
  370.         if(output!=null) {
  371.             output.append("\n\n");
  372.             output.append("=== Erogazioni autenticazione properties ===\n\n");
  373.         }
  374.        
  375.         updateProperties(CostantiDB.PORTE_APPLICATIVE_AUTENTICAZIONE_PROP, CostantiDB.PORTE_APPLICATIVE_AUTENTICAZIONE_PROP_COLUMN_NOME,
  376.                 CostantiDB.PORTE_APPLICATIVE_AUTENTICAZIONE_PROP_COLUMN_VALORE, CostantiDB.PORTE_APPLICATIVE_AUTENTICAZIONE_PROP_COLUMN_ENC_VALUE, output,
  377.                 false, false);
  378.        
  379.         if(output!=null) {
  380.             output.append("\n\n");
  381.             output.append("=== Erogazioni autorizzazione properties ===\n\n");
  382.         }
  383.        
  384.         updateProperties(CostantiDB.PORTE_APPLICATIVE_AUTORIZZAZIONE_PROP, CostantiDB.PORTE_APPLICATIVE_AUTORIZZAZIONE_PROP_COLUMN_NOME,
  385.                 CostantiDB.PORTE_APPLICATIVE_AUTORIZZAZIONE_PROP_COLUMN_VALORE, CostantiDB.PORTE_APPLICATIVE_AUTORIZZAZIONE_PROP_COLUMN_ENC_VALUE, output,
  386.                 false, false);
  387.        
  388.         if(output!=null) {
  389.             output.append("\n\n");
  390.             output.append("=== Erogazioni autorizzazione contenuti properties ===\n\n");
  391.         }
  392.        
  393.         updateProperties(CostantiDB.PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI_PROP, CostantiDB.PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI_PROP_COLUMN_NOME,
  394.                 CostantiDB.PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI_PROP_COLUMN_VALORE, CostantiDB.PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI_PROP_COLUMN_ENC_VALUE, output,
  395.                 false, false);
  396.        
  397.         if(output!=null) {
  398.             output.append("\n\n");
  399.             output.append("=== Erogazioni properties ===\n\n");
  400.         }
  401.        
  402.         updateProperties(CostantiDB.PORTE_APPLICATIVE_PROP, CostantiDB.PORTE_APPLICATIVE_PROP_COLUMN_NOME,
  403.                 CostantiDB.PORTE_APPLICATIVE_PROP_COLUMN_VALORE, CostantiDB.PORTE_APPLICATIVE_PROP_COLUMN_ENC_VALUE, output,
  404.                 false, false);
  405.     }
  406.     private void processFruizioniProperties(StringBuilder output) throws CoreException {
  407.         if(output!=null) {
  408.             output.append("\n\n");
  409.             output.append("=== Fruizioni message security request properties ===\n\n");
  410.         }
  411.        
  412.         updateProperties(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST, CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_COLUMN_NOME,
  413.                 CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_COLUMN_VALORE, CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_COLUMN_ENC_VALUE, output,
  414.                 true, false);
  415.        
  416.         if(output!=null) {
  417.             output.append("\n\n");
  418.             output.append("=== Fruizioni message security response properties ===\n\n");
  419.         }
  420.        
  421.         updateProperties(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE, CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_COLUMN_NOME,
  422.                 CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_COLUMN_VALORE, CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_COLUMN_ENC_VALUE, output,
  423.                 false, true);
  424.        
  425.         if(output!=null) {
  426.             output.append("\n\n");
  427.             output.append("=== Fruizioni autenticazione properties ===\n\n");
  428.         }
  429.        
  430.         updateProperties(CostantiDB.PORTE_DELEGATE_AUTENTICAZIONE_PROP, CostantiDB.PORTE_DELEGATE_AUTENTICAZIONE_PROP_COLUMN_NOME,
  431.                 CostantiDB.PORTE_DELEGATE_AUTENTICAZIONE_PROP_COLUMN_VALORE, CostantiDB.PORTE_DELEGATE_AUTENTICAZIONE_PROP_COLUMN_ENC_VALUE, output,
  432.                 false, false);
  433.        
  434.         if(output!=null) {
  435.             output.append("\n\n");
  436.             output.append("=== Fruizioni autorizzazione properties ===\n\n");
  437.         }
  438.        
  439.         updateProperties(CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_PROP, CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_PROP_COLUMN_NOME,
  440.                 CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_PROP_COLUMN_VALORE, CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_PROP_COLUMN_ENC_VALUE, output,
  441.                 false, false);
  442.        
  443.         if(output!=null) {
  444.             output.append("\n\n");
  445.             output.append("=== Fruizioni autorizzazione contenuti properties ===\n\n");
  446.         }
  447.        
  448.         updateProperties(CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_PROP, CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_PROP_COLUMN_NOME,
  449.                 CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_PROP_COLUMN_VALORE, CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_PROP_COLUMN_ENC_VALUE, output,
  450.                 false, false);
  451.        
  452.         if(output!=null) {
  453.             output.append("\n\n");
  454.             output.append("=== Fruizioni properties ===\n\n");
  455.         }
  456.        
  457.         updateProperties(CostantiDB.PORTE_DELEGATE_PROP, CostantiDB.PORTE_DELEGATE_PROP_COLUMN_NOME,
  458.                 CostantiDB.PORTE_DELEGATE_PROP_COLUMN_VALORE, CostantiDB.PORTE_DELEGATE_PROP_COLUMN_ENC_VALUE, output,
  459.                 false, false);
  460.     }
  461.    
  462.    
  463.    
  464.    
  465.     // UTILS
  466.    
  467.     private Connection getConnection() throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, SQLException {
  468.         Connection connectionSQL = null;
  469.         org.openspcoop2.utils.resources.Loader.getInstance().newInstance(this.driver);
  470.         if(this.username!=null && this.password!=null){
  471.             connectionSQL = DriverManager.getConnection(this.connectionURL,this.username,this.password);
  472.         }else{
  473.             connectionSQL = DriverManager.getConnection(this.connectionURL);
  474.         }
  475.         return connectionSQL;
  476.     }
  477.     private void closeConnection(Connection connectionSQL) {
  478.         if(connectionSQL!=null) {
  479.             try {
  480.                 connectionSQL.close();
  481.             }catch(Exception e) {
  482.                 // ignore
  483.             }
  484.         }
  485.     }
  486.    
  487.     private void skip(StringBuilder output, String prefix, String value, boolean wrapped) {
  488.         if(output!=null) {
  489.             output.append(prefix).append("\n");
  490.             output.append(wrapped ? LOG_ORIG_SKIPPED : LOG_ORIG_SKIPPED_NO_WRAPPED).append(value).append("\n");
  491.         }
  492.     }
  493.     private void skipWithPolicy(StringBuilder output, String prefix, String value) {
  494.         if(output!=null) {
  495.             output.append(prefix).append("\n");
  496.             output.append(LOG_ORIG_SKIPPED_WITH_POLICY).append(value).append("\n");
  497.         }
  498.     }
  499.     private void skipAlreadyWrapped(StringBuilder output, String prefix, String value) {
  500.         if(output!=null) {
  501.             output.append(prefix).append("\n");
  502.             output.append(LOG_ORIG_SKIPPED_ALREADY_WRAPPED).append(value).append("\n");
  503.         }
  504.     }
  505.    
  506.     private void updateValue(Connection connectionSQL, ResultSet rs, String nomeColonna,
  507.             String prefix, StringBuilder output,
  508.             VaultUpdateConfigValue c) throws UtilsException, SQLException, SQLQueryObjectException {
  509.        
  510.         String plainStringValue = rs.getString(nomeColonna);
  511.         String updatedValue = null;
  512.         if(this.inDriverBYOK!=null &&
  513.                 plainStringValue!=null && StringUtils.isNotEmpty(plainStringValue)) {
  514.             if(BYOKUtilities.isWrappedValue(plainStringValue)) {
  515.                 if(this.inDriverBYOK.isWrappedWithInternalPolicy(plainStringValue)) {
  516.                     updatedValue = this.inDriverBYOK.unwrapAsString(plainStringValue);
  517.                 }
  518.                 else {
  519.                     // trovato un valore cifrato con una security policy differente ?
  520.                     // non effettua il wrap anche se richiesto
  521.                     skip(output, prefix, plainStringValue, true);
  522.                     return;
  523.                 }
  524.             }
  525.             else {
  526.                 // trovato un valore non cifrato con una security policy
  527.                 // non effettua il wrap anche se richiesto
  528.                 skip(output, prefix, plainStringValue, false);
  529.                 return;
  530.             }
  531.         }
  532.         else {
  533.             if(plainStringValue!=null && StringUtils.isNotEmpty(plainStringValue) && BYOKUtilities.isWrappedValue(plainStringValue)) {
  534.                 // trovato un valore cifrato con una security policy, non devo quindi considerarlo
  535.                 skipWithPolicy(output, prefix, plainStringValue);
  536.                 return;
  537.             }
  538.         }
  539.        
  540.         if(this.outDriverBYOK!=null || updatedValue!=null) {
  541.             updateValue(connectionSQL, output,
  542.                     plainStringValue, updatedValue,
  543.                     c, prefix);
  544.         }
  545.        
  546.     }
  547.     private void updateValue(Connection connectionSQL, StringBuilder output,
  548.             String plainStringValue, String updatedValue,
  549.             VaultUpdateConfigValue c, String prefix) throws SQLQueryObjectException, SQLException, UtilsException {
  550.        
  551.         if(this.outDriverBYOK!=null) {
  552.             String v = updatedValue!=null ? updatedValue : plainStringValue;
  553.             if(this.outDriverBYOK.isWrappedWithInternalPolicy(v)) {
  554.                 // Il valore di destinazione risulta già cifrato con la policy richiesta
  555.                 skipAlreadyWrapped(output, prefix, v);
  556.                 return;
  557.             }
  558.         }
  559.        
  560.         if(output!=null) {
  561.             output.append(prefix).append("\n");
  562.             output.append(LOG_ORIG).append(plainStringValue).append("\n");
  563.         }
  564.        
  565.         updateValue(connectionSQL, output,
  566.                 plainStringValue, updatedValue,
  567.                 c);
  568.        
  569.         if(output!=null) {
  570.             output.append("\n\n");
  571.         }
  572.     }
  573.     private void updateValue(Connection connectionSQL, StringBuilder output,
  574.             String plainStringValue, String updatedValue,
  575.             VaultUpdateConfigValue updateConfig) throws SQLQueryObjectException, SQLException, UtilsException {
  576.        
  577.         PreparedStatement stmUpdate = null;
  578.         try {
  579.             BYOKWrappedValue wrappedValue =null;
  580.             if(this.outDriverBYOK!=null) {
  581.                 wrappedValue = this.outDriverBYOK.wrap(updatedValue!=null ? updatedValue : plainStringValue);
  582.             }  
  583.            
  584.             ISQLQueryObject sqlQueryObjectUpdate = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  585.             sqlQueryObjectUpdate.addUpdateTable(updateConfig.tabella);
  586.             sqlQueryObjectUpdate.addUpdateField(updateConfig.nomeColonna, "?");
  587.             sqlQueryObjectUpdate.addWhereCondition(CONDITION_WHERE_ID);
  588.             sqlQueryObjectUpdate.setANDLogicOperator(true);
  589.             String sqlUpdate = sqlQueryObjectUpdate.createSQLUpdate();
  590.             stmUpdate = connectionSQL.prepareStatement(sqlUpdate);
  591.             int index = 1;
  592.             if(wrappedValue!=null) {
  593.                 stmUpdate.setString(index++, wrappedValue.getWrappedValue());
  594.                 if(output!=null) {
  595.                     output.append(LOG_NEW).append(wrappedValue.getWrappedValue()).append("\n");
  596.                 }
  597.             }
  598.             else {
  599.                 stmUpdate.setString(index++, updatedValue);
  600.                 if(output!=null) {
  601.                     output.append(LOG_NEW).append(updatedValue).append("\n");
  602.                 }
  603.             }
  604.             stmUpdate.setLong(index++, updateConfig.id);
  605.             int row = stmUpdate.executeUpdate();
  606.             if(output!=null) {
  607.                 output.append(LOG_ROW_UPDATE).append(row).append("\n");
  608.             }
  609.             stmUpdate.close();
  610.         } finally {
  611.             JDBCUtilities.closeResources(stmUpdate);
  612.         }
  613.     }
  614.    
  615.    
  616.     private void updatePlainEncValue(Connection connectionSQL, ResultSet rs, String nomeColonnaPlain, String nomeColonnaCodificata,
  617.             String prefix, StringBuilder output,
  618.             VaultUpdateConfigPlainEnc c) throws UtilsException, SQLException, SQLQueryObjectException {
  619.        
  620.         String plainStringValue = rs.getString(nomeColonnaPlain);
  621.         String encStringValue = rs.getString(nomeColonnaCodificata);
  622.         String updatedValue = null;
  623.         if(this.inDriverBYOK!=null) {
  624.             if(encStringValue!=null && StringUtils.isNotEmpty(encStringValue)) {
  625.                 if(this.inDriverBYOK.isWrappedWithInternalPolicy(encStringValue)) {
  626.                     updatedValue = this.inDriverBYOK.unwrapAsString(encStringValue);
  627.                 }
  628.                 else {
  629.                     // trovato un valore cifrato con una security policy differente ?
  630.                     // non effettua il wrap anche se richiesto
  631.                     skip(output, prefix, encStringValue, true);
  632.                     return;
  633.                 }
  634.             }
  635.             else {
  636.                 // trovato un valore non cifrato con una security policy
  637.                 // non effettua il wrap anche se richiesto
  638.                 skip(output, prefix, plainStringValue, false);
  639.                 return;
  640.             }
  641.         }
  642.         else {
  643.             if(encStringValue!=null && StringUtils.isNotEmpty(encStringValue)) {
  644.                 // trovato un valore cifrato con una security policy, non devo quindi considerarlo
  645.                 skipWithPolicy(output, prefix, encStringValue);
  646.                 return;
  647.             }
  648.         }
  649.        
  650.         if(this.outDriverBYOK!=null || updatedValue!=null) {
  651.             updatePlainEncValue(connectionSQL, output,
  652.                     plainStringValue, encStringValue, updatedValue,
  653.                     c, prefix);
  654.         }
  655.        
  656.     }
  657.     private void updatePlainEncValue(Connection connectionSQL, StringBuilder output,
  658.             String plainStringValue, String encStringValue, String updatedValue,
  659.             VaultUpdateConfigPlainEnc c, String prefix) throws SQLQueryObjectException, SQLException, UtilsException {
  660.        
  661.         if(this.outDriverBYOK!=null) {
  662.             String v = updatedValue!=null ? updatedValue : plainStringValue;
  663.             if(this.outDriverBYOK.isWrappedWithInternalPolicy(v)) {
  664.                 // Il valore di destinazione risulta già cifrato con la policy richiesta
  665.                 skipAlreadyWrapped(output, prefix, v);
  666.                 return;
  667.             }
  668.         }
  669.        
  670.         if(output!=null) {
  671.             output.append(prefix).append("\n");
  672.             output.append(LOG_ORIG).append(encStringValue!=null && StringUtils.isNotEmpty(encStringValue) ? encStringValue : plainStringValue).append("\n");
  673.         }
  674.        
  675.         updatePlainEncValue(connectionSQL, output,
  676.                 plainStringValue, updatedValue,
  677.                 c);
  678.        
  679.         if(output!=null) {
  680.             output.append("\n\n");
  681.         }
  682.     }
  683.     private void updatePlainEncValue(Connection connectionSQL, StringBuilder output,
  684.             String plainStringValue, String updatedValue,
  685.             VaultUpdateConfigPlainEnc plainEncConfig) throws SQLQueryObjectException, SQLException, UtilsException {
  686.        
  687.         PreparedStatement stmUpdate = null;
  688.         try {
  689.             BYOKWrappedValue wrappedValue =null;
  690.             if(this.outDriverBYOK!=null) {
  691.                 wrappedValue = this.outDriverBYOK.wrap(updatedValue!=null ? updatedValue : plainStringValue);
  692.             }  
  693.            
  694.             ISQLQueryObject sqlQueryObjectUpdate = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  695.             sqlQueryObjectUpdate.addUpdateTable(plainEncConfig.tabella);
  696.             sqlQueryObjectUpdate.addUpdateField(plainEncConfig.nomeColonnaPlain, "?");
  697.             sqlQueryObjectUpdate.addUpdateField(plainEncConfig.nomeColonnaCodificata, "?");
  698.             sqlQueryObjectUpdate.addWhereCondition(CONDITION_WHERE_ID);
  699.             sqlQueryObjectUpdate.setANDLogicOperator(true);
  700.             String sqlUpdate = sqlQueryObjectUpdate.createSQLUpdate();
  701.             stmUpdate = connectionSQL.prepareStatement(sqlUpdate);
  702.             int index = 1;
  703.             if(wrappedValue!=null) {
  704.                 stmUpdate.setString(index++, wrappedValue.getWrappedPlainValue());
  705.                 stmUpdate.setString(index++, wrappedValue.getWrappedValue());
  706.                 if(output!=null) {
  707.                     output.append(LOG_NEW).append(wrappedValue.getWrappedValue()).append("\n");
  708.                 }
  709.             }
  710.             else {
  711.                 stmUpdate.setString(index++, updatedValue);
  712.                 stmUpdate.setString(index++, null);
  713.                 if(output!=null) {
  714.                     output.append(LOG_NEW).append(updatedValue).append("\n");
  715.                 }
  716.             }
  717.             stmUpdate.setLong(index++, plainEncConfig.id);
  718.             int row = stmUpdate.executeUpdate();
  719.             if(output!=null) {
  720.                 output.append(LOG_ROW_UPDATE).append(row).append("\n");
  721.             }
  722.             stmUpdate.close();
  723.         } finally {
  724.             JDBCUtilities.closeResources(stmUpdate);
  725.         }
  726.     }

  727.    
  728.     private void updateBinaryProtocolProperty(IJDBCAdapter jdbcAdapter, Connection connectionSQL, ResultSet rs, String nomeColonna,
  729.             String prefix, StringBuilder output,
  730.             VaultUpdateConfigValue c) throws UtilsException, SQLException, SQLQueryObjectException {

  731.         byte[]binaryValue = jdbcAdapter.getBinaryData(rs,nomeColonna);
  732.         byte[]updateValue = null;
  733.         if(this.inDriverBYOK!=null &&
  734.             binaryValue!=null && binaryValue.length>0) {
  735.             if(BYOKUtilities.isWrappedValue(binaryValue)) {
  736.                 if(this.inDriverBYOK.isWrappedWithInternalPolicy(binaryValue)) {
  737.                     updateValue = this.inDriverBYOK.unwrap(binaryValue);
  738.                 }
  739.                 else {
  740.                     // trovato un valore cifrato con una security policy differente ?
  741.                     // non effettua il wrap anche se richiesto
  742.                     skip(output, prefix, BYOKUtilities.extractPrefixWrappedValue(binaryValue), true);
  743.                     return;
  744.                 }
  745.             }
  746.             else {
  747.                 // trovato un valore non cifrato con una security policy
  748.                 // non effettua il wrap anche se richiesto
  749.                 skip(output, prefix, "--binary-value--", false);
  750.                 return;
  751.             }
  752.         }
  753.         else {
  754.             if(binaryValue!=null && binaryValue.length>0 && BYOKUtilities.isWrappedValue(binaryValue)) {
  755.                 // trovato un valore cifrato con una security policy, non devo quindi considerarlo
  756.                 skipWithPolicy(output, prefix, BYOKUtilities.extractPrefixWrappedValue(binaryValue));
  757.                 return;
  758.             }
  759.         }
  760.        
  761.         if(this.outDriverBYOK!=null || updateValue!=null) {
  762.             updateBinaryValue(jdbcAdapter, connectionSQL, output,
  763.                     binaryValue, updateValue,
  764.                     c, prefix);        
  765.         }
  766.        
  767.     }
  768.     private void updateBinaryValue(IJDBCAdapter jdbcAdapter, Connection connectionSQL, StringBuilder output,
  769.             byte[]binaryValue, byte[]updateValue,
  770.             VaultUpdateConfigValue c, String prefix) throws UtilsException, SQLQueryObjectException, SQLException {
  771.        
  772.         if(this.outDriverBYOK!=null) {
  773.             byte[] v = updateValue!=null ? updateValue : binaryValue;
  774.             if(this.outDriverBYOK.isWrappedWithInternalPolicy(v)) {
  775.                 // Il valore di destinazione risulta già cifrato con la policy richiesta
  776.                 skipAlreadyWrapped(output, prefix, BYOKUtilities.extractPrefixWrappedValue(v));
  777.                 return;
  778.             }
  779.         }
  780.        
  781.         if(output!=null) {
  782.             output.append(prefix).append("\n");
  783.             String base64 = Base64Utilities.encodeAsString(binaryValue);
  784.             output.append(LOG_ORIG).append(base64).append("\n");
  785.         }
  786.        
  787.         updateBinaryValue(jdbcAdapter, connectionSQL, output,
  788.                 binaryValue, updateValue,
  789.                 c);
  790.        
  791.         if(output!=null) {
  792.             output.append("\n\n");
  793.         }
  794.     }
  795.     private void updateBinaryValue(IJDBCAdapter jdbcAdapter, Connection connectionSQL, StringBuilder output,
  796.             byte[]binaryValue, byte[]updateValue,
  797.             VaultUpdateConfigValue binaryConfig) throws UtilsException, SQLQueryObjectException, SQLException {
  798.         PreparedStatement stmUpdate = null;
  799.         try {
  800.             BYOKWrappedValue wrappedValue =null;
  801.             if(this.outDriverBYOK!=null) {
  802.                 wrappedValue = this.outDriverBYOK.wrap(updateValue!=null ? updateValue : binaryValue);
  803.             }
  804.            
  805.             ISQLQueryObject sqlQueryObjectUpdate = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  806.             sqlQueryObjectUpdate.addUpdateTable(binaryConfig.tabella);
  807.             sqlQueryObjectUpdate.addUpdateField(binaryConfig.nomeColonna, "?");
  808.             sqlQueryObjectUpdate.addWhereCondition(CONDITION_WHERE_ID);
  809.             sqlQueryObjectUpdate.setANDLogicOperator(true);
  810.             String sqlUpdate = sqlQueryObjectUpdate.createSQLUpdate();
  811.             stmUpdate = connectionSQL.prepareStatement(sqlUpdate);
  812.             int index = 1;
  813.             if(wrappedValue!=null) {
  814.                 jdbcAdapter.setBinaryData(stmUpdate,index++,wrappedValue.getWrappedValue().getBytes());
  815.                 if(output!=null) {
  816.                     String base64 = Base64Utilities.encodeAsString(wrappedValue.getWrappedValue().getBytes());
  817.                     output.append(LOG_NEW).append(base64).append("\n");
  818.                 }
  819.             }
  820.             else {
  821.                 jdbcAdapter.setBinaryData(stmUpdate,index++,updateValue);
  822.                 if(output!=null) {
  823.                     String base64 = Base64Utilities.encodeAsString(updateValue);
  824.                     output.append(LOG_NEW).append(base64).append("\n");
  825.                 }
  826.             }
  827.             stmUpdate.setLong(index++, binaryConfig.id);
  828.             int row = stmUpdate.executeUpdate();
  829.             if(output!=null) {
  830.                 output.append(LOG_ROW_UPDATE).append(row).append("\n");
  831.             }
  832.             stmUpdate.close();
  833.         } finally {
  834.             JDBCUtilities.closeResources(stmUpdate);
  835.         }
  836.     }
  837.    
  838.    
  839.    
  840.    
  841.    
  842.     // CONNETTORI
  843.    
  844.     private void updateConnettori(String nomeColonnaPlain, String nomeColonnaCodificata, StringBuilder output) throws CoreException {
  845.         PreparedStatement stmRead = null;
  846.         ResultSet rs=null;
  847.        
  848.         Connection connectionSQL = null;
  849.         try {
  850.             connectionSQL = getConnection();
  851.            
  852.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  853.             sqlQueryObject.addFromTable(CostantiDB.CONNETTORI);
  854.             sqlQueryObject.addWhereIsNotNullCondition(nomeColonnaPlain);
  855.             if(!TipiDatabase.ORACLE.equals(this.tipoDatabase)) {
  856.                 // In oracle le stringhe vuote equivalgono a null
  857.                 sqlQueryObject.addWhereIsNotEmptyCondition(nomeColonnaPlain);
  858.             }
  859.             sqlQueryObject.setANDLogicOperator(true);
  860.             sqlQueryObject.addOrderBy(CostantiDB.CONNETTORI_COLUMN_NOME);
  861.             String sqlQuery = sqlQueryObject.createSQLQuery();
  862.             stmRead = connectionSQL.prepareStatement(sqlQuery);
  863.             rs = stmRead.executeQuery();
  864.            
  865.             while(rs.next()){
  866.                
  867.                 long id = rs.getLong("id");
  868.                 String nomeConnettore = rs.getString(CostantiDB.CONNETTORI_COLUMN_NOME);
  869.                 String endpointtype = rs.getString(CostantiDB.CONNETTORI_COLUMN_ENDPOINT_TYPE);
  870.                 String prefix = "["+nomeConnettore+"][tipoConnettore:"+endpointtype+"][idConnettore:"+id+"] '"+nomeColonnaPlain+"' ";
  871.                
  872.                 if(nomeColonnaCodificata!=null) {
  873.                     VaultUpdateConfigPlainEnc c = new VaultUpdateConfigPlainEnc();
  874.                     c.tabella = CostantiDB.CONNETTORI;
  875.                     c.nomeColonnaPlain = nomeColonnaPlain;
  876.                     c.nomeColonnaCodificata = nomeColonnaCodificata;
  877.                     c.id = id;
  878.                     updatePlainEncValue(connectionSQL, rs, nomeColonnaPlain, nomeColonnaCodificata,
  879.                             prefix, output,
  880.                             c);
  881.                 }
  882.                 else {
  883.                     VaultUpdateConfigValue c = new VaultUpdateConfigValue();
  884.                     c.tabella = CostantiDB.CONNETTORI;
  885.                     c.nomeColonna = nomeColonnaPlain;
  886.                     c.id = id;
  887.                     updateValue(connectionSQL, rs, nomeColonnaPlain,
  888.                             prefix, output,
  889.                             c);
  890.                 }
  891.            
  892.             }
  893.            
  894.         } catch (Exception se) {
  895.             throw new CoreException("[updateConnettori] failed: " + se.getMessage(),se);
  896.         } finally {
  897.             JDBCUtilities.closeResources(rs, stmRead);
  898.             closeConnection(connectionSQL);
  899.         }
  900.     }
  901.    
  902.     private void updateConnettoriCustom(String nomeProprieta, StringBuilder output) throws CoreException {
  903.         PreparedStatement stmRead = null;
  904.         ResultSet rs=null;
  905.        
  906.         Connection connectionSQL = null;
  907.         try {
  908.             connectionSQL = getConnection();
  909.            
  910.             String aliasIdConnettore = "idCon";
  911.             String aliasNomeConnettore = "nomeCon";
  912.             String aliasTipoConnettore = "tipoCon";
  913.             String aliasIdConnettoreCustsom = "idConCustom";
  914.             String aliasNomeConnettoreCustsom = "nomeConCustom";
  915.             String aliasPlanValueConnettoreCustsom = "plainConCustom";
  916.             String aliasEncValueConnettoreCustsom = "encConCustom";
  917.            
  918.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  919.             sqlQueryObject.addFromTable(CostantiDB.CONNETTORI);
  920.             sqlQueryObject.addFromTable(CostantiDB.CONNETTORI_CUSTOM);
  921.             sqlQueryObject.addSelectAliasField(CostantiDB.CONNETTORI, CostantiDB.CONNETTORI_COLUMN_NOME, aliasNomeConnettore);
  922.             sqlQueryObject.addSelectAliasField(CostantiDB.CONNETTORI, CostantiDB.CONNETTORI_COLUMN_ENDPOINT_TYPE, aliasTipoConnettore);
  923.             sqlQueryObject.addSelectAliasField(CostantiDB.CONNETTORI, "id", aliasIdConnettore);
  924.             sqlQueryObject.addSelectAliasField(CostantiDB.CONNETTORI_CUSTOM, "id", aliasIdConnettoreCustsom);
  925.             sqlQueryObject.addSelectAliasField(CostantiDB.CONNETTORI_CUSTOM, CostantiDB.CONNETTORI_CUSTOM_COLUMN_NAME, aliasNomeConnettoreCustsom);
  926.             sqlQueryObject.addSelectAliasField(CostantiDB.CONNETTORI_CUSTOM, CostantiDB.CONNETTORI_CUSTOM_COLUMN_VALUE, aliasPlanValueConnettoreCustsom);
  927.             sqlQueryObject.addSelectAliasField(CostantiDB.CONNETTORI_CUSTOM, CostantiDB.CONNETTORI_CUSTOM_COLUMN_ENC_VALUE, aliasEncValueConnettoreCustsom);
  928.             sqlQueryObject.addWhereCondition(CostantiDB.CONNETTORI+CONDITION_JOIN_ID+CostantiDB.CONNETTORI_CUSTOM+"."+CostantiDB.CONNETTORI_CUSTOM_COLUMN_ID_CONNETTORE);
  929.             sqlQueryObject.addWhereCondition(CostantiDB.CONNETTORI_CUSTOM+"."+CostantiDB.CONNETTORI_CUSTOM_COLUMN_NAME+"=?");
  930.             sqlQueryObject.addWhereIsNotNullCondition(CostantiDB.CONNETTORI_CUSTOM+"."+CostantiDB.CONNETTORI_CUSTOM_COLUMN_VALUE);
  931.             if(!TipiDatabase.ORACLE.equals(this.tipoDatabase)) {
  932.                 // In oracle le stringhe vuote equivalgono a null
  933.                 sqlQueryObject.addWhereIsNotEmptyCondition(CostantiDB.CONNETTORI_CUSTOM+"."+CostantiDB.CONNETTORI_CUSTOM_COLUMN_VALUE);
  934.             }
  935.             sqlQueryObject.addWhereCondition(true, true, CostantiDB.CONNETTORI_CUSTOM+"."+CostantiDB.CONNETTORI_CUSTOM_COLUMN_VALUE+"='"+CostantiDB.MODIPA_VALUE_UNDEFINED+"'"); // vale anche per security properties
  936.             sqlQueryObject.setANDLogicOperator(true);
  937.             sqlQueryObject.addOrderBy(CostantiDB.CONNETTORI_COLUMN_NOME);
  938.             sqlQueryObject.setSelectDistinct(true);
  939.             String sqlQuery = sqlQueryObject.createSQLQuery();
  940.             stmRead = connectionSQL.prepareStatement(sqlQuery);
  941.             stmRead.setString(1, nomeProprieta);
  942.             rs = stmRead.executeQuery();
  943.            
  944.             while(rs.next()){
  945.                
  946.                 long idCustom = rs.getLong(aliasIdConnettoreCustsom);
  947.                 long idConnettore = rs.getLong(aliasIdConnettore);
  948.                 String nomeConnettore = rs.getString(aliasNomeConnettore);
  949.                 String endpointtype = rs.getString(aliasTipoConnettore);
  950.                 String prefix = "["+nomeConnettore+"][tipoConnettore:"+endpointtype+"][idConnettore:"+idConnettore+"][idCustomProp:"+idCustom+"] '"+nomeProprieta+"' ";
  951.                
  952.                 VaultUpdateConfigPlainEnc c = new VaultUpdateConfigPlainEnc();
  953.                 c.tabella = CostantiDB.CONNETTORI_CUSTOM;
  954.                 c.nomeColonnaPlain = CostantiDB.CONNETTORI_CUSTOM_COLUMN_VALUE;
  955.                 c.nomeColonnaCodificata = CostantiDB.CONNETTORI_CUSTOM_COLUMN_ENC_VALUE;
  956.                 c.id = idCustom;
  957.                 updatePlainEncValue(connectionSQL, rs, aliasPlanValueConnettoreCustsom, aliasEncValueConnettoreCustsom,
  958.                         prefix, output,
  959.                         c);
  960.            
  961.             }
  962.            
  963.         } catch (Exception se) {
  964.             throw new CoreException("[updateConnettoriCustom] failed: " + se.getMessage(),se);
  965.         } finally {
  966.             JDBCUtilities.closeResources(rs, stmRead);
  967.             closeConnection(connectionSQL);
  968.         }
  969.     }

  970.    
  971.    
  972.    
  973.    
  974.    
  975.    
  976.    
  977.    
  978.     // SERVIZI APPLICATIVI
  979.    
  980.     private void updateServiziApplicativi(String nomeColonnaPlain, String nomeColonnaCodificata, StringBuilder output) throws CoreException {
  981.         PreparedStatement stmRead = null;
  982.         ResultSet rs=null;
  983.        
  984.         Connection connectionSQL = null;
  985.         try {
  986.             connectionSQL = getConnection();
  987.            
  988.             String aliasNomeSA = "nomeSA";
  989.             String aliasTipoSoggetto = "tipoSogg";
  990.             String aliasNomeSoggetto = "nomeSogg";
  991.            
  992.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  993.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI_APPLICATIVI);
  994.             sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  995.             sqlQueryObject.addSelectAliasField(CostantiDB.SERVIZI_APPLICATIVI, "id", "idSA");
  996.             sqlQueryObject.addSelectAliasField(CostantiDB.SERVIZI_APPLICATIVI, "nome", aliasNomeSA);
  997.             sqlQueryObject.addSelectAliasField(CostantiDB.SERVIZI_APPLICATIVI, "tipo", "tipoSA");
  998.             sqlQueryObject.addSelectAliasField(CostantiDB.SOGGETTI, "tipo_soggetto", aliasTipoSoggetto);
  999.             sqlQueryObject.addSelectAliasField(CostantiDB.SOGGETTI, "nome_soggetto", aliasNomeSoggetto);
  1000.             sqlQueryObject.addSelectAliasField(CostantiDB.SERVIZI_APPLICATIVI, nomeColonnaPlain, ALIAS_PLAIN_VALUE);
  1001.             sqlQueryObject.addSelectAliasField(CostantiDB.SERVIZI_APPLICATIVI, nomeColonnaCodificata, ALIAS_ENC_VALUE);
  1002.             sqlQueryObject.addWhereCondition(CostantiDB.SERVIZI_APPLICATIVI+".id_soggetto = "+CostantiDB.SOGGETTI+".id");
  1003.             sqlQueryObject.addWhereIsNotNullCondition(nomeColonnaPlain);
  1004.             if(!TipiDatabase.ORACLE.equals(this.tipoDatabase)) {
  1005.                 // In oracle le stringhe vuote equivalgono a null
  1006.                 sqlQueryObject.addWhereIsNotEmptyCondition(nomeColonnaPlain);
  1007.             }
  1008.             sqlQueryObject.addOrderBy(aliasTipoSoggetto);
  1009.             sqlQueryObject.addOrderBy(aliasNomeSoggetto);
  1010.             sqlQueryObject.addOrderBy(aliasNomeSA);
  1011.             sqlQueryObject.setANDLogicOperator(true);
  1012.             sqlQueryObject.setSelectDistinct(true);
  1013.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1014.             stmRead = connectionSQL.prepareStatement(sqlQuery);
  1015.             rs = stmRead.executeQuery();
  1016.            
  1017.             while(rs.next()){
  1018.                
  1019.                 long idSA = rs.getLong("idSA");
  1020.                 String nome = rs.getString(aliasNomeSA);
  1021.                 String tipo = rs.getString("tipoSA");
  1022.                 String tipoSoggetto = rs.getString(aliasTipoSoggetto);
  1023.                 String nomeSoggetto = rs.getString(aliasNomeSoggetto);
  1024.                 String prefix = "["+nome+"][soggetto:"+tipoSoggetto+"/"+nomeSoggetto+"][tipoSA:"+tipo+"][idSA:"+idSA+"] '"+nomeColonnaPlain+"' ";
  1025.                
  1026.                 VaultUpdateConfigPlainEnc c = new VaultUpdateConfigPlainEnc();
  1027.                 c.tabella = CostantiDB.SERVIZI_APPLICATIVI;
  1028.                 c.nomeColonnaPlain = nomeColonnaPlain;
  1029.                 c.nomeColonnaCodificata = nomeColonnaCodificata;
  1030.                 c.id = idSA;
  1031.                 updatePlainEncValue(connectionSQL, rs, ALIAS_PLAIN_VALUE, ALIAS_ENC_VALUE,
  1032.                         prefix, output,
  1033.                         c);
  1034.            
  1035.             }
  1036.            
  1037.         } catch (Exception se) {
  1038.             throw new CoreException("[updateServiziApplicativi] failed: " + se.getMessage(),se);
  1039.         } finally {
  1040.             JDBCUtilities.closeResources(rs, stmRead);
  1041.             closeConnection(connectionSQL);
  1042.         }
  1043.     }
  1044.    
  1045.    
  1046.    
  1047.    
  1048.    
  1049.    
  1050.    
  1051.    
  1052.    
  1053.    
  1054.     // MESSAGE SECURITY
  1055.    
  1056.     private void updateMessageSecurity(String tabellaPadre, String tabella,
  1057.             String nomeColonnaNomeProprieta, String nomeColonnaPlain, String nomeColonnaCodificata,
  1058.             String nomeProprieta, StringBuilder output) throws CoreException {
  1059.         PreparedStatement stmRead = null;
  1060.         ResultSet rs=null;
  1061.        
  1062.         Connection connectionSQL = null;
  1063.         try {
  1064.             connectionSQL = getConnection();
  1065.            
  1066.             String aliasIdSecProp = "idSecProp";
  1067.             String aliasIdPorta = "idP";
  1068.             String aliasNomePorta = "nomeP";
  1069.            
  1070.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1071.             sqlQueryObject.addFromTable(tabellaPadre);
  1072.             sqlQueryObject.addFromTable(tabella);
  1073.             sqlQueryObject.addSelectAliasField(tabellaPadre, "id", aliasIdPorta);
  1074.             sqlQueryObject.addSelectAliasField(tabellaPadre, "nome_porta", aliasNomePorta);
  1075.             sqlQueryObject.addSelectAliasField(tabella, "id", aliasIdSecProp);
  1076.             sqlQueryObject.addSelectAliasField(tabella, nomeColonnaPlain, ALIAS_PLAIN_VALUE);
  1077.             sqlQueryObject.addSelectAliasField(tabella, nomeColonnaCodificata, ALIAS_ENC_VALUE);
  1078.             sqlQueryObject.addWhereCondition(tabellaPadre+CONDITION_JOIN_ID+tabella+".id_porta");
  1079.            
  1080.             ISQLQueryObject sqlQueryObjectOrName = sqlQueryObject.newSQLQueryObject();
  1081.             sqlQueryObjectOrName.addFromTable(tabella);
  1082.             sqlQueryObjectOrName.addWhereCondition(tabella+"."+nomeColonnaNomeProprieta+" = ?");
  1083.             sqlQueryObjectOrName.addWhereLikeCondition(tabella+"."+nomeColonnaNomeProprieta, CostantiProprieta.KEY_PROPERTIES_CUSTOM_SEPARATOR+nomeProprieta, LikeConfig.endsWith(false)); // puo' contenere l'id del properties
  1084.             sqlQueryObjectOrName.addWhereLikeCondition(tabella+"."+nomeColonnaNomeProprieta, CostantiProprieta.KEY_PROPERTIES_DEFAULT_SEPARATOR+nomeProprieta, LikeConfig.endsWith(false)); // puo' contenere l'id del properties
  1085.             sqlQueryObjectOrName.setANDLogicOperator(false);
  1086.             sqlQueryObject.addWhereCondition(sqlQueryObjectOrName.createSQLConditions());

  1087.             sqlQueryObject.addWhereIsNotNullCondition(nomeColonnaPlain);
  1088.             if(!TipiDatabase.ORACLE.equals(this.tipoDatabase)) {
  1089.                 // In oracle le stringhe vuote equivalgono a null
  1090.                 sqlQueryObject.addWhereIsNotEmptyCondition(nomeColonnaPlain);
  1091.             }
  1092.             // campo clob, non gestito tramite condizione uguale su oracle
  1093.             /**sqlQueryObject.addWhereCondition(true, true, tabella+"."+nomeColonnaPlain+"='"+CostantiDB.MODIPA_VALUE_UNDEFINED+"'"); // vale anche per security properties*/
  1094.             sqlQueryObject.addWhereCondition(true, true, sqlQueryObject.getWhereLikeCondition(tabella+"."+nomeColonnaPlain, CostantiDB.MODIPA_VALUE_UNDEFINED, true)); // vale anche per security properties
  1095.                        
  1096.             sqlQueryObject.addOrderBy(aliasNomePorta);
  1097.             sqlQueryObject.setANDLogicOperator(true);
  1098.             sqlQueryObject.setSelectDistinct(true);
  1099.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1100.             stmRead = connectionSQL.prepareStatement(sqlQuery);
  1101.             stmRead.setString(1, nomeProprieta);
  1102.             rs = stmRead.executeQuery();

  1103.             while(rs.next()){
  1104.                
  1105.                 long idSecProp = rs.getLong(aliasIdSecProp);
  1106.                 String nome = rs.getString(aliasNomePorta);
  1107.                 long idPorta = rs.getLong(aliasIdPorta);
  1108.                 String prefix = "["+nome+"][idPorta:"+idPorta+"][idSecProp:"+idSecProp+"] '"+nomeProprieta+"' ";
  1109.                
  1110.                 VaultUpdateConfigPlainEnc c = new VaultUpdateConfigPlainEnc();
  1111.                 c.tabella = tabella;
  1112.                 c.nomeColonnaPlain = nomeColonnaPlain;
  1113.                 c.nomeColonnaCodificata = nomeColonnaCodificata;
  1114.                 c.id = idSecProp;
  1115.                 updatePlainEncValue(connectionSQL, rs, ALIAS_PLAIN_VALUE, ALIAS_ENC_VALUE,
  1116.                         prefix, output,
  1117.                         c);
  1118.            
  1119.             }
  1120.            
  1121.         } catch (Exception se) {
  1122.             throw new CoreException("[updateMessageSecurity] failed: " + se.getMessage(),se);
  1123.         } finally {
  1124.             JDBCUtilities.closeResources(rs, stmRead);
  1125.             closeConnection(connectionSQL);
  1126.         }
  1127.     }
  1128.    
  1129.    
  1130.    
  1131.    
  1132.    
  1133.    
  1134.    
  1135.    
  1136.    
  1137.     // GENERIC PROPERTIES
  1138.    
  1139.     private void updateGenericProperties(String tipologia, String nomeProprieta, StringBuilder output) throws CoreException {
  1140.         PreparedStatement stmRead = null;
  1141.         ResultSet rs=null;
  1142.        
  1143.         Connection connectionSQL = null;
  1144.         try {
  1145.             connectionSQL = getConnection();
  1146.            
  1147.             String aliasNomeConfig = "nomeConfig";
  1148.            
  1149.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1150.             sqlQueryObject.addFromTable(CostantiDB.CONFIG_GENERIC_PROPERTY);
  1151.             sqlQueryObject.addFromTable(CostantiDB.CONFIG_GENERIC_PROPERTIES);
  1152.             sqlQueryObject.addSelectAliasField(CostantiDB.CONFIG_GENERIC_PROPERTY, "id", "idProp");
  1153.             sqlQueryObject.addSelectAliasField(CostantiDB.CONFIG_GENERIC_PROPERTIES, CostantiDB.CONFIG_GENERIC_PROPERTY_COLUMN_NOME, aliasNomeConfig);
  1154.             sqlQueryObject.addSelectAliasField(CostantiDB.CONFIG_GENERIC_PROPERTY, CostantiDB.CONFIG_GENERIC_PROPERTY_COLUMN_VALORE, ALIAS_PLAIN_VALUE);
  1155.             sqlQueryObject.addSelectAliasField(CostantiDB.CONFIG_GENERIC_PROPERTY, CostantiDB.CONFIG_GENERIC_PROPERTY_COLUMN_ENC_VALUE, ALIAS_ENC_VALUE);
  1156.             sqlQueryObject.addWhereCondition(CostantiDB.CONFIG_GENERIC_PROPERTIES+CONDITION_JOIN_ID+CostantiDB.CONFIG_GENERIC_PROPERTY+".id_props");
  1157.             sqlQueryObject.addWhereCondition(CostantiDB.CONFIG_GENERIC_PROPERTIES+".tipo = ?");
  1158.            
  1159.             ISQLQueryObject sqlQueryObjectOrName = sqlQueryObject.newSQLQueryObject();
  1160.             sqlQueryObjectOrName.addFromTable(CostantiDB.CONFIG_GENERIC_PROPERTY);
  1161.             sqlQueryObjectOrName.addWhereCondition(CostantiDB.CONFIG_GENERIC_PROPERTY+"."+CostantiDB.CONFIG_GENERIC_PROPERTY_COLUMN_NOME+" = ?");
  1162.             sqlQueryObjectOrName.addWhereLikeCondition(CostantiDB.CONFIG_GENERIC_PROPERTY+"."+CostantiDB.CONFIG_GENERIC_PROPERTY_COLUMN_NOME, CostantiProprieta.KEY_PROPERTIES_CUSTOM_SEPARATOR+nomeProprieta, LikeConfig.endsWith(false)); // puo' contenere l'id del properties
  1163.             sqlQueryObjectOrName.addWhereLikeCondition(CostantiDB.CONFIG_GENERIC_PROPERTY+"."+CostantiDB.CONFIG_GENERIC_PROPERTY_COLUMN_NOME, CostantiProprieta.KEY_PROPERTIES_DEFAULT_SEPARATOR+nomeProprieta, LikeConfig.endsWith(false)); // puo' contenere l'id del properties
  1164.             sqlQueryObjectOrName.setANDLogicOperator(false);
  1165.             sqlQueryObject.addWhereCondition(sqlQueryObjectOrName.createSQLConditions());
  1166.            
  1167.             sqlQueryObject.addWhereIsNotNullCondition(CostantiDB.CONFIG_GENERIC_PROPERTY+"."+CostantiDB.CONFIG_GENERIC_PROPERTY_COLUMN_VALORE);
  1168.             if(!TipiDatabase.ORACLE.equals(this.tipoDatabase)) {
  1169.                 // In oracle le stringhe vuote equivalgono a null
  1170.                 sqlQueryObject.addWhereIsNotEmptyCondition(CostantiDB.CONFIG_GENERIC_PROPERTY+"."+CostantiDB.CONFIG_GENERIC_PROPERTY_COLUMN_VALORE);
  1171.             }
  1172.             sqlQueryObject.addWhereCondition(true, true, CostantiDB.CONFIG_GENERIC_PROPERTY+"."+CostantiDB.CONFIG_GENERIC_PROPERTY_COLUMN_VALORE+"='"+CostantiDB.MODIPA_VALUE_UNDEFINED+"'"); // vale anche per generic properties
  1173.            
  1174.             sqlQueryObject.addOrderBy(aliasNomeConfig);
  1175.             sqlQueryObject.setANDLogicOperator(true);
  1176.             /**sqlQueryObject.setSelectDistinct(true);*/ // Ritornando il field 'id' di CONFIG_GENERIC_PROPERTY il distinct non serve; lasciandolo si ottiene l'erore oracle: failed: ORA-00932: inconsistent datatypes: expected - got CLOB per via della colonna encValue ritornata  
  1177.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1178.             stmRead = connectionSQL.prepareStatement(sqlQuery);
  1179.             stmRead.setString(1, tipologia);
  1180.             stmRead.setString(2, nomeProprieta);
  1181.             rs = stmRead.executeQuery();

  1182.             while(rs.next()){
  1183.                
  1184.                 long id = rs.getLong("idProp");
  1185.                 String nomeConfig = rs.getString(aliasNomeConfig);
  1186.                 String prefix = "[config:"+nomeConfig+"][tipo:"+tipologia+"][idGP:"+id+"] '"+nomeProprieta+"' ";
  1187.                
  1188.                 VaultUpdateConfigPlainEnc c = new VaultUpdateConfigPlainEnc();
  1189.                 c.tabella = CostantiDB.CONFIG_GENERIC_PROPERTY;
  1190.                 c.nomeColonnaPlain = CostantiDB.CONFIG_GENERIC_PROPERTY_COLUMN_VALORE;
  1191.                 c.nomeColonnaCodificata = CostantiDB.CONFIG_GENERIC_PROPERTY_COLUMN_ENC_VALUE;
  1192.                 c.id = id;
  1193.                 updatePlainEncValue(connectionSQL, rs, ALIAS_PLAIN_VALUE, ALIAS_ENC_VALUE,
  1194.                         prefix, output,
  1195.                         c);
  1196.                            
  1197.             }
  1198.            
  1199.         } catch (Exception se) {
  1200.             throw new CoreException("[updateGenericProperties] failed: " + se.getMessage(),se);
  1201.         } finally {
  1202.             JDBCUtilities.closeResources(rs, stmRead);
  1203.             closeConnection(connectionSQL);
  1204.         }
  1205.     }
  1206.    
  1207.    
  1208.    
  1209.    
  1210.     // PROTOCOL PROPERTIES
  1211.    
  1212.     private void updateProtocolProperties(String nomeProprieta, boolean binary, StringBuilder output) throws CoreException {
  1213.         PreparedStatement stmRead = null;
  1214.         ResultSet rs=null;
  1215.        
  1216.         Connection connectionSQL = null;
  1217.         try {
  1218.             connectionSQL = getConnection();
  1219.            
  1220.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1221.             sqlQueryObject.addFromTable(CostantiDB.PROTOCOL_PROPERTIES);
  1222.             sqlQueryObject.addWhereCondition(CostantiDB.PROTOCOL_PROPERTIES_COLUMN_NAME+" = ?");
  1223.             if(binary) {
  1224.                 sqlQueryObject.addWhereIsNotNullCondition(CostantiDB.PROTOCOL_PROPERTIES_COLUMN_VALUE_BINARY);
  1225.             }
  1226.             else {
  1227.                 sqlQueryObject.addWhereIsNotNullCondition(CostantiDB.PROTOCOL_PROPERTIES_COLUMN_VALUE_STRING);
  1228.                 if(!TipiDatabase.ORACLE.equals(this.tipoDatabase)) {
  1229.                     // In oracle le stringhe vuote equivalgono a null
  1230.                     sqlQueryObject.addWhereIsNotEmptyCondition(CostantiDB.PROTOCOL_PROPERTIES_COLUMN_VALUE_STRING);
  1231.                 }
  1232.                 sqlQueryObject.addWhereCondition(true, true, CostantiDB.PROTOCOL_PROPERTIES_COLUMN_VALUE_STRING+"='"+CostantiDB.MODIPA_VALUE_UNDEFINED+"'");
  1233.             }
  1234.             sqlQueryObject.setANDLogicOperator(true);
  1235.             sqlQueryObject.addOrderBy(CostantiDB.PROTOCOL_PROPERTIES_COLUMN_TIPO_PROPRIETARIO);
  1236.             sqlQueryObject.addOrderBy(CostantiDB.PROTOCOL_PROPERTIES_COLUMN_ID_PROPRIETARIO);
  1237.             sqlQueryObject.addOrderBy(CostantiDB.PROTOCOL_PROPERTIES_COLUMN_NAME);
  1238.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1239.             stmRead = connectionSQL.prepareStatement(sqlQuery);
  1240.             stmRead.setString(1, nomeProprieta);
  1241.             rs = stmRead.executeQuery();
  1242.            
  1243.             IJDBCAdapter jdbcAdapter = null;
  1244.             if(binary) {
  1245.                 jdbcAdapter = JDBCAdapterFactory.createJDBCAdapter(this.tipoDatabase);
  1246.             }
  1247.            
  1248.            
  1249.             while(rs.next()){
  1250.                
  1251.                 long id = rs.getLong(CostantiDB.PROTOCOL_PROPERTIES_COLUMN_ID);
  1252.                 long idProprietario = rs.getLong(CostantiDB.PROTOCOL_PROPERTIES_COLUMN_ID_PROPRIETARIO);
  1253.                 String proprietario = rs.getString(CostantiDB.PROTOCOL_PROPERTIES_COLUMN_TIPO_PROPRIETARIO);
  1254.                
  1255.                 String identificativoOggetto = getIdentificativoOggettoProtocolProperties(proprietario,idProprietario, id);
  1256.                
  1257.                 String prefix = "[tipoProprietario:"+proprietario+"][idProprietario:"+idProprietario+"]["+identificativoOggetto+"][idProp:"+id+"] '"+nomeProprieta+"' ";
  1258.                
  1259.                 if(binary) {
  1260.                     VaultUpdateConfigValue c = new VaultUpdateConfigValue();
  1261.                     c.tabella = CostantiDB.PROTOCOL_PROPERTIES;
  1262.                     c.nomeColonna = CostantiDB.PROTOCOL_PROPERTIES_COLUMN_VALUE_BINARY;
  1263.                     c.id = id;
  1264.                     updateBinaryProtocolProperty(jdbcAdapter, connectionSQL, rs, CostantiDB.PROTOCOL_PROPERTIES_COLUMN_VALUE_BINARY,
  1265.                             prefix, output,
  1266.                             c);
  1267.                 }
  1268.                 else {
  1269.                     VaultUpdateConfigPlainEnc c = new VaultUpdateConfigPlainEnc();
  1270.                     c.tabella = CostantiDB.PROTOCOL_PROPERTIES;
  1271.                     c.nomeColonnaPlain = CostantiDB.PROTOCOL_PROPERTIES_COLUMN_VALUE_STRING;
  1272.                     c.nomeColonnaCodificata = CostantiDB.PROTOCOL_PROPERTIES_COLUMN_VALUE_ENCODING_STRING;
  1273.                     c.id = id;
  1274.                     updatePlainEncValue(connectionSQL, rs, CostantiDB.PROTOCOL_PROPERTIES_COLUMN_VALUE_STRING, CostantiDB.PROTOCOL_PROPERTIES_COLUMN_VALUE_ENCODING_STRING,
  1275.                             prefix, output,
  1276.                             c);
  1277.                 }
  1278.            
  1279.             }
  1280.            
  1281.         } catch (Exception se) {
  1282.             throw new CoreException("[updateProtocolProperties] failed: " + se.getMessage(),se);
  1283.         } finally {
  1284.             JDBCUtilities.closeResources(rs, stmRead);
  1285.             closeConnection(connectionSQL);
  1286.         }
  1287.     }
  1288.     private String getIdentificativoOggettoProtocolProperties(String proprietario, long id, long idProp) throws CoreException {
  1289.         PreparedStatement stmRead = null;
  1290.         ResultSet rs=null;
  1291.        
  1292.         Connection connectionSQL = null;
  1293.         try {
  1294.             connectionSQL = getConnection();        
  1295.        
  1296.             ProprietariProtocolProperty proprietarioProtocolProperty = ProprietariProtocolProperty.valueOf(proprietario);
  1297.            
  1298.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1299.             addTableProtocolProperties(sqlQueryObject, proprietarioProtocolProperty);
  1300.             sqlQueryObject.addWhereCondition(CONDITION_WHERE_ID);
  1301.             sqlQueryObject.setANDLogicOperator(true);
  1302.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1303.             stmRead = connectionSQL.prepareStatement(sqlQuery);
  1304.             stmRead.setLong(1, id);
  1305.             rs = stmRead.executeQuery();
  1306.             if(rs.next()){
  1307.                 return readInfoProtocolProperties(connectionSQL, rs, proprietarioProtocolProperty);
  1308.             }
  1309.             throw new CoreException("Entry not found for (idProp:"+idProp+") '"+proprietarioProtocolProperty+"' ("+sqlQuery+" id:"+id+")");
  1310.        
  1311.         } catch (Exception se) {
  1312.             throw new CoreException(se.getMessage(),se);
  1313.         } finally {
  1314.             JDBCUtilities.closeResources(rs, stmRead);
  1315.             closeConnection(connectionSQL);
  1316.         }
  1317.        
  1318.     }
  1319.     private void addTableProtocolProperties(ISQLQueryObject sqlQueryObject, ProprietariProtocolProperty proprietarioProtocolProperty) throws SQLQueryObjectException {
  1320.         switch(proprietarioProtocolProperty) {
  1321.         case ACCORDO_COOPERAZIONE:
  1322.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI_COOPERAZIONE);
  1323.             break;
  1324.         case ACCORDO_SERVIZIO_PARTE_COMUNE:
  1325.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  1326.             break;
  1327.         case ACCORDO_SERVIZIO_PARTE_SPECIFICA:
  1328.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  1329.             break;
  1330.         case AZIONE_ACCORDO:
  1331.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI_AZIONI);
  1332.             break;
  1333.         case OPERATION:
  1334.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE_AZIONI);
  1335.             break;
  1336.         case PORT_TYPE:
  1337.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  1338.             break;
  1339.         case RESOURCE:
  1340.             sqlQueryObject.addFromTable(CostantiDB.API_RESOURCES);
  1341.             break;
  1342.         case FRUITORE:
  1343.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI_FRUITORI);
  1344.             break;
  1345.         case SERVIZIO_APPLICATIVO:
  1346.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI_APPLICATIVI);
  1347.             break;
  1348.         case SOGGETTO:
  1349.             sqlQueryObject.addFromTable(CostantiDB.SOGGETTI);
  1350.             break;
  1351.         default:
  1352.             break;
  1353.     }
  1354.     }
  1355.     private String readInfoProtocolProperties(Connection connectionSQL, ResultSet rs, ProprietariProtocolProperty proprietarioProtocolProperty) throws SQLException, CoreException, DriverRegistroServiziException {
  1356.         switch(proprietarioProtocolProperty) {
  1357.         case ACCORDO_COOPERAZIONE:{
  1358.             return rs.getString("nome");
  1359.         }
  1360.         case ACCORDO_SERVIZIO_PARTE_COMUNE:{
  1361.             String nome = rs.getString("nome");
  1362.             long idSoggetto = rs.getLong(CostantiDB.ACCORDI_COLUMN_ID_REFERENTE_REF);
  1363.             int versione = rs.getInt("versione");
  1364.             IDSoggetto idS = DBUtils.getIdSoggetto(idSoggetto, connectionSQL, this.tipoDatabase);
  1365.             return IDAccordoFactory.getInstance().getUriFromValues(nome, idS, versione);
  1366.         }
  1367.         case ACCORDO_SERVIZIO_PARTE_SPECIFICA:{
  1368.             String tipoServizio = rs.getString("tipo_servizio");
  1369.             String nomeServizio = rs.getString("nome_servizio");
  1370.             int versioneServizio = rs.getInt("versione_servizio");
  1371.             long idSoggetto = rs.getLong(CostantiDB.SERVIZI_COLUMN_ID_SOGGETTO_REF);
  1372.             IDSoggetto idS = DBUtils.getIdSoggetto(idSoggetto, connectionSQL, this.tipoDatabase);
  1373.             return IDServizioFactory.getInstance().getUriFromValues(tipoServizio, nomeServizio, idS, versioneServizio);
  1374.         }
  1375.         case AZIONE_ACCORDO:{
  1376.             String nome = rs.getString("nome");
  1377.             long idAccordo = rs.getLong(CostantiDB.ACCORDI_COLUMN_ID_ACCORDO_REF);
  1378.             return "api:"+readDatiAccordo(connectionSQL, idAccordo) + " azione:"+nome;
  1379.         }
  1380.         case OPERATION:{
  1381.             String nome = rs.getString("nome");
  1382.             long idPortType = rs.getLong("id_port_type");
  1383.             return "api:"+readDatiPT(connectionSQL, idPortType) + " operation:"+nome;
  1384.         }
  1385.         case PORT_TYPE:{
  1386.             String nome = rs.getString("nome");
  1387.             long idAccordo = rs.getLong(CostantiDB.ACCORDI_COLUMN_ID_ACCORDO_REF);
  1388.             return "api:"+readDatiAccordo(connectionSQL, idAccordo) + " portType:"+nome;
  1389.         }
  1390.         case RESOURCE:{
  1391.             String nome = rs.getString("nome");
  1392.             long idAccordo = rs.getLong(CostantiDB.ACCORDI_COLUMN_ID_ACCORDO_REF);
  1393.             return "api:"+readDatiAccordo(connectionSQL, idAccordo) + " resource:"+nome;
  1394.         }
  1395.         case FRUITORE:{
  1396.             long idServizio = rs.getLong("id_servizio");
  1397.             long idSoggetto = rs.getLong(CostantiDB.SERVIZI_COLUMN_ID_SOGGETTO_REF);
  1398.             IDSoggetto idS = DBUtils.getIdSoggetto(idSoggetto, connectionSQL, this.tipoDatabase);
  1399.             return idS.toString() +" -> " + readDatiServizio(connectionSQL, idServizio);
  1400.         }
  1401.         case SERVIZIO_APPLICATIVO:{
  1402.             String nome = rs.getString("nome");
  1403.             long idSoggetto = rs.getLong("id_soggetto");
  1404.             IDSoggetto idS = DBUtils.getIdSoggetto(idSoggetto, connectionSQL, this.tipoDatabase);
  1405.             return idS.toString()+" sa:"+nome;
  1406.         }
  1407.         case SOGGETTO:{
  1408.             String tipoSoggetto = rs.getString("tipo_soggetto");
  1409.             String nomeSoggetto = rs.getString("nome_soggetto");
  1410.             return new IDSoggetto(tipoSoggetto, nomeSoggetto).toString();
  1411.         }
  1412.         default:
  1413.             break;
  1414.         }
  1415.         return null;
  1416.     }
  1417.    
  1418.    
  1419.    
  1420.    
  1421.     // PROPERTIES
  1422.    
  1423.     private void updateProperties(String tabella, String nomeColonna, String nomeColonnaPlain, String nomeColonnaCodificata, StringBuilder output,
  1424.             boolean checkRequestSec, boolean checkResponseCheck) throws CoreException {
  1425.         PreparedStatement stmRead = null;
  1426.         ResultSet rs=null;
  1427.        
  1428.         Connection connectionSQL = null;
  1429.         try {
  1430.             connectionSQL = getConnection();
  1431.            
  1432.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1433.             sqlQueryObject.addFromTable(tabella);
  1434.             sqlQueryObject.addWhereIsNotNullCondition(nomeColonnaCodificata);
  1435.             if(!TipiDatabase.ORACLE.equals(this.tipoDatabase)) {
  1436.                 // In oracle le stringhe vuote equivalgono a null
  1437.                 sqlQueryObject.addWhereIsNotEmptyCondition(nomeColonnaCodificata);
  1438.             }
  1439.             sqlQueryObject.addOrderBy(nomeColonna);
  1440.             sqlQueryObject.setANDLogicOperator(true);
  1441.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1442.             stmRead = connectionSQL.prepareStatement(sqlQuery);
  1443.             rs = stmRead.executeQuery();
  1444.            
  1445.             while(rs.next()){
  1446.                
  1447.                 long idP = rs.getLong("id");
  1448.                 String nomeProprieta = rs.getString(nomeColonna);
  1449.                
  1450.                 if(checkRequestSec || checkResponseCheck) {
  1451.                     long idPorta = rs.getLong(CostantiDB.PORTA_COLUMN_ID_REF);
  1452.                     String tabellaPorta = CostantiDB.PORTE_DELEGATE;
  1453.                     if(CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST.equals(tabella) ||
  1454.                             CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE.equals(tabella)) {
  1455.                         tabellaPorta = CostantiDB.PORTE_APPLICATIVE;
  1456.                     }
  1457.                     String sec = readMessageSecurityPorta(connectionSQL, idPorta, tabellaPorta, checkRequestSec);
  1458.                     if(sec!=null && StringUtils.isNotEmpty(sec) && !"-".equals(sec) && !CostantiDB.SICUREZZA_MESSAGGIO_SCHEMA_DEFAULT.equals(sec)) {
  1459.                         // viene gestita con il processamento specifico delle proprietà fatto in precedenza
  1460.                         continue;
  1461.                     }
  1462.                 }
  1463.                
  1464.                 String identificativoOggetto = getIdentificativoOggettoProperties(tabella,connectionSQL,rs);
  1465.                
  1466.                 String prefix = "[proprietario:"+tabella+"]["+identificativoOggetto+"][idProp:"+idP+"] '"+nomeProprieta+"' ";
  1467.                
  1468.                 VaultUpdateConfigPlainEnc c = new VaultUpdateConfigPlainEnc();
  1469.                 c.tabella = tabella;
  1470.                 c.nomeColonnaPlain = nomeColonnaPlain;
  1471.                 c.nomeColonnaCodificata = nomeColonnaCodificata;
  1472.                 c.id = idP;
  1473.                
  1474.                 updatePlainEncValue(connectionSQL, rs, nomeColonnaPlain, nomeColonnaCodificata,
  1475.                         prefix, output,
  1476.                         c);
  1477.            
  1478.             }
  1479.            
  1480.         } catch (Exception se) {
  1481.             throw new CoreException("[updateProperties-"+tabella+"] failed: " + se.getMessage(),se);
  1482.         } finally {
  1483.             JDBCUtilities.closeResources(rs, stmRead);
  1484.             closeConnection(connectionSQL);
  1485.         }
  1486.     }
  1487.     private String getIdentificativoOggettoProperties(String tabella, Connection connectionSQL, ResultSet rs) throws SQLException, CoreException {
  1488.         if(CostantiDB.SOGGETTI_PROPS.equals(tabella)) {
  1489.             long idSoggetto = rs.getLong("id_soggetto");
  1490.             IDSoggetto idS = DBUtils.getIdSoggetto(idSoggetto, connectionSQL, this.tipoDatabase);
  1491.             return idS.toString();
  1492.         }
  1493.         else if(CostantiDB.SERVIZI_APPLICATIVI_PROPS.equals(tabella)) {
  1494.             long idSA = rs.getLong("id_servizio_applicativo");
  1495.             return readDatiSA(connectionSQL, idSA);
  1496.         }
  1497.         else if(CostantiDB.SYSTEM_PROPERTIES_PDD.equals(tabella)) {
  1498.             return "configurazione-generale";
  1499.         }
  1500.         else if(CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST.equals(tabella) ||
  1501.                 CostantiDB.PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE.equals(tabella) ||
  1502.                 CostantiDB.PORTE_APPLICATIVE_AUTENTICAZIONE_PROP.equals(tabella) ||
  1503.                 CostantiDB.PORTE_APPLICATIVE_AUTORIZZAZIONE_PROP.equals(tabella) ||
  1504.                 CostantiDB.PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI_PROP.equals(tabella) ||
  1505.                 CostantiDB.PORTE_APPLICATIVE_PROP.equals(tabella)) {
  1506.             long idPorta = rs.getLong(CostantiDB.PORTA_COLUMN_ID_REF);
  1507.             return readDatiPortaApplicativa(connectionSQL, idPorta);
  1508.         }
  1509.         else if(CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST.equals(tabella) ||
  1510.                 CostantiDB.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE.equals(tabella) ||
  1511.                 CostantiDB.PORTE_DELEGATE_AUTENTICAZIONE_PROP.equals(tabella) ||
  1512.                 CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_PROP.equals(tabella) ||
  1513.                 CostantiDB.PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_PROP.equals(tabella) ||
  1514.                 CostantiDB.PORTE_DELEGATE_PROP.equals(tabella)) {
  1515.             long idPorta = rs.getLong(CostantiDB.PORTA_COLUMN_ID_REF);
  1516.             return readDatiPortaDelegata(connectionSQL, idPorta);
  1517.         }
  1518.         return null;
  1519.        
  1520.     }
  1521.    
  1522.    
  1523.    
  1524.     // READ UTILS
  1525.        
  1526.     private String readDatiAccordo(Connection connectionSQL, long idAccordo) throws CoreException {
  1527.         PreparedStatement stmReadInternal = null;
  1528.         ResultSet rsInternal=null;
  1529.         try {
  1530.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1531.             sqlQueryObject.addFromTable(CostantiDB.ACCORDI);
  1532.             sqlQueryObject.addWhereCondition(CONDITION_WHERE_ID);
  1533.             sqlQueryObject.setANDLogicOperator(true);
  1534.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1535.             stmReadInternal = connectionSQL.prepareStatement(sqlQuery);
  1536.             stmReadInternal.setLong(1, idAccordo);
  1537.             rsInternal = stmReadInternal.executeQuery();
  1538.             String nome = rsInternal.getString("nome");
  1539.             if(rsInternal.next()) {
  1540.                 long idSoggetto = rsInternal.getLong(CostantiDB.ACCORDI_COLUMN_ID_REFERENTE_REF);
  1541.                 int versione = rsInternal.getInt("versione");
  1542.                 IDSoggetto idS = DBUtils.getIdSoggetto(idSoggetto, connectionSQL, this.tipoDatabase);
  1543.                 return IDAccordoFactory.getInstance().getUriFromValues(nome, idS, versione);
  1544.             }
  1545.             return null;
  1546.         } catch (Exception se) {
  1547.             throw new CoreException(se.getMessage(),se);
  1548.         } finally {
  1549.             JDBCUtilities.closeResources(rsInternal, stmReadInternal);
  1550.         }
  1551.     }
  1552.     private String readDatiPT(Connection connectionSQL, long idPortType) throws CoreException {
  1553.         PreparedStatement stmReadInternal = null;
  1554.         ResultSet rsInternal=null;
  1555.         try {
  1556.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1557.             sqlQueryObject.addFromTable(CostantiDB.PORT_TYPE);
  1558.             sqlQueryObject.addWhereCondition(CONDITION_WHERE_ID);
  1559.             sqlQueryObject.setANDLogicOperator(true);
  1560.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1561.             stmReadInternal = connectionSQL.prepareStatement(sqlQuery);
  1562.             stmReadInternal.setLong(1, idPortType);
  1563.             rsInternal = stmReadInternal.executeQuery();
  1564.             if(rsInternal.next()) {
  1565.                 String nome = rsInternal.getString("nome");
  1566.                 long idAccordo = rsInternal.getLong(CostantiDB.ACCORDI_COLUMN_ID_ACCORDO_REF);
  1567.                 return readDatiAccordo(connectionSQL, idAccordo) + " portType:"+nome;
  1568.             }
  1569.             return null;
  1570.         } catch (Exception se) {
  1571.             throw new CoreException(se.getMessage(),se);
  1572.         } finally {
  1573.             JDBCUtilities.closeResources(rsInternal, stmReadInternal);
  1574.         }
  1575.     }
  1576.     private String readDatiServizio(Connection connectionSQL, long idServizio) throws CoreException {
  1577.         PreparedStatement stmReadInternal = null;
  1578.         ResultSet rsInternal=null;
  1579.         try {
  1580.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1581.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI);
  1582.             sqlQueryObject.addWhereCondition(CONDITION_WHERE_ID);
  1583.             sqlQueryObject.setANDLogicOperator(true);
  1584.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1585.             stmReadInternal = connectionSQL.prepareStatement(sqlQuery);
  1586.             stmReadInternal.setLong(1, idServizio);
  1587.             rsInternal = stmReadInternal.executeQuery();
  1588.             if(rsInternal.next()) {
  1589.                 String tipoServizio = rsInternal.getString("tipo_servizio");
  1590.                 String nomeServizio = rsInternal.getString("nome_servizio");
  1591.                 int versioneServizio = rsInternal.getInt("versione_servizio");
  1592.                 long idSoggetto = rsInternal.getLong(CostantiDB.SERVIZI_COLUMN_ID_SOGGETTO_REF);
  1593.                 IDSoggetto idS = DBUtils.getIdSoggetto(idSoggetto, connectionSQL, this.tipoDatabase);
  1594.                 return IDServizioFactory.getInstance().getUriFromValues(tipoServizio, nomeServizio, idS, versioneServizio);
  1595.             }
  1596.             return null;
  1597.         } catch (Exception se) {
  1598.             throw new CoreException(se.getMessage(),se);
  1599.         } finally {
  1600.             JDBCUtilities.closeResources(rsInternal, stmReadInternal);
  1601.         }
  1602.     }
  1603.     private String readDatiSA(Connection connectionSQL, long idServizioApplicativo) throws CoreException {
  1604.         PreparedStatement stmReadInternal = null;
  1605.         ResultSet rsInternal=null;
  1606.         try {
  1607.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1608.             sqlQueryObject.addFromTable(CostantiDB.SERVIZI_APPLICATIVI);
  1609.             sqlQueryObject.addWhereCondition(CONDITION_WHERE_ID);
  1610.             sqlQueryObject.setANDLogicOperator(true);
  1611.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1612.             stmReadInternal = connectionSQL.prepareStatement(sqlQuery);
  1613.             stmReadInternal.setLong(1, idServizioApplicativo);
  1614.             rsInternal = stmReadInternal.executeQuery();
  1615.             if(rsInternal.next()) {
  1616.                 String nome = rsInternal.getString("nome");
  1617.                 long idSoggetto = rsInternal.getLong(CostantiDB.SERVIZI_APPLICATIVI_COLUMN_ID_SOGGETTO);
  1618.                 IDSoggetto idS = DBUtils.getIdSoggetto(idSoggetto, connectionSQL, this.tipoDatabase);
  1619.                 return idS.toString()+" sa:"+nome;
  1620.             }
  1621.             return null;
  1622.         } catch (Exception se) {
  1623.             throw new CoreException(se.getMessage(),se);
  1624.         } finally {
  1625.             JDBCUtilities.closeResources(rsInternal, stmReadInternal);
  1626.         }
  1627.     }
  1628.     private String readDatiPortaDelegata(Connection connectionSQL, long idPorta) throws CoreException {
  1629.         return readDatiPorta(connectionSQL, idPorta, CostantiDB.PORTE_DELEGATE) ;
  1630.     }
  1631.     private String readDatiPortaApplicativa(Connection connectionSQL, long idPorta) throws CoreException {
  1632.         return readDatiPorta(connectionSQL, idPorta, CostantiDB.PORTE_APPLICATIVE) ;
  1633.     }
  1634.     private String readDatiPorta(Connection connectionSQL, long idPorta, String tabella) throws CoreException {
  1635.         PreparedStatement stmReadInternal = null;
  1636.         ResultSet rsInternal=null;
  1637.         try {
  1638.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1639.             sqlQueryObject.addFromTable(tabella);
  1640.             sqlQueryObject.addWhereCondition(CONDITION_WHERE_ID);
  1641.             sqlQueryObject.setANDLogicOperator(true);
  1642.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1643.             stmReadInternal = connectionSQL.prepareStatement(sqlQuery);
  1644.             stmReadInternal.setLong(1, idPorta);
  1645.             rsInternal = stmReadInternal.executeQuery();
  1646.             if(rsInternal.next()) {
  1647.                 return rsInternal.getString("nome_porta");
  1648.             }
  1649.             return null;
  1650.         } catch (Exception se) {
  1651.             throw new CoreException(se.getMessage(),se);
  1652.         } finally {
  1653.             JDBCUtilities.closeResources(rsInternal, stmReadInternal);
  1654.         }
  1655.     }
  1656.     private String readMessageSecurityPorta(Connection connectionSQL, long idPorta, String tabella, boolean request) throws CoreException {
  1657.         PreparedStatement stmReadInternal = null;
  1658.         ResultSet rsInternal=null;
  1659.         try {
  1660.             ISQLQueryObject sqlQueryObject = SQLObjectFactory.createSQLQueryObject(this.tipoDatabase);
  1661.             sqlQueryObject.addFromTable(tabella);
  1662.             sqlQueryObject.addWhereCondition(CONDITION_WHERE_ID);
  1663.             sqlQueryObject.setANDLogicOperator(true);
  1664.             String sqlQuery = sqlQueryObject.createSQLQuery();
  1665.             stmReadInternal = connectionSQL.prepareStatement(sqlQuery);
  1666.             stmReadInternal.setLong(1, idPorta);
  1667.             rsInternal = stmReadInternal.executeQuery();
  1668.             if(rsInternal.next()) {
  1669.                 return rsInternal.getString(request ? "security_request_mode" : "security_response_mode");
  1670.             }
  1671.             return null;
  1672.         } catch (Exception se) {
  1673.             throw new CoreException(se.getMessage(),se);
  1674.         } finally {
  1675.             JDBCUtilities.closeResources(rsInternal, stmReadInternal);
  1676.         }
  1677.     }
  1678. }

  1679. class VaultUpdateConfigPlainEnc{
  1680.    
  1681.     String tabella;
  1682.     String nomeColonnaPlain;
  1683.     String nomeColonnaCodificata;
  1684.     long id;
  1685.    
  1686. }

  1687. class VaultUpdateConfigValue{
  1688.    
  1689.     String tabella;
  1690.     String nomeColonna;
  1691.     long id;
  1692.    
  1693. }