ModIDynamicConfigurationApplicativiUtilities.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.protocol.modipa.properties;

  21. import java.util.List;

  22. import org.apache.commons.lang.StringUtils;
  23. import org.openspcoop2.core.config.ConfigurazioneMultitenant;
  24. import org.openspcoop2.core.config.GenericProperties;
  25. import org.openspcoop2.core.config.ServizioApplicativo;
  26. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  27. import org.openspcoop2.core.config.constants.PortaApplicativaSoggettiFruitori;
  28. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  29. import org.openspcoop2.core.id.IDServizioApplicativo;
  30. import org.openspcoop2.core.id.IDSoggetto;
  31. import org.openspcoop2.core.mvc.properties.provider.InputValidationUtils;
  32. import org.openspcoop2.core.registry.Soggetto;
  33. import org.openspcoop2.core.registry.constants.PddTipologia;
  34. import org.openspcoop2.pdd.core.dynamic.DynamicHelperCostanti;
  35. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  36. import org.openspcoop2.protocol.engine.constants.Costanti;
  37. import org.openspcoop2.protocol.engine.utils.NamingUtils;
  38. import org.openspcoop2.protocol.modipa.constants.ModIConsoleCostanti;
  39. import org.openspcoop2.protocol.modipa.validator.IdentificazioneApplicativoMittenteUtils;
  40. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  41. import org.openspcoop2.protocol.sdk.ProtocolException;
  42. import org.openspcoop2.protocol.sdk.constants.ConsoleItemType;
  43. import org.openspcoop2.protocol.sdk.constants.ConsoleItemValueType;
  44. import org.openspcoop2.protocol.sdk.constants.ConsoleOperationType;
  45. import org.openspcoop2.protocol.sdk.properties.AbstractConsoleItem;
  46. import org.openspcoop2.protocol.sdk.properties.BaseConsoleItem;
  47. import org.openspcoop2.protocol.sdk.properties.BinaryProperty;
  48. import org.openspcoop2.protocol.sdk.properties.BooleanConsoleItem;
  49. import org.openspcoop2.protocol.sdk.properties.BooleanProperty;
  50. import org.openspcoop2.protocol.sdk.properties.ConsoleConfiguration;
  51. import org.openspcoop2.protocol.sdk.properties.ConsoleItemInfo;
  52. import org.openspcoop2.protocol.sdk.properties.IConsoleHelper;
  53. import org.openspcoop2.protocol.sdk.properties.ProtocolProperties;
  54. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesFactory;
  55. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesUtils;
  56. import org.openspcoop2.protocol.sdk.properties.StringConsoleItem;
  57. import org.openspcoop2.protocol.sdk.properties.StringProperty;
  58. import org.openspcoop2.protocol.sdk.registry.IConfigIntegrationReader;
  59. import org.openspcoop2.protocol.sdk.registry.IRegistryReader;
  60. import org.openspcoop2.protocol.sdk.registry.ProtocolFiltroRicercaServiziApplicativi;
  61. import org.openspcoop2.protocol.sdk.registry.RegistryException;
  62. import org.openspcoop2.protocol.sdk.registry.RegistryNotFound;
  63. import org.openspcoop2.utils.certificate.CertificateInfo;

  64. /**
  65.  * ModIDynamicConfigurationApplicativiUtilities
  66.  *
  67.  * @author Poli Andrea (apoli@link.it)
  68.  * @author $Author$
  69.  * @version $Rev$, $Date$
  70.  */
  71. public class ModIDynamicConfigurationApplicativiUtilities {
  72.    
  73.     private ModIDynamicConfigurationApplicativiUtilities() {}

  74.     private static final String VERIFICARE_CONFIG_ASSOCIAZIONE_APPLICATIVO = "Verificare le configurazioni dove risulta associato l'applicativo.";
  75.    
  76.     private static List<String> getPddOperative(IRegistryReader registryReader) throws RegistryException{
  77.         List<String> pddOperative = null;
  78.         try {
  79.             pddOperative = registryReader.findIdPorteDominio(true);
  80.         }catch(RegistryNotFound notFound) {
  81.             // ignore
  82.         }
  83.         return pddOperative;
  84.     }
  85.    
  86.     static ConsoleConfiguration getDynamicConfigServizioApplicativo(ConsoleOperationType consoleOperationType, IConsoleHelper consoleHelper, IRegistryReader registryReader,
  87.             IConfigIntegrationReader configIntegrationReader, IDServizioApplicativo id) throws ProtocolException {
  88.        
  89.         ConsoleConfiguration configuration = new ConsoleConfiguration();
  90.        
  91.         boolean esterno = false;
  92.         try {
  93.             String dominio = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_SOGGETTO_DOMINIO);
  94.             if(
  95.                     (dominio==null || "".equals(dominio))
  96.                     &&
  97.                     ConsoleOperationType.CHANGE.equals(consoleOperationType)
  98.                 ) {
  99.                 Soggetto soggetto = registryReader.getSoggetto(id.getIdSoggettoProprietario());
  100.                 if(soggetto.getPortaDominio()==null || "".equals(soggetto.getPortaDominio())) {
  101.                     dominio = PddTipologia.ESTERNO.toString();
  102.                 }
  103.                 else {
  104.                     List<String> pddOperative = getPddOperative(registryReader);
  105.                     if(pddOperative==null || pddOperative.isEmpty() || !pddOperative.contains(soggetto.getPortaDominio())) {
  106.                         dominio = PddTipologia.ESTERNO.toString();  
  107.                     }
  108.                     else {
  109.                         dominio = PddTipologia.OPERATIVO.toString();
  110.                     }
  111.                 }
  112.             }
  113.             esterno = PddTipologia.ESTERNO.toString().equals(dominio);
  114.         }catch(Exception e) {
  115.             throw new ProtocolException(e.getMessage(),e);
  116.         }
  117.        
  118.         boolean isClient = true;
  119.         try {
  120.             String client = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_SERVIZI_APPLICATIVI_TIPO_SA);
  121.             isClient = (client==null) || ("".equals(client)) || (CostantiConfigurazione.CLIENT.equals(client)) || (CostantiConfigurazione.CLIENT_OR_SERVER.equals(client));
  122.             if(ConsoleOperationType.CHANGE.equals(consoleOperationType)) {
  123.                 ServizioApplicativo sa = configIntegrationReader.getServizioApplicativo(id);
  124.                 isClient = CostantiConfigurazione.CLIENT.equals(sa.getTipo()) || sa.isUseAsClient();
  125.             }
  126.         }catch(Exception e) {
  127.             throw new ProtocolException(e.getMessage(),e);
  128.         }
  129.        
  130.         if(isClient) {
  131.             if(!esterno) {
  132.                
  133.                 BaseConsoleItem titolo = ProtocolPropertiesFactory.newTitleItem(
  134.                         ModIConsoleCostanti.MODIPA_APPLICATIVI_ID,
  135.                         ModIConsoleCostanti.MODIPA_APPLICATIVI_LABEL);
  136.                 configuration.addConsoleItem(titolo );
  137.                
  138.                 BaseConsoleItem subTitolo = ProtocolPropertiesFactory.newSubTitleItem(
  139.                         ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_CERTIFICATO_SUBTITLE_ID,
  140.                         ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_CERTIFICATO_SUBTITLE_LABEL);
  141.                 configuration.addConsoleItem(subTitolo );
  142.                
  143.                 BooleanConsoleItem booleanConsoleItem =
  144.                         (BooleanConsoleItem) ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.BOOLEAN, ConsoleItemType.CHECKBOX,
  145.                                 ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_ID, ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_LABEL);
  146.                 booleanConsoleItem.setDefaultValue(false);
  147.                 booleanConsoleItem.setReloadOnChange(true, true);
  148.                 configuration.addConsoleItem(booleanConsoleItem);
  149.                
  150.                 ModIDynamicConfigurationKeystoreUtilities.addKeystoreConfig(configuration, false, true, true);
  151.                
  152.                 BaseConsoleItem subTitoloModiAUTH = ProtocolPropertiesFactory.newSubTitleItem(
  153.                         ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_MODI_AUTH_SUBTITLE_ID,
  154.                         ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_MODI_AUTH_SUBTITLE_LABEL);
  155.                 configuration.addConsoleItem(subTitoloModiAUTH);
  156.             }
  157.            
  158.             if(esterno) {
  159.                 BaseConsoleItem subTitolo = ProtocolPropertiesFactory.newSubTitleItem(
  160.                         ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_CERTIFICATO_SUBTITLE_ID,
  161.                         ModIConsoleCostanti.MODIPA_API_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_LABEL_PARAMETRI_RISPOSTA);
  162.                 configuration.addConsoleItem(subTitolo );
  163.             }
  164.            
  165.             String labelSicurezzaMessaggioAudienceItem = esterno ?
  166.                     ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_INFO_DOMINIO_ESTERNO_LABEL :
  167.                     ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_INFO_DOMINIO_INTERNO_LABEL;
  168.             StringConsoleItem profiloSicurezzaMessaggioAudienceItem = (StringConsoleItem)
  169.                     ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  170.                     ConsoleItemType.TEXT_AREA,
  171.                     ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_ID,
  172.                     labelSicurezzaMessaggioAudienceItem);
  173.             profiloSicurezzaMessaggioAudienceItem.setRows(2);
  174.             profiloSicurezzaMessaggioAudienceItem.setNote(esterno ?
  175.                     ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_INFO_DOMINIO_ESTERNO_NOTE:
  176.                     ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_INFO_DOMINIO_INTERNO_NOTE);
  177.             ConsoleItemInfo infoAud = new ConsoleItemInfo(labelSicurezzaMessaggioAudienceItem);
  178.             if(esterno) {
  179.                 infoAud.setHeaderBody(ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_INFO_DOMINIO_ESTERNO);
  180.             }
  181.             else {
  182.                 infoAud.setHeaderBody(ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_INFO_DOMINIO_INTERNO);
  183.             }
  184.             profiloSicurezzaMessaggioAudienceItem.setInfo(infoAud);
  185.             profiloSicurezzaMessaggioAudienceItem.setRequired(false);
  186.             configuration.addConsoleItem(profiloSicurezzaMessaggioAudienceItem);
  187.            
  188.             if(!esterno) {
  189.                 StringConsoleItem profiloSicurezzaMessaggioX5UItem = (StringConsoleItem)
  190.                     ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  191.                     ConsoleItemType.TEXT_AREA,
  192.                     ModIConsoleCostanti.MODIPA_APPLICATIVI_PROFILO_SICUREZZA_MESSAGGIO_REST_X5U_URL_ID,
  193.                     ModIConsoleCostanti.MODIPA_APPLICATIVI_PROFILO_SICUREZZA_MESSAGGIO_REST_X5U_URL_LABEL);
  194.                 profiloSicurezzaMessaggioX5UItem.setRows(2);
  195.                 profiloSicurezzaMessaggioX5UItem.setNote(ModIConsoleCostanti.MODIPA_APPLICATIVI_PROFILO_SICUREZZA_MESSAGGIO_REST_X5U_URL_NOTE);
  196.                 ConsoleItemInfo infoX5U = new ConsoleItemInfo(ModIConsoleCostanti.MODIPA_APPLICATIVI_PROFILO_SICUREZZA_MESSAGGIO_REST_X5U_URL_LABEL);
  197.                 infoX5U.setHeaderBody(ModIConsoleCostanti.MODIPA_APPLICATIVI_PROFILO_SICUREZZA_MESSAGGIO_REST_X5U_URL_INFO);
  198.                 profiloSicurezzaMessaggioX5UItem.setInfo(infoX5U);
  199.                 profiloSicurezzaMessaggioX5UItem.setRequired(false);
  200.                 configuration.addConsoleItem(profiloSicurezzaMessaggioX5UItem);
  201.             }
  202.                        
  203.             if(!esterno) {
  204.                 BaseConsoleItem subTitolo = ProtocolPropertiesFactory.newSubTitleItem(
  205.                         ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_SUBTITLE_ID,
  206.                         ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_SUBTITLE_LABEL);
  207.                 configuration.addConsoleItem(subTitolo );
  208.                
  209.                 BooleanConsoleItem booleanConsoleItem =
  210.                         (BooleanConsoleItem) ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.BOOLEAN, ConsoleItemType.CHECKBOX,
  211.                                 ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_ID, ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_LABEL);
  212.                 booleanConsoleItem.setDefaultValue(false);
  213.                 booleanConsoleItem.setReloadOnChange(true, true);
  214.                 configuration.addConsoleItem(booleanConsoleItem);
  215.                
  216.                 StringConsoleItem tokenPolicyItem = (StringConsoleItem)
  217.                         ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  218.                         ConsoleItemType.SELECT,
  219.                         ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_POLICY_ID,
  220.                         ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_POLICY_LABEL);
  221.                
  222.                 List<GenericProperties> gestorePolicyTokenList = null;
  223.                 try {
  224.                     gestorePolicyTokenList = configIntegrationReader.getTokenPolicyValidazione();
  225.                 }catch(Exception e) {
  226.                     throw new ProtocolException(e.getMessage(),e);
  227.                 }
  228.                
  229.                 String [] policyLabels = null;
  230.                 String [] policyValues = null;
  231.                 boolean tokenPolicyUndefined = true; // !ConsoleOperationType.CHANGE.equals(consoleOperationType)
  232.                 if(tokenPolicyUndefined){
  233.                     policyLabels = new String[gestorePolicyTokenList.size() + 1];
  234.                     policyValues = new String[gestorePolicyTokenList.size() + 1];
  235.                    
  236.                     policyLabels[0] = ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED;
  237.                     policyValues[0] = ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED;
  238.                 }
  239.                 else {
  240.                     policyLabels = new String[gestorePolicyTokenList.size()];
  241.                     policyValues = new String[gestorePolicyTokenList.size()];
  242.                 }
  243.                
  244.                 for (int i = 0; i < gestorePolicyTokenList.size(); i++) {
  245.                     GenericProperties genericProperties = gestorePolicyTokenList.get(i);
  246.                     if(tokenPolicyUndefined){
  247.                         policyLabels[(i+1)] = genericProperties.getNome();
  248.                         policyValues[(i+1)] = genericProperties.getNome();
  249.                     }
  250.                     else {
  251.                         policyLabels[i] = genericProperties.getNome();
  252.                         policyValues[i] = genericProperties.getNome();
  253.                     }
  254.                 }
  255.                
  256.                 for (int i = 0; i < policyValues.length; i++) {
  257.                     tokenPolicyItem.addLabelValue(policyLabels[i],policyValues[i]);
  258.                 }
  259.                 if(!ConsoleOperationType.CHANGE.equals(consoleOperationType)){
  260.                     tokenPolicyItem.setDefaultValue(ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED);
  261.                 }
  262.                 tokenPolicyItem.setReloadOnChange(false, true);
  263.                 configuration.addConsoleItem(tokenPolicyItem);
  264.                
  265.                 StringConsoleItem tokenClientIdItem = (StringConsoleItem)
  266.                         ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  267.                         ConsoleItemType.TEXT_AREA,
  268.                         ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_CLIENT_ID,
  269.                         ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_CLIENT_LABEL);
  270.                 tokenClientIdItem.setRows(ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_CLIENT_ROWS);
  271.                 tokenClientIdItem.setRequired(true);
  272.                 configuration.addConsoleItem(tokenClientIdItem);
  273.                
  274.                 StringConsoleItem tokenKIDItem = (StringConsoleItem)
  275.                         ProtocolPropertiesFactory.newConsoleItem(ConsoleItemValueType.STRING,
  276.                         ConsoleItemType.TEXT_AREA,
  277.                         ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_KID_ID,
  278.                         ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_KID_LABEL);
  279.                 tokenKIDItem.setRows(ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_KID_ROWS);
  280.                 tokenKIDItem.setRequired(false);
  281.                 ConsoleItemInfo info = new ConsoleItemInfo(ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_KID_LABEL);
  282.                 info.setHeaderBody(DynamicHelperCostanti.LABEL_PARAMETRO_MODIPA_API_IMPL_PROFILO_SICUREZZA_OAUTH_INFO);
  283.                 info.setListBody(DynamicHelperCostanti.LABEL_PARAMETRO_MODIPA_API_IMPL_PROFILO_SICUREZZA_OAUTH_REST_INFO_VALORI_REQUEST); // uso rest volutamente
  284.                 tokenKIDItem.setInfo(info);
  285.                 configuration.addConsoleItem(tokenKIDItem);
  286.             }
  287.            
  288.             return configuration;
  289.         }
  290.         else {
  291.             return null;
  292.         }
  293.        
  294.     }
  295.    
  296.     static void updateDynamicConfigServizioApplicativo(ConsoleConfiguration consoleConfiguration,
  297.             ConsoleOperationType consoleOperationType, IConsoleHelper consoleHelper,
  298.             ProtocolProperties properties,
  299.             IConfigIntegrationReader configIntegrationReader, IDServizioApplicativo id) throws ProtocolException {
  300.        
  301.         boolean esterno = false;
  302.         try {
  303.             String dominio = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_SOGGETTO_DOMINIO);
  304.             esterno = PddTipologia.ESTERNO.toString().equals(dominio);
  305.         }catch(Exception e) {
  306.             throw new ProtocolException(e.getMessage(),e);
  307.         }
  308.        
  309.         boolean isClient = true;
  310.         try {
  311.             String client = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_SERVIZI_APPLICATIVI_TIPO_SA);
  312.             isClient = (client==null) || ("".equals(client)) || (CostantiConfigurazione.CLIENT.equals(client)) || (CostantiConfigurazione.CLIENT_OR_SERVER.equals(client));
  313.             if(ConsoleOperationType.CHANGE.equals(consoleOperationType)) {
  314.                 ServizioApplicativo sa = configIntegrationReader.getServizioApplicativo(id);
  315.                 isClient = CostantiConfigurazione.CLIENT.equals(sa.getTipo()) || sa.isUseAsClient();
  316.             }
  317.         }catch(Exception e) {
  318.             throw new ProtocolException(e.getMessage(),e);
  319.         }
  320.        
  321.        
  322.         if(!esterno && isClient) {
  323.            
  324.             ConfigurazioneMultitenant configurazioneMultitenant = null;
  325.                        
  326.             BooleanProperty booleanModeItemValue = (BooleanProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_ID);
  327.             if(booleanModeItemValue!=null && booleanModeItemValue.getValue()!=null && booleanModeItemValue.getValue().booleanValue()) {
  328.                 boolean hideSceltaArchivioFilePath = false;
  329.                 try {
  330.                     configurazioneMultitenant = configIntegrationReader.getConfigurazioneMultitenant();
  331.                 }
  332.                 catch(RegistryNotFound notFound) {
  333.                     // ignore
  334.                 }
  335.                 catch(Exception e) {
  336.                     throw new ProtocolException(e.getMessage(),e);
  337.                 }
  338.                 /**
  339.                 if(configurazioneMultitenant!=null &&
  340.                         StatoFunzionalita.ABILITATO.equals(configurazioneMultitenant.getStato()) &&
  341.                         !PortaApplicativaSoggettiFruitori.SOGGETTI_ESTERNI.equals(configurazioneMultitenant.getErogazioneSceltaSoggettiFruitori())) {
  342.                     hideSceltaArchivioFilePath = true;
  343.                 }
  344.                 FIX: visualizzo sempre: ho aggiunto un commento. Altrimenti se poi uno modifica la configurazione multitenat, gli applicativi gia' configurati con modalita 'path' vanno in errore
  345.                 */          
  346.                 boolean addHiddenSubjectIssuer = true;
  347.                 boolean rest = true; // un applicativo può essere utilizzato sia da API REST che da API SOAP
  348.                 ModIDynamicConfigurationKeystoreUtilities.updateKeystoreConfig(consoleConfiguration, properties, false,
  349.                         hideSceltaArchivioFilePath, addHiddenSubjectIssuer,
  350.                         true, configurazioneMultitenant,
  351.                         rest);
  352.                
  353.                 BaseConsoleItem subTitoloModIAuth = ProtocolPropertiesUtils.getBaseConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_MODI_AUTH_SUBTITLE_ID);
  354.                 if(subTitoloModIAuth!=null) {
  355.                     subTitoloModIAuth.setType(ConsoleItemType.SUBTITLE);
  356.                 }

  357.             }
  358.             else {

  359.                 // devo annullare eventuale archivio caricato
  360.                 BinaryProperty archiveItemValue = (BinaryProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_ARCHIVE_ID);
  361.                 if(archiveItemValue!=null) {
  362.                     archiveItemValue.setValue(null);
  363.                     archiveItemValue.setFileName(null);
  364.                     archiveItemValue.setClearContent(true);
  365.                 }
  366.                
  367.                 // devo annullare eventuale certificato caricato
  368.                 BinaryProperty certificateItemValue = (BinaryProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_CERTIFICATO_ID);
  369.                 if(certificateItemValue!=null) {
  370.                     certificateItemValue.setValue(null);
  371.                     certificateItemValue.setFileName(null);
  372.                     certificateItemValue.setClearContent(true);
  373.                 }
  374.                
  375.                 StringProperty keyAliasMODIItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEY_ALIAS_ID);
  376.                 if(keyAliasMODIItemValue!=null) {
  377.                     keyAliasMODIItemValue.setValue(null);
  378.                 }
  379.                
  380.                 StringProperty keyPasswordMODIItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEY_PASSWORD_ID);
  381.                 if(keyPasswordMODIItemValue!=null) {
  382.                     keyPasswordMODIItemValue.setValue(null);
  383.                 }
  384.                
  385.                 StringProperty keyCNIssuerMODIItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEY_CN_ISSUER_ID);
  386.                 if(keyCNIssuerMODIItemValue!=null) {
  387.                     keyCNIssuerMODIItemValue.setValue(null);
  388.                 }
  389.                
  390.                 StringProperty keyCNSubjectMODIItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEY_CN_SUBJECT_ID);
  391.                 if(keyCNSubjectMODIItemValue!=null) {
  392.                     keyCNSubjectMODIItemValue.setValue(null);
  393.                 }
  394.                
  395.                 StringProperty keystoreModeMODIItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_MODE_ID);
  396.                 if(keystoreModeMODIItemValue!=null) {
  397.                     keystoreModeMODIItemValue.setValue(null);
  398.                 }
  399.                
  400.                 StringProperty keystorePasswordMODIItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_PASSWORD_ID);
  401.                 if(keystorePasswordMODIItemValue!=null) {
  402.                     keystorePasswordMODIItemValue.setValue(null);
  403.                 }
  404.                
  405.                 StringProperty keystorePathMODIItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_PATH_ID);
  406.                 if(keystorePathMODIItemValue!=null) {
  407.                     keystorePathMODIItemValue.setValue(null);
  408.                 }
  409.                
  410.                 StringProperty keystorePathPublicKeyMODIItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_PATH_PUBLIC_KEY_ID);
  411.                 if(keystorePathPublicKeyMODIItemValue!=null) {
  412.                     keystorePathPublicKeyMODIItemValue.setValue(null);
  413.                 }
  414.                
  415.                 StringProperty keystoreKeyAlgoMODIItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_KEY_ALGORITHM_ID);
  416.                 if(keystoreKeyAlgoMODIItemValue!=null) {
  417.                     keystoreKeyAlgoMODIItemValue.setValue(null);
  418.                 }
  419.                
  420.                 StringProperty keystoreTypeMODIItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_TYPE_ID);
  421.                 if(keystoreTypeMODIItemValue!=null) {
  422.                     keystoreTypeMODIItemValue.setValue(null);
  423.                 }
  424.                
  425.                 StringProperty keystoreByokPolicyMODIItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_BYOK_POLICY_ID);
  426.                 if(keystoreByokPolicyMODIItemValue!=null) {
  427.                     keystoreByokPolicyMODIItemValue.setValue(null);
  428.                 }
  429.                
  430.                 AbstractConsoleItem<?> profiloSicurezzaMessaggioAudienceItem = ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_ID);
  431.                 if(profiloSicurezzaMessaggioAudienceItem!=null) {
  432.                     profiloSicurezzaMessaggioAudienceItem.setType(ConsoleItemType.HIDDEN);
  433.                 }
  434.                 StringProperty profiloSicurezzaMessaggioAudienceItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_ID);
  435.                 if(profiloSicurezzaMessaggioAudienceItemValue!=null) {
  436.                     profiloSicurezzaMessaggioAudienceItemValue.setValue(null);
  437.                 }
  438.                
  439.                 AbstractConsoleItem<?> profiloSicurezzaMessaggioX5UItem = ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_APPLICATIVI_PROFILO_SICUREZZA_MESSAGGIO_REST_X5U_URL_ID);
  440.                 if(profiloSicurezzaMessaggioX5UItem!=null) {
  441.                     profiloSicurezzaMessaggioX5UItem.setType(ConsoleItemType.HIDDEN);
  442.                 }
  443.                 StringProperty profiloSicurezzaMessaggioX5UItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_APPLICATIVI_PROFILO_SICUREZZA_MESSAGGIO_REST_X5U_URL_ID);
  444.                 if(profiloSicurezzaMessaggioX5UItemValue!=null) {
  445.                     profiloSicurezzaMessaggioX5UItemValue.setValue(null);
  446.                 }
  447.                
  448.                 BaseConsoleItem subTitoloModIAuth = ProtocolPropertiesUtils.getBaseConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_MODI_AUTH_SUBTITLE_ID);
  449.                 if(subTitoloModIAuth!=null) {
  450.                     subTitoloModIAuth.setType(ConsoleItemType.HIDDEN);
  451.                 }
  452.                
  453.             }
  454.        
  455.            
  456.             BooleanProperty booleanModeItemTokenValue = (BooleanProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_ID);
  457.             if(booleanModeItemTokenValue!=null && booleanModeItemTokenValue.getValue()!=null && booleanModeItemTokenValue.getValue().booleanValue()) {
  458.                
  459.                 StringProperty tokenPolicyItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_POLICY_ID);
  460.                
  461.                 AbstractConsoleItem<?> tokenPolicyItem = ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_POLICY_ID);
  462.                 boolean tokenPolicyDefined = false;
  463.                 if(tokenPolicyItem!=null) {
  464.                     if(configurazioneMultitenant==null) {
  465.                         try {
  466.                             configurazioneMultitenant = configIntegrationReader.getConfigurazioneMultitenant();
  467.                         }
  468.                         catch(RegistryNotFound notFound) {
  469.                             // ignore
  470.                         }
  471.                         catch(Exception e) {
  472.                             throw new ProtocolException(e.getMessage(),e);
  473.                         }
  474.                     }
  475.                    
  476.                     if(configurazioneMultitenant!=null &&
  477.                             StatoFunzionalita.ABILITATO.equals(configurazioneMultitenant.getStato()) &&
  478.                             !PortaApplicativaSoggettiFruitori.SOGGETTI_ESTERNI.equals(configurazioneMultitenant.getErogazioneSceltaSoggettiFruitori())) {
  479.                         if(tokenPolicyItemValue==null || tokenPolicyItemValue.getValue()==null || StringUtils.isEmpty(tokenPolicyItemValue.getValue()) ||
  480.                                 ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED.equals(tokenPolicyItemValue.getValue())) {
  481.                             tokenPolicyItem.setNote(ModIConsoleCostanti.MODIPASICUREZZA_TOKEN_POLICY_NOTE);
  482.                         }
  483.                         else {
  484.                             tokenPolicyDefined = true;
  485.                         }
  486.                         tokenPolicyItem.setType(ConsoleItemType.SELECT);
  487.                         tokenPolicyItem.setRequired(false);
  488.                         tokenPolicyItem.setReloadOnChange(true, true);
  489.                     }
  490.                     else {
  491.                         tokenPolicyItem.setNote(null);
  492.                         tokenPolicyItem.setType(ConsoleItemType.HIDDEN);
  493.                         tokenPolicyItem.setRequired(false);
  494.                     }
  495.                 }
  496.                
  497.                 AbstractConsoleItem<?> tokenClientIdItem = ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_CLIENT_ID);
  498.                 if(tokenClientIdItem!=null) {
  499.                     tokenClientIdItem.setType(ConsoleItemType.TEXT_AREA);
  500.                     tokenClientIdItem.setRequired(true);
  501.                     if(tokenPolicyDefined) {
  502.                         tokenClientIdItem.setInfo(null);
  503.                     }
  504.                     else {
  505.                         ConsoleItemInfo info = new ConsoleItemInfo(ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_CLIENT_LABEL);
  506.                         info.setHeaderBody(DynamicHelperCostanti.LABEL_PARAMETRO_MODIPA_API_IMPL_PROFILO_SICUREZZA_OAUTH_INFO);
  507.                         info.setListBody(DynamicHelperCostanti.LABEL_PARAMETRO_MODIPA_API_IMPL_PROFILO_SICUREZZA_OAUTH_REST_INFO_VALORI_REQUEST); // uso rest volutamente
  508.                         tokenClientIdItem.setInfo(info);
  509.                     }
  510.                 }
  511.                
  512.                 AbstractConsoleItem<?> tokenKidItem = ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_KID_ID);
  513.                 if(tokenKidItem!=null) {
  514.                     // verifico se abilitato il certificato
  515.                     if(booleanModeItemValue!=null && booleanModeItemValue.getValue()!=null && booleanModeItemValue.getValue().booleanValue()) {
  516.                         tokenKidItem.setType(ConsoleItemType.TEXT_AREA);
  517.                     }
  518.                     else {
  519.                         tokenKidItem.setType(ConsoleItemType.HIDDEN);
  520.                     }
  521.                 }
  522.             }
  523.             else {
  524.                
  525.                 StringProperty tokenPolicyItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_POLICY_ID);
  526.                 if(tokenPolicyItemValue!=null) {
  527.                     tokenPolicyItemValue.setValue(null);
  528.                 }
  529.                                
  530.                 AbstractConsoleItem<?> tokenPolicyItem = ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_POLICY_ID);
  531.                 if(tokenPolicyItem!=null) {
  532.                     tokenPolicyItem.setType(ConsoleItemType.HIDDEN);
  533.                     tokenPolicyItem.setRequired(false);
  534.                     tokenPolicyItem.setNote(null);
  535.                 }
  536.                
  537.                
  538.                 AbstractConsoleItem<?> tokenClientIdItem = ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_CLIENT_ID);
  539.                 if(tokenClientIdItem!=null) {
  540.                     tokenClientIdItem.setType(ConsoleItemType.HIDDEN);
  541.                     tokenClientIdItem.setRequired(false);
  542.                 }
  543.                
  544.                 StringProperty tokenClientIdItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_CLIENT_ID);
  545.                 if(tokenClientIdItemValue!=null) {
  546.                     tokenClientIdItemValue.setValue(null);
  547.                 }
  548.                
  549.                 AbstractConsoleItem<?> tokenKidItem = ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(), ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_KID_ID);
  550.                 if(tokenKidItem!=null) {
  551.                     tokenKidItem.setType(ConsoleItemType.HIDDEN);
  552.                 }
  553.                
  554.                 StringProperty tokenKidItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_KID_ID);
  555.                 if(tokenKidItemValue!=null) {
  556.                     tokenKidItemValue.setValue(null);
  557.                 }
  558.                
  559.             }

  560.         }
  561.        
  562.     }
  563.    
  564.     static void validateDynamicConfigServizioApplicativo(ConsoleConfiguration consoleConfiguration,
  565.             ConsoleOperationType consoleOperationType, IConsoleHelper consoleHelper, ProtocolProperties properties,
  566.             IConfigIntegrationReader configIntegrationReader, IDServizioApplicativo id) throws ProtocolException {
  567.        
  568.         boolean esterno = false;
  569.         try {
  570.             String dominio = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_SOGGETTO_DOMINIO);
  571.             esterno = PddTipologia.ESTERNO.toString().equals(dominio);
  572.         }catch(Exception e) {
  573.             throw new ProtocolException(e.getMessage(),e);
  574.         }
  575.        
  576.         boolean isClient = true;
  577.         try {
  578.             String client = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_SERVIZI_APPLICATIVI_TIPO_SA);
  579.             isClient = (client==null) || ("".equals(client)) || (CostantiConfigurazione.CLIENT.equals(client)) || (CostantiConfigurazione.CLIENT_OR_SERVER.equals(client));
  580.             if(ConsoleOperationType.CHANGE.equals(consoleOperationType)) {
  581.                 ServizioApplicativo sa = configIntegrationReader.getServizioApplicativo(id);
  582.                 isClient = CostantiConfigurazione.CLIENT.equals(sa.getTipo()) || sa.isUseAsClient();
  583.             }
  584.         }catch(Exception e) {
  585.             throw new ProtocolException(e.getMessage(),e);
  586.         }
  587.        
  588.         if(isClient) {
  589.                        
  590.             boolean verifyKeystoreConfig = false;
  591.             boolean verifyCertificateConfig = false;
  592.             boolean changeBinary = false;
  593.             if(ConsoleOperationType.CHANGE.equals(consoleOperationType)) {
  594.                 try {
  595.                     String p = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_PP_CHANGE_BINARY);
  596.                     if(Costanti.CONSOLE_PARAMETRO_PP_CHANGE_BINARY_VALUE_TRUE.equalsIgnoreCase(p)) {
  597.                         verifyKeystoreConfig = true;
  598.                        
  599.                         changeBinary = true;
  600.                        
  601.                         StringProperty selectModeItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_MODE_ID);
  602.                         if(selectModeItemValue!=null && selectModeItemValue.getValue()!=null && !"".equals(selectModeItemValue.getValue())) {
  603.                             String modalita = selectModeItemValue.getValue();
  604.                             if(ModIConsoleCostanti.MODIPA_KEYSTORE_MODE_VALUE_ARCHIVE.equals(modalita)) {
  605.                                 verifyKeystoreConfig = true;
  606.                             }
  607.                             else {
  608.                                 verifyCertificateConfig = true;
  609.                                 verifyKeystoreConfig = false;
  610.                             }
  611.                         }
  612.                        
  613.                         if(verifyKeystoreConfig) {
  614.                             BinaryProperty archiveItemValue = (BinaryProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_ARCHIVE_ID);
  615.                             if(archiveItemValue==null || archiveItemValue.getValue()==null) {
  616.                                 throw new ProtocolException("Archivio non fornito");
  617.                             }
  618.                         }
  619.                         else if(verifyCertificateConfig) {
  620.                             BinaryProperty certificateItemValue = (BinaryProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_CERTIFICATO_ID);
  621.                             if(certificateItemValue==null || certificateItemValue.getValue()==null) {
  622.                                 throw new ProtocolException("Certificato non fornito");
  623.                             }
  624.                         }
  625.                     }
  626.                     else {
  627.                         // devo verificare se c'e' stato un cambio nella modalita
  628.                         StringProperty selectModeItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_MODE_ID);
  629.                         if(selectModeItemValue!=null && selectModeItemValue.getValue()!=null && !"".equals(selectModeItemValue.getValue())) {
  630.                             String modalita = selectModeItemValue.getValue();
  631.                             if(ModIConsoleCostanti.MODIPA_KEYSTORE_MODE_VALUE_ARCHIVE.equals(modalita)) {
  632.                                 verifyKeystoreConfig = true;
  633.                             }
  634.                             else {
  635.                                 verifyCertificateConfig = true;
  636.                             }
  637.                         }
  638.                     }
  639.                 }catch(Exception e) {
  640.                     throw new ProtocolException(e.getMessage(),e);
  641.                 }
  642.             }
  643.             else if(ConsoleOperationType.ADD.equals(consoleOperationType)) {
  644.                
  645.                 StringProperty selectModeItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_MODE_ID);
  646.                 if(selectModeItemValue!=null && selectModeItemValue.getValue()!=null && !"".equals(selectModeItemValue.getValue())) {
  647.                     String modalita = selectModeItemValue.getValue();
  648.                     if(ModIConsoleCostanti.MODIPA_KEYSTORE_MODE_VALUE_ARCHIVE.equals(modalita)) {
  649.                         verifyKeystoreConfig = true;
  650.                     }
  651.                     else {
  652.                         verifyCertificateConfig = true;
  653.                     }
  654.                 }

  655.             }
  656.    
  657.             CertificateInfo cert = null;
  658.             if(!esterno) {
  659.            
  660.                 if(verifyKeystoreConfig) {
  661.                     // NOTA: se si attiva anche la validazione durante il change binary, poi non si riesce a modificarlo poiche' la password o l'alis, o qualche parametro non ĆØ compatibile con il nuovo archivio.
  662.                    
  663.                     try {
  664.                         cert = ModIDynamicConfigurationKeystoreUtilities.readKeystoreConfig(properties, false);
  665.                     }catch(Exception e) {
  666.                         throw new ProtocolException("Verificare i parametri indicati per il keystore in "+ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_CERTIFICATO_SUBTITLE_LABEL_MSG_ERROR+": "+e.getMessage(),e);
  667.                     }
  668.                 }
  669.                 else if(verifyCertificateConfig) {
  670.                     try {
  671.                         cert = ModIDynamicConfigurationKeystoreUtilities.readKeystoreConfig(properties, true);
  672.                     }catch(Exception e) {
  673.                         throw new ProtocolException("Verificare il certificato caricato in "+ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_CERTIFICATO_SUBTITLE_LABEL_MSG_ERROR+": "+e.getMessage(),e);
  674.                     }
  675.                
  676.                 }
  677.                    
  678.                 if(verifyCertificateConfig &&
  679.                     // il controllo lo devo fare solamente se definisco una modalitĆ  per cui consente di fornire a parte il certificato
  680.                     // la modalita 'verifyKeystoreConfig' ĆØ associata alla modalitĆ  archivio dove si carica il PKCS12.
  681.                     // in questo caso se abilito la validazione sotto indicata, non posso definire 2 applicativi con lo stesso PKCS12, che invece potrebbe dover servire.
  682.                     // Serve in una fase di fruizione, nella fase di erogazione con multitenant, poi verrĆ  identificato uno a casa ma non ĆØ evitabile.
  683.                     // In questi casi si consiglia di usare anzi una modalitĆ  filesyste o HSM dove si fornirĆ  il certificato in più solo per l'applicativo che deve essere identificato lato erogazione
  684.                     cert!=null && cert.getSubject()!=null) {
  685.                        
  686.                     ProtocolFiltroRicercaServiziApplicativi filtro = IdentificazioneApplicativoMittenteUtils.createFilter(cert.getSubject().toString(),
  687.                             cert.getIssuer().toString());
  688.                    
  689.                     List<IDServizioApplicativo> list = null;
  690.                     try {
  691.                         list = configIntegrationReader.findIdServiziApplicativi(filtro);
  692.                     }catch(RegistryNotFound notFound) {
  693.                         // ignore
  694.                     }
  695.                     catch(Exception t) {
  696.                         throw new ProtocolException("Errore non atteso durante la verfica del certificato caricato in "+ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_CERTIFICATO_SUBTITLE_LABEL_MSG_ERROR+": "+t.getMessage(),t);
  697.                     }
  698.                     if(list!=null) {
  699.                         for (IDServizioApplicativo idServizioApplicativoSubjectIssuerCheck : list) {
  700.                             // Possono esistere piu' sil che hanno un CN con subject e issuer.
  701.                            
  702.                             java.security.cert.Certificate certificatoCheck = null;
  703.                             try {
  704.                                 ServizioApplicativo sa = configIntegrationReader.getServizioApplicativo(idServizioApplicativoSubjectIssuerCheck);
  705.                                 certificatoCheck = IdentificazioneApplicativoMittenteUtils.readServizioApplicativoByCertificate(sa, null);
  706.                             }catch(Exception t) {
  707.                                 throw new ProtocolException("Errore non atteso durante la verfica del certificato caricato in "+ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_CERTIFICATO_SUBTITLE_LABEL_MSG_ERROR+": "+t.getMessage(),t);
  708.                             }
  709.                            
  710.                             if(certificatoCheck instanceof java.security.cert.X509Certificate &&
  711.                                 cert.equals(((java.security.cert.X509Certificate)certificatoCheck),true) &&
  712.                                 (ConsoleOperationType.ADD.equals(consoleOperationType) || !idServizioApplicativoSubjectIssuerCheck.equals(id))
  713.                             ){
  714.                                 throw new ProtocolException("Il certificato caricato in "+ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_CERTIFICATO_SUBTITLE_LABEL_MSG_ERROR+" risulta giĆ  assegnato all'applicativo '"+idServizioApplicativoSubjectIssuerCheck.getNome()+"'");
  715.                             }
  716.                            
  717.                         }
  718.                     }
  719.                    
  720.                 }
  721.                
  722.                 if(changeBinary) {
  723.                     try {
  724.                         if(cert!=null && cert.getSubject()!=null) {
  725.                             StringProperty subjectItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEY_CN_SUBJECT_ID);
  726.                             subjectItemValue.setValue(cert.getSubject().toString());
  727.                            
  728.                             StringProperty issuerItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEY_CN_ISSUER_ID);
  729.                             if(cert.getIssuer()!=null) {
  730.                                 issuerItemValue.setValue(cert.getIssuer().toString());
  731.                             }
  732.                             else {
  733.                                 if(issuerItemValue!=null) {
  734.                                     issuerItemValue.setValue(null);
  735.                                 }
  736.                             }
  737.                         }
  738.                     }catch(Exception e) {
  739.                         // errore sollevato in validazione
  740.                     }
  741.                 }
  742.                
  743.             }
  744.            
  745.             // Audience Risposta
  746.             AbstractConsoleItem<?> audienceRispostaItem =  
  747.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  748.                             ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_ID
  749.                             );
  750.             if(audienceRispostaItem!=null) {
  751.                 StringProperty audienceRispostaItemValue =
  752.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_ID);
  753.                 if(audienceRispostaItemValue!=null && audienceRispostaItemValue.getValue()!=null && !"".equals(audienceRispostaItemValue.getValue())) {
  754.                     try {
  755.                         String labelSicurezzaMessaggioAudienceItem = esterno ?
  756.                                 ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_INFO_DOMINIO_ESTERNO_LABEL :
  757.                                 ModIConsoleCostanti.MODIPA_APPLICATIVI_AUDIENCE_RISPOSTA_INFO_DOMINIO_INTERNO_LABEL;
  758.                         InputValidationUtils.validateTextAreaInput(audienceRispostaItemValue.getValue(),
  759.                                 labelSicurezzaMessaggioAudienceItem);
  760.                     }catch(Exception e) {
  761.                         throw new ProtocolException(e.getMessage(),e);
  762.                     }
  763.                 }
  764.             }
  765.            
  766.             // Public X5U URL
  767.             if(!esterno) {
  768.                
  769.                 AbstractConsoleItem<?> x5uUrlItem =    
  770.                         ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  771.                                 ModIConsoleCostanti.MODIPA_APPLICATIVI_PROFILO_SICUREZZA_MESSAGGIO_REST_X5U_URL_ID
  772.                                 );
  773.                 if(x5uUrlItem!=null) {
  774.                     StringProperty x5uUrlItemValue =
  775.                             (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_APPLICATIVI_PROFILO_SICUREZZA_MESSAGGIO_REST_X5U_URL_ID);
  776.                     if(x5uUrlItemValue!=null && x5uUrlItemValue.getValue()!=null && !"".equals(x5uUrlItemValue.getValue())) {
  777.                         try {
  778.                             InputValidationUtils.validateTextAreaInput(x5uUrlItemValue.getValue(),
  779.                                     ModIConsoleCostanti.MODIPA_APPLICATIVI_PROFILO_SICUREZZA_MESSAGGIO_REST_X5U_URL_LABEL);
  780.                         }catch(Exception e) {
  781.                             throw new ProtocolException(e.getMessage(),e);
  782.                         }
  783.                     }
  784.                 }
  785.             }
  786.            
  787.             // Keystore Path
  788.             AbstractConsoleItem<?> keystorePathItem =  
  789.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  790.                             ModIConsoleCostanti.MODIPA_KEYSTORE_PATH_ID
  791.                             );
  792.             if(keystorePathItem!=null) {
  793.                 StringProperty keystorePathItemValue =
  794.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_PATH_ID);
  795.                 if(keystorePathItemValue!=null && keystorePathItemValue.getValue()!=null && !"".equals(keystorePathItemValue.getValue())) {
  796.                     try {
  797.                         String keystoreType = null;
  798.                         StringProperty keystoreTypeItemValue =
  799.                                 (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_TYPE_ID);
  800.                         if(keystoreTypeItemValue!=null && keystoreTypeItemValue.getValue()!=null) {
  801.                             keystoreType = keystoreTypeItemValue.getValue();
  802.                         }
  803.                        
  804.                         InputValidationUtils.validateTextAreaInput(keystorePathItemValue.getValue(),
  805.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_RICHIESTA_LABEL +" - "+
  806.                                 ((ModIConsoleCostanti.MODIPA_KEYSTORE_TYPE_VALUE_KEY_PAIR.equals(keystoreType))? ModIConsoleCostanti.MODIPA_KEYSTORE_PATH_PRIVATE_KEY_LABEL : ModIConsoleCostanti.MODIPA_KEYSTORE_PATH_LABEL));
  807.                     }catch(Exception e) {
  808.                         throw new ProtocolException(e.getMessage(),e);
  809.                     }
  810.                 }
  811.             }
  812.            
  813.             // Keystore Path 'PublicKey'
  814.             AbstractConsoleItem<?> keystorePathPublicKeyItem =  
  815.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  816.                             ModIConsoleCostanti.MODIPA_KEYSTORE_PATH_PUBLIC_KEY_ID
  817.                             );
  818.             if(keystorePathPublicKeyItem!=null) {
  819.                 StringProperty keystorePathPublicKeyItemValue =
  820.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_PATH_PUBLIC_KEY_ID);
  821.                 if(keystorePathPublicKeyItemValue!=null && keystorePathPublicKeyItemValue.getValue()!=null && !"".equals(keystorePathPublicKeyItemValue.getValue())) {
  822.                     try {
  823.                         InputValidationUtils.validateTextAreaInput(keystorePathPublicKeyItemValue.getValue(),
  824.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_RICHIESTA_LABEL +" - "+
  825.                                 ModIConsoleCostanti.MODIPA_KEYSTORE_PATH_PUBLIC_KEY_LABEL);
  826.                     }catch(Exception e) {
  827.                         throw new ProtocolException(e.getMessage(),e);
  828.                     }
  829.                 }
  830.             }
  831.            
  832.             // Keystore password
  833.             AbstractConsoleItem<?> keystorePasswordItem =  
  834.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  835.                             ModIConsoleCostanti.MODIPA_KEYSTORE_PASSWORD_ID
  836.                             );
  837.             if(keystorePasswordItem!=null) {
  838.                 StringProperty keystoreItemValue =
  839.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_PASSWORD_ID);
  840.                 if(keystoreItemValue!=null && keystoreItemValue.getValue()!=null && !"".equals(keystoreItemValue.getValue())) {
  841.                     try {
  842.                         InputValidationUtils.validateTextInput(keystoreItemValue.getValue(),
  843.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_KEYSTORE_LABEL +" - "+
  844.                                 ModIConsoleCostanti.MODIPA_KEYSTORE_PASSWORD_LABEL);
  845.                     }catch(Exception e) {
  846.                         throw new ProtocolException(e.getMessage(),e);
  847.                     }
  848.                 }
  849.             }
  850.            
  851.             // Key password
  852.             AbstractConsoleItem<?> keyPasswordItem =    
  853.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  854.                             ModIConsoleCostanti.MODIPA_KEY_PASSWORD_ID
  855.                             );
  856.             if(keyPasswordItem!=null) {
  857.                 StringProperty keystoreItemValue =
  858.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEY_PASSWORD_ID);
  859.                 if(keystoreItemValue!=null && keystoreItemValue.getValue()!=null && !"".equals(keystoreItemValue.getValue())) {
  860.                     try {
  861.                         InputValidationUtils.validateTextInput(keystoreItemValue.getValue(),
  862.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_KEYSTORE_LABEL +" - "+
  863.                                 ModIConsoleCostanti.MODIPA_KEY_PASSWORD_LABEL);
  864.                     }catch(Exception e) {
  865.                         throw new ProtocolException(e.getMessage(),e);
  866.                     }
  867.                 }
  868.             }
  869.             // Key alias
  870.             AbstractConsoleItem<?> keyAliasItem =  
  871.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  872.                             ModIConsoleCostanti.MODIPA_KEY_ALIAS_ID
  873.                             );
  874.             if(keyAliasItem!=null) {
  875.                 StringProperty keystoreItemValue =
  876.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEY_ALIAS_ID);
  877.                 if(keystoreItemValue!=null && keystoreItemValue.getValue()!=null && !"".equals(keystoreItemValue.getValue())) {
  878.                     try {
  879.                         InputValidationUtils.validateTextInput(keystoreItemValue.getValue(),
  880.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_KEYSTORE_LABEL +" - "+
  881.                                 ModIConsoleCostanti.MODIPA_KEY_ALIAS_LABEL);
  882.                     }catch(Exception e) {
  883.                         throw new ProtocolException(e.getMessage(),e);
  884.                     }
  885.                 }
  886.             }
  887.            
  888.             String tokenPolicyName = null;
  889.             if(!esterno) {
  890.                
  891.                 BooleanProperty booleanModeItemTokenValue = (BooleanProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_ID);
  892.                 if(booleanModeItemTokenValue!=null && booleanModeItemTokenValue.getValue()!=null && booleanModeItemTokenValue.getValue().booleanValue()) {
  893.                    
  894.                     StringProperty tokenPolicyItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_POLICY_ID);
  895.                     if(tokenPolicyItemValue==null || tokenPolicyItemValue.getValue()==null || StringUtils.isEmpty(tokenPolicyItemValue.getValue()) ||
  896.                             ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED.equals(tokenPolicyItemValue.getValue())) {
  897.                         /** NON e' OBBLIGATORIA!
  898.                         //throw new ProtocolException("Deve essere selezionata una "+ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_POLICY_LABEL);*/
  899.                     }
  900.                     else {
  901.                         tokenPolicyName = tokenPolicyItemValue.getValue();
  902.                     }
  903.                    
  904.                     // Altrimenti la select list ĆØ valorizzata con quelli esistenti
  905.                     if(tokenPolicyName!=null) {
  906.                         GenericProperties gp = null;
  907.                         try {
  908.                             gp = configIntegrationReader.getTokenPolicyValidazione(tokenPolicyName);
  909.                         }
  910.                         catch(RegistryNotFound notFound) {
  911.                             // ignore
  912.                         }
  913.                         catch(RegistryException e) {
  914.                             throw new ProtocolException(ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_POLICY_LABEL+" indicata '"+tokenPolicyName+"' non esiste? (errore: "+e.getMessage()+")",e);
  915.                         }
  916.                         if(gp==null) {
  917.                             throw new ProtocolException(ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_POLICY_LABEL+" indicata '"+tokenPolicyName+"' non esiste");
  918.                         }
  919.                     }
  920.                                        
  921.                     StringProperty tokenClientIdItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_CLIENT_ID);
  922.                     if(tokenClientIdItemValue==null || tokenClientIdItemValue.getValue()==null || StringUtils.isEmpty(tokenClientIdItemValue.getValue())) {
  923.                         throw new ProtocolException("Deve essere indicato un "+ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_CLIENT_LABEL);
  924.                     }
  925.                     try {
  926.                         InputValidationUtils.validateTextAreaInput(tokenClientIdItemValue.getValue(),
  927.                                 ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_CLIENT_LABEL);
  928.                     }catch(Exception e) {
  929.                         throw new ProtocolException(e.getMessage(),e);
  930.                     }
  931.                    
  932.                     StringProperty tokenKidItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_KID_ID);
  933.                     if(tokenKidItemValue!=null && tokenKidItemValue.getValue()!=null && StringUtils.isNotEmpty(tokenKidItemValue.getValue())) {
  934.                         try {
  935.                             InputValidationUtils.validateTextAreaInput(tokenKidItemValue.getValue(),
  936.                                 ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_KID_LABEL);
  937.                         }catch(Exception e) {
  938.                             throw new ProtocolException(e.getMessage(),e);
  939.                         }
  940.                     }
  941.                    
  942.                     boolean tokenWithHttpsEnabled = false;
  943.                     // basta un protocollo che lo supporta per doverli cercare anche con la funzionalita' abilitata
  944.                     for(IProtocolFactory<?> protocolFactory: ProtocolFactoryManager.getInstance().getProtocolFactories().values()) {
  945.                         if(protocolFactory.createProtocolConfiguration().isSupportatoAutenticazioneApplicativiHttpsConToken()) {
  946.                             tokenWithHttpsEnabled = true;
  947.                             break;
  948.                         }
  949.                     }
  950.                    
  951.                     ServizioApplicativo sa = null;
  952.                     if(tokenPolicyName!=null) {
  953.                         try {
  954.                             sa = configIntegrationReader.getServizioApplicativoByCredenzialiToken(tokenPolicyName, tokenClientIdItemValue.getValue(), tokenWithHttpsEnabled);
  955.                             boolean alreadyExists = false;
  956.                             if(sa!=null) {
  957.                                 if(ConsoleOperationType.ADD.equals(consoleOperationType)) {
  958.                                     alreadyExists=true;
  959.                                 }
  960.                                 else {
  961.                                     IDServizioApplicativo idSAFind = new IDServizioApplicativo();
  962.                                     idSAFind.setIdSoggettoProprietario(new IDSoggetto(sa.getTipoSoggettoProprietario(), sa.getNomeSoggettoProprietario()));
  963.                                     idSAFind.setNome(sa.getNome());
  964.                                     if(!id.equals(idSAFind)) {
  965.                                         alreadyExists=true;
  966.                                     }
  967.                                 }
  968.                             }
  969.                             if(alreadyExists) {
  970.                                 String labelSoggetto = NamingUtils.getLabelSoggetto(new IDSoggetto(sa.getTipoSoggettoProprietario(), sa.getNomeSoggettoProprietario()));
  971.                                 throw new ProtocolException("L'applicativo "+sa.getNome()+" (soggetto: "+labelSoggetto+") possiede giĆ  l'identificativo client indicato");
  972.                             }
  973.                         }catch(RegistryNotFound notFound) {
  974.                             // ignore
  975.                         }
  976.                         catch(Exception e) {
  977.                             throw new ProtocolException(e.getMessage(),e);
  978.                         }
  979.                     }
  980.                 }
  981.                
  982.                 if(ConsoleOperationType.CHANGE.equals(consoleOperationType)) {
  983.                    
  984.                     BooleanProperty booleanModeItemSicurezzaMessaggioValue = (BooleanProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_ID);
  985.                     boolean sicurezzaMessaggio = false;
  986.                     if(booleanModeItemSicurezzaMessaggioValue!=null && booleanModeItemSicurezzaMessaggioValue.getValue()!=null) {
  987.                         sicurezzaMessaggio = booleanModeItemSicurezzaMessaggioValue.getValue();
  988.                     }
  989.                    
  990.                     ServizioApplicativo sa = null;
  991.                     try {
  992.                         sa = configIntegrationReader.getServizioApplicativo(id);
  993.                     }catch(Exception t) {
  994.                         // ignore
  995.                     }
  996.                     if(sa!=null) {
  997.                         String oldTokenPolicyName = null;
  998.                         String oldCnSubject = null;
  999.                         /**String oldCnIssuer = null;*/
  1000.                         if(sa.sizeProtocolPropertyList()>0) {
  1001.                             for (org.openspcoop2.core.config.ProtocolProperty pp : sa.getProtocolPropertyList()) {
  1002.                                 if(ModIConsoleCostanti.MODIPA_SICUREZZA_TOKEN_POLICY_ID.equals(pp.getName())) {
  1003.                                     oldTokenPolicyName = pp.getValue();
  1004.                                 }
  1005.                                 else if(ModIConsoleCostanti.MODIPA_KEY_CN_SUBJECT_ID.equals(pp.getName())) {
  1006.                                     oldCnSubject = pp.getValue();
  1007.                                 }
  1008.                                 /**else if(ModIConsoleCostanti.MODIPA_KEY_CN_ISSUER_ID.equals(pp.getName())) {
  1009.                                     oldCnIssuer = pp.getValue();
  1010.                                 }*/
  1011.                             }
  1012.                         }
  1013.                        
  1014.                         StringBuilder sbWarningChange = new StringBuilder();
  1015.                         if(oldTokenPolicyName!=null && StringUtils.isNotEmpty(oldTokenPolicyName) && !"-".equals(oldTokenPolicyName)) {
  1016.                             if(tokenPolicyName==null || StringUtils.isEmpty(tokenPolicyName)) {
  1017.                                 sbWarningChange.append("L'applicativo potrebbe essere stato associato ad una erogazione o fruizione che richiede la token policy '"+oldTokenPolicyName+"' eliminata.");
  1018.                                 sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1019.                                 sbWarningChange.append(VERIFICARE_CONFIG_ASSOCIAZIONE_APPLICATIVO);
  1020.                             }
  1021.                             else if(!oldTokenPolicyName.equals(tokenPolicyName)) {
  1022.                                 sbWarningChange.append("L'applicativo potrebbe essere stato associato ad una erogazione o fruizione che richiede la precedente token policy '"+oldTokenPolicyName+"' modificata in '"+tokenPolicyName+"'.");
  1023.                                 sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1024.                                 sbWarningChange.append(VERIFICARE_CONFIG_ASSOCIAZIONE_APPLICATIVO);
  1025.                             }
  1026.                         }
  1027.                        
  1028.                         if(oldCnSubject!=null && StringUtils.isNotEmpty(oldCnSubject) &&
  1029.                             !sicurezzaMessaggio) {
  1030.                             if(sbWarningChange.length()>0) {
  1031.                                 sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1032.                                 sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1033.                             }
  1034.                             sbWarningChange.append("L'applicativo potrebbe essere stato associato ad una erogazione o fruizione che richiede il certificato eliminato ("+oldCnSubject+").");
  1035.                             sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1036.                             sbWarningChange.append(VERIFICARE_CONFIG_ASSOCIAZIONE_APPLICATIVO);
  1037.                         }
  1038.                        
  1039.                         /**
  1040.                         boolean certWarning = false;
  1041.                         if(oldCnSubject!=null && StringUtils.isNotEmpty(oldCnSubject)) {
  1042.                             if(cert==null || cert.getSubject()==null) {
  1043.                                 if(sbWarningChange.length()>0) {
  1044.                                     sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1045.                                     sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1046.                                 }
  1047.                                 sbWarningChange.append("L'applicativo potrebbe essere stato associato ad una erogazione o fruizione che richiede il certificato eliminato ("+oldCnSubject+").");
  1048.                                 sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1049.                                 sbWarningChange.append(VERIFICARE_CONFIG_ASSOCIAZIONE_APPLICATIVO);
  1050.                                 certWarning = true;
  1051.                             }
  1052.                             else if(!oldCnSubject.equals(cert.getSubject().toString())) {
  1053.                                 if(sbWarningChange.length()>0) {
  1054.                                     sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1055.                                     sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1056.                                 }
  1057.                                 sbWarningChange.append("L'applicativo potrebbe essere stato associato ad una erogazione o fruizione che richiede il precedente certificato ("+oldCnSubject+").");
  1058.                                 sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1059.                                 sbWarningChange.append(VERIFICARE_CONFIG_ASSOCIAZIONE_APPLICATIVO);
  1060.                                 certWarning = true;
  1061.                             }
  1062.                         }
  1063.                        
  1064.                         if(!certWarning && oldCnIssuer!=null && StringUtils.isNotEmpty(oldCnIssuer)) {
  1065.                             if(cert==null || cert.getIssuer()==null) {
  1066.                                 if(sbWarningChange.length()>0) {
  1067.                                     sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1068.                                     sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1069.                                 }
  1070.                                 sbWarningChange.append("L'applicativo potrebbe essere stato associato ad una erogazione o fruizione che richiede il certificato eliminato (subject["+oldCnSubject+"] issuer["+oldCnIssuer+"]).");
  1071.                                 sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1072.                                 sbWarningChange.append(VERIFICARE_CONFIG_ASSOCIAZIONE_APPLICATIVO);
  1073.                             }
  1074.                             else if(!oldCnIssuer.equals(cert.getIssuer().toString())) {
  1075.                                 if(sbWarningChange.length()>0) {
  1076.                                     sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1077.                                     sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1078.                                 }
  1079.                                 sbWarningChange.append("L'applicativo potrebbe essere stato associato ad una erogazione o fruizione che richiede il precedente certificato (subject["+oldCnSubject+"] issuer["+oldCnIssuer+"]).");
  1080.                                 sbWarningChange.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  1081.                                 sbWarningChange.append(VERIFICARE_CONFIG_ASSOCIAZIONE_APPLICATIVO);
  1082.                             }
  1083.                         }
  1084.                         */
  1085.                        
  1086.                         if(sbWarningChange.length()>0) {
  1087.                             try {
  1088.                                 consoleHelper.setMessage(sbWarningChange.toString(), true, "warn");
  1089.                             }catch(Exception t) {
  1090.                                 // ignore
  1091.                             }
  1092.                         }
  1093.                     }
  1094.                    
  1095.                 }
  1096.             }
  1097.         }
  1098.     }
  1099. }