ConfigurazioneSistema.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.core.jmx;

  21. import java.security.Provider;
  22. import java.security.Security;
  23. import java.sql.Connection;
  24. import java.sql.PreparedStatement;
  25. import java.sql.ResultSet;
  26. import java.sql.SQLException;
  27. import java.util.ArrayList;
  28. import java.util.Arrays;
  29. import java.util.Collections;
  30. import java.util.Enumeration;
  31. import java.util.HashMap;
  32. import java.util.Iterator;
  33. import java.util.List;
  34. import java.util.Map;
  35. import java.util.Properties;
  36. import java.util.Set;
  37. import java.util.concurrent.Callable;

  38. import javax.crypto.Cipher;
  39. import javax.management.Attribute;
  40. import javax.management.AttributeList;
  41. import javax.management.AttributeNotFoundException;
  42. import javax.management.DynamicMBean;
  43. import javax.management.InvalidAttributeValueException;
  44. import javax.management.JMException;
  45. import javax.management.MBeanAttributeInfo;
  46. import javax.management.MBeanConstructorInfo;
  47. import javax.management.MBeanException;
  48. import javax.management.MBeanInfo;
  49. import javax.management.MBeanOperationInfo;
  50. import javax.management.MBeanParameterInfo;
  51. import javax.management.NotificationBroadcasterSupport;
  52. import javax.management.ReflectionException;

  53. import org.openspcoop2.core.byok.BYOKWrappedValue;
  54. import org.openspcoop2.core.commons.CoreException;
  55. import org.openspcoop2.core.config.GenericProperties;
  56. import org.openspcoop2.core.config.Property;
  57. import org.openspcoop2.core.config.driver.DriverConfigurazioneNotFound;
  58. import org.openspcoop2.core.constants.CostantiDB;
  59. import org.openspcoop2.core.id.IDSoggetto;
  60. import org.openspcoop2.message.OpenSPCoop2MessageFactory;
  61. import org.openspcoop2.pdd.config.ConfigurazionePdDManager;
  62. import org.openspcoop2.pdd.config.DBManager;
  63. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  64. import org.openspcoop2.pdd.config.Resource;
  65. import org.openspcoop2.pdd.core.CostantiPdD;
  66. import org.openspcoop2.pdd.core.byok.BYOKMapProperties;
  67. import org.openspcoop2.pdd.core.byok.DriverBYOK;
  68. import org.openspcoop2.pdd.core.byok.DriverBYOKUtilities;
  69. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  70. import org.openspcoop2.pdd.logger.filetrace.FileTraceConfig;
  71. import org.openspcoop2.pdd.logger.filetrace.FileTraceGovWayState;
  72. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  73. import org.openspcoop2.protocol.manifest.Context;
  74. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  75. import org.openspcoop2.utils.Utilities;
  76. import org.openspcoop2.utils.UtilsException;
  77. import org.openspcoop2.utils.UtilsMultiException;
  78. import org.openspcoop2.utils.certificate.hsm.HSMManager;
  79. import org.openspcoop2.utils.certificate.ocsp.OCSPManager;
  80. import org.openspcoop2.utils.datasource.DataSourceFactory;
  81. import org.openspcoop2.utils.date.DateUtils;
  82. import org.openspcoop2.utils.io.Base64Utilities;
  83. import org.openspcoop2.utils.io.HexBinaryUtilities;
  84. import org.openspcoop2.utils.jdbc.JDBCUtilities;
  85. import org.openspcoop2.utils.properties.MapProperties;
  86. import org.openspcoop2.utils.resources.CharsetUtilities;
  87. import org.openspcoop2.utils.resources.MapReader;
  88. import org.openspcoop2.utils.transport.http.SSLConstants;
  89. import org.openspcoop2.utils.transport.http.SSLUtilities;
  90. import org.slf4j.Logger;

  91. import com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl;


  92. /**
  93.  * Implementazione JMX per la gestione della Configurazione di Sistema della Porta
  94.  *  
  95.  * @author Poli Andrea (apoli@link.it)
  96.  * @author $Author$
  97.  * @version $Rev$, $Date$
  98.  */
  99. public class ConfigurazioneSistema extends NotificationBroadcasterSupport implements DynamicMBean {

  100.     private static final String LUNGHEZZA_PARAMETRI_ERRORE = "] Lunghezza parametri non corretta: ";
  101.     private static final String CHIAVE = "Chiave";
  102.    
  103.     /** Nomi metodi */
  104.     public static final String VERSIONE_PDD = "getVersionePdD";
  105.     public static final String VERSIONE_BASE_DATI = "getVersioneBaseDati";
  106.     public static final String VERSIONE_JAVA = "getVersioneJava";
  107.     public static final String VENDOR_JAVA = "getVendorJava";
  108.     public static final String TIPO_DATABASE = "getTipoDatabase";  
  109.     public static final String INFORMAZIONI_DATABASE = "getInformazioniDatabase";
  110.     public static final String INFORMAZIONI_SSL = "getInformazioniSSL";
  111.     public static final String INFORMAZIONI_COMPLETE_SSL = "getInformazioniCompleteSSL";
  112.     public static final String INFORMAZIONI_CRYPTOGRAPHY_KEY_LENGTH = "getInformazioniCryptographyKeyLength";
  113.     public static final String INFORMAZIONI_CHARSET = "getInformazioniCharset";
  114.     public static final String INFORMAZIONI_INTERNAZIONALIZZAZIONE = "getInformazioniInternazionalizzazione";
  115.     public static final String INFORMAZIONI_COMPLETE_INTERNAZIONALIZZAZIONE = "getInformazioniCompleteInternazionalizzazione";
  116.     public static final String INFORMAZIONI_TIMEZONE= "getInformazioniTimeZone";
  117.     public static final String INFORMAZIONI_COMPLETE_TIMEZONE = "getInformazioniCompleteTimeZone";
  118.     public static final String INFORMAZIONI_PROPRIETA_JAVA_NETWORKING= "getInformazioniProprietaJavaNetworking";
  119.     public static final String INFORMAZIONI_COMPLETE_PROPRIETA_JAVA_NETWORKING= "getInformazioniCompleteProprietaJavaNetworking";
  120.     public static final String INFORMAZIONI_PROPRIETA_JAVA_ALTRO= "getInformazioniProprietaJavaAltro";
  121.     public static final String INFORMAZIONI_PROPRIETA_SISTEMA= "getInformazioniProprietaSistema";
  122.     public static final String MESSAGE_FACTORY = "getMessageFactory";
  123.     public static final String DIRECTORY_CONFIGURAZIONE = "getDirectoryConfigurazione";
  124.     public static final String PROTOCOLS = "getPluginProtocols";
  125.     public static final String INFORMAZIONI_INSTALLAZIONE = "getInformazioniInstallazione";
  126.     public static final String FILE_TRACE_CONFIG = "getFileTrace";
  127.     public static final String FILE_TRACE_UPDATE = "updateFileTrace";
  128.     public static final String BYOK_WRAP = "wrapKey";
  129.     public static final String BYOK_WRAP_BASE64 = "wrapBase64Key";
  130.     public static final String BYOK_WRAP_HEX = "wrapHexKey";
  131.     public static final String BYOK_UNWRAP = "unwrapKey";
  132.     public static final String BYOK_UNWRAP_BASE64 = "unwrapKeyAsBase64";
  133.     public static final String BYOK_UNWRAP_HEX = "unwrapKeyAsHex";
  134.    
  135.     private static boolean includePassword = false;
  136.     public static boolean isIncludePassword() {
  137.         return includePassword;
  138.     }
  139.     public static void setIncludePassword(boolean includePassword) {
  140.         ConfigurazioneSistema.includePassword = includePassword;
  141.     }

  142.     /** getAttribute */
  143.     @Override
  144.     public Object getAttribute(String attributeName) throws AttributeNotFoundException,MBeanException,ReflectionException{

  145.         if( (attributeName==null) || (attributeName.equals("")) )
  146.             throw new IllegalArgumentException("Il nome dell'attributo e' nullo o vuoto");

  147.         throw new AttributeNotFoundException("Attributo "+attributeName+" non trovato");
  148.     }

  149.     /** getAttributes */
  150.     @Override
  151.     public AttributeList getAttributes(String [] attributesNames){

  152.         if(attributesNames==null)
  153.             throw new IllegalArgumentException("Array nullo");

  154.         AttributeList list = new AttributeList();
  155.         for (int i=0; i<attributesNames.length; i++){
  156.             try{
  157.                 list.add(new Attribute(attributesNames[i],getAttribute(attributesNames[i])));
  158.             }catch(JMException ex){
  159.                 // ignore
  160.             }
  161.         }
  162.         return list;
  163.     }

  164.     /** setAttribute */
  165.     @Override
  166.     public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException{

  167.         if( attribute==null )
  168.             throw new IllegalArgumentException("Il nome dell'attributo e' nullo");

  169.         try{

  170.             throw new AttributeNotFoundException("Attributo "+attribute.getName()+" non trovato");

  171.         }catch(ClassCastException ce){
  172.             throw new InvalidAttributeValueException("il tipo "+attribute.getValue().getClass()+" dell'attributo "+attribute.getName()+" non e' valido");
  173.         }catch(JMException j){
  174.             throw new MBeanException(j);
  175.         }

  176.     }

  177.     /** setAttributes */
  178.     @Override
  179.     public AttributeList setAttributes(AttributeList list){

  180.         if(list==null)
  181.             throw new IllegalArgumentException("Lista degli attributi e' nulla");

  182.         AttributeList ret = new AttributeList();
  183.         Iterator<?> it = ret.iterator();

  184.         while(it.hasNext()){
  185.             try{
  186.                 Attribute attribute = (Attribute) it.next();
  187.                 setAttribute(attribute);
  188.                 ret.add(attribute);
  189.             }catch(JMException ex){
  190.                 // ignore
  191.             }
  192.         }

  193.         return ret;

  194.     }

  195.     /** invoke */
  196.     @Override
  197.     public Object invoke(String actionName, Object[]params, String[]signature) throws MBeanException,ReflectionException{

  198.         if( (actionName==null) || (actionName.equals("")) )
  199.             throw new IllegalArgumentException("Nessuna operazione definita");

  200.         if(actionName.equals(VERSIONE_PDD)){
  201.             return this.getVersionePdD();
  202.         }

  203.         else if(actionName.equals(VERSIONE_BASE_DATI)){
  204.             return this.getVersioneBaseDati();
  205.         }

  206.         else if(actionName.equals(VERSIONE_JAVA)){
  207.             return this.getVersioneJava();
  208.         }
  209.        
  210.         else if(actionName.equals(VENDOR_JAVA)){
  211.             return this.getVendorJava();
  212.         }

  213.         else if(actionName.equals(TIPO_DATABASE)){
  214.             return this.getTipoDatabase();
  215.         }

  216.         else if(actionName.equals(INFORMAZIONI_DATABASE)){
  217.             return this.getInformazioniDatabase();
  218.         }
  219.        
  220.         else if(actionName.equals(INFORMAZIONI_SSL)){
  221.             return this.getInformazioniSSL(false,false,false,false);
  222.         }
  223.        
  224.         else if(actionName.equals(INFORMAZIONI_COMPLETE_SSL)){
  225.             return this.getInformazioniSSL(true,true,true,true);
  226.         }
  227.        
  228.         else if(actionName.equals(INFORMAZIONI_CRYPTOGRAPHY_KEY_LENGTH)){
  229.             return this.getInformazioniCryptographyKeyLength();
  230.         }
  231.        
  232.         else if(actionName.equals(INFORMAZIONI_CHARSET)){
  233.             return this.getInformazioniCharset();
  234.         }
  235.        
  236.         else if(actionName.equals(INFORMAZIONI_INTERNAZIONALIZZAZIONE)){
  237.             return this.getInformazioniInternazionalizzazione(false);
  238.         }
  239.        
  240.         else if(actionName.equals(INFORMAZIONI_COMPLETE_INTERNAZIONALIZZAZIONE)){
  241.             return this.getInformazioniInternazionalizzazione(true);
  242.         }
  243.        
  244.         else if(actionName.equals(INFORMAZIONI_TIMEZONE)){
  245.             return this.getInformazioniTimeZone(false);
  246.         }
  247.        
  248.         else if(actionName.equals(INFORMAZIONI_COMPLETE_TIMEZONE)){
  249.             return this.getInformazioniTimeZone(true);
  250.         }
  251.        
  252.         else if(actionName.equals(INFORMAZIONI_PROPRIETA_JAVA_NETWORKING)){
  253.             return this.getInformazioniProprietaJava(false, true,false,ConfigurazioneSistema.includePassword);
  254.         }
  255.        
  256.         else if(actionName.equals(INFORMAZIONI_COMPLETE_PROPRIETA_JAVA_NETWORKING)){
  257.             return this.getInformazioniProprietaJava(true, true,false,ConfigurazioneSistema.includePassword);
  258.         }
  259.        
  260.         else if(actionName.equals(INFORMAZIONI_PROPRIETA_JAVA_ALTRO)){
  261.             return this.getInformazioniProprietaJava(true, false, true,ConfigurazioneSistema.includePassword);
  262.         }
  263.        
  264.         else if(actionName.equals(INFORMAZIONI_PROPRIETA_SISTEMA)){
  265.             return this.getInformazioniProprietaSistema();
  266.         }
  267.        
  268.         else if(actionName.equals(MESSAGE_FACTORY)){
  269.             return this.getMessageFactory();
  270.         }
  271.        
  272.         else if(actionName.equals(DIRECTORY_CONFIGURAZIONE)){
  273.             return this.getDirectoryConfigurazione();
  274.         }
  275.        
  276.         else if(actionName.equals(PROTOCOLS)){
  277.             return this.getPluginProtocols();
  278.         }
  279.        
  280.         else if(actionName.equals(INFORMAZIONI_INSTALLAZIONE)){
  281.             return this.getInformazioniInstallazione();
  282.         }
  283.        
  284.         else if(actionName.equals(FILE_TRACE_CONFIG)){
  285.             return this.getFileTrace();
  286.         }
  287.        
  288.         else if(actionName.equals(FILE_TRACE_UPDATE)){
  289.             return this.updateFileTrace();
  290.         }
  291.        
  292.         else if(actionName.equals(BYOK_UNWRAP)){
  293.            
  294.             if(params.length != 1)
  295.                 throw new MBeanException(new Exception("["+BYOK_UNWRAP+LUNGHEZZA_PARAMETRI_ERRORE+params.length));
  296.            
  297.             String param1 = null;
  298.             if(params[0]!=null && !"".equals(params[0])){
  299.                 param1 = (String)params[0];
  300.             }
  301.            
  302.             return this.byokUnwrap(param1);
  303.         }
  304.        
  305.         else if(actionName.equals(BYOK_UNWRAP_BASE64)){
  306.                    
  307.             if(params.length != 1)
  308.                 throw new MBeanException(new Exception("["+BYOK_UNWRAP_BASE64+LUNGHEZZA_PARAMETRI_ERRORE+params.length));
  309.            
  310.             String param1 = null;
  311.             if(params[0]!=null && !"".equals(params[0])){
  312.                 param1 = (String)params[0];
  313.             }
  314.            
  315.             return this.byokBase64Unwrap(param1);
  316.         }
  317.                
  318.         else if(actionName.equals(BYOK_UNWRAP_HEX)){
  319.            
  320.             if(params.length != 1)
  321.                 throw new MBeanException(new Exception("["+BYOK_UNWRAP_HEX+LUNGHEZZA_PARAMETRI_ERRORE+params.length));
  322.            
  323.             String param1 = null;
  324.             if(params[0]!=null && !"".equals(params[0])){
  325.                 param1 = (String)params[0];
  326.             }
  327.            
  328.             return this.byokHexUnwrap(param1);
  329.         }
  330.        
  331.         else if(actionName.equals(BYOK_WRAP)){
  332.            
  333.             if(params.length != 1)
  334.                 throw new MBeanException(new Exception("["+BYOK_WRAP+LUNGHEZZA_PARAMETRI_ERRORE+params.length));
  335.            
  336.             String param1 = null;
  337.             if(params[0]!=null && !"".equals(params[0])){
  338.                 param1 = (String)params[0];
  339.             }
  340.            
  341.             return this.byokWrap(param1);
  342.         }
  343.        
  344.         else if(actionName.equals(BYOK_WRAP_BASE64)){
  345.            
  346.             if(params.length != 1)
  347.                 throw new MBeanException(new Exception("["+BYOK_WRAP_BASE64+LUNGHEZZA_PARAMETRI_ERRORE+params.length));
  348.            
  349.             String param1 = null;
  350.             if(params[0]!=null && !"".equals(params[0])){
  351.                 param1 = (String)params[0];
  352.             }
  353.            
  354.             return this.byokWrapBase64Key(param1);
  355.         }
  356.        
  357.         else if(actionName.equals(BYOK_WRAP_HEX)){
  358.            
  359.             if(params.length != 1)
  360.                 throw new MBeanException(new Exception("["+BYOK_WRAP_HEX+LUNGHEZZA_PARAMETRI_ERRORE+params.length));
  361.            
  362.             String param1 = null;
  363.             if(params[0]!=null && !"".equals(params[0])){
  364.                 param1 = (String)params[0];
  365.             }
  366.            
  367.             return this.byokWrapHexKey(param1);
  368.         }

  369.         throw new UnsupportedOperationException("Operazione "+actionName+" sconosciuta");
  370.     }

  371.     /* MBean info */
  372.     @Override
  373.     public MBeanInfo getMBeanInfo(){

  374.         // Descrizione della classe nel MBean
  375.         String className = this.getClass().getName();
  376.         String description = "Configurazione di Sistema ("+this.openspcoopProperties.getVersione()+")";

  377.         // VERSIONE_PDD
  378.         MBeanOperationInfo versionePddOp = new MBeanOperationInfo(VERSIONE_PDD,"Visualizza la versione di GovWay",
  379.                         null,
  380.                         String.class.getName(),
  381.                         MBeanOperationInfo.ACTION);
  382.        
  383.         // VERSIONE_BASE_DATI
  384.         MBeanOperationInfo versioneBaseDatiOp = new MBeanOperationInfo(VERSIONE_BASE_DATI,"Visualizza la versione della base dati",
  385.                         null,
  386.                         String.class.getName(),
  387.                         MBeanOperationInfo.ACTION);
  388.        
  389.         // VERSIONE_JAVA
  390.         MBeanOperationInfo versioneJavaOp = new MBeanOperationInfo(VERSIONE_JAVA,"Visualizza la versione di Java",
  391.                         null,
  392.                         String.class.getName(),
  393.                         MBeanOperationInfo.ACTION);
  394.        
  395.         // VENDOR_JAVA
  396.         MBeanOperationInfo vendorJavaOp = new MBeanOperationInfo(VENDOR_JAVA,"Visualizza le informazioni sul vendor di Java",
  397.                         null,
  398.                         String.class.getName(),
  399.                         MBeanOperationInfo.ACTION);
  400.        
  401.         // TIPO_DATABASE
  402.         MBeanOperationInfo versioneTipoDatabaseOp = new MBeanOperationInfo(TIPO_DATABASE,"Visualizza il tipo di Database",
  403.                         null,
  404.                         String.class.getName(),
  405.                         MBeanOperationInfo.ACTION);
  406.        
  407.         // INFORMAZIONI_DATABASE
  408.         MBeanOperationInfo informazioniDatabaseOp = new MBeanOperationInfo(INFORMAZIONI_DATABASE,"Visualizza le informazioni sul Database",
  409.                         null,
  410.                         String.class.getName(),
  411.                         MBeanOperationInfo.ACTION);
  412.        
  413.         // INFORMAZIONI_SSL
  414.         MBeanOperationInfo informazioniSSLOp = new MBeanOperationInfo(INFORMAZIONI_SSL,"Visualizza le informazioni sulle connessioni SSL",
  415.                         null,
  416.                         String.class.getName(),
  417.                         MBeanOperationInfo.ACTION);
  418.        
  419.         // INFORMAZIONI_COMPLETE_SSL
  420.         MBeanOperationInfo informazioniCompleteSSLOp = new MBeanOperationInfo(INFORMAZIONI_COMPLETE_SSL,"Visualizza le informazioni complete di algoritmi sulle connessioni SSL",
  421.                         null,
  422.                         String.class.getName(),
  423.                         MBeanOperationInfo.ACTION);
  424.        
  425.         // INFORMAZIONI_CRYPTOGRAPHY_KEY_LENGTH
  426.         MBeanOperationInfo informazioniCRYPTOOp = new MBeanOperationInfo(INFORMAZIONI_CRYPTOGRAPHY_KEY_LENGTH,"Visualizza le informazioni sulla lunghezza delle chiavi di cifratura",
  427.                         null,
  428.                         String.class.getName(),
  429.                         MBeanOperationInfo.ACTION);
  430.        
  431.         // INFORMAZIONI_CHARSET
  432.         MBeanOperationInfo informazioniCHARSETOp = new MBeanOperationInfo(INFORMAZIONI_CHARSET,"Visualizza le informazioni sul Charset",
  433.                         null,
  434.                         String.class.getName(),
  435.                         MBeanOperationInfo.ACTION);
  436.        
  437.         // INFORMAZIONI_INTERNAZIONALIZZAZIONE
  438.         MBeanOperationInfo informazioniINTERNAZIONALIZZAZIONEOp = new MBeanOperationInfo(INFORMAZIONI_INTERNAZIONALIZZAZIONE,"Visualizza le informazioni sull'internazionalizzazione",
  439.                         null,
  440.                         String.class.getName(),
  441.                         MBeanOperationInfo.ACTION);
  442.        
  443.         // INFORMAZIONI_COMPLETE_INTERNAZIONALIZZAZIONE
  444.         MBeanOperationInfo informazioniCompleteINTERNAZIONALIZZAZIONEOp = new MBeanOperationInfo(INFORMAZIONI_COMPLETE_INTERNAZIONALIZZAZIONE,"Visualizza le informazioni complete sull'internazionalizzazione",
  445.                         null,
  446.                         String.class.getName(),
  447.                         MBeanOperationInfo.ACTION);
  448.        
  449.         // INFORMAZIONI_TIMEZONE
  450.         MBeanOperationInfo informazioniTIMEZONEOp = new MBeanOperationInfo(INFORMAZIONI_TIMEZONE,"Visualizza le informazioni sul TimeZone",
  451.                         null,
  452.                         String.class.getName(),
  453.                         MBeanOperationInfo.ACTION);
  454.        
  455.         // INFORMAZIONI_COMPLETE_TIMEZONE
  456.         MBeanOperationInfo informazioniCompleteTIMEZONEOp = new MBeanOperationInfo(INFORMAZIONI_COMPLETE_TIMEZONE,"Visualizza le informazioni complete sul TimeZone",
  457.                         null,
  458.                         String.class.getName(),
  459.                         MBeanOperationInfo.ACTION);
  460.        
  461.         // INFORMAZIONI_PROPRIETA_JAVA_NETWORKING
  462.         MBeanOperationInfo informazioniProprietaJavaNetworkingOp = new MBeanOperationInfo(INFORMAZIONI_PROPRIETA_JAVA_NETWORKING,"Visualizza le proprietà java riguardanti il networking",
  463.                         null,
  464.                         String.class.getName(),
  465.                         MBeanOperationInfo.ACTION);
  466.        
  467.         // INFORMAZIONI_COMPLETE_PROPRIETA_JAVA_NETWORKING
  468.         MBeanOperationInfo informazioniCompleteProprietaJavaNetworkingOp = new MBeanOperationInfo(INFORMAZIONI_COMPLETE_PROPRIETA_JAVA_NETWORKING,"Visualizza tutte le proprietà java riguardanti il networking",
  469.                         null,
  470.                         String.class.getName(),
  471.                         MBeanOperationInfo.ACTION);
  472.        
  473.         // INFORMAZIONI_PROPRIETA_JAVA_ALTRO
  474.         MBeanOperationInfo informazioniProprietaJavaAltroOp = new MBeanOperationInfo(INFORMAZIONI_PROPRIETA_JAVA_ALTRO,"Visualizza le proprietà java escluse quelle riguardanti il networking",
  475.                         null,
  476.                         String.class.getName(),
  477.                         MBeanOperationInfo.ACTION);
  478.        
  479.         // INFORMAZIONI_PROPRIETA_SISTEMA
  480.         MBeanOperationInfo informazioniProprietaSistemaOp = new MBeanOperationInfo(INFORMAZIONI_PROPRIETA_SISTEMA,"Visualizza le proprietà di sistema",
  481.                         null,
  482.                         String.class.getName(),
  483.                         MBeanOperationInfo.ACTION);

  484.         // MESSAGE_FACTORY
  485.         MBeanOperationInfo messageFactoryOp = new MBeanOperationInfo(MESSAGE_FACTORY,"Visualizza la MessageFactory utilizzata dal prodotto",
  486.                         null,
  487.                         String.class.getName(),
  488.                         MBeanOperationInfo.ACTION);
  489.        
  490.         // DIRECTORY_CONFIGURAZIONE
  491.         MBeanOperationInfo confDirectoryOp = new MBeanOperationInfo(DIRECTORY_CONFIGURAZIONE,"Visualizza la directory di configurazione",
  492.                         null,
  493.                         String.class.getName(),
  494.                         MBeanOperationInfo.ACTION);
  495.                
  496.         // PROTOCOLS
  497.         MBeanOperationInfo protocolsOp = new MBeanOperationInfo(PROTOCOLS,"Visualizza i protocolli installati",
  498.                         null,
  499.                         String.class.getName(),
  500.                         MBeanOperationInfo.ACTION);

  501.         // FILE_TRACE_CONFIG
  502.         MBeanOperationInfo fileTraceConfigOp = new MBeanOperationInfo(FILE_TRACE_CONFIG,"Visualizza il path della configurazione del FileTrace",
  503.                 null,
  504.                 String.class.getName(),
  505.                 MBeanOperationInfo.ACTION);
  506.        
  507.         // FILE_TRACE_UPDATE
  508.         MBeanOperationInfo fileTraceUpdateOp = new MBeanOperationInfo(FILE_TRACE_UPDATE,"Aggiorna la configurazione del FileTrace",
  509.                 null,
  510.                 String.class.getName(),
  511.                 MBeanOperationInfo.ACTION);
  512.        
  513.         // BYOK_UNWRAP
  514.         MBeanOperationInfo byokUnwrapOp = new MBeanOperationInfo(BYOK_UNWRAP,"Effettua l'unwrap della chiave fornita",
  515.                 new MBeanParameterInfo[]{
  516.                         new MBeanParameterInfo("key",String.class.getName(),CHIAVE),
  517.                 },
  518.                 String.class.getName(),
  519.                 MBeanOperationInfo.ACTION);
  520.        
  521.         // BYOK_UNWRAP_BASE64
  522.         MBeanOperationInfo byokBase64UnwrapOp = new MBeanOperationInfo(BYOK_UNWRAP_BASE64,"Effettua l'unwrap della chiave fornita (ritorna codificata in base64)",
  523.                 new MBeanParameterInfo[]{
  524.                         new MBeanParameterInfo("key",String.class.getName(),CHIAVE),
  525.                 },
  526.                 String.class.getName(),
  527.                 MBeanOperationInfo.ACTION);
  528.        
  529.         // BYOK_UNWRAP_HEX
  530.         MBeanOperationInfo byokHexUnwrapOp = new MBeanOperationInfo(BYOK_UNWRAP_HEX,"Effettua l'unwrap della chiave fornita (ritorna codificata in hex)",
  531.                 new MBeanParameterInfo[]{
  532.                         new MBeanParameterInfo("key",String.class.getName(),CHIAVE),
  533.                 },
  534.                 String.class.getName(),
  535.                 MBeanOperationInfo.ACTION);

  536.         // BYOK_WRAP
  537.         MBeanOperationInfo byokWrapOp = new MBeanOperationInfo(BYOK_WRAP,"Effettua il wrap della chiave fornita",
  538.                 new MBeanParameterInfo[]{
  539.                         new MBeanParameterInfo("key",String.class.getName(),CHIAVE),
  540.                 },
  541.                 String.class.getName(),
  542.                 MBeanOperationInfo.ACTION);
  543.        
  544.         // BYOK_WRAP_BASE64
  545.         MBeanOperationInfo byokWrapBase64KeyOp = new MBeanOperationInfo(BYOK_WRAP_BASE64,"Effettua il wrap della chiave fornita codificata in base64",
  546.                 new MBeanParameterInfo[]{
  547.                         new MBeanParameterInfo("key",String.class.getName(),"Chiave codificata in base64"),
  548.                 },
  549.                 String.class.getName(),
  550.                 MBeanOperationInfo.ACTION);
  551.        
  552.         // BYOK_WRAP_HEX
  553.         MBeanOperationInfo byokWrapHexKeyOp = new MBeanOperationInfo(BYOK_WRAP_HEX,"Effettua il wrap della chiave fornita codificata in esadecimale",
  554.                 new MBeanParameterInfo[]{
  555.                         new MBeanParameterInfo("key",String.class.getName(),"Chiave codificata in hex"),
  556.                 },
  557.                 String.class.getName(),
  558.                 MBeanOperationInfo.ACTION);
  559.        
  560.         // Mbean costruttore
  561.         MBeanConstructorInfo defaultConstructor = new MBeanConstructorInfo("Default Constructor","Crea e inizializza una nuova istanza del MBean",null);

  562.         // Lista attributi
  563.         MBeanAttributeInfo[] attributes = null;

  564.         // Lista Costruttori
  565.         MBeanConstructorInfo[] constructors = new MBeanConstructorInfo[]{defaultConstructor};

  566.         // Lista operazioni
  567.         MBeanOperationInfo[] operations = new MBeanOperationInfo[]{versionePddOp,versioneBaseDatiOp,vendorJavaOp,versioneJavaOp,
  568.                 versioneTipoDatabaseOp,informazioniDatabaseOp,informazioniSSLOp,informazioniCompleteSSLOp,informazioniCRYPTOOp,
  569.                 informazioniCHARSETOp, informazioniINTERNAZIONALIZZAZIONEOp,informazioniCompleteINTERNAZIONALIZZAZIONEOp,
  570.                 informazioniTIMEZONEOp, informazioniCompleteTIMEZONEOp,
  571.                 informazioniProprietaJavaNetworkingOp, informazioniCompleteProprietaJavaNetworkingOp,
  572.                 informazioniProprietaJavaAltroOp, informazioniProprietaSistemaOp,
  573.                 messageFactoryOp,confDirectoryOp,protocolsOp,
  574.                 fileTraceConfigOp, fileTraceUpdateOp,
  575.                 byokUnwrapOp, byokBase64UnwrapOp, byokHexUnwrapOp,
  576.                 byokWrapOp, byokWrapBase64KeyOp, byokWrapHexKeyOp};

  577.         return new MBeanInfo(className,description,attributes,constructors,operations,null);
  578.     }

  579.     /* Variabili per la gestione JMX */
  580.     private Logger log;
  581.     org.openspcoop2.pdd.config.OpenSPCoop2Properties openspcoopProperties = null;

  582.     /* Costruttore */
  583.     public ConfigurazioneSistema(){
  584.         this.log = OpenSPCoop2Logger.getLoggerOpenSPCoopCore();
  585.         this.openspcoopProperties = org.openspcoop2.pdd.config.OpenSPCoop2Properties.getInstance();
  586.     }

  587.     /* Metodi di management JMX */

  588.     public String getVersionePdD(){
  589.         try{
  590.             return OpenSPCoop2Properties.getVersionePdD(this.openspcoopProperties);
  591.         }catch(Exception e){
  592.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  593.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  594.         }
  595.     }

  596.     public String getVersioneBaseDati(){
  597.         try{
  598.             boolean isNodoRun = true;
  599.             VersioneBaseDatiChecker versioneBaseDatiChecker = new VersioneBaseDatiChecker(this.openspcoopProperties, isNodoRun);
  600.             return Utilities.execute(5, versioneBaseDatiChecker);
  601.         }catch(Exception e){
  602.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  603.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  604.         }
  605.     }

  606.     public String getVersioneJava(){
  607.         try{
  608.             String v = System.getProperty("java.version");
  609.             if(v!=null && !"".equals(v)){
  610.                 return v;
  611.             }
  612.             throw new CoreException("Versione di Java non disponibile");

  613.         }catch(Exception e){
  614.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  615.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  616.         }
  617.     }
  618.    
  619.     public String getVendorJava(){
  620.         try{
  621.             String v = System.getProperty("java.vendor");
  622.             if(v==null || "".equals(v)){
  623.                 v = System.getProperty("java.vm.vendor");
  624.             }
  625.             if(v==null || "".equals(v)){
  626.                 v = null;
  627.             }
  628.            
  629.             String name = System.getProperty("java.vm.name");
  630.             if(name==null || "".equals(name)){
  631.                 name = null;
  632.             }
  633.            
  634.             if(v!=null && name!=null){
  635.                 return v + " " + name;
  636.             }
  637.             else if(v!=null){
  638.                 return v;
  639.             }
  640.             else if(name!=null){
  641.                 return name;
  642.             }
  643.            
  644.             throw new CoreException("Vendor Java non disponibile");

  645.         }catch(Exception e){
  646.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  647.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  648.         }
  649.     }

  650.     public String getTipoDatabase(){
  651.         try{
  652.             if(this.openspcoopProperties!=null){
  653.                 return this.openspcoopProperties.getDatabaseType();
  654.             }
  655.             throw new CoreException("Tipo di Database non disponibile");

  656.         }catch(Exception e){
  657.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  658.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  659.         }
  660.     }

  661.     public String getInformazioniDatabase(){
  662.         try{
  663.             InformazioniDatabaseChecker versioneBaseDatiChecker = new InformazioniDatabaseChecker(this.openspcoopProperties);
  664.             return Utilities.execute(5, versioneBaseDatiChecker);
  665.         }catch(Exception e){
  666.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  667.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  668.         }
  669.     }
  670.    
  671.     public Map<String, String> getInformazioniAltriDatabase(){
  672.         Map<String, String> map = null;
  673.         try{
  674.             if(DataSourceFactory.sizeDatasources()>0) {
  675.                 List<String> jndiNames = DataSourceFactory.getJndiNameDatasources();
  676.                 if(jndiNames!=null && !jndiNames.isEmpty()) {
  677.                     map = new HashMap<>();
  678.                     for (String jndiName : jndiNames) {
  679.                         addInformazioniAltriDatabase(map, jndiName);
  680.                     }
  681.                     return map;
  682.                 }
  683.             }
  684.         }catch(Exception e){
  685.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  686.         }
  687.         return map;
  688.     }
  689.     private void addInformazioniAltriDatabase(Map<String, String> map, String jndiName){
  690.         try{
  691.             map.put(jndiName, DataSourceFactory.getInstance(jndiName).getInformazioniDatabase());
  692.         }catch(Exception e){
  693.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  694.             map.put(jndiName, JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage());
  695.         }
  696.     }
  697.    
  698.     public String getInformazioniSSL(boolean cipherSuites, boolean providerInfo, boolean hsmInfo, boolean ocspInfo){
  699.         try{
  700.             StringBuilder bf = new StringBuilder();
  701.             bf.append("SupportedProtocols: "+SSLUtilities.getSSLSupportedProtocols());
  702.             bf.append("\n");
  703.             // Molto verboso
  704.             if(cipherSuites){
  705.                 bf.append("SupportedCipherSuites: "+SSLUtilities.getSSLSupportedCipherSuites());
  706.                 bf.append("\n");
  707.             }
  708.             addInformazioniSSL(bf, cipherSuites);

  709.             if(providerInfo){
  710.                 bf.append("\n");
  711.                 bf.append("Providers: "+SSLUtilities.getSSLProvidersName());
  712.                 bf.append("\n");
  713.                 List<Provider> lProviders = SSLUtilities.getSSLProviders();
  714.                 for (Provider provider : lProviders) {
  715.                     printSSLProviderInfo(provider, bf);
  716.                 }
  717.             }
  718.            
  719.             if(hsmInfo) {
  720.                 bf.append("\n");
  721.                 HSMManager hsmManager = HSMManager.getInstance();
  722.                 if(hsmManager!=null) {
  723.                     bf.append("HSM Keystore registered: "+hsmManager.getKeystoreTypes());
  724.                 }
  725.                 else {
  726.                     bf.append("HSM disabled");
  727.                 }
  728.                 bf.append("\n");
  729.             }
  730.            
  731.            
  732.             if(ocspInfo) {
  733.                 bf.append("\n");
  734.                 OCSPManager ocspManager = OCSPManager.getInstance();
  735.                 if(ocspManager!=null) {
  736.                     bf.append("OCSP policy registered: "+ocspManager.getOCSPConfigTypes());
  737.                 }
  738.                 else {
  739.                     bf.append("OCSP disabled");
  740.                 }
  741.                 bf.append("\n");
  742.             }
  743.            
  744.             if(bf.length()<=0){
  745.                 throw new CoreException("Non sono disponibili informazioni sul contesto SSL");
  746.             }else{
  747.                 return bf.toString();
  748.             }

  749.         }catch(Exception e){
  750.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  751.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  752.         }
  753.     }
  754.     private void addInformazioniSSL(StringBuilder bf, boolean cipherSuites) throws UtilsException {
  755.         List<String> p = SSLUtilities.getSSLSupportedProtocols();
  756.         if(p!=null && !p.isEmpty()){
  757.             for (String protocol : p) {
  758.                 if(cipherSuites){
  759.                     bf.append("\n");
  760.                 }
  761.                 printSSLInfo(protocol, bf, cipherSuites);
  762.             }
  763.             // Per retrocompatibilità verifico anche alias SSL e TLS in modo da sapere come si comportano se sono stati associati a delle configurazioni
  764.             addInformazioniSSL(p, bf, cipherSuites);
  765.         }
  766.     }
  767.     private void addInformazioniSSL(List<String> p, StringBuilder bf, boolean cipherSuites) {
  768.         if(!p.contains(SSLConstants.PROTOCOL_TLS)){
  769.             if(cipherSuites){
  770.                 bf.append("\n");
  771.             }
  772.             printSSLInfo(SSLConstants.PROTOCOL_TLS, bf, cipherSuites);
  773.         }
  774.         if(!p.contains(SSLConstants.PROTOCOL_SSL)){
  775.             if(cipherSuites){
  776.                 bf.append("\n");
  777.             }
  778.             printSSLInfo(SSLConstants.PROTOCOL_SSL, bf, cipherSuites);
  779.         }
  780.     }
  781.     private void printSSLInfo(String protocol,StringBuilder bf,boolean cipherSuites){
  782.         bf.append(protocol+": ");
  783.         try{
  784.             bf.append(SSLUtilities.getSSLEnabledProtocols(protocol));
  785.         }catch(Exception n){
  786.             bf.append(n.getMessage());
  787.         }
  788.         bf.append("\n");
  789.         if(cipherSuites){
  790.             bf.append("CipherSuites: ");
  791.             try{
  792.                 bf.append(SSLUtilities.getSSLEnabledCipherSuites(protocol));
  793.             }catch(Exception n){
  794.                 bf.append(n.getMessage());
  795.             }
  796.             bf.append("\n");    
  797.         }
  798.     }
  799.     private void printSSLProviderInfo(Provider provider,StringBuilder bf){
  800.         bf.append("\n");
  801.         bf.append(provider.getName());
  802.         bf.append("\n");    
  803.         bf.append("Versione: v").append(provider.getVersionStr()).append(" ");
  804.         bf.append(provider.getInfo());
  805.         bf.append("\n");
  806.         try{
  807.             List<String> serviceTypes = SSLUtilities.getServiceTypes(provider);
  808.             bf.append("ServiceTypes: "+serviceTypes);
  809.             bf.append("\n");    
  810.             for (String serviceType : serviceTypes) {  
  811.                 bf.append(serviceType+" Algorithms: "+SSLUtilities.getServiceTypeAlgorithms(provider, serviceType));
  812.                 bf.append("\n");    
  813.             }
  814.         }catch(Exception n){
  815.             bf.append(n.getMessage());
  816.         }
  817.     }
  818.    
  819.     public String getInformazioniCryptographyKeyLength(){
  820.         try{
  821.             StringBuilder bf = new StringBuilder();
  822.             Set<?> algorithms = Security.getAlgorithms("Cipher");
  823.             if(algorithms!=null && !algorithms.isEmpty()){
  824.                 Iterator<?> it = algorithms.iterator();
  825.                 while (it.hasNext()) {
  826.                     String algorithm = (String) it.next();
  827.                     bf.append(algorithm).append(": ");
  828.                     addInformazioniCryptographyKeyLength(bf, algorithm);
  829.                     bf.append("\n");
  830.                 }
  831.             }
  832.             if(bf.length()<=0){
  833.                 throw new CoreException("Non sono disponibili informazioni sulla lunghezza delle chiavi di cifratura");
  834.             }else{
  835.                 return bf.toString();
  836.             }
  837.         }catch(Exception e){
  838.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  839.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  840.         }
  841.     }
  842.     private void addInformazioniCryptographyKeyLength(StringBuilder bf, String algorithm){
  843.         try{
  844.             bf.append(Cipher.getMaxAllowedKeyLength(algorithm));
  845.             bf.append(" bit");
  846.         }catch(Exception e){
  847.             bf.append(e.getMessage());
  848.         }
  849.     }
  850.    
  851.     public String getInformazioniCharset(){
  852.         try{
  853.             StringBuilder bf = new StringBuilder();
  854.            
  855.             bf.append("Property 'file.encoding': ").append(CharsetUtilities.getDefaultCharsetByProperties()).append("\n");
  856.             bf.append("java.io.Reader: ").append(CharsetUtilities.getDefaultCharsetByCode()).append("\n");
  857.             bf.append("java.nio.charset.Charset: ").append(CharsetUtilities.getDefaultCharsetByCharset()).append("\n");
  858.            
  859.             if(bf.length()<=0){
  860.                 throw new CoreException("Non sono disponibili informazioni sul charset");
  861.             }else{
  862.                 return bf.toString();
  863.             }
  864.         }catch(Exception e){
  865.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  866.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  867.         }
  868.     }
  869.    
  870.     public String getInformazioniInternazionalizzazione(boolean all){
  871.         try{
  872.             StringBuilder bf = new StringBuilder();
  873.            
  874.             StringBuilder bfInternal = new StringBuilder();
  875.             Utilities.toString(java.util.Locale.getDefault(), bfInternal, "\n");
  876.             if(bfInternal.length()>0){
  877.                 if(all){
  878.                     bf.append("DEFAULT ");
  879.                 }
  880.                 bf.append(bfInternal.toString());
  881.             }

  882.             if(all){
  883.                 addInformazioniInternazionalizzazione(bf);
  884.             }
  885.            
  886.             if(bf.length()<=0){
  887.                 throw new CoreException("Non sono disponibili informazioni sulla internazionalizzazione");
  888.             }else{
  889.                 return bf.toString();
  890.             }
  891.         }catch(Exception e){
  892.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  893.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  894.         }
  895.     }
  896.     private void addInformazioniInternazionalizzazione(StringBuilder bf){
  897.         java.util.Locale [] l = java.util.Locale.getAvailableLocales();
  898.         if(l!=null){
  899.             List<String> ll = new ArrayList<>();
  900.             Map<String,java.util.Locale> llMap = new HashMap<>();
  901.             for (int i = 0; i < l.length; i++) {
  902.                 ll.add(l[i].getDisplayName());
  903.                 llMap.put(l[i].getDisplayName(), l[i]);
  904.             }
  905.             Collections.sort(ll);
  906.             for (String name : ll) {
  907.                 java.util.Locale locale = llMap.get(name);
  908.                 if(bf.length()>0){
  909.                     bf.append("\n");
  910.                 }
  911.                 Utilities.toString(locale, bf, "\n");
  912.             }
  913.         }
  914.     }
  915.    
  916.     public String getInformazioniTimeZone(boolean all){
  917.         try{
  918.             StringBuilder bf = new StringBuilder();
  919.            
  920.             StringBuilder bfInternal = new StringBuilder();
  921.             Utilities.toString(java.util.TimeZone.getDefault(), bfInternal, all);
  922.             if(bfInternal.length()>0){
  923.                 if(all){
  924.                     bf.append("DEFAULT ");
  925.                 }
  926.                 bf.append(bfInternal.toString());
  927.             }
  928.            
  929.             if(all){
  930.                 addInformazioniTimeZone(bf, all);
  931.             }
  932.            
  933.             if(bf.length()>0){
  934.                 bf.append("\n");
  935.             }
  936.             bf.append("DateTimeFormatter: "+DateUtils.getDEFAULT_DATA_ENGINE_TYPE());
  937.            
  938.             if(bf.length()<=0){
  939.                 throw new CoreException("Non sono disponibili informazioni sulla internazionalizzazione");
  940.             }else{
  941.                 return bf.toString();
  942.             }
  943.         }catch(Exception e){
  944.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  945.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  946.         }
  947.     }
  948.     private void addInformazioniTimeZone(StringBuilder bf, boolean all){
  949.         String [] ids = java.util.TimeZone.getAvailableIDs();
  950.         if(ids!=null){
  951.             List<String> ll = new ArrayList<>();
  952.             if(ids.length>0) {
  953.                 ll.addAll(Arrays.asList(ids));
  954.             }
  955.             Collections.sort(ll);
  956.             for (String id : ll) {
  957.                 if(bf.length()>0){
  958.                     bf.append("\n");
  959.                 }
  960.                 Utilities.toString(java.util.TimeZone.getTimeZone(id), bf, all);
  961.             }
  962.         }
  963.     }
  964.    
  965.     private boolean isPasswordProperty(String key, boolean java) {
  966.        
  967.         try {
  968.             MapProperties mapProperties = MapProperties.getInstance();
  969.             if(mapProperties!=null && !MapProperties.OBFUSCATED_MODE_NON_INIZIALIZZATO.equals(mapProperties.getObfuscateModeDescription())) {
  970.                 List<String> mapObfuscateKey = java ? mapProperties.getJavaMap().keys() : mapProperties.getEnvMap().keys();
  971.                 if(mapObfuscateKey.contains(key)) {
  972.                     return false; // gestione effettuata dentro il file govway.map
  973.                 }
  974.             }
  975.            
  976.             BYOKMapProperties secretsProperties = BYOKMapProperties.getInstance();
  977.             if(secretsProperties!=null && !MapProperties.OBFUSCATED_MODE_NON_INIZIALIZZATO.equals(secretsProperties.getObfuscateModeDescription())) {
  978.                 List<String> secretsObfuscateKey = java ? secretsProperties.getJavaMap().keys() : secretsProperties.getEnvMap().keys();
  979.                 if(secretsObfuscateKey.contains(key)) {
  980.                     return false; // gestione effettuata dentro il file govway.secrets
  981.                 }
  982.             }
  983.         }catch(Exception e) {
  984.             // ignore
  985.         }
  986.        
  987.         return key.toLowerCase().contains("password");
  988.     }
  989.     private boolean isNetworkProperties(boolean allNetwork, String key) {
  990.         boolean net = key.startsWith("java.net.") ||
  991.                 key.startsWith("javax.net.") ||
  992.                 key.startsWith("networkaddress.") ||
  993.                 key.startsWith("http.") ||
  994.                 key.startsWith("https.");
  995.        
  996.         if(allNetwork) {
  997.             return net
  998.                     ||
  999.                     (
  1000.                         key.startsWith("ftp.") ||
  1001.                         key.startsWith("socks") ||
  1002.                         key.startsWith("sun.net.") // implement specific
  1003.                     );  
  1004.         }
  1005.         else {
  1006.             return net;
  1007.         }
  1008.                
  1009.     }
  1010.    
  1011.     public String getInformazioniProprietaJava(boolean allNetwork, boolean includeNetwork, boolean includeNotNetwork, boolean includePassword){
  1012.         try{
  1013.             StringBuilder bf = new StringBuilder();
  1014.            
  1015.             if(System.getSecurityManager()!=null) {
  1016.                 bf.append("SecurityManager=").append(System.getSecurityManager().getClass().getName());
  1017.             }
  1018.             else {
  1019.                 bf.append("SecurityManager non attivo");
  1020.             }
  1021.            
  1022.             Properties p = System.getProperties();
  1023.             List<String> ll = new ArrayList<>();
  1024.             addInformazioniProprietaJava(allNetwork, includeNetwork, includeNotNetwork, includePassword,
  1025.                     p, ll);
  1026.             Collections.sort(ll);
  1027.             if(!ll.isEmpty()) {
  1028.                 bf.append("\n"); // Separo security manager
  1029.             }
  1030.            
  1031.             printProprietaJava(ll, bf, p);
  1032.            
  1033.             if(bf.length()<=0){
  1034.                 throw new CoreException("Non sono disponibili proprietà java");
  1035.             }else{
  1036.                 return bf.toString();
  1037.             }
  1038.            
  1039.         }catch(Exception e){
  1040.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1041.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1042.         }
  1043.     }
  1044.     private void printProprietaJava(List<String> ll, StringBuilder bf, Properties p) throws UtilsException {
  1045.         MapProperties mapProperties = MapProperties.getInstance();
  1046.         List<String> mapObfuscateKey = null;
  1047.         if(mapProperties.isObfuscatedModeEnabled()) {
  1048.             mapObfuscateKey = mapProperties.getObfuscatedJavaKeys();
  1049.         }
  1050.        
  1051.         BYOKMapProperties secretsProperties = BYOKMapProperties.getInstance();
  1052.         List<String> secretsObfuscateKey = null;
  1053.         if(secretsProperties.isObfuscatedModeEnabled()) {
  1054.             /**secretsObfuscateKey = secretsProperties.getObfuscatedJavaKeys(); Tutte le variabili definite in secrets sono da offuscare*/
  1055.             secretsObfuscateKey = secretsProperties.getJavaMap().keys();
  1056.         }
  1057.        
  1058.         List<String> govwayEncryptedProperties = getGovwayEncryptedProperties();
  1059.        
  1060.         for (String key : ll) {
  1061.            
  1062.             Object value = p.get(key);
  1063.             if(value instanceof String) {
  1064.                 if(mapObfuscateKey!=null && mapObfuscateKey.contains(key)) {
  1065.                     value = mapProperties.obfuscateJavaProperty(key, (String)value);
  1066.                 }
  1067.                 else if(secretsObfuscateKey!=null && secretsObfuscateKey.contains(key)) {
  1068.                     value = secretsProperties.obfuscateJavaProperty(key, (String)value);
  1069.                 }
  1070.                 else if(govwayEncryptedProperties!=null && govwayEncryptedProperties.contains(key)) {
  1071.                     value = obfuscateGovWayEncryptedProperty(mapProperties, key, (String)value);
  1072.                 }
  1073.             }
  1074.            
  1075.             if(bf.length()>0){
  1076.                 bf.append("\n");
  1077.             }
  1078.             bf.append(key).append("=").append(value);
  1079.         }
  1080.     }
  1081.     private void addInformazioniProprietaJava(boolean allNetwork, boolean includeNetwork, boolean includeNotNetwork, boolean includePassword,
  1082.             Properties p, List<String> ll) throws CoreException{
  1083.         Iterator<Object> keys = p.keySet().iterator();
  1084.         while (keys.hasNext()) {
  1085.             Object o = keys.next();
  1086.             if(!(o instanceof String)) {
  1087.                 continue;
  1088.             }
  1089.             String key = (String) o;
  1090.             addInformazioniProprietaJava(allNetwork, includeNetwork, includeNotNetwork, includePassword,
  1091.                     ll, key);
  1092.         }
  1093.     }
  1094.     private void addInformazioniProprietaJava(boolean allNetwork, boolean includeNetwork, boolean includeNotNetwork, boolean includePassword,
  1095.             List<String> ll, String key) throws CoreException{
  1096.         if(!includeNetwork && !includeNotNetwork) {
  1097.             throw new CoreException("Invocazione errata, almeno un parametro deve essere abilitato");
  1098.         }
  1099.         else if(includeNetwork && !includeNotNetwork) {
  1100.             if(this.isNetworkProperties(allNetwork, key)&&
  1101.                 (includePassword || !isPasswordProperty(key, true))
  1102.                 ){
  1103.                 ll.add(key);
  1104.             }
  1105.         }
  1106.         else if(
  1107.                 // includeNotNetwork && sempre true
  1108.                 !includeNetwork) {
  1109.             addInformazioniProprietaJavaIncludeNotNetwork(ll, key);
  1110.         }
  1111.         else {
  1112.             if(includePassword || !isPasswordProperty(key, true)) {
  1113.                 ll.add(key);
  1114.             }
  1115.         }
  1116.     }
  1117.     private void addInformazioniProprietaJavaIncludeNotNetwork(List<String> ll, String key) {
  1118.         if(
  1119.                 (!this.isNetworkProperties(true, key)) &&
  1120.                 (includePassword || !isPasswordProperty(key, true))
  1121.             ){
  1122.             ll.add(key);
  1123.         }
  1124.     }
  1125.    
  1126.     public String getInformazioniProprietaSistema(){
  1127.         try{
  1128.             StringBuilder bf = new StringBuilder();
  1129.            
  1130.             if(System.getSecurityManager()!=null) {
  1131.                 bf.append("SecurityManager=").append(System.getSecurityManager().getClass().getName());
  1132.             }
  1133.             else {
  1134.                 bf.append("SecurityManager non attivo");
  1135.             }
  1136.            
  1137.             Map<String, String> map = System.getenv();
  1138.             Iterator<String> keys = map.keySet().iterator();
  1139.             List<String> ll = new ArrayList<>();
  1140.             while (keys.hasNext()) {
  1141.                 String key = keys.next();
  1142.                 ll.add(key);
  1143.             }
  1144.             Collections.sort(ll);
  1145.             if(!ll.isEmpty()) {
  1146.                 bf.append("\n"); // Separo security manager
  1147.             }
  1148.            
  1149.             printProprietaSistema(ll, bf, map);
  1150.            
  1151.             if(bf.length()<=0){
  1152.                 throw new CoreException("Non sono disponibili proprietà di sistema");
  1153.             }else{
  1154.                 return bf.toString();
  1155.             }
  1156.         }catch(Exception e){
  1157.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1158.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1159.         }
  1160.     }
  1161.     private void printProprietaSistema(List<String> ll, StringBuilder bf, Map<String, String> map) throws UtilsException {
  1162.         MapProperties mapProperties = MapProperties.getInstance();
  1163.         List<String> mapObfuscateKey = null;
  1164.         if(mapProperties!=null && mapProperties.isObfuscatedModeEnabled()) {
  1165.             mapObfuscateKey = mapProperties.getObfuscatedEnvKeys();
  1166.         }
  1167.        
  1168.         BYOKMapProperties secretsProperties = BYOKMapProperties.getInstance();
  1169.         List<String> secretsObfuscateKey = null;
  1170.         if(secretsProperties!=null && secretsProperties.isObfuscatedModeEnabled()) {
  1171.             /**secretsObfuscateKey = secretsProperties.getObfuscatedEnvKeys(); Tutte le variabili definite in secrets sono da offuscare*/
  1172.             secretsObfuscateKey = secretsProperties.getEnvMap().keys();
  1173.         }
  1174.        
  1175.         /** Vengono impostate come proprieta java List<String> govwayEncryptedProperties = getGovwayEncryptedProperties();*/
  1176.        
  1177.         for (String key : ll) {
  1178.            
  1179.             String value = map.get(key);
  1180.             if(mapObfuscateKey!=null && mapObfuscateKey.contains(key)) {
  1181.                 value = mapProperties.obfuscateEnvProperty(key, value);
  1182.             }
  1183.             else if(secretsObfuscateKey!=null && secretsObfuscateKey.contains(key)) {
  1184.                 value = secretsProperties.obfuscateEnvProperty(key, value);
  1185.             }
  1186.             /** Vengono impostate come proprieta java else if(govwayEncryptedProperties!=null && govwayEncryptedProperties.contains(key)) {
  1187.                 value = obfuscateGovWayEncryptedProperty(mapProperties, key, value);
  1188.             }*/
  1189.            
  1190.             if(bf.length()>0){
  1191.                 bf.append("\n");
  1192.             }
  1193.             bf.append(key).append("=").append(value);
  1194.         }
  1195.     }
  1196.    
  1197.     private List<String> getGovwayEncryptedProperties() throws UtilsException{
  1198.         List<String> govwayEncryptedProperties = null;
  1199.         ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance();
  1200.         if(configurazionePdDManager!=null) {
  1201.             try {
  1202.                 govwayEncryptedProperties = configurazionePdDManager.getEncryptedSystemPropertiesPdD();
  1203.             }catch(Exception e) {
  1204.                 throw new UtilsException(e.getMessage(),e);
  1205.             }
  1206.         }
  1207.         return govwayEncryptedProperties;
  1208.     }  
  1209.     private String obfuscateGovWayEncryptedProperty(MapProperties mapProperties, String key, String value) throws UtilsException {
  1210.         if(mapProperties!=null && mapProperties.isObfuscatedModeEnabled()) {
  1211.             value = mapProperties.obfuscateEnvProperty(key, value);
  1212.         }
  1213.         else {
  1214.             try {
  1215.                 value = MapProperties.obfuscateByDigest(value);
  1216.             }catch(Exception e) {
  1217.                 if(this.log!=null) {
  1218.                     this.log.error(e.getMessage(),e);
  1219.                 }
  1220.                 value = "---***---***";
  1221.             }
  1222.         }
  1223.         return value;
  1224.     }
  1225.    
  1226.     public String getMessageFactory(){
  1227.         try{
  1228.             StringBuilder sb = new StringBuilder();
  1229.             OpenSPCoop2MessageFactory factory = OpenSPCoop2MessageFactory.getDefaultMessageFactory();
  1230.            
  1231.             String docOp2 = factory.getDocumentBuilderFactoryClass();
  1232.             String docSaaj = SOAPDocumentImpl.newInstanceDocumentBuilderFactory().getClass().getName();
  1233.             sb.append("DocumentBuilderFactory:").append(docSaaj).append(" ");
  1234.             if(!docSaaj.equals(docOp2)) {
  1235.                 sb.append("OpenSPCoop2DocumentBuilderFactory:").append(docOp2).append(" ");
  1236.                    
  1237.             }
  1238.            
  1239.             String saxOp2 = factory.getSAXParserFactoryClass();
  1240.             String saxSaaj = SOAPDocumentImpl.newInstanceSAXParserFactory().getClass().getName();
  1241.             sb.append("SAXParserFactory:").append(saxSaaj).append(" ");
  1242.             if(!saxSaaj.equals(saxOp2)) {
  1243.                 sb.append("OpenSPCoop2SAXParserFactory:").append(saxOp2).append(" ");
  1244.                    
  1245.             }
  1246.            
  1247.             return sb.toString();
  1248.            
  1249.         }catch(Exception e){
  1250.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1251.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1252.         }
  1253.     }
  1254.    
  1255.     public String getDirectoryConfigurazione(){
  1256.         try{
  1257.             if(this.openspcoopProperties!=null){
  1258.                
  1259.                 StringBuilder bf = new StringBuilder();
  1260.                 if(System.getenv(CostantiPdD.OPENSPCOOP2_LOCAL_HOME)!=null){
  1261.                     if(bf.length()>0){
  1262.                         bf.append("\n");
  1263.                     }
  1264.                     bf.append("SystemProperty["+CostantiPdD.OPENSPCOOP2_LOCAL_HOME+"]=["+System.getenv(CostantiPdD.OPENSPCOOP2_LOCAL_HOME)+"]");
  1265.                 }
  1266.                 if(System.getProperty(CostantiPdD.OPENSPCOOP2_LOCAL_HOME)!=null){
  1267.                     if(bf.length()>0){
  1268.                         bf.append("\n");
  1269.                     }
  1270.                     bf.append("JavaProperty["+CostantiPdD.OPENSPCOOP2_LOCAL_HOME+"]=["+System.getProperty(CostantiPdD.OPENSPCOOP2_LOCAL_HOME)+"]");
  1271.                 }
  1272.                 if(bf.length()>0){
  1273.                     bf.append("\n");
  1274.                 }
  1275.                 bf.append("GovWayProperties["+this.openspcoopProperties.getRootDirectory()+"]");
  1276.                
  1277.                 return bf.toString();
  1278.             }
  1279.             throw new CoreException("Directory di Configurazione non disponibile");
  1280.         }catch(Exception e){
  1281.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1282.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1283.         }
  1284.     }
  1285.    
  1286.     public String getPluginProtocols(){
  1287.         try{
  1288.             MapReader<String, IProtocolFactory<?>> prots = ProtocolFactoryManager.getInstance().getProtocolFactories();
  1289.             if(prots.size()<=0){
  1290.                 throw new CoreException("No protocol installed");
  1291.             }
  1292.             else{
  1293.                 StringBuilder bfProtocols = new StringBuilder();
  1294.                 addPluginProtocols(prots, bfProtocols);
  1295.                 return bfProtocols.toString();
  1296.             }
  1297.         }catch(Exception e){
  1298.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1299.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1300.         }
  1301.     }
  1302.     private void addPluginProtocols(MapReader<String, IProtocolFactory<?>> prots, StringBuilder bfProtocols){
  1303.         Enumeration<String> keys = prots.keys();
  1304.         while (keys.hasMoreElements()) {
  1305.             String key = keys.nextElement();
  1306.             IProtocolFactory<?> pf = prots.get(key);
  1307.             addPluginProtocols(key, pf, bfProtocols);
  1308.         }
  1309.     }
  1310.     private void addPluginProtocols(String key, IProtocolFactory<?> pf, StringBuilder bfProtocols){
  1311.         if(pf.getManifest().getWeb().getEmptyContext()!=null && pf.getManifest().getWeb().getEmptyContext().isEnabled()){
  1312.             if(bfProtocols.length()>0){
  1313.                 bfProtocols.append("\n");
  1314.             }
  1315.             bfProtocols.append("\"\" (protocol:"+key+")");
  1316.         }
  1317.         if(pf.getManifest().getWeb().sizeContextList()>0){
  1318.             for (Context context : pf.getManifest().getWeb().getContextList()) {
  1319.                 if(bfProtocols.length()>0){
  1320.                     bfProtocols.append("\n");
  1321.                 }
  1322.                 bfProtocols.append(context.getName()+" (protocol:"+key+")");
  1323.             }
  1324.         }
  1325.     }

  1326.     public String getInformazioniInstallazione(){
  1327.         try {
  1328.             List<GenericProperties> installerProperties = ConfigurazionePdDManager.getInstance().getGenericProperties(CostantiPdD.TIPOLOGIA_INSTALLER);
  1329.             if(installerProperties==null || installerProperties.isEmpty()) {
  1330.                 throw new DriverConfigurazioneNotFound();
  1331.             }
  1332.             StringBuilder bf = new StringBuilder();
  1333.             // raccolto id
  1334.             List<String> ids = new ArrayList<>();
  1335.             for (int i = 0; i < installerProperties.size(); i++) {
  1336.                 ids.add(installerProperties.get(i).getNome());
  1337.             }
  1338.             Collections.sort(ids, Collections.reverseOrder());
  1339.             for (String name : ids) {
  1340.                 addInformazioniInstallazioneProperty(installerProperties, name, bf);
  1341.             }
  1342.            
  1343.             if(bf.length()>0) {
  1344.                 return bf.toString();
  1345.             }
  1346.             else {
  1347.                 return "Informazioni non presenti";
  1348.             }
  1349.            
  1350.         }catch(DriverConfigurazioneNotFound notFound) {
  1351.             return "Informazioni non presenti";
  1352.         }catch(Exception e){
  1353.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1354.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1355.         }
  1356.        
  1357.     }
  1358.     private void addInformazioniInstallazioneProperty(List<GenericProperties> installerProperties, String name, StringBuilder bf) {
  1359.         for (GenericProperties gp : installerProperties) {
  1360.             if(gp.getNome().equals(name)) {
  1361.                 addInformazioniInstallazioneProperty(gp, bf);
  1362.                 break;
  1363.             }
  1364.         }
  1365.     }
  1366.     private void addInformazioniInstallazioneProperty(GenericProperties gp, StringBuilder bf) {
  1367.         if(bf.length()>0) {
  1368.             bf.append("\n");
  1369.         }
  1370.         bf.append(gp.getDescrizione());
  1371.         bf.append("\n");
  1372.        
  1373.         List<String> idParams = new ArrayList<>();
  1374.         for (Property p : gp.getPropertyList()) {
  1375.             idParams.add(p.getNome());
  1376.         }
  1377.         Collections.sort(idParams);
  1378.         for (String idP : idParams) {
  1379.             for (Property p : gp.getPropertyList()) {
  1380.                 if(addInformazioniInstallazioneProperty(p, idP, bf)) {
  1381.                     break;
  1382.                 }
  1383.             }
  1384.         }
  1385.     }
  1386.     private boolean addInformazioniInstallazioneProperty(Property p, String idP, StringBuilder bf) {
  1387.         if(p.getNome().equals(idP)) {
  1388.            
  1389.             if(p.getNome().endsWith("-000:sezione")) {
  1390.                 bf.append(p.getValore());
  1391.                 bf.append("\n");
  1392.             }
  1393.             else {
  1394.                 bf.append("\t");
  1395.                 String [] split = p.getNome().split(":");
  1396.                 if(split!=null && split.length==3) {
  1397.                     bf.append(split[1]);
  1398.                     bf.append(" (");
  1399.                     bf.append(split[2]);
  1400.                     bf.append(") = ");
  1401.                 }
  1402.                 else {
  1403.                     bf.append(p.getNome());
  1404.                     bf.append(" = ");
  1405.                 }
  1406.                 bf.append(p.getValore());
  1407.                 bf.append("\n");
  1408.             }
  1409.            
  1410.             return true;
  1411.         }
  1412.         return false;
  1413.     }
  1414.    
  1415.     public String getFileTrace(){
  1416.         try {
  1417.             FileTraceGovWayState state = this.openspcoopProperties.getFileTraceGovWayState();
  1418.             return state.toString();
  1419.         }catch(Exception e){
  1420.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1421.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1422.         }
  1423.     }
  1424.    
  1425.     public String updateFileTrace(){
  1426.         try {
  1427.             if(this.openspcoopProperties.isTransazioniFileTraceEnabled()){
  1428.                 FileTraceConfig.update(this.openspcoopProperties.getTransazioniFileTraceConfig(), true);
  1429.                 return JMXUtils.MSG_OPERAZIONE_EFFETTUATA_SUCCESSO;
  1430.             }
  1431.             else {
  1432.                 throw new CoreException("Funzionalità 'FileTrace' disabilitata");
  1433.             }
  1434.         }catch(Exception e){
  1435.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1436.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1437.         }
  1438.     }
  1439.    
  1440.     private void checkByokJmx(boolean wrap) throws CoreException {
  1441.         boolean enabled = wrap ? this.openspcoopProperties.isBYOKJmxWrapEnbled() : this.openspcoopProperties.isBYOKJmxUnwrapEnbled();
  1442.         if(!enabled) {
  1443.             throw new CoreException("not enabled");
  1444.         }
  1445.     }
  1446.    
  1447.     public String byokUnwrap(String value){
  1448.         try {
  1449.             checkByokJmx(false);
  1450.            
  1451.             DriverBYOK driverBYOK = DriverBYOKUtilities.newInstanceDriverBYOKRuntimeNodeForJmxOperation(this.log, false, true);
  1452.             if(driverBYOK!=null) {
  1453.                 return driverBYOK.unwrapAsString(value, true);
  1454.             }
  1455.             return value;
  1456.         }catch(Exception e){
  1457.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1458.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1459.         }
  1460.     }
  1461.        
  1462.     public String byokBase64Unwrap(String value){
  1463.         try {
  1464.             checkByokJmx(false);
  1465.            
  1466.             DriverBYOK driverBYOK = DriverBYOKUtilities.newInstanceDriverBYOKRuntimeNodeForJmxOperation(this.log, false, true);
  1467.             if(driverBYOK!=null) {
  1468.                 byte [] c = driverBYOK.unwrap(value, true);
  1469.                 return Base64Utilities.encodeAsString(c);
  1470.             }
  1471.             return value;
  1472.         }catch(Exception e){
  1473.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1474.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1475.         }
  1476.     }
  1477.    
  1478.     public String byokHexUnwrap(String value){
  1479.         try {
  1480.             checkByokJmx(false);
  1481.            
  1482.             DriverBYOK driverBYOK = DriverBYOKUtilities.newInstanceDriverBYOKRuntimeNodeForJmxOperation(this.log, false, true);
  1483.             if(driverBYOK!=null) {
  1484.                 byte [] c = driverBYOK.unwrap(value, true);
  1485.                 return HexBinaryUtilities.encodeAsString(c);
  1486.             }
  1487.             return value;
  1488.         }catch(Exception e){
  1489.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1490.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1491.         }
  1492.     }
  1493.    
  1494.     public String byokWrap(String value){
  1495.         try {
  1496.             checkByokJmx(true);
  1497.            
  1498.             DriverBYOK driverBYOK = DriverBYOKUtilities.newInstanceDriverBYOKRuntimeNodeForJmxOperation(this.log, true, false);
  1499.             if(driverBYOK!=null) {
  1500.                 BYOKWrappedValue v = driverBYOK.wrap(value);
  1501.                 if(v!=null) {
  1502.                     return v.getWrappedValue();
  1503.                 }
  1504.                 else {
  1505.                     return null;
  1506.                 }
  1507.             }
  1508.             return value;
  1509.         }catch(Exception e){
  1510.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1511.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1512.         }
  1513.     }
  1514.    
  1515.     public String byokWrapBase64Key(String value){
  1516.         try {
  1517.             checkByokJmx(true);
  1518.            
  1519.             byte[] decoded = Base64Utilities.decode(value);
  1520.            
  1521.             DriverBYOK driverBYOK = DriverBYOKUtilities.newInstanceDriverBYOKRuntimeNodeForJmxOperation(this.log, true, false);
  1522.             if(driverBYOK!=null) {
  1523.                 BYOKWrappedValue v = driverBYOK.wrap(decoded);
  1524.                 if(v!=null) {
  1525.                     return v.getWrappedValue();
  1526.                 }
  1527.                 else {
  1528.                     return null;
  1529.                 }
  1530.             }
  1531.             return value;
  1532.         }catch(Exception e){
  1533.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1534.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1535.         }
  1536.     }
  1537.    
  1538.     public String byokWrapHexKey(String value){
  1539.         try {
  1540.             checkByokJmx(true);
  1541.            
  1542.             byte[] decoded = HexBinaryUtilities.decode(value);
  1543.            
  1544.             DriverBYOK driverBYOK = DriverBYOKUtilities.newInstanceDriverBYOKRuntimeNodeForJmxOperation(this.log, true, false);
  1545.             if(driverBYOK!=null) {
  1546.                 BYOKWrappedValue v = driverBYOK.wrap(decoded);
  1547.                 if(v!=null) {
  1548.                     return v.getWrappedValue();
  1549.                 }
  1550.                 else {
  1551.                     return null;
  1552.                 }
  1553.             }
  1554.             return value;
  1555.         }catch(Exception e){
  1556.             this.log.error(JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage(),e);
  1557.             return JMXUtils.MSG_OPERAZIONE_NON_EFFETTUATA+e.getMessage();
  1558.         }
  1559.     }
  1560. }

  1561. class VersioneBaseDatiChecker implements Callable<String>{

  1562.     private OpenSPCoop2Properties openspcoopProperties;
  1563.     private boolean isNodoRun;
  1564.     public VersioneBaseDatiChecker(OpenSPCoop2Properties openspcoopProperties, boolean isNodoRun) {
  1565.         this.openspcoopProperties = openspcoopProperties;
  1566.         this.isNodoRun = isNodoRun;
  1567.     }
  1568.    
  1569.     @Override
  1570.     public String call() throws Exception {
  1571.        
  1572.         if(!DBManager.isInitialized()){
  1573.             throw new CoreException("Inizializzazione DBManager non effettuata");
  1574.         }
  1575.         DBManager dbManager = DBManager.getInstance();
  1576.         Resource resource = null;
  1577.         IDSoggetto dominio = this.openspcoopProperties.getIdentitaPortaDefaultWithoutProtocol();
  1578.         String modulo = this.getClass().getName();
  1579.         try{
  1580.             resource = dbManager.getResource(dominio, modulo, null);
  1581.             Connection c = (Connection) resource.getResource();
  1582.            
  1583.             StringBuilder bf = new StringBuilder();
  1584.             checkTable(c, bf);

  1585.             if(bf.length()<=0){
  1586.                 throw new CoreException("BaseDati non possiede informazioni sul versionamento");
  1587.             }else{
  1588.                 return bf.toString();
  1589.             }

  1590.         }finally{
  1591.             try{
  1592.                 dbManager.releaseResource(dominio, modulo, resource);
  1593.             }catch(Exception eClose){
  1594.                 // close
  1595.             }
  1596.         }
  1597.        
  1598.     }
  1599.    
  1600.     private void checkTable(Connection c, StringBuilder bf) throws UtilsMultiException, SQLException {
  1601.         PreparedStatement pstmt = null;
  1602.         ResultSet rs = null;
  1603.         try{
  1604.             String table1 = this.isNodoRun ? CostantiDB.DB_INFO : CostantiDB.DB_INFO_CONSOLE;
  1605.             String sql = "select * from "+table1 +" order by id DESC";
  1606.             pstmt = c.prepareStatement(sql);
  1607.             try {
  1608.                 rs = pstmt.executeQuery();
  1609.                 while (rs.next()) {
  1610.                     int majorVersion = rs.getInt("major_version");
  1611.                     int minorVersion = rs.getInt("minor_version");
  1612.                     String details = rs.getString("notes");
  1613.                     if(bf.length()>0){
  1614.                         bf.append("\n");
  1615.                     }
  1616.                     bf.append("["+majorVersion+"."+minorVersion+"] "+details);
  1617.                 }
  1618.             }catch(Throwable t) {
  1619.                
  1620.                 JDBCUtilities.closeResources(rs, pstmt);
  1621.                 rs=null;
  1622.                 pstmt=null;
  1623.                
  1624.                 checkTable2(c, bf, t);
  1625.             }

  1626.         }finally{
  1627.             try{
  1628.                 if(rs!=null)
  1629.                     rs.close();
  1630.             }catch(Exception eClose){
  1631.                 // close
  1632.             }
  1633.             try{
  1634.                 if(pstmt!=null)
  1635.                     pstmt.close();
  1636.             }catch(Exception eClose){
  1637.                 // close
  1638.             }
  1639.         }
  1640.     }
  1641.     private void checkTable2(Connection c, StringBuilder bf, Throwable t) throws UtilsMultiException, SQLException {
  1642.         PreparedStatement pstmt = null;
  1643.         ResultSet rs = null;
  1644.         try{
  1645.             String table2 = this.isNodoRun ? CostantiDB.DB_INFO_CONSOLE : CostantiDB.DB_INFO;
  1646.             String sql = "select * from "+table2 +" order by id DESC";
  1647.             pstmt = c.prepareStatement(sql);
  1648.             rs = pstmt.executeQuery();
  1649.             try {
  1650.                 while (rs.next()) {
  1651.                     int majorVersion = rs.getInt("major_version");
  1652.                     int minorVersion = rs.getInt("minor_version");
  1653.                     String details = rs.getString("notes");
  1654.                     if(bf.length()>0){
  1655.                         bf.append("\n");
  1656.                     }
  1657.                     bf.append("["+majorVersion+"."+minorVersion+"] "+details);
  1658.                 }
  1659.             }catch(Throwable tInternal) {
  1660.                 throw new UtilsMultiException(t,tInternal);
  1661.             }
  1662.         }finally{
  1663.             JDBCUtilities.closeResources(rs, pstmt);
  1664.         }
  1665.     }
  1666.    
  1667. }

  1668. class InformazioniDatabaseChecker implements Callable<String>{

  1669.     private OpenSPCoop2Properties openspcoopProperties;
  1670.     public InformazioniDatabaseChecker(OpenSPCoop2Properties openspcoopProperties) {
  1671.         this.openspcoopProperties = openspcoopProperties;
  1672.     }
  1673.    
  1674.     @Override
  1675.     public String call() throws Exception {
  1676.         if(!DBManager.isInitialized()){
  1677.             throw new CoreException("Inizializzazione DBManager non effettuata");
  1678.         }
  1679.         DBManager dbManager = DBManager.getInstance();
  1680.         Resource resource = null;
  1681.         if(this.openspcoopProperties==null) {
  1682.             throw new CoreException("Inizializzazione OpenSPCoop2Properties non effettuata");
  1683.         }
  1684.         IDSoggetto dominio = this.openspcoopProperties.getIdentitaPortaDefaultWithoutProtocol();
  1685.         String modulo = this.getClass().getName();
  1686.         StringBuilder bf = new StringBuilder();

  1687.         if(this.openspcoopProperties.getDatabaseType()!=null){
  1688.             bf.append("TipoDatabase: "+this.openspcoopProperties.getDatabaseType());
  1689.         }
  1690.         else{
  1691.             throw new CoreException("Tipo di Database non disponibile");
  1692.         }

  1693.         try{
  1694.             resource = dbManager.getResource(dominio, modulo, null);
  1695.             Connection c = (Connection) resource.getResource();

  1696.             JDBCUtilities.addInformazioniDatabaseFromMetaData(c, bf);
  1697.            
  1698.             if(bf.length()<=0){
  1699.                 throw new CoreException("Non sono disponibili informazioni sul database");
  1700.             }else{
  1701.                 return bf.toString();
  1702.             }

  1703.         }finally{
  1704.             try{
  1705.                 dbManager.releaseResource(dominio, modulo, resource);
  1706.             }catch(Exception eClose){
  1707.                 // close
  1708.             }
  1709.         }
  1710.     }
  1711.    
  1712. }