ModIDynamicConfigurationAccordiParteSpecificaUtilities.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 java.util.Properties;

  23. import org.apache.commons.lang.StringUtils;
  24. import org.openspcoop2.core.id.IDAccordo;
  25. import org.openspcoop2.core.id.IDServizio;
  26. import org.openspcoop2.core.id.IDSoggetto;
  27. import org.openspcoop2.core.mvc.properties.provider.InputValidationUtils;
  28. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  29. import org.openspcoop2.core.registry.constants.ServiceBinding;
  30. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  31. import org.openspcoop2.pdd.core.dynamic.DynamicHelperCostanti;
  32. import org.openspcoop2.pdd.core.token.parser.Claims;
  33. import org.openspcoop2.protocol.engine.constants.Costanti;
  34. import org.openspcoop2.protocol.modipa.config.ModIProperties;
  35. import org.openspcoop2.protocol.modipa.constants.ModIConsoleCostanti;
  36. import org.openspcoop2.protocol.modipa.utils.SOAPHeader;
  37. import org.openspcoop2.protocol.sdk.ProtocolException;
  38. import org.openspcoop2.protocol.sdk.constants.ConsoleOperationType;
  39. import org.openspcoop2.protocol.sdk.properties.AbstractConsoleItem;
  40. import org.openspcoop2.protocol.sdk.properties.ConsoleConfiguration;
  41. import org.openspcoop2.protocol.sdk.properties.IConsoleHelper;
  42. import org.openspcoop2.protocol.sdk.properties.ProtocolProperties;
  43. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesUtils;
  44. import org.openspcoop2.protocol.sdk.properties.StringProperty;
  45. import org.openspcoop2.protocol.sdk.registry.IConfigIntegrationReader;
  46. import org.openspcoop2.protocol.sdk.registry.IRegistryReader;
  47. import org.openspcoop2.protocol.utils.ModISecurityUtils;
  48. import org.openspcoop2.utils.properties.PropertiesUtilities;
  49. import org.slf4j.Logger;

  50. /**
  51.  * ModIDynamicConfigurationAccordiParteSpecificaUtilities
  52.  *
  53.  * @author Poli Andrea (apoli@link.it)
  54.  * @author $Author$
  55.  * @version $Rev$, $Date$
  56.  */
  57. public class ModIDynamicConfigurationAccordiParteSpecificaUtilities {
  58.    
  59.     private ModIDynamicConfigurationAccordiParteSpecificaUtilities() {}

  60.     private static String getErrorLetturaAPIFallita(Exception e) {
  61.         return "Lettura API fallita: "+e.getMessage();
  62.     }
  63.     static ConsoleConfiguration getDynamicConfigParteSpecifica(Logger log, ModIProperties modiProperties,
  64.             ConsoleOperationType consoleOperationType,
  65.             IConsoleHelper consoleHelper, IRegistryReader registryReader,
  66.             IConfigIntegrationReader configIntegrationReader, IDServizio id, IDSoggetto idFruitore, boolean fruizioni) throws ProtocolException {
  67.        
  68.         if(consoleHelper.isModalitaCompleta()) {
  69.             return null;
  70.         }
  71.         if(ConsoleOperationType.DEL.equals(consoleOperationType)) {
  72.             return null;
  73.         }
  74.         if(!isMascheraGestioneFruizioneOrErogazione(consoleHelper)) {
  75.             return null;
  76.         }
  77.         boolean casoSpecialeModificaNomeFruizione = !fruizioni && isMascheraGestioneFruizione(consoleHelper);
  78.        
  79.         // Identificazione API
  80.         AccordoServizioParteComune api = null;
  81.         IDAccordo idAccordo = null;
  82.         String portType = null;
  83.         try {
  84.             if(id!=null && id.getUriAccordoServizioParteComune()!=null) {
  85.                 idAccordo = IDAccordoFactory.getInstance().getIDAccordoFromUri(id.getUriAccordoServizioParteComune());
  86.                 api = registryReader.getAccordoServizioParteComune(idAccordo, false, false);
  87.             }
  88.            
  89.             portType = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_APS_PORT_TYPE);
  90.             if((portType==null || "".equals(portType)) && id!=null) {
  91.                 portType = id.getPortType();
  92.             }
  93.            
  94.         }catch(Exception e) {
  95.             throw new ProtocolException(getErrorLetturaAPIFallita(e),e);
  96.         }
  97.         if(api==null) {
  98.             return null;
  99.         }
  100.        
  101.         boolean rest = ServiceBinding.REST.equals(api.getServiceBinding());
  102.         ConsoleConfiguration configuration = new ConsoleConfiguration();
  103.                
  104.         boolean corniceSicurezza = ModISecurityUtils.isProfiloSicurezzaMessaggioCorniceSicurezza(api, portType);
  105.         String patternDatiCorniceSicurezza = null;
  106.         String schemaDatiCorniceSicurezza = null;
  107.         if(corniceSicurezza) {
  108.             patternDatiCorniceSicurezza = ModISecurityUtils.getProfiloSicurezzaMessaggioCorniceSicurezzaPattern(api, portType);
  109.             if(patternDatiCorniceSicurezza==null) {
  110.                 // backward compatibility
  111.                 patternDatiCorniceSicurezza = ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD;
  112.             }
  113.             if(!ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD.equals(patternDatiCorniceSicurezza)) {
  114.                 schemaDatiCorniceSicurezza = ModISecurityUtils.getProfiloSicurezzaMessaggioCorniceSicurezzaSchema(api, portType);
  115.             }
  116.         }
  117.        
  118.         boolean addSignalHub = false;
  119.         if(fruizioni && idAccordo!=null && ModIDynamicConfigurationAccordiParteComuneUtilities.isApiSignalHubPushAPI(idAccordo, registryReader, modiProperties, log)) {
  120.             ModIDynamicConfigurationAccordiParteSpecificaSicurezzaMessaggioUtilities.addSignaHubFruizioneConfig(modiProperties,
  121.                     configuration, rest);
  122.             // è un accordo built-in che si assume esista, ma deve comunque essere configurabile anche nelle parti restanti
  123.             /**return configuration;*/
  124.             addSignalHub = true;
  125.         }
  126.        
  127.         boolean pdnd = ModISecurityUtils.isSicurezzaMessaggioGenerazioneTokenIdAuthPDND(api, portType);
  128.         if(pdnd && !fruizioni) {
  129.             ModIDynamicConfigurationAccordiParteSpecificaSicurezzaMessaggioUtilities.addPdndInfo(modiProperties,
  130.                     configuration, rest);
  131.         }
  132.        
  133.         // Identificazione se è richiesta la sicurezza
  134.         if(ModISecurityUtils.isSicurezzaMessaggioRequired(api, portType)) {
  135.        
  136.             boolean digest = ModISecurityUtils.isProfiloSicurezzaMessaggioConIntegrita(api, portType);
  137.            
  138.             boolean headerDuplicati = false;
  139.             boolean riferimentoX509 = false;
  140.             boolean kidMode = false;
  141.             if(rest) {
  142.                 headerDuplicati = ModISecurityUtils.isProfiloSicurezzaMessaggioConHeaderDuplicati(api, portType);
  143.                 riferimentoX509 = ModISecurityUtils.isSicurezzaMessaggioRiferimentoX509Required(api, portType);
  144.                 kidMode =  ModISecurityUtils.isSicurezzaMessaggioKidModeSupported(api, portType);
  145.             }
  146.            
  147.             boolean tokenNonLocale = true;
  148.             if(rest || fruizioni) {
  149.                 tokenNonLocale = ModISecurityUtils.isProfiloSicurezzaMessaggioConSorgenteTokenNonLocale(api, portType, rest);  
  150.             }
  151.            
  152.             if(ModISecurityUtils.isProfiloSicurezzaMessaggioApplicabileRichiesta(api, portType, true)) {
  153.                 ModIDynamicConfigurationAccordiParteSpecificaSicurezzaMessaggioUtilities.addSicurezzaMessaggio(modiProperties,
  154.                     configuration, rest, fruizioni, true, casoSpecialeModificaNomeFruizione, digest,
  155.                     patternDatiCorniceSicurezza, schemaDatiCorniceSicurezza,
  156.                     headerDuplicati,
  157.                     consoleOperationType, consoleHelper, registryReader, configIntegrationReader, id, idFruitore,
  158.                     riferimentoX509, kidMode,
  159.                     false,
  160.                     tokenNonLocale);
  161.             }
  162.             if(ModISecurityUtils.isProfiloSicurezzaMessaggioApplicabileRisposta(api, portType, true)) {
  163.                 ModIDynamicConfigurationAccordiParteSpecificaSicurezzaMessaggioUtilities.addSicurezzaMessaggio(modiProperties,
  164.                     configuration, rest, fruizioni, false, casoSpecialeModificaNomeFruizione, digest,
  165.                     patternDatiCorniceSicurezza, schemaDatiCorniceSicurezza,
  166.                     headerDuplicati,
  167.                     consoleOperationType, consoleHelper, registryReader, configIntegrationReader, id, idFruitore,
  168.                     riferimentoX509, kidMode,
  169.                     false,
  170.                     tokenNonLocale);
  171.             }
  172.            
  173.             return configuration;
  174.            
  175.         }
  176.         else {
  177.            
  178.             // Sicurezza Audit
  179.            
  180.             if( corniceSicurezza && !ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD.equals(patternDatiCorniceSicurezza) &&
  181.                 schemaDatiCorniceSicurezza!=null) {
  182.                    
  183.                 boolean forceRest = true;
  184.                
  185.                 boolean tokenNonLocale = false;
  186.                 if(fruizioni) {
  187.                     tokenNonLocale = ModISecurityUtils.isProfiloSicurezzaMessaggioConSorgenteTokenNonLocale(api, portType, rest);  
  188.                 }
  189.                
  190.                 ModIDynamicConfigurationAccordiParteSpecificaSicurezzaMessaggioUtilities.addSicurezzaMessaggio(modiProperties,
  191.                         configuration, forceRest, fruizioni, true, casoSpecialeModificaNomeFruizione,
  192.                         false,  // digest
  193.                         patternDatiCorniceSicurezza, schemaDatiCorniceSicurezza,
  194.                         false, // headerDuplicati
  195.                         consoleOperationType, consoleHelper, registryReader, configIntegrationReader, id, idFruitore,
  196.                         false, // riferimentoX509
  197.                         false, // kidMode
  198.                         true, // audit
  199.                         tokenNonLocale // tokenNonLocale
  200.                         );
  201.                
  202.                 return configuration; // NOTA: contiene già i dati richiesti in sicurezza OAuth
  203.                
  204.             }
  205.            
  206.            
  207.             // Sicurezza OAuth
  208.            
  209.             if( fruizioni ) {
  210.                 boolean sicurezzaMessaggioNonPresente = false;
  211.                 boolean tokenSignedJWT = ModIDynamicConfigurationAccordiParteSpecificaSicurezzaMessaggioUtilities.addSicurezzaTokenSignedJWT(rest,
  212.                         configuration,
  213.                         consoleOperationType, consoleHelper,
  214.                         registryReader, configIntegrationReader,
  215.                         id, idFruitore,
  216.                         sicurezzaMessaggioNonPresente);
  217.                
  218.                 if(tokenSignedJWT) {
  219.                     /**this.addKeStoreConfigOAuth_choice(configuration);*/
  220.                     ModIDynamicConfigurationKeystoreUtilities.addTrustStoreKeystoreFruizioneOAuthConfigChoice(configuration);
  221.                    
  222.                     /**boolean requiredValue = casoSpecialeModificaNomeFruizione ? false : true;*/
  223.                     boolean requiredValue = true;
  224.                     ModIDynamicConfigurationKeystoreUtilities.addKeystoreConfig(configuration, true, false, requiredValue);
  225.                
  226.                     return configuration;
  227.                 }
  228.             }
  229.            
  230.            
  231.         }
  232.        
  233.         if(pdnd || addSignalHub) {
  234.             return configuration;
  235.         }
  236.         else {
  237.             return null;
  238.         }
  239.        
  240.     }
  241.    
  242.     static boolean updateDynamicConfigParteSpecifica(Logger log, ModIProperties modiProperties,
  243.             ConsoleConfiguration consoleConfiguration,
  244.             ConsoleOperationType consoleOperationType, IConsoleHelper consoleHelper, ProtocolProperties properties,
  245.             IDServizio id, IRegistryReader registryReader, IConfigIntegrationReader configIntegrationReader, boolean fruizioni) throws ProtocolException {
  246.         if(consoleHelper.isModalitaCompleta()) {
  247.             return false;
  248.         }
  249.         if(ConsoleOperationType.DEL.equals(consoleOperationType)) {
  250.             return false;
  251.         }
  252.         if(!isMascheraGestioneFruizioneOrErogazione(consoleHelper)) {
  253.             return false;
  254.         }
  255.         boolean casoSpecialeModificaNomeFruizione = !fruizioni && isMascheraGestioneFruizione(consoleHelper);
  256.        
  257.         // Identificazione API
  258.         AccordoServizioParteComune api = null;
  259.         IDAccordo idAccordo = null;
  260.         String portType = null;
  261.         try {
  262.             if(id!=null && id.getUriAccordoServizioParteComune()!=null) {
  263.                 idAccordo = IDAccordoFactory.getInstance().getIDAccordoFromUri(id.getUriAccordoServizioParteComune());
  264.                 api = registryReader.getAccordoServizioParteComune(idAccordo, false, false);
  265.             }
  266.            
  267.             portType = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_APS_PORT_TYPE);
  268.             if((portType==null || "".equals(portType)) && id!=null) {
  269.                 portType = id.getPortType();
  270.             }
  271.            
  272.         }catch(Exception e) {
  273.             throw new ProtocolException(getErrorLetturaAPIFallita(e),e);
  274.         }
  275.         if(api==null) {
  276.             return false;
  277.         }
  278.         boolean rest = ServiceBinding.REST.equals(api.getServiceBinding());
  279.        
  280.         boolean corniceSicurezza = ModISecurityUtils.isProfiloSicurezzaMessaggioCorniceSicurezza(api, portType);
  281.         String patternDatiCorniceSicurezza = null;
  282.         String schemaDatiCorniceSicurezza = null;
  283.         if(corniceSicurezza) {
  284.             patternDatiCorniceSicurezza = ModISecurityUtils.getProfiloSicurezzaMessaggioCorniceSicurezzaPattern(api, portType);
  285.             if(patternDatiCorniceSicurezza==null) {
  286.                 // backward compatibility
  287.                 patternDatiCorniceSicurezza = ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD;
  288.             }
  289.             if(!ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD.equals(patternDatiCorniceSicurezza)) {
  290.                 schemaDatiCorniceSicurezza = ModISecurityUtils.getProfiloSicurezzaMessaggioCorniceSicurezzaSchema(api, portType);
  291.             }
  292.         }
  293.        
  294.         if(fruizioni && idAccordo!=null && ModIDynamicConfigurationAccordiParteComuneUtilities.isApiSignalHubPushAPI(idAccordo, registryReader, modiProperties, log)) {
  295.             ModIDynamicConfigurationAccordiParteSpecificaSicurezzaMessaggioUtilities.updateSignaHubFruizioneConfig(modiProperties,
  296.                     consoleConfiguration, properties);
  297.             // è un accordo built-in che si assume esista, ma deve comunque essere configurabile anche nelle parti restanti
  298.             /**return true;*/
  299.         }
  300.        
  301.         boolean pdnd = ModISecurityUtils.isSicurezzaMessaggioGenerazioneTokenIdAuthPDND(api, portType);
  302.         if(pdnd && !fruizioni) {
  303.             ModIDynamicConfigurationAccordiParteSpecificaSicurezzaMessaggioUtilities.updatePdndInfo(consoleConfiguration, properties,
  304.                     api, portType, id,
  305.                     registryReader,
  306.                     configIntegrationReader,
  307.                     log);
  308.         }
  309.        
  310.         // Identificazione se è richiesta la sicurezza
  311.         if(ModISecurityUtils.isSicurezzaMessaggioRequired(api, portType)) {
  312.                    
  313.             boolean headerDuplicati = false;
  314.             if(rest) {
  315.                 headerDuplicati = ModISecurityUtils.isProfiloSicurezzaMessaggioConHeaderDuplicati(api, portType);
  316.             }
  317.            
  318.             boolean kidMode = ModISecurityUtils.isSicurezzaMessaggioKidModeSupported(api, portType);
  319.            
  320.             boolean tokenNonLocale = ModISecurityUtils.isProfiloSicurezzaMessaggioConSorgenteTokenNonLocale(api, portType, rest);
  321.            
  322.             if(ModISecurityUtils.isProfiloSicurezzaMessaggioApplicabileRichiesta(api, portType, true)) {
  323.                 ModIDynamicConfigurationAccordiParteSpecificaSicurezzaMessaggioUtilities.updateSicurezzaMessaggio(modiProperties,
  324.                     consoleConfiguration, properties, rest, fruizioni, true, casoSpecialeModificaNomeFruizione,
  325.                     patternDatiCorniceSicurezza, schemaDatiCorniceSicurezza,
  326.                     headerDuplicati, consoleHelper,
  327.                     kidMode,
  328.                     tokenNonLocale);
  329.             }
  330.             if(ModISecurityUtils.isProfiloSicurezzaMessaggioApplicabileRisposta(api, portType, true)) {
  331.                 ModIDynamicConfigurationAccordiParteSpecificaSicurezzaMessaggioUtilities.updateSicurezzaMessaggio(modiProperties,
  332.                     consoleConfiguration, properties, rest, fruizioni, false, casoSpecialeModificaNomeFruizione,
  333.                     patternDatiCorniceSicurezza, schemaDatiCorniceSicurezza,
  334.                     headerDuplicati, consoleHelper,
  335.                     kidMode,
  336.                     tokenNonLocale);
  337.             }
  338.            
  339.         }
  340.         else {
  341.            
  342.             // Sicurezza Audit
  343.            
  344.             if( corniceSicurezza && !ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD.equals(patternDatiCorniceSicurezza) &&
  345.                     schemaDatiCorniceSicurezza!=null) {
  346.                    
  347.                 boolean forceRest = true;
  348.                
  349.                 boolean kidMode = true;
  350.                
  351.                 ModIDynamicConfigurationAccordiParteSpecificaSicurezzaMessaggioUtilities.updateSicurezzaMessaggio(modiProperties,
  352.                         consoleConfiguration, properties, forceRest, fruizioni, true, casoSpecialeModificaNomeFruizione,
  353.                         patternDatiCorniceSicurezza, schemaDatiCorniceSicurezza,
  354.                         false, // headerDuplicati
  355.                         consoleHelper,
  356.                         kidMode,
  357.                         false // tokenNonLocale
  358.                         );
  359.                
  360.             }
  361.            
  362.            
  363.             // Sicurezza OAuth
  364.            
  365.             if(fruizioni) {
  366.                
  367.                 /**boolean requiredValue = casoSpecialeModificaNomeFruizione ? false : true;*/
  368.                 boolean requiredValue = true;
  369.                
  370.                 boolean hideSceltaArchivioFilePath = false;
  371.                 boolean addHiddenSubjectIssuer = false;
  372.                
  373.                 /**boolean checkRidefinisciOauth = true;*/
  374.                 boolean checkRidefinisciOauth = false;
  375.                
  376.                 rest = true; // forzo comportamento come fosse REST poichè si tratta della configurazione necessaria per generare token JWT
  377.                
  378.                 ModIDynamicConfigurationKeystoreUtilities.updateKeystoreConfig(consoleConfiguration, properties, true, checkRidefinisciOauth,
  379.                         hideSceltaArchivioFilePath, addHiddenSubjectIssuer,
  380.                         requiredValue, null,
  381.                         rest);
  382.             }
  383.            
  384.         }
  385.        
  386.         return true;
  387.     }
  388.    
  389.     private static final String PREFIX_VERIFICATO_QUANTO_INDICATO_IN = "Verificare quanto indicato in ";
  390.    
  391.     static boolean validateDynamicConfigParteSpecifica(ModIProperties modiProperties,
  392.             ConsoleConfiguration consoleConfiguration, IConsoleHelper consoleHelper, ProtocolProperties properties, IDServizio id,
  393.             IRegistryReader registryReader, IConfigIntegrationReader configIntegrationReader, boolean fruizioni) throws ProtocolException {
  394.        
  395.         if(!isMascheraGestioneFruizioneOrErogazione(consoleHelper)) {
  396.             return false;
  397.         }
  398.         boolean casoSpecialeModificaNomeFruizione = !fruizioni && isMascheraGestioneFruizione(consoleHelper);
  399.         if(casoSpecialeModificaNomeFruizione) {
  400.             return false;
  401.         }
  402.        
  403.         AccordoServizioParteComune api = null;
  404.         String portType = null;
  405.         try {
  406.             if(id!=null && id.getUriAccordoServizioParteComune()!=null) {
  407.                 IDAccordo idAccordo = IDAccordoFactory.getInstance().getIDAccordoFromUri(id.getUriAccordoServizioParteComune());
  408.                 api = registryReader.getAccordoServizioParteComune(idAccordo, false, false);
  409.             }
  410.            
  411.             portType = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_APS_PORT_TYPE);
  412.             if((portType==null || "".equals(portType)) && id!=null) {
  413.                 portType = id.getPortType();
  414.             }
  415.            
  416.         }catch(Exception e) {
  417.             throw new ProtocolException(getErrorLetturaAPIFallita(e),e);
  418.         }
  419.         if(api==null) {
  420.             return false;
  421.         }
  422.        
  423.        
  424.         boolean corniceSicurezza = ModISecurityUtils.isProfiloSicurezzaMessaggioCorniceSicurezza(api, portType);
  425.         String patternDatiCorniceSicurezza = null;
  426.         String schemaDatiCorniceSicurezza = null;
  427.         if(corniceSicurezza) {
  428.             patternDatiCorniceSicurezza = ModISecurityUtils.getProfiloSicurezzaMessaggioCorniceSicurezzaPattern(api, portType);
  429.             if(patternDatiCorniceSicurezza==null) {
  430.                 // backward compatibility
  431.                 patternDatiCorniceSicurezza = ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD;
  432.             }
  433.             if(!ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD.equals(patternDatiCorniceSicurezza)) {
  434.                 schemaDatiCorniceSicurezza = ModISecurityUtils.getProfiloSicurezzaMessaggioCorniceSicurezzaSchema(api, portType);
  435.             }
  436.         }
  437.        
  438.        
  439.         boolean pdnd = ModISecurityUtils.isSicurezzaMessaggioGenerazioneTokenIdAuthPDND(api, portType);
  440.         if(pdnd && !fruizioni) {
  441.             ModIDynamicConfigurationAccordiParteSpecificaSicurezzaMessaggioUtilities.validatePdndInfo(registryReader, configIntegrationReader, api, id, portType, consoleConfiguration, properties);
  442.         }
  443.        
  444.        
  445.         // Sicurezza Audit
  446.         boolean sicurezzaAudit = false;
  447.         if( fruizioni  &&
  448.                 corniceSicurezza && !ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD.equals(patternDatiCorniceSicurezza) &&
  449.                 schemaDatiCorniceSicurezza!=null) {
  450.             sicurezzaAudit = true;
  451.         }
  452.        
  453.        
  454.         // Identificazione se è richiesta la sicurezza
  455.         if(ModISecurityUtils.isSicurezzaMessaggioRequired(api, portType) || sicurezzaAudit) {
  456.            
  457.             AbstractConsoleItem<?> profiloSicurezzaMessaggioHttpHeadersItem =  
  458.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  459.                             ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_HTTP_HEADERS_REST_ID
  460.                             );
  461.             if(profiloSicurezzaMessaggioHttpHeadersItem!=null) {
  462.                
  463.                 StringProperty profiloSicurezzaMessaggioHttpHeadersItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_HTTP_HEADERS_REST_ID);
  464.                 if(profiloSicurezzaMessaggioHttpHeadersItemValue!=null && profiloSicurezzaMessaggioHttpHeadersItemValue.getValue()!=null && !"".equals(profiloSicurezzaMessaggioHttpHeadersItemValue.getValue())) {
  465.                     try {
  466.                         String [] hdrObbligatori = modiProperties.getRestSecurityTokenSignedHeaders();
  467.                         if(hdrObbligatori!=null && hdrObbligatori.length>0) {
  468.                            
  469.                             String [] hdrImpostati = profiloSicurezzaMessaggioHttpHeadersItemValue.getValue().split(",");
  470.                             if(hdrImpostati==null || hdrImpostati.length<=0) {
  471.                                 throw new ProtocolException("Nessun header indicato");
  472.                             }
  473.                            
  474.                             for (String hdrObbligatorio : hdrObbligatori) {
  475.                                 boolean found = false;
  476.                                 for (String hdrImpostato : hdrImpostati) {
  477.                                     if(hdrImpostato.equalsIgnoreCase(hdrObbligatorio)) {
  478.                                         found = true;
  479.                                         break;
  480.                                     }
  481.                                 }
  482.                                 if(!found) {
  483.                                     throw new ProtocolException("Header obbligatorio '"+hdrObbligatorio+"' non indicato");
  484.                                 }
  485.                             }
  486.                            
  487.                         }
  488.                     }catch(Exception e) {
  489.                         throw new ProtocolException(PREFIX_VERIFICATO_QUANTO_INDICATO_IN+ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_HTTP_HEADERS_REST_LABEL+": "+e.getMessage(),e);
  490.                     }
  491.                 }
  492.                 else {
  493.                     throw new ProtocolException(PREFIX_VERIFICATO_QUANTO_INDICATO_IN+ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_HTTP_HEADERS_REST_LABEL+": nessun header indicato");
  494.                 }
  495.                
  496.             }
  497.            
  498.             AbstractConsoleItem<?> profiloSicurezzaMessaggioSoapHeadersItem =  
  499.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  500.                             ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_SOAP_HEADERS_SOAP_ID
  501.                             );
  502.             if(profiloSicurezzaMessaggioSoapHeadersItem!=null) {
  503.                
  504.                 StringProperty profiloSicurezzaMessaggioSoapHeadersItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_SOAP_HEADERS_SOAP_ID);
  505.                 if(profiloSicurezzaMessaggioSoapHeadersItemValue!=null && profiloSicurezzaMessaggioSoapHeadersItemValue.getValue()!=null && !"".equals(profiloSicurezzaMessaggioSoapHeadersItemValue.getValue())) {
  506.                     try {
  507.                         String sValue = profiloSicurezzaMessaggioSoapHeadersItemValue.getValue();
  508.                         SOAPHeader.parse(sValue);
  509.                     }catch(Exception e) {
  510.                         throw new ProtocolException(PREFIX_VERIFICATO_QUANTO_INDICATO_IN+ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_SOAP_HEADERS_SOAP_LABEL+": "+e.getMessage(),e);
  511.                     }
  512.                 }
  513.                
  514.             }
  515.            
  516.             if(!fruizioni) {
  517.                 try {
  518.                     ModIDynamicConfigurationKeystoreUtilities.readKeystoreConfig(properties, false);
  519.                 }catch(Exception e) {
  520.                     throw new ProtocolException("Verificare i parametri indicati per il keystore in "+ModIConsoleCostanti.MODIPA_SICUREZZA_MESSAGGIO_SUBTITLE_LABEL+": "+e.getMessage(),e);
  521.                 }
  522.             }
  523.            
  524.             boolean rest = ServiceBinding.REST.equals(api.getServiceBinding());
  525.             boolean digest = ModISecurityUtils.isProfiloSicurezzaMessaggioConIntegrita(api, portType);
  526.             boolean corniceSicurezzaLegacy = false;
  527.             if(corniceSicurezza) {
  528.                 corniceSicurezzaLegacy = ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD.equals(patternDatiCorniceSicurezza);
  529.             }
  530.             boolean headerDuplicati = false;
  531.             if(rest) {
  532.                 headerDuplicati = ModISecurityUtils.isProfiloSicurezzaMessaggioConHeaderDuplicati(api, portType);
  533.             }
  534.             boolean requestCalcolatoSuInfoFruizioni = fruizioni;
  535.                        
  536.             // Claims
  537.             if(rest) {
  538.                 String idProperty = (fruizioni ? ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_REST_JWT_CLAIMS_RICHIESTA_ID : ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_REST_JWT_CLAIMS_RISPOSTA_ID);
  539.                 StringProperty profiloSicurezzaMessaggioRestJwtClaimsItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, idProperty);
  540.                 if(profiloSicurezzaMessaggioRestJwtClaimsItemValue!=null && profiloSicurezzaMessaggioRestJwtClaimsItemValue.getValue()!=null) {
  541.                     Properties claims = PropertiesUtilities.convertTextToProperties(profiloSicurezzaMessaggioRestJwtClaimsItemValue.getValue());
  542.                     checkClaims(modiProperties, claims, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_REST_JWT_CLAIMS_LABEL, requestCalcolatoSuInfoFruizioni, digest, corniceSicurezzaLegacy);
  543.                 }
  544.             }
  545.        
  546.             // Header Duplicati
  547.             if(rest && headerDuplicati) {
  548.                 String idProperty = (fruizioni ? ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_JWT_CLAIMS_AUTHORIZATION_RICHIESTA_ID : ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_JWT_CLAIMS_AUTHORIZATION_RISPOSTA_ID);
  549.                 StringProperty profiloSicurezzaMessaggioRestJwtAuthorizationClaimsItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, idProperty);
  550.                 if(profiloSicurezzaMessaggioRestJwtAuthorizationClaimsItemValue!=null && profiloSicurezzaMessaggioRestJwtAuthorizationClaimsItemValue.getValue()!=null) {
  551.                     Properties claims = PropertiesUtilities.convertTextToProperties(profiloSicurezzaMessaggioRestJwtAuthorizationClaimsItemValue.getValue());
  552.                     checkClaims(modiProperties, claims, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_JWT_CLAIMS_AUTHORIZATION_LABEL, requestCalcolatoSuInfoFruizioni, digest, corniceSicurezzaLegacy);
  553.                 }
  554.                
  555.                 idProperty = (fruizioni ? ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_JWT_CLAIMS_MODI_RICHIESTA_ID : ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_JWT_CLAIMS_MODI_RISPOSTA_ID);
  556.                 StringProperty profiloSicurezzaMessaggioRestJwtModiClaimsItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, idProperty);
  557.                 if(profiloSicurezzaMessaggioRestJwtModiClaimsItemValue!=null && profiloSicurezzaMessaggioRestJwtModiClaimsItemValue.getValue()!=null) {
  558.                     Properties claims = PropertiesUtilities.convertTextToProperties(profiloSicurezzaMessaggioRestJwtModiClaimsItemValue.getValue());
  559.                     checkClaims(modiProperties, claims, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_JWT_CLAIMS_MODI_LABEL.
  560.                             replace(ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_SUBSECTION_TEMPLATE_HEADER_AGID, modiProperties.getRestSecurityTokenHeaderModI()),
  561.                             requestCalcolatoSuInfoFruizioni, digest, corniceSicurezzaLegacy);
  562.                 }
  563.             }
  564.            
  565.            
  566.             // X5U URL
  567.             if(rest) {
  568.                
  569.                 String idUrl = null;
  570.                 if(fruizioni) {
  571.                     idUrl = ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_REST_RICHIESTA_X5U_URL_ID;
  572.                 }
  573.                 else if(!fruizioni) {
  574.                     idUrl = ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_REST_RISPOSTA_X5U_URL_ID;
  575.                 }
  576.                 if(idUrl!=null) {
  577.                     AbstractConsoleItem<?> profiloSicurezzaMessaggioRestUrlItem =  
  578.                             ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  579.                                     idUrl
  580.                                     );
  581.                     if(profiloSicurezzaMessaggioRestUrlItem!=null) {
  582.                        
  583.                         StringProperty profiloSicurezzaMessaggioRestUrlItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, idUrl);
  584.                         if(profiloSicurezzaMessaggioRestUrlItemValue!=null && profiloSicurezzaMessaggioRestUrlItemValue.getValue()!=null && !"".equals(profiloSicurezzaMessaggioRestUrlItemValue.getValue())) {
  585.                             try {
  586.                                 InputValidationUtils.validateTextAreaInput(profiloSicurezzaMessaggioRestUrlItemValue.getValue(), ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_REST_X5U_URL_LABEL);
  587.                             }catch(Exception e) {
  588.                                 throw new ProtocolException(e.getMessage(),e);
  589.                             }
  590.                         }
  591.                        
  592.                     }
  593.                 }
  594.             }
  595.            
  596.             // Audit
  597.             String idAudit = ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_AUDIENCE_RICHIESTA_ID;
  598.             String labelAudit = rest ? ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_AUDIENCE_RICHIESTA_REST_LABEL :  ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_AUDIENCE_RICHIESTA_SOAP_LABEL;
  599.             AbstractConsoleItem<?> profiloSicurezzaMessaggioAudienceItem =  
  600.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  601.                             idAudit
  602.                             );
  603.             if(profiloSicurezzaMessaggioAudienceItem!=null) {
  604.                
  605.                 StringProperty profiloSicurezzaMessaggioAudienceItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, idAudit);
  606.                 if(profiloSicurezzaMessaggioAudienceItemValue!=null && profiloSicurezzaMessaggioAudienceItemValue.getValue()!=null && !"".equals(profiloSicurezzaMessaggioAudienceItemValue.getValue())) {
  607.                     try {
  608.                         InputValidationUtils.validateTextAreaInput(profiloSicurezzaMessaggioAudienceItemValue.getValue(), labelAudit);
  609.                     }catch(Exception e) {
  610.                         throw new ProtocolException(e.getMessage(),e);
  611.                     }
  612.                 }
  613.                
  614.             }
  615.            
  616.             // Audit Risposta
  617.             if(fruizioni) {
  618.                 idAudit = ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_AUDIENCE_RISPOSTA_VALORE_ID;
  619.                 labelAudit = rest ? ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_AUDIENCE_RISPOSTA_REST_LABEL :  ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_AUDIENCE_RISPOSTA_SOAP_LABEL;
  620.                 profiloSicurezzaMessaggioAudienceItem =    
  621.                         ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  622.                                 idAudit
  623.                                 );
  624.                 if(profiloSicurezzaMessaggioAudienceItem!=null) {
  625.                    
  626.                     StringProperty profiloSicurezzaMessaggioAudienceItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, idAudit);
  627.                     if(profiloSicurezzaMessaggioAudienceItemValue!=null && profiloSicurezzaMessaggioAudienceItemValue.getValue()!=null && !"".equals(profiloSicurezzaMessaggioAudienceItemValue.getValue())) {
  628.                         try {
  629.                             InputValidationUtils.validateTextAreaInput(profiloSicurezzaMessaggioAudienceItemValue.getValue(), labelAudit);
  630.                         }catch(Exception e) {
  631.                             throw new ProtocolException(e.getMessage(),e);
  632.                         }
  633.                     }
  634.                    
  635.                 }
  636.             }

  637.             // Cornice Sicurezza - CodiceEnte
  638.             AbstractConsoleItem<?> profiloSicurezzaMessaggioCorniceSicurezzaCodiceEnteItem =    
  639.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  640.                             ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_CODICE_ENTE_ID
  641.                             );
  642.             if(profiloSicurezzaMessaggioCorniceSicurezzaCodiceEnteItem!=null) {
  643.                 StringProperty profiloSicurezzaMessaggioCorniceSicurezzaCodiceEnteItemValue =
  644.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_CODICE_ENTE_ID);
  645.                 if(profiloSicurezzaMessaggioCorniceSicurezzaCodiceEnteItemValue!=null && profiloSicurezzaMessaggioCorniceSicurezzaCodiceEnteItemValue.getValue()!=null && !"".equals(profiloSicurezzaMessaggioCorniceSicurezzaCodiceEnteItemValue.getValue())) {
  646.                     try {
  647.                         InputValidationUtils.validateTextAreaInput(profiloSicurezzaMessaggioCorniceSicurezzaCodiceEnteItemValue.getValue(),
  648.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_CODICE_ENTE_MODE_LABEL,
  649.                                 true); // possono essere presenti spazi all'interno
  650.                     }catch(Exception e) {
  651.                         throw new ProtocolException(e.getMessage(),e);
  652.                     }
  653.                 }
  654.             }
  655.            
  656.             // Cornice Sicurezza - UserId
  657.             AbstractConsoleItem<?> profiloSicurezzaMessaggioCorniceSicurezzaUserIdItem =    
  658.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  659.                             ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_USER_ID
  660.                             );
  661.             if(profiloSicurezzaMessaggioCorniceSicurezzaUserIdItem!=null) {
  662.                 StringProperty profiloSicurezzaMessaggioCorniceSicurezzaUserIdItemValue =
  663.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_USER_ID);
  664.                 if(profiloSicurezzaMessaggioCorniceSicurezzaUserIdItemValue!=null && profiloSicurezzaMessaggioCorniceSicurezzaUserIdItemValue.getValue()!=null && !"".equals(profiloSicurezzaMessaggioCorniceSicurezzaUserIdItemValue.getValue())) {
  665.                     try {
  666.                         InputValidationUtils.validateTextAreaInput(profiloSicurezzaMessaggioCorniceSicurezzaUserIdItemValue.getValue(),
  667.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_USER_MODE_LABEL,
  668.                                 true); // possono essere presenti spazi all'interno
  669.                     }catch(Exception e) {
  670.                         throw new ProtocolException(e.getMessage(),e);
  671.                     }
  672.                 }
  673.             }
  674.            
  675.             // Cornice Sicurezza - IPUser
  676.             AbstractConsoleItem<?> profiloSicurezzaMessaggioCorniceSicurezzaIPUserItem =    
  677.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  678.                             ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_IP_USER_ID
  679.                             );
  680.             if(profiloSicurezzaMessaggioCorniceSicurezzaIPUserItem!=null) {
  681.                 StringProperty profiloSicurezzaMessaggioCorniceSicurezzaIPUserItemValue =
  682.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_IP_USER_ID);
  683.                 if(profiloSicurezzaMessaggioCorniceSicurezzaIPUserItemValue!=null && profiloSicurezzaMessaggioCorniceSicurezzaIPUserItemValue.getValue()!=null && !"".equals(profiloSicurezzaMessaggioCorniceSicurezzaIPUserItemValue.getValue())) {
  684.                     try {
  685.                         InputValidationUtils.validateTextAreaInput(profiloSicurezzaMessaggioCorniceSicurezzaIPUserItemValue.getValue(),
  686.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_IP_USER_MODE_LABEL,
  687.                                 true); // possono essere presenti spazi all'interno
  688.                     }catch(Exception e) {
  689.                         throw new ProtocolException(e.getMessage(),e);
  690.                     }
  691.                 }
  692.             }
  693.            
  694.             // Audience Integrity
  695.             if(fruizioni) {
  696.                 AbstractConsoleItem<?> profiloSicurezzaMessaggioAudienceIntegrityItem =    
  697.                         ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  698.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_AUDIENCE_INTEGRITY_RICHIESTA_ID
  699.                                 );
  700.                 if(profiloSicurezzaMessaggioAudienceIntegrityItem!=null) {
  701.                     StringProperty profiloSicurezzaMessaggioAudienceIntegrityItemValue =
  702.                             (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_AUDIENCE_INTEGRITY_RICHIESTA_ID);
  703.                     if(profiloSicurezzaMessaggioAudienceIntegrityItemValue!=null && profiloSicurezzaMessaggioAudienceIntegrityItemValue.getValue()!=null && !"".equals(profiloSicurezzaMessaggioAudienceIntegrityItemValue.getValue())) {
  704.                         try {
  705.                             InputValidationUtils.validateTextAreaInput(profiloSicurezzaMessaggioAudienceIntegrityItemValue.getValue(),
  706.                                     ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_SUBSECTION_LABEL.
  707.                                     replace(ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_SUBSECTION_TEMPLATE_HEADER_AGID, modiProperties.getRestSecurityTokenHeaderModI())
  708.                                     + " - "+
  709.                                     ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_AUDIENCE_LABEL);
  710.                         }catch(Exception e) {
  711.                             throw new ProtocolException(e.getMessage(),e);
  712.                         }
  713.                     }
  714.                 }
  715.             }
  716.             // Header Duplicati
  717.             if(rest && headerDuplicati) {
  718.                 String idAud = ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_AUDIENCE_INTEGRITY_RICHIESTA_ID;
  719.                 AbstractConsoleItem<?> profiloSicurezzaMessaggioAudienceIntegrityItem =    
  720.                         ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  721.                                 idAud
  722.                                 );
  723.                 if(profiloSicurezzaMessaggioAudienceIntegrityItem!=null) {
  724.                     StringProperty profiloSicurezzaMessaggioAudienceIntegrityItemValue =
  725.                             (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, idAud);
  726.                     if(profiloSicurezzaMessaggioAudienceIntegrityItemValue!=null && profiloSicurezzaMessaggioAudienceIntegrityItemValue.getValue()!=null && !"".equals(profiloSicurezzaMessaggioAudienceIntegrityItemValue.getValue())) {
  727.                         try {
  728.                             InputValidationUtils.validateTextAreaInput(profiloSicurezzaMessaggioAudienceIntegrityItemValue.getValue(),
  729.                                     ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_SUBSECTION_LABEL.
  730.                                     replace(ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_SUBSECTION_TEMPLATE_HEADER_AGID, modiProperties.getRestSecurityTokenHeaderModI())
  731.                                     + " - "+
  732.                                     ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_AUDIENCE_LABEL);
  733.                         }catch(Exception e) {
  734.                             throw new ProtocolException(e.getMessage(),e);
  735.                         }
  736.                     }
  737.                 }
  738.                
  739.                 idAud = ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_AUDIENCE_INTEGRITY_RISPOSTA_ID;
  740.                 profiloSicurezzaMessaggioAudienceIntegrityItem =    
  741.                         ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  742.                                 idAud
  743.                                 );
  744.                 if(profiloSicurezzaMessaggioAudienceIntegrityItem!=null) {
  745.                     StringProperty profiloSicurezzaMessaggioAudienceIntegrityItemValue =
  746.                             (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, idAud);
  747.                     if(profiloSicurezzaMessaggioAudienceIntegrityItemValue!=null && profiloSicurezzaMessaggioAudienceIntegrityItemValue.getValue()!=null && !"".equals(profiloSicurezzaMessaggioAudienceIntegrityItemValue.getValue())) {
  748.                         try {
  749.                             InputValidationUtils.validateTextAreaInput(profiloSicurezzaMessaggioAudienceIntegrityItemValue.getValue(),
  750.                                     ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_SUBSECTION_LABEL.
  751.                                     replace(ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_SUBSECTION_TEMPLATE_HEADER_AGID, modiProperties.getRestSecurityTokenHeaderModI())
  752.                                     + " - "+
  753.                                     ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_DOPPI_HEADER_AUDIENCE_LABEL);
  754.                         }catch(Exception e) {
  755.                             throw new ProtocolException(e.getMessage(),e);
  756.                         }
  757.                     }
  758.                 }
  759.                
  760.             }
  761.            
  762.             // Keystore Path
  763.             AbstractConsoleItem<?> keystorePathItem =  
  764.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  765.                             ModIConsoleCostanti.MODIPA_KEYSTORE_PATH_ID
  766.                             );
  767.             if(keystorePathItem!=null) {
  768.                 StringProperty keystorePathItemValue =
  769.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_PATH_ID);
  770.                 if(keystorePathItemValue!=null && keystorePathItemValue.getValue()!=null && !"".equals(keystorePathItemValue.getValue())) {
  771.                     try {
  772.                         InputValidationUtils.validateTextAreaInput(keystorePathItemValue.getValue(),
  773.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_KEYSTORE_LABEL +" - "+
  774.                                 ModIConsoleCostanti.MODIPA_KEYSTORE_PATH_LABEL);
  775.                     }catch(Exception e) {
  776.                         throw new ProtocolException(e.getMessage(),e);
  777.                     }
  778.                 }
  779.             }
  780.            
  781.             // Keystore password
  782.             AbstractConsoleItem<?> keystorePasswordItem =  
  783.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  784.                             ModIConsoleCostanti.MODIPA_KEYSTORE_PASSWORD_ID
  785.                             );
  786.             if(keystorePasswordItem!=null) {
  787.                 StringProperty keystoreItemValue =
  788.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEYSTORE_PASSWORD_ID);
  789.                 if(keystoreItemValue!=null && keystoreItemValue.getValue()!=null && !"".equals(keystoreItemValue.getValue())) {
  790.                     try {
  791.                         InputValidationUtils.validateTextInput(keystoreItemValue.getValue(),
  792.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_KEYSTORE_LABEL +" - "+
  793.                                 ModIConsoleCostanti.MODIPA_KEYSTORE_PASSWORD_LABEL);
  794.                     }catch(Exception e) {
  795.                         throw new ProtocolException(e.getMessage(),e);
  796.                     }
  797.                 }
  798.             }
  799.            
  800.             // Key password
  801.             AbstractConsoleItem<?> keyPasswordItem =    
  802.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  803.                             ModIConsoleCostanti.MODIPA_KEY_PASSWORD_ID
  804.                             );
  805.             if(keyPasswordItem!=null) {
  806.                 StringProperty keystoreItemValue =
  807.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEY_PASSWORD_ID);
  808.                 if(keystoreItemValue!=null && keystoreItemValue.getValue()!=null && !"".equals(keystoreItemValue.getValue())) {
  809.                     try {
  810.                         InputValidationUtils.validateTextInput(keystoreItemValue.getValue(),
  811.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_KEYSTORE_LABEL +" - "+
  812.                                 ModIConsoleCostanti.MODIPA_KEY_PASSWORD_LABEL);
  813.                     }catch(Exception e) {
  814.                         throw new ProtocolException(e.getMessage(),e);
  815.                     }
  816.                 }
  817.             }
  818.             // Key alias
  819.             AbstractConsoleItem<?> keyAliasItem =  
  820.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  821.                             ModIConsoleCostanti.MODIPA_KEY_ALIAS_ID
  822.                             );
  823.             if(keyAliasItem!=null) {
  824.                 StringProperty keystoreItemValue =
  825.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_KEY_ALIAS_ID);
  826.                 if(keystoreItemValue!=null && keystoreItemValue.getValue()!=null && !"".equals(keystoreItemValue.getValue())) {
  827.                     try {
  828.                         InputValidationUtils.validateTextInput(keystoreItemValue.getValue(),
  829.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_KEYSTORE_LABEL +" - "+
  830.                                 ModIConsoleCostanti.MODIPA_KEY_ALIAS_LABEL);
  831.                     }catch(Exception e) {
  832.                         throw new ProtocolException(e.getMessage(),e);
  833.                     }
  834.                 }
  835.             }
  836.            
  837.             // TrustStore Path
  838.             AbstractConsoleItem<?> truststorePathItem =    
  839.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  840.                             ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_TRUSTSTORE_PATH_ID
  841.                             );
  842.             if(truststorePathItem!=null) {
  843.                 StringProperty truststorePathItemValue =
  844.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_TRUSTSTORE_PATH_ID);
  845.                 if(truststorePathItemValue!=null && truststorePathItemValue.getValue()!=null && !"".equals(truststorePathItemValue.getValue())) {
  846.                     try {
  847.                         InputValidationUtils.validateTextAreaInput(truststorePathItemValue.getValue(),
  848.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_CERTIFICATI_TRUSTSTORE_LABEL +" - "+
  849.                                         ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_TRUSTSTORE_PATH_LABEL);
  850.                     }catch(Exception e) {
  851.                         throw new ProtocolException(e.getMessage(),e);
  852.                     }
  853.                 }
  854.             }
  855.            
  856.             // TrustStore Password
  857.             AbstractConsoleItem<?> truststorePasswordItem =    
  858.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  859.                             ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_TRUSTSTORE_PASSWORD_ID
  860.                             );
  861.             if(truststorePasswordItem!=null) {
  862.                 StringProperty truststoreItemValue =
  863.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_TRUSTSTORE_PASSWORD_ID);
  864.                 if(truststoreItemValue!=null && truststoreItemValue.getValue()!=null && !"".equals(truststoreItemValue.getValue())) {
  865.                     try {
  866.                         InputValidationUtils.validateTextInput(truststoreItemValue.getValue(),
  867.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_CERTIFICATI_TRUSTSTORE_LABEL +" - "+
  868.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_TRUSTSTORE_PASSWORD_LABEL);
  869.                     }catch(Exception e) {
  870.                         throw new ProtocolException(e.getMessage(),e);
  871.                     }
  872.                 }
  873.             }
  874.            
  875.             // TrustStore CRL
  876.             AbstractConsoleItem<?> truststoreCRLPathItem =  
  877.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  878.                             ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_TRUSTSTORE_CRLS_ID
  879.                             );
  880.             if(truststoreCRLPathItem!=null) {
  881.                 StringProperty truststoreCRLPathItemValue =
  882.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_TRUSTSTORE_CRLS_ID);
  883.                 if(truststoreCRLPathItemValue!=null && truststoreCRLPathItemValue.getValue()!=null && !"".equals(truststoreCRLPathItemValue.getValue())) {
  884.                     try {
  885.                         InputValidationUtils.validateTextAreaInput(truststoreCRLPathItemValue.getValue(),
  886.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_CERTIFICATI_TRUSTSTORE_LABEL +" - "+
  887.                                         ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_CERTIFICATI_TRUSTSTORE_CRLS_LABEL);
  888.                     }catch(Exception e) {
  889.                         throw new ProtocolException(e.getMessage(),e);
  890.                     }
  891.                 }
  892.             }
  893.            
  894.             // TrustStore Path (SSL)
  895.             truststorePathItem =    
  896.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  897.                             ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_SSL_TRUSTSTORE_PATH_ID
  898.                             );
  899.             if(truststorePathItem!=null) {
  900.                 StringProperty truststorePathItemValue =
  901.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_SSL_TRUSTSTORE_PATH_ID);
  902.                 if(truststorePathItemValue!=null && truststorePathItemValue.getValue()!=null && !"".equals(truststorePathItemValue.getValue())) {
  903.                     try {
  904.                         InputValidationUtils.validateTextAreaInput(truststorePathItemValue.getValue(),
  905.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_SSL_TRUSTSTORE_LABEL +" - "+
  906.                                         ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_SSL_TRUSTSTORE_PATH_LABEL);
  907.                     }catch(Exception e) {
  908.                         throw new ProtocolException(e.getMessage(),e);
  909.                     }
  910.                 }
  911.             }
  912.                        
  913.             // TrustStore CRL (SSL)
  914.             truststoreCRLPathItem =    
  915.                     ProtocolPropertiesUtils.getAbstractConsoleItem(consoleConfiguration.getConsoleItem(),
  916.                             ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_SSL_TRUSTSTORE_CRLS_ID
  917.                             );
  918.             if(truststoreCRLPathItem!=null) {
  919.                 StringProperty truststoreCRLPathItemValue =
  920.                         (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_SSL_TRUSTSTORE_CRLS_ID);
  921.                 if(truststoreCRLPathItemValue!=null && truststoreCRLPathItemValue.getValue()!=null && !"".equals(truststoreCRLPathItemValue.getValue())) {
  922.                     try {
  923.                         InputValidationUtils.validateTextAreaInput(truststoreCRLPathItemValue.getValue(),
  924.                                 ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_SSL_TRUSTSTORE_LABEL +" - "+
  925.                                         ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_MESSAGGIO_SSL_TRUSTSTORE_CRLS_LABEL);
  926.                     }catch(Exception e) {
  927.                         throw new ProtocolException(e.getMessage(),e);
  928.                     }
  929.                 }
  930.             }

  931.         }
  932.        
  933.         // validazione dati OAuth se forniti

  934.         StringProperty tokenIdentificativoClientItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_OAUTH_IDENTIFICATIVO_ID);
  935.         if(tokenIdentificativoClientItemValue!=null && tokenIdentificativoClientItemValue.getValue()!=null && StringUtils.isNotEmpty(tokenIdentificativoClientItemValue.getValue())) {
  936.             try {
  937.                 InputValidationUtils.validateTextAreaInput(tokenIdentificativoClientItemValue.getValue(),
  938.                         ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_OAUTH_IDENTIFICATIVO_LABEL);
  939.             }catch(Exception e) {
  940.                 throw new ProtocolException(e.getMessage(),e);
  941.             }
  942.         }
  943.        
  944.         StringProperty tokenKidItemValue = (StringProperty) ProtocolPropertiesUtils.getAbstractPropertyById(properties, ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_OAUTH_KID_ID);
  945.         if(tokenKidItemValue!=null && tokenKidItemValue.getValue()!=null && StringUtils.isNotEmpty(tokenKidItemValue.getValue())) {
  946.             try {
  947.                 InputValidationUtils.validateTextAreaInput(tokenKidItemValue.getValue(),
  948.                         ModIConsoleCostanti.MODIPA_API_IMPL_PROFILO_SICUREZZA_OAUTH_KID_LABEL);
  949.             }catch(Exception e) {
  950.                 throw new ProtocolException(e.getMessage(),e);
  951.             }
  952.         }

  953.        
  954.        
  955.         return true;
  956.     }
  957.    
  958.     private static void checkClaims(ModIProperties modiProperties,
  959.             Properties claims, String elemento, boolean request, boolean digest, boolean corniceSicurezzaLegacy) throws ProtocolException {
  960.         List<String> denyClaims = null;
  961.         String claimNameClientId = null;
  962.         try {
  963.             denyClaims = modiProperties.getUsedRestSecurityClaims(request, digest);
  964.             claimNameClientId = modiProperties.getRestSecurityTokenClaimsClientIdHeader();
  965.         }catch(Exception e) {
  966.             throw new ProtocolException(e.getMessage(),e);
  967.         }
  968.         if(claims!=null && !claims.isEmpty()) {
  969.             for (Object oClaim : claims.keySet()) {
  970.                 if(oClaim instanceof String) {
  971.                     String claim = (String) oClaim;
  972.                     String value = claims.getProperty(claim);
  973.                    
  974.                     String debugS = "'"+claim+"', indicato nel campo "+elemento;
  975.                    
  976.                     if(value!=null &&  DynamicHelperCostanti.NOT_GENERATE.equalsIgnoreCase(value.trim())) {
  977.                         if(claim.equalsIgnoreCase(claimNameClientId) ||
  978.                                 (claim.equalsIgnoreCase(Claims.INTROSPECTION_RESPONSE_RFC_7662_ISSUER) && !corniceSicurezzaLegacy) ||
  979.                                 (claim.equalsIgnoreCase(Claims.INTROSPECTION_RESPONSE_RFC_7662_SUBJECT) && !corniceSicurezzaLegacy)
  980.                             ) {
  981.                             continue;
  982.                         }
  983.                         else {
  984.                             throw new ProtocolException("Keyword '"+DynamicHelperCostanti.NOT_GENERATE+"' non utilizzabile nel claim "+debugS);
  985.                         }
  986.                     }
  987.                     if(denyClaims.contains(claim) || denyClaims.contains(claim.toLowerCase())) {
  988.                         throw new ProtocolException("Il claim "+debugS+", non può essere configurato");
  989.                     }
  990.                     if(value==null || StringUtils.isEmpty(value)) {
  991.                         throw new ProtocolException("Claim "+debugS+", non valorizzato");
  992.                     }
  993.                 }
  994.             }
  995.         }
  996.     }
  997.    
  998.     private static boolean isMascheraGestioneFruizioneOrErogazione(IConsoleHelper consoleHelper) {
  999.         boolean gestioneFruitori = isMascheraGestioneFruizione(consoleHelper);
  1000.         boolean gestioneErogatori = isMascheraGestioneErogazione(consoleHelper);
  1001.         return gestioneErogatori || gestioneFruitori;
  1002.     }
  1003.    
  1004.     private static boolean isMascheraGestioneErogazione(IConsoleHelper consoleHelper) {
  1005.         String tipologia = consoleHelper.getAttributeFromSession(Costanti.CONSOLE_PARAMETRO_APS_TIPO_EROGAZIONE, String.class);
  1006.         if(tipologia == null) {
  1007.             try {
  1008.                 String p = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_APS_TIPO_EROGAZIONE_VIA_PARAM);
  1009.                 if(p!=null) {
  1010.                     tipologia = p;
  1011.                 }
  1012.             }catch(Exception e) {
  1013.                 // ignore
  1014.             }
  1015.         }
  1016.         return tipologia!=null &&
  1017.             Costanti.CONSOLE_PARAMETRO_APS_TIPO_EROGAZIONE_VALUE_EROGAZIONE.equals(tipologia);
  1018.     }
  1019.     private static boolean isMascheraGestioneFruizione(IConsoleHelper consoleHelper) {
  1020.         String tipologia = consoleHelper.getAttributeFromSession(Costanti.CONSOLE_PARAMETRO_APS_TIPO_EROGAZIONE, String.class);
  1021.         if(tipologia == null) {
  1022.             try {
  1023.                 String p = consoleHelper.getParameter(Costanti.CONSOLE_PARAMETRO_APS_TIPO_EROGAZIONE_VIA_PARAM);
  1024.                 if(p!=null) {
  1025.                     tipologia = p;
  1026.                 }
  1027.             }catch(Exception e) {
  1028.                 // ignore
  1029.             }
  1030.         }
  1031.         return tipologia!=null &&
  1032.             Costanti.CONSOLE_PARAMETRO_APS_TIPO_EROGAZIONE_VALUE_FRUIZIONE.equals(tipologia);
  1033.     }
  1034. }