ModIPropertiesUtils.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.utils;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import org.apache.commons.lang.StringUtils;
  24. import org.openspcoop2.core.config.GenericProperties;
  25. import org.openspcoop2.core.constants.CostantiConnettori;
  26. import org.openspcoop2.core.constants.TipiConnettore;
  27. import org.openspcoop2.core.id.IDSoggetto;
  28. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  29. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  30. import org.openspcoop2.core.registry.Azione;
  31. import org.openspcoop2.core.registry.ConfigurazioneServizioAzione;
  32. import org.openspcoop2.core.registry.Fruitore;
  33. import org.openspcoop2.core.registry.Operation;
  34. import org.openspcoop2.core.registry.PortType;
  35. import org.openspcoop2.core.registry.Property;
  36. import org.openspcoop2.core.registry.ProtocolProperty;
  37. import org.openspcoop2.core.registry.Resource;
  38. import org.openspcoop2.message.OpenSPCoop2Message;
  39. import org.openspcoop2.protocol.engine.constants.Costanti;
  40. import org.openspcoop2.protocol.modipa.config.ModIAuditConfig;
  41. import org.openspcoop2.protocol.modipa.config.ModIProperties;
  42. import org.openspcoop2.protocol.modipa.constants.ModIConsoleCostanti;
  43. import org.openspcoop2.protocol.modipa.constants.ModICostanti;
  44. import org.openspcoop2.protocol.sdk.ProtocolException;
  45. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesUtils;
  46. import org.openspcoop2.protocol.sdk.registry.IConfigIntegrationReader;
  47. import org.openspcoop2.protocol.utils.ModISecurityUtils;
  48. import org.openspcoop2.protocol.utils.ModIUtils;
  49. import org.openspcoop2.utils.transport.http.ContentTypeUtilities;
  50. import org.openspcoop2.utils.transport.http.HttpConstants;
  51. import org.slf4j.Logger;

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

  62.    
  63.     public static String readPropertySecurityChannelProfile(AccordoServizioParteComune aspc, AccordoServizioParteSpecifica asps) throws ProtocolException {
  64.         try {
  65.             return ModIPropertiesUtils.readPropertySecurityChannelProfileEngine(aspc).toUpperCase();
  66.         } catch (ProtocolException e) {
  67.             if (ModISecurityUtils.isSicurezzaMessaggioRequired(aspc, asps.getPortType()))
  68.                 throw e;
  69.         }
  70.         return null;
  71.     }
  72.    
  73.     public static String readPropertySecurityChannelProfileEngine(AccordoServizioParteComune aspc) throws ProtocolException {
  74.         return ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  75.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_CANALE);
  76.     }
  77.    
  78.    
  79.    
  80.    
  81.     // ACTION
  82.    
  83.     public static String readPropertyInteractionProfile(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  84.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_INTERAZIONE);
  85.     }
  86.     public static String readPropertyAsyncInteractionProfile(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  87.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA);
  88.     }
  89.     public static String readPropertyAsyncInteractionRole(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  90.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO);
  91.     }
  92.     public static String readPropertyAsyncInteractionRequestApi(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  93.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA);
  94.     }
  95.     public static String readPropertyAsyncInteractionRequestService(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  96.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_SERVIZIO_RICHIESTA_CORRELATA);
  97.     }
  98.     public static String readPropertyAsyncInteractionRequestAction(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  99.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA);
  100.     }
  101.     public static String readPropertySecurityMessageProfile(AccordoServizioParteComune aspc, String nomePortType, String azione, boolean filterPDND) throws ProtocolException {
  102.         try {
  103.             return ModIPropertiesUtils.readPropertySecurityMessageProfileEngine(aspc, nomePortType, azione, filterPDND);
  104.         } catch (ProtocolException e) {
  105.             if (ModISecurityUtils.isSicurezzaMessaggioRequired(aspc, nomePortType))
  106.                 throw e;
  107.         }
  108.         return null;
  109.     }
  110.     public static String readPropertySecurityMessageProfileEngine(AccordoServizioParteComune aspc, String nomePortType, String azione, boolean filterPDND) throws ProtocolException {
  111.         String profile = readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO);
  112.         if(filterPDND &&
  113.             (
  114.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM01.equals(profile)
  115.                 ||
  116.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM02.equals(profile)
  117.             )
  118.         ){
  119.             String sorgenteToken = readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH);
  120.             if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_PDND.equals(sorgenteToken) ||
  121.                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_OAUTH.equals(sorgenteToken)) {
  122.                 profile = null;
  123.             }
  124.         }
  125.         return profile;
  126.     }
  127.     public static String readPropertySecurityMessageHeader(AccordoServizioParteComune aspc, String nomePortType, String azione, boolean request, boolean filterPDND) throws ProtocolException {
  128.         String header = readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER, request);
  129.         if(header!=null && filterPDND) {
  130.             String sorgenteToken = readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH);
  131.             if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_PDND.equals(sorgenteToken) ||
  132.                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_OAUTH.equals(sorgenteToken)) {
  133.                 header = header.replace(HttpConstants.AUTHORIZATION, "");
  134.                 header = header.trim();
  135.             }
  136.         }
  137.         return header;
  138.     }
  139.     public static String readPropertySecurityMessageSorgenteToken(AccordoServizioParteComune aspc, String nomePortType, String azione, boolean request) throws ProtocolException {
  140.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH, request);
  141.     }
  142.     public static boolean isPropertySecurityMessageHeaderCustom(AccordoServizioParteComune aspc, String nomePortType, String azione, boolean request) throws ProtocolException {
  143.         String tmp = readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM, request);
  144.         return tmp!=null && Boolean.valueOf(tmp);
  145.     }
  146.     public static String getPropertySecurityMessageHeaderCustomMode(AccordoServizioParteComune aspc, String nomePortType, String azione, boolean request) throws ProtocolException {
  147.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM_MODE, request);
  148.     }
  149.     public static boolean isPropertySecurityMessageConCorniceSicurezza(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  150.         String tmp = readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA);
  151.         return tmp!=null && Boolean.valueOf(tmp);
  152.     }
  153.     public static String readPropertySecurityMessageCorniceSicurezzaPattern(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  154.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN);
  155.     }
  156.     public static String readPropertySecurityMessageCorniceSicurezzaSchema(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  157.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_SCHEMA);
  158.     }
  159.     public static boolean isPropertySecurityMessageCorniceSicurezzaOpzionale(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  160.         String tmp = readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_OPZIONALE);
  161.         return tmp!=null && Boolean.valueOf(tmp);
  162.     }
  163.     public static boolean isPropertySecurityMessageIncludiRequestDigest(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  164.         String tmp = readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_REQUEST_DIGEST);
  165.         return tmp!=null && Boolean.valueOf(tmp);
  166.     }
  167.     public static String readPropertySecurityMessageApplicabilita(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  168.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE);
  169.     }
  170.     public static String readPropertySecurityMessageApplicabilitaRichiesta(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  171.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE);
  172.     }
  173.     public static String readPropertySecurityMessageApplicabilitaRichiestaContentType(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  174.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_CONTENT_TYPE_MODE_ID);
  175.     }
  176.     public static String readPropertySecurityMessageApplicabilitaRisposta(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  177.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE);
  178.     }
  179.     public static String readPropertySecurityMessageApplicabilitaRispostaContentType(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  180.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_CONTENT_TYPE_MODE_ID);
  181.     }
  182.     public static String readPropertySecurityMessageApplicabilitaRispostaReturnCode(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  183.         return readPropertyEngine(aspc, nomePortType, azione, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_ID);
  184.     }
  185.     private static String readPropertyEngine(AccordoServizioParteComune aspc, String nomePortType, String azione,
  186.             String propertyName) throws ProtocolException {
  187.         return readPropertyEngine(aspc, nomePortType, azione, propertyName, null);
  188.     }
  189.     private static String readPropertyEngine(AccordoServizioParteComune aspc, String nomePortType, String azione,
  190.             String propertyName, Boolean request) throws ProtocolException {
  191.        
  192.         String interactionProfile = null;
  193.         String asyncInteractionProfile = null;
  194.         String asyncInteractionRole = null;
  195.         String asyncInteractionRequestApi = null;
  196.         String asyncInteractionRequestService = null;
  197.         String asyncInteractionRequestAction = null;
  198.         String securityMessageProfile = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  199.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO);
  200.         String securityMessageProfileSorgenteTokenIdAuth = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  201.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH);
  202.         String securityMessageProfileHeader = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  203.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER);
  204.         String securityMessageProfileHeaderCustom = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  205.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM);
  206.         String securityMessageProfileHeaderCustomMode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  207.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM_MODE);
  208.         String securityMessageCorniceSicurezza = ProtocolPropertiesUtils.getBooleanValuePropertyRegistry(aspc.getProtocolPropertyList(),
  209.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA, false)+"";
  210.         String securityMessageCorniceSicurezzaPattern = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  211.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN);
  212.         String securityMessageCorniceSicurezzaSchema = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  213.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_SCHEMA);
  214.         String securityMessageCorniceSicurezzaOpzionale = ProtocolPropertiesUtils.getBooleanValuePropertyRegistry(aspc.getProtocolPropertyList(),
  215.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_OPZIONALE, false)+"";
  216.         String securityMessageRequestDigest = ProtocolPropertiesUtils.getBooleanValuePropertyRegistry(aspc.getProtocolPropertyList(),
  217.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_REQUEST_DIGEST, false)+"";
  218.         String securityMessageApplicabilita = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  219.                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE);
  220.         String securityMessageApplicabilitaRichiesta = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  221.                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE);
  222.         String securityMessageApplicabilitaRichiestaContentType = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  223.                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_CONTENT_TYPE_MODE_ID);
  224.         String securityMessageApplicabilitaRisposta = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  225.                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE);
  226.         String securityMessageApplicabilitaRispostaContentType = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  227.                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_CONTENT_TYPE_MODE_ID);
  228.         String securityMessageApplicabilitaRispostaReturnCode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(aspc.getProtocolPropertyList(),
  229.                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_ID);
  230.        
  231.         if(org.openspcoop2.core.registry.constants.ServiceBinding.REST.equals(aspc.getServiceBinding())) {
  232.             for (Resource resource : aspc.getResourceList()) {
  233.                 if(resource.getNome().equals(azione)) {
  234.                     interactionProfile = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  235.                             ModICostanti.MODIPA_PROFILO_INTERAZIONE);
  236.                     if(interactionProfile==null) {
  237.                         interactionProfile = ModICostanti.MODIPA_PROFILO_INTERAZIONE_DEFAULT_REST_VALUE;
  238.                     }
  239.                     if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE.equals(interactionProfile)) {
  240.                         asyncInteractionProfile = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  241.                                 ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA);
  242.                         asyncInteractionRole = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  243.                                 ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO);
  244.                         if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH.equals(asyncInteractionProfile)) {
  245.                             // push
  246.                             if(!ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(asyncInteractionRole)) {
  247.                                 asyncInteractionRequestApi = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  248.                                         ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA);
  249.                                 asyncInteractionRequestAction = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  250.                                         ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA);
  251.                             }
  252.                         }
  253.                         else {
  254.                             // pull
  255.                             if(!ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(asyncInteractionRole)) {
  256.                                 asyncInteractionRequestAction = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  257.                                         ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA);
  258.                             }
  259.                         }
  260.                        
  261.                     }
  262.                     String securityMessageProfileMode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  263.                             ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_ACTION_MODE);
  264.                     if(securityMessageProfileMode==null) {
  265.                         securityMessageProfileMode = ModICostanti.MODIPA_PROFILO_DEFAULT; // default
  266.                     }
  267.                     if(ModICostanti.MODIPA_PROFILO_RIDEFINISCI.equals(securityMessageProfileMode)) {
  268.                         securityMessageProfile = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  269.                                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO);
  270.                         securityMessageProfileSorgenteTokenIdAuth = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  271.                                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH);
  272.                         securityMessageProfileHeader = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  273.                                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER);
  274.                         securityMessageProfileHeaderCustom = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  275.                                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM);
  276.                         securityMessageProfileHeaderCustomMode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  277.                                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM_MODE);
  278.                         securityMessageCorniceSicurezza = ProtocolPropertiesUtils.getBooleanValuePropertyRegistry(resource.getProtocolPropertyList(),
  279.                                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA, false)+"";
  280.                         securityMessageCorniceSicurezzaPattern = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  281.                                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN);
  282.                         securityMessageCorniceSicurezzaSchema = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  283.                                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_SCHEMA);
  284.                         securityMessageCorniceSicurezzaOpzionale = ProtocolPropertiesUtils.getBooleanValuePropertyRegistry(resource.getProtocolPropertyList(),
  285.                                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_OPZIONALE, false)+"";
  286.                         securityMessageRequestDigest = ProtocolPropertiesUtils.getBooleanValuePropertyRegistry(resource.getProtocolPropertyList(),
  287.                                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_REQUEST_DIGEST, false)+"";
  288.                         securityMessageApplicabilita = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  289.                                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE);
  290.                         securityMessageApplicabilitaRichiesta = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  291.                                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE);
  292.                         securityMessageApplicabilitaRichiestaContentType = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  293.                                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_CONTENT_TYPE_MODE_ID);
  294.                         securityMessageApplicabilitaRisposta = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  295.                                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE);
  296.                         securityMessageApplicabilitaRispostaContentType = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  297.                                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_CONTENT_TYPE_MODE_ID);
  298.                         securityMessageApplicabilitaRispostaReturnCode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  299.                                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_ID);
  300.                     }
  301.                     break;
  302.                 }
  303.             }
  304.         }
  305.         else {
  306.             if(nomePortType!=null) {
  307.                 for (PortType pt : aspc.getPortTypeList()) {
  308.                     if(pt.getNome().equals(nomePortType)) {
  309.                         for (Operation op : pt.getAzioneList()) {
  310.                             if(op.getNome().equals(azione)) {
  311.                                 interactionProfile = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  312.                                         ModICostanti.MODIPA_PROFILO_INTERAZIONE);
  313.                                 if(interactionProfile==null) {
  314.                                     interactionProfile = ModICostanti.MODIPA_PROFILO_INTERAZIONE_DEFAULT_SOAP_VALUE;
  315.                                 }
  316.                                 if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE.equals(interactionProfile)) {
  317.                                     asyncInteractionProfile = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(op.getProtocolPropertyList(),
  318.                                             ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA);
  319.                                     asyncInteractionRole = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(op.getProtocolPropertyList(),
  320.                                             ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO);
  321.                                     if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH.equals(asyncInteractionProfile)) {
  322.                                         // push
  323.                                         if(!ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(asyncInteractionRole)) {
  324.                                             asyncInteractionRequestApi = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(op.getProtocolPropertyList(),
  325.                                                     ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA);
  326.                                             asyncInteractionRequestService = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(op.getProtocolPropertyList(),
  327.                                                     ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_SERVIZIO_RICHIESTA_CORRELATA);
  328.                                             asyncInteractionRequestAction = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(op.getProtocolPropertyList(),
  329.                                                     ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA);
  330.                                         }
  331.                                     }
  332.                                     else {
  333.                                         // pull
  334.                                         if(!ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(asyncInteractionRole)) {
  335.                                             asyncInteractionRequestAction = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(op.getProtocolPropertyList(),
  336.                                                     ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA);
  337.                                         }
  338.                                     }
  339.                                 }
  340.                                 String securityMessageProfileMode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  341.                                         ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_ACTION_MODE);
  342.                                 if(securityMessageProfileMode==null) {
  343.                                     securityMessageProfileMode = ModICostanti.MODIPA_PROFILO_DEFAULT; // default
  344.                                 }
  345.                                 if(ModICostanti.MODIPA_PROFILO_RIDEFINISCI.equals(securityMessageProfileMode)) {
  346.                                     securityMessageProfile = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  347.                                             ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO);
  348.                                     securityMessageProfileSorgenteTokenIdAuth = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  349.                                             ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH);
  350.                                     securityMessageProfileHeader = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  351.                                             ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER);
  352.                                     securityMessageProfileHeaderCustom = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  353.                                             ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM);
  354.                                     securityMessageProfileHeaderCustomMode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  355.                                             ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM_MODE);
  356.                                     securityMessageCorniceSicurezza = ProtocolPropertiesUtils.getBooleanValuePropertyRegistry(op.getProtocolPropertyList(),
  357.                                             ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA, false)+"";
  358.                                     securityMessageCorniceSicurezzaPattern = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  359.                                             ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN);
  360.                                     securityMessageCorniceSicurezzaSchema = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  361.                                             ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_SCHEMA);
  362.                                     securityMessageCorniceSicurezzaOpzionale = ProtocolPropertiesUtils.getBooleanValuePropertyRegistry(op.getProtocolPropertyList(),
  363.                                             ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_OPZIONALE, false)+"";
  364.                                     securityMessageRequestDigest = ProtocolPropertiesUtils.getBooleanValuePropertyRegistry(op.getProtocolPropertyList(),
  365.                                             ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_REQUEST_DIGEST, false)+"";
  366.                                     securityMessageApplicabilita = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  367.                                             ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE);
  368.                                     securityMessageApplicabilitaRichiesta = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  369.                                             ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE);
  370.                                     securityMessageApplicabilitaRichiestaContentType = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  371.                                             ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_CONTENT_TYPE_MODE_ID);
  372.                                     securityMessageApplicabilitaRisposta = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  373.                                             ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE);
  374.                                     securityMessageApplicabilitaRispostaContentType = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  375.                                             ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_CONTENT_TYPE_MODE_ID);
  376.                                     securityMessageApplicabilitaRispostaReturnCode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  377.                                             ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_ID);
  378.                                 }
  379.                                 break;
  380.                             }
  381.                         }
  382.                         break;
  383.                     }
  384.                 }
  385.             }
  386.             else {
  387.                 for (Azione azioneAccordo : aspc.getAzioneList()) {
  388.                     if(azioneAccordo.getNome().equals(azione)) {
  389.                         interactionProfile = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  390.                                 ModICostanti.MODIPA_PROFILO_INTERAZIONE);
  391.                         if(interactionProfile==null) {
  392.                             interactionProfile = ModICostanti.MODIPA_PROFILO_INTERAZIONE_DEFAULT_SOAP_VALUE;
  393.                         }
  394.                         if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE.equals(interactionProfile)) {
  395.                             asyncInteractionProfile = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  396.                                     ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA);
  397.                             asyncInteractionRole = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  398.                                     ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO);
  399.                             if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH.equals(asyncInteractionProfile)) {
  400.                                 // push
  401.                                 if(!ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(asyncInteractionRole)) {
  402.                                     asyncInteractionRequestApi = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  403.                                             ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA);
  404.                                     asyncInteractionRequestService = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  405.                                             ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_SERVIZIO_RICHIESTA_CORRELATA);
  406.                                     asyncInteractionRequestAction = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  407.                                             ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA);
  408.                                 }
  409.                             }
  410.                             else {
  411.                                 // pull
  412.                                 if(!ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(asyncInteractionRole)) {
  413.                                     asyncInteractionRequestAction = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  414.                                             ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA);
  415.                                 }
  416.                             }
  417.                         }
  418.                         String securityMessageProfileMode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  419.                                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_ACTION_MODE);
  420.                         if(securityMessageProfileMode==null) {
  421.                             securityMessageProfileMode = ModICostanti.MODIPA_PROFILO_DEFAULT; // default
  422.                         }
  423.                         if(ModICostanti.MODIPA_PROFILO_RIDEFINISCI.equals(securityMessageProfileMode)) {
  424.                             securityMessageProfile = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  425.                                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO);
  426.                             securityMessageProfileSorgenteTokenIdAuth = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  427.                                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH);
  428.                             securityMessageProfileHeader = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  429.                                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER);
  430.                             securityMessageProfileHeaderCustom = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  431.                                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM);
  432.                             securityMessageProfileHeaderCustomMode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  433.                                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM_MODE);
  434.                             securityMessageCorniceSicurezza = ProtocolPropertiesUtils.getBooleanValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  435.                                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA, false)+"";
  436.                             securityMessageCorniceSicurezzaPattern = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  437.                                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN);
  438.                             securityMessageCorniceSicurezzaSchema = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  439.                                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_SCHEMA);
  440.                             securityMessageCorniceSicurezzaOpzionale = ProtocolPropertiesUtils.getBooleanValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  441.                                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_OPZIONALE, false)+"";
  442.                             securityMessageRequestDigest = ProtocolPropertiesUtils.getBooleanValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  443.                                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_REQUEST_DIGEST, false)+"";
  444.                             securityMessageApplicabilita = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  445.                                     ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE);
  446.                             securityMessageApplicabilitaRichiesta = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  447.                                     ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE);
  448.                             securityMessageApplicabilitaRichiestaContentType = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  449.                                     ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_CONTENT_TYPE_MODE_ID);
  450.                             securityMessageApplicabilitaRisposta = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  451.                                     ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE);
  452.                             securityMessageApplicabilitaRispostaContentType = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  453.                                     ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_CONTENT_TYPE_MODE_ID);
  454.                             securityMessageApplicabilitaRispostaReturnCode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  455.                                     ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_ID);
  456.                         }
  457.                         break;
  458.                     }
  459.                 }
  460.             }
  461.         }
  462.         if(ModICostanti.MODIPA_PROFILO_INTERAZIONE.equals(propertyName)) {
  463.             return interactionProfile;
  464.         }
  465.         else if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA.equals(propertyName)) {
  466.             return asyncInteractionProfile;
  467.         }
  468.         else if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO.equals(propertyName)) {
  469.             return asyncInteractionRole;
  470.         }
  471.         else if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA.equals(propertyName)) {
  472.             return asyncInteractionRequestApi;
  473.         }
  474.         else if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_SERVIZIO_RICHIESTA_CORRELATA.equals(propertyName)) {
  475.             return asyncInteractionRequestService;
  476.         }
  477.         else if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA.equals(propertyName)) {
  478.             return asyncInteractionRequestAction;
  479.         }
  480.         else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO.equals(propertyName)) {
  481.             return securityMessageProfile;
  482.         }
  483.         else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH.equals(propertyName)) {
  484.             return securityMessageProfileSorgenteTokenIdAuth;
  485.         }
  486.         else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER.equals(propertyName)) {
  487.            
  488.             if(securityMessageProfileHeader==null || StringUtils.isEmpty(securityMessageProfileHeader)) {
  489.                 boolean integritaX5c = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0301.equals(securityMessageProfile) ||
  490.                         ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0302.equals(securityMessageProfile);
  491.                 boolean integritaKid = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0401.equals(securityMessageProfile) ||
  492.                         ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0402.equals(securityMessageProfile);
  493.                 boolean integrita = integritaX5c || integritaKid;
  494.                 if(integrita) {
  495.                     securityMessageProfileHeader = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_IDAM03_DEFAULT_VALUE;
  496.                 }
  497.                 else {
  498.                     securityMessageProfileHeader = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_NOT_IDAM03_DEFAULT_VALUE;
  499.                 }
  500.             }
  501.             if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_MODIPA.equals(securityMessageProfileHeader)) {
  502.                 return ModIProperties.getInstance().getRestSecurityTokenHeaderModI();
  503.             }
  504.             else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION.equals(securityMessageProfileHeader)) {
  505.                 return HttpConstants.AUTHORIZATION;
  506.             }
  507.             else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_MODIPA_AUTH_IN_RESPONSE.equals(securityMessageProfileHeader)) {
  508.                 return HttpConstants.AUTHORIZATION + " " +ModIProperties.getInstance().getRestSecurityTokenHeaderModI();
  509.             }
  510.             else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_MODIPA.equals(securityMessageProfileHeader)) {
  511.                 if(request!=null && request) {
  512.                     return HttpConstants.AUTHORIZATION + " " +ModIProperties.getInstance().getRestSecurityTokenHeaderModI();
  513.                 }
  514.                 else {
  515.                     return ModIProperties.getInstance().getRestSecurityTokenHeaderModI();
  516.                 }
  517.             }
  518.             else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_CUSTOM.equals(securityMessageProfileHeader)) {
  519.                 // integrityCustom
  520.                 return (securityMessageProfileHeaderCustom!=null && StringUtils.isNotEmpty(securityMessageProfileHeaderCustom)) ?
  521.                         securityMessageProfileHeaderCustom : ModIProperties.getInstance().getRestSecurityTokenHeaderModI();
  522.             }
  523.             else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_CUSTOM_AUTH_IN_RESPONSE.equals(securityMessageProfileHeader)) {
  524.                 String integrityCustom = (securityMessageProfileHeaderCustom!=null && StringUtils.isNotEmpty(securityMessageProfileHeaderCustom)) ?
  525.                         securityMessageProfileHeaderCustom : ModIProperties.getInstance().getRestSecurityTokenHeaderModI();
  526.                 return HttpConstants.AUTHORIZATION + " " +integrityCustom;
  527.             }
  528.             else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_CUSTOM.equals(securityMessageProfileHeader)) {
  529.                 String integrityCustom = (securityMessageProfileHeaderCustom!=null && StringUtils.isNotEmpty(securityMessageProfileHeaderCustom)) ?
  530.                         securityMessageProfileHeaderCustom : ModIProperties.getInstance().getRestSecurityTokenHeaderModI();
  531.                 if(request!=null && request) {
  532.                     return HttpConstants.AUTHORIZATION + " " +integrityCustom;
  533.                 }
  534.                 else {
  535.                     return integrityCustom;
  536.                 }
  537.             }
  538.             else {
  539.                 // caso che non dovrebbe capitare
  540.                 return HttpConstants.AUTHORIZATION;
  541.             }
  542.            
  543.         }
  544.         else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM.equals(propertyName)) {
  545.             // devo ritornare l'indicazione che e' abilitata. Il nome degli header viene gestita nella chiamata ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER sopra
  546.             return (ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_CUSTOM.equals(securityMessageProfileHeader)
  547.                     ||
  548.                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_CUSTOM_AUTH_IN_RESPONSE.equals(securityMessageProfileHeader)
  549.                     ||
  550.                     ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_CUSTOM.equals(securityMessageProfileHeader)) + "";
  551.         }
  552.         else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM_MODE.equals(propertyName)) {
  553.             return securityMessageProfileHeaderCustomMode;
  554.         }
  555.         else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA.equals(propertyName)) {
  556.             return securityMessageCorniceSicurezza;
  557.         }
  558.         else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN.equals(propertyName)) {
  559.             return securityMessageCorniceSicurezzaPattern;
  560.         }
  561.         else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_SCHEMA.equals(propertyName)) {
  562.             return securityMessageCorniceSicurezzaSchema;
  563.         }
  564.         else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_OPZIONALE.equals(propertyName)) {
  565.             return securityMessageCorniceSicurezzaOpzionale;
  566.         }
  567.         else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_REQUEST_DIGEST.equals(propertyName)) {
  568.             return securityMessageRequestDigest;
  569.         }
  570.         else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE.equals(propertyName)) {
  571.             return securityMessageApplicabilita;
  572.         }
  573.         else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE.equals(propertyName)) {
  574.             return securityMessageApplicabilitaRichiesta;
  575.         }
  576.         else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_CONTENT_TYPE_MODE_ID.equals(propertyName)) {
  577.             return securityMessageApplicabilitaRichiestaContentType;
  578.         }
  579.         else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE.equals(propertyName)) {
  580.             return securityMessageApplicabilitaRisposta;
  581.         }
  582.         else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_CONTENT_TYPE_MODE_ID.equals(propertyName)) {
  583.             return securityMessageApplicabilitaRispostaContentType;
  584.         }
  585.         else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_ID.equals(propertyName)) {
  586.             return securityMessageApplicabilitaRispostaReturnCode;
  587.         }
  588.         return null;
  589.     }
  590.    
  591.    
  592.    
  593.     public static boolean readSicurezzaMessaggioRidefinitaOperazioneEngine(AccordoServizioParteComune aspc, String nomePortType, String azione) throws ProtocolException {
  594.            
  595.         if(org.openspcoop2.core.registry.constants.ServiceBinding.REST.equals(aspc.getServiceBinding())) {
  596.             for (Resource resource : aspc.getResourceList()) {
  597.                 if(resource.getNome().equals(azione)) {
  598.                    
  599.                     String securityMessageProfileMode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(resource.getProtocolPropertyList(),
  600.                             ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_ACTION_MODE);
  601.                     if(securityMessageProfileMode==null) {
  602.                         securityMessageProfileMode = ModICostanti.MODIPA_PROFILO_DEFAULT; // default
  603.                     }
  604.                     if(ModICostanti.MODIPA_PROFILO_RIDEFINISCI.equals(securityMessageProfileMode)) {
  605.                         return true;
  606.                     }
  607.                     break;
  608.                 }
  609.             }
  610.         }
  611.         else {
  612.             if(nomePortType!=null) {
  613.                 for (PortType pt : aspc.getPortTypeList()) {
  614.                     if(pt.getNome().equals(nomePortType)) {
  615.                         for (Operation op : pt.getAzioneList()) {
  616.                             if(op.getNome().equals(azione)) {
  617.                                
  618.                                 String securityMessageProfileMode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(op.getProtocolPropertyList(),
  619.                                         ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_ACTION_MODE);
  620.                                 if(securityMessageProfileMode==null) {
  621.                                     securityMessageProfileMode = ModICostanti.MODIPA_PROFILO_DEFAULT; // default
  622.                                 }
  623.                                 if(ModICostanti.MODIPA_PROFILO_RIDEFINISCI.equals(securityMessageProfileMode)) {
  624.                                     return true;
  625.                                 }
  626.                                 break;
  627.                             }
  628.                         }
  629.                         break;
  630.                     }
  631.                 }
  632.             }
  633.             else {
  634.                 for (Azione azioneAccordo : aspc.getAzioneList()) {
  635.                     if(azioneAccordo.getNome().equals(azione)) {
  636.                        
  637.                         String securityMessageProfileMode = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(azioneAccordo.getProtocolPropertyList(),
  638.                                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_ACTION_MODE);
  639.                         if(securityMessageProfileMode==null) {
  640.                             securityMessageProfileMode = ModICostanti.MODIPA_PROFILO_DEFAULT; // default
  641.                         }
  642.                         if(ModICostanti.MODIPA_PROFILO_RIDEFINISCI.equals(securityMessageProfileMode)) {
  643.                             return true;
  644.                         }
  645.                         break;
  646.                     }
  647.                 }
  648.             }
  649.         }
  650.         return false;
  651.     }

  652.     public static List<ProtocolProperty> getProtocolProperties(boolean fruizione, IDSoggetto soggettoFruitore, AccordoServizioParteSpecifica asps) throws ProtocolException {
  653.         return ProtocolPropertiesUtils.getProtocolProperties(fruizione, soggettoFruitore, asps);
  654.     }
  655.    
  656.     public static Fruitore getFruitore(IDSoggetto soggettoFruitore, AccordoServizioParteSpecifica asps) throws ProtocolException {
  657.         return ProtocolPropertiesUtils.getFruitore(soggettoFruitore, asps);
  658.     }
  659.    
  660.     public static String convertProfiloSicurezzaToSDKValue(String securityMessageProfile, boolean rest) {
  661.         return ModIUtils.convertProfiloSicurezzaToSDKValue(securityMessageProfile, rest);
  662.     }
  663.     public static String convertProfiloSicurezzaToConfigurationValue(String securityMessageProfileSDKValue) {
  664.         return ModIUtils.convertProfiloSicurezzaToConfigurationValue(securityMessageProfileSDKValue);
  665.     }
  666.    
  667.     private static ProtocolException newProtocolExceptionUnknown(String prefix, String value) {
  668.         return ModIUtils.newProtocolExceptionUnknown(prefix, value);
  669.     }
  670.    
  671.     public static String convertProfiloSicurezzaSorgenteTokenToSDKValue(String sorgenteToken) {
  672.         return ModIUtils.convertProfiloSicurezzaSorgenteTokenToSDKValue(sorgenteToken);
  673.     }
  674.     public static String convertProfiloSicurezzaSorgenteTokenToConfigurationValue(String sorgenteTokenSDKValue) throws ProtocolException {
  675.         return ModIUtils.convertProfiloSicurezzaSorgenteTokenToConfigurationValue(sorgenteTokenSDKValue);
  676.     }
  677.    
  678.     public static String convertProfiloAuditToSDKValue(String patternCorniceSicurezza) throws ProtocolException {
  679.         return ModIUtils.convertProfiloAuditToSDKValue(patternCorniceSicurezza);
  680.     }
  681.     public static String convertProfiloAuditToConfigurationValue(String patternCorniceSicurezzaSDKValue) throws ProtocolException {
  682.         return ModIUtils.convertProfiloAuditToConfigurationValue(patternCorniceSicurezzaSDKValue);
  683.     }
  684.    
  685.     public static String convertSchemaAuditToSDKValue(String schemaCorniceSicurezza, ModIProperties modiProperties) throws ProtocolException {
  686.         if(modiProperties.getAuditConfig()!=null && !modiProperties.getAuditConfig().isEmpty()) {
  687.             for (ModIAuditConfig c : modiProperties.getAuditConfig()) {
  688.                 if(c.getNome().equals(schemaCorniceSicurezza)) {
  689.                     return c.getLabel();
  690.                 }
  691.             }
  692.         }
  693.         throw newProtocolExceptionUnknown("Schema value",schemaCorniceSicurezza);
  694.     }
  695.     public static String convertSchemaAuditToConfigurationValue(String schemaCorniceSicurezzaSDKValue, ModIProperties modiProperties) throws ProtocolException {
  696.         if(modiProperties.getAuditConfig()!=null && !modiProperties.getAuditConfig().isEmpty()) {
  697.             for (ModIAuditConfig c : modiProperties.getAuditConfig()) {
  698.                 if(c.getLabel().equals(schemaCorniceSicurezzaSDKValue)) {
  699.                     return c.getNome();
  700.                 }
  701.             }
  702.         }
  703.         throw newProtocolExceptionUnknown("Schema label",schemaCorniceSicurezzaSDKValue);
  704.     }

  705.     public static boolean isAttachmentsSignature(AccordoServizioParteComune aspc, String nomePortType, String azione, boolean isRichiesta,
  706.             OpenSPCoop2Message message) throws ProtocolException {
  707.         boolean sign = false;
  708.         String securityMessageApplicabilita = ModIPropertiesUtils.readPropertySecurityMessageApplicabilita(aspc, nomePortType, azione);
  709.         if(securityMessageApplicabilita==null || StringUtils.isEmpty(securityMessageApplicabilita)) {
  710.             securityMessageApplicabilita = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_DEFAULT;
  711.         }
  712.        
  713.         if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_ENTRAMBI_CON_ATTACHMENTS.equals(securityMessageApplicabilita)) {
  714.             sign = true;
  715.         }
  716.         else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RICHIESTA_CON_ATTACHMENTS.equals(securityMessageApplicabilita)) {
  717.             sign = isRichiesta;
  718.         }
  719.         else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RISPOSTA_CON_ATTACHMENTS.equals(securityMessageApplicabilita)) {
  720.             sign = !isRichiesta;
  721.         }
  722.        
  723.         if(sign) {
  724.             try {
  725.                 return message.castAsSoap().hasAttachments();
  726.             }catch(Exception e) {
  727.                 throw new ProtocolException(e.getMessage(),e);
  728.             }
  729.         }
  730.        
  731.         return false;
  732.     }

  733.     public static boolean processSecurity(Logger log, AccordoServizioParteComune aspc, String nomePortType, String azione, boolean isRichiesta,
  734.             OpenSPCoop2Message message, boolean rest, ModIProperties modiProperties) throws Exception {
  735.         boolean processSecurity = false;
  736.         String securityMessageApplicabilita = ModIPropertiesUtils.readPropertySecurityMessageApplicabilita(aspc, nomePortType, azione);
  737.         if(securityMessageApplicabilita==null || StringUtils.isEmpty(securityMessageApplicabilita)) {
  738.             securityMessageApplicabilita = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_DEFAULT;
  739.         }
  740.        
  741.         boolean configurazionePersonalizzata = false;
  742.         if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_ENTRAMBI.equals(securityMessageApplicabilita) ||
  743.                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_ENTRAMBI_CON_ATTACHMENTS.equals(securityMessageApplicabilita)) {
  744.             processSecurity = true;
  745.         }
  746.         else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RICHIESTA.equals(securityMessageApplicabilita) ||
  747.                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RICHIESTA_CON_ATTACHMENTS.equals(securityMessageApplicabilita)) {
  748.             processSecurity = isRichiesta;
  749.         }
  750.         else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RISPOSTA.equals(securityMessageApplicabilita) ||
  751.                 ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RISPOSTA_CON_ATTACHMENTS.equals(securityMessageApplicabilita)) {
  752.             processSecurity = !isRichiesta;
  753.         }
  754.         else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_PERSONALIZZATO.equals(securityMessageApplicabilita)) {
  755.            
  756.             if(isRichiesta) {
  757.                
  758.                 String securityMessageApplicabilitaRichiesta = ModIPropertiesUtils.readPropertySecurityMessageApplicabilitaRichiesta(aspc, nomePortType, azione);
  759.                 if(securityMessageApplicabilitaRichiesta==null || StringUtils.isEmpty(securityMessageApplicabilitaRichiesta)) {
  760.                     securityMessageApplicabilitaRichiesta = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE_VALUE_DEFAULT;
  761.                 }
  762.                
  763.                 if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE_VALUE_ABILITATO.equals(securityMessageApplicabilitaRichiesta)) {
  764.                     processSecurity = true;
  765.                 }
  766.                 else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE_VALUE_DISABILITATO.equals(securityMessageApplicabilitaRichiesta)) {
  767.                     processSecurity = false;
  768.                 }
  769.                 else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE_VALUE_PERSONALIZZATO.equals(securityMessageApplicabilitaRichiesta)) {
  770.            
  771.                     configurazionePersonalizzata = true;
  772.                    
  773.                     String securityMessageApplicabilitaRichiestaContentType = ModIPropertiesUtils.readPropertySecurityMessageApplicabilitaRichiestaContentType(aspc, nomePortType, azione);
  774.                     List<String> check = readValues(securityMessageApplicabilitaRichiestaContentType);
  775.                     if(!check.isEmpty()) {
  776.                         try {
  777.                             processSecurity = ContentTypeUtilities.isMatch(log, message.getContentType(), check);
  778.                         }catch(Exception e) {
  779.                             throw new ProtocolException(e.getMessage(),e);
  780.                         }
  781.                     }
  782.                 }
  783.                
  784.             }
  785.             else {
  786.                
  787.                 String securityMessageApplicabilitaRisposta = ModIPropertiesUtils.readPropertySecurityMessageApplicabilitaRisposta(aspc, nomePortType, azione);
  788.                 if(securityMessageApplicabilitaRisposta==null || StringUtils.isEmpty(securityMessageApplicabilitaRisposta)) {
  789.                     securityMessageApplicabilitaRisposta = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE_VALUE_DEFAULT;
  790.                 }
  791.                
  792.                 if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE_VALUE_ABILITATO.equals(securityMessageApplicabilitaRisposta)) {
  793.                     processSecurity = true;
  794.                 }
  795.                 else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE_VALUE_DISABILITATO.equals(securityMessageApplicabilitaRisposta)) {
  796.                     processSecurity = false;
  797.                 }
  798.                 else if(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE_VALUE_PERSONALIZZATO.equals(securityMessageApplicabilitaRisposta)) {
  799.                    
  800.                     configurazionePersonalizzata = true;
  801.                    
  802.                     String securityMessageApplicabilitaRispostaContentType = ModIPropertiesUtils.readPropertySecurityMessageApplicabilitaRispostaContentType(aspc, nomePortType, azione);
  803.                     List<String> check = readValues(securityMessageApplicabilitaRispostaContentType);
  804.                     if(!check.isEmpty()) {
  805.                         try {
  806.                             processSecurity = ContentTypeUtilities.isMatch(log, message.getContentType(), check);
  807.                         }catch(Exception e) {
  808.                             throw new ProtocolException(e.getMessage(),e);
  809.                         }
  810.                     }
  811.                     else {
  812.                         processSecurity = false; // non dovrebbe accadere
  813.                     }
  814.                    
  815.                     if(processSecurity) {
  816.                        
  817.                         // verifico anche codice
  818.                         String securityMessageApplicabilitaRispostaReturnCode = ModIPropertiesUtils.readPropertySecurityMessageApplicabilitaRispostaReturnCode(aspc, nomePortType, azione);
  819.                         List<String> checkReturnCode = readValues(securityMessageApplicabilitaRispostaReturnCode);
  820.                         if(checkReturnCode.size()>0) {
  821.                            
  822.                             int httpStatus = -1;
  823.                             if(message.getTransportResponseContext()!=null) {
  824.                                 try {
  825.                                     httpStatus = Integer.parseInt(message.getTransportResponseContext().getCodiceTrasporto());
  826.                                 }catch(Exception e) {
  827.                                     throw new ProtocolException("Transport Response Context non contiene un http status valido ("+message.getTransportResponseContext().getCodiceTrasporto()+")");
  828.                                 }
  829.                             }
  830.                             else {
  831.                                 throw new ProtocolException("Transport Response Context non disponibile");
  832.                             }
  833.                            
  834.                             boolean match = false;
  835.                             for (String codice : checkReturnCode) {
  836.                                 if(codice.contains("-")) {
  837.                                     String [] tmp = codice.split("-");
  838.                                     if(tmp==null || tmp.length!=2) {
  839.                                         throw new ProtocolException(ModIConsoleCostanti.MODIPA_API_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_LABEL+
  840.                                                 " '"+codice+"' possiede un formato errato; atteso: codiceMin-codiceMax");
  841.                                     }
  842.                                     String codiceMin = tmp[0];
  843.                                     String codiceMax = tmp[1];
  844.                                     if(codiceMin==null || StringUtils.isEmpty(codiceMin.trim())) {
  845.                                         throw new ProtocolException(ModIConsoleCostanti.MODIPA_API_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_LABEL+
  846.                                                 " '"+codice+"' possiede un formato errato (intervallo minimo non definito); atteso: codiceMin-codiceMax");
  847.                                     }
  848.                                     if(codiceMax==null || StringUtils.isEmpty(codiceMax.trim())) {
  849.                                         throw new ProtocolException(ModIConsoleCostanti.MODIPA_API_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_LABEL+
  850.                                                 " '"+codice+"' possiede un formato errato (intervallo massimo non definito); atteso: codiceMin-codiceMax");
  851.                                     }
  852.                                     codiceMin = codiceMin.trim();
  853.                                     codiceMax = codiceMax.trim();
  854.                                     int codiceMinInt = -1;
  855.                                     try {
  856.                                         codiceMinInt = Integer.valueOf(codiceMin);
  857.                                     }catch(Exception e) {
  858.                                         throw new ProtocolException(ModIConsoleCostanti.MODIPA_API_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_LABEL+
  859.                                                 " '"+codice+"' contiene un intervallo minimo '"+codiceMin+"' che non è un numero intero");
  860.                                     }
  861.                                     int codiceMaxInt = -1;
  862.                                     try {
  863.                                         codiceMaxInt = Integer.valueOf(codiceMax);
  864.                                     }catch(Exception e) {
  865.                                         throw new ProtocolException(ModIConsoleCostanti.MODIPA_API_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_LABEL+
  866.                                                 " '"+codice+"' contiene un intervallo massimo '"+codiceMax+"' che non è un numero intero");
  867.                                     }
  868.                                     if(codiceMaxInt<=codiceMinInt) {
  869.                                         throw new ProtocolException(ModIConsoleCostanti.MODIPA_API_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_LABEL+
  870.                                                 " '"+codice+"' contiene un intervallo massimo '"+codiceMax+"' minore o uguale all'intervallo minimo '"+codiceMin+"'");
  871.                                     }
  872.                                     if( (codiceMinInt <= httpStatus) && (httpStatus <= codiceMaxInt)) {
  873.                                         match = true;
  874.                                         break;
  875.                                     }
  876.                                 }
  877.                                 else {
  878.                                     try {
  879.                                         int codiceInt = Integer.parseInt(codice);
  880.                                         if(codiceInt == httpStatus) {
  881.                                             match = true;
  882.                                             break;
  883.                                         }
  884.                                     }catch(Exception e) {
  885.                                         throw new ProtocolException(ModIConsoleCostanti.MODIPA_API_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_LABEL+
  886.                                                 " '"+codice+"' non è un numero intero");
  887.                                     }
  888.                                 }
  889.                             }
  890.                            
  891.                             processSecurity = match;
  892.                         }
  893.                         else {
  894.                             processSecurity = false; // non dovrebbe accadere
  895.                         }
  896.                        
  897.                     }
  898.                 }
  899.                
  900.             }
  901.            
  902.         }
  903.        
  904.         if(processSecurity && !configurazionePersonalizzata) {
  905.            
  906.             // check Fault (Da properties)
  907.             boolean isFault = false;
  908.             boolean processFault = false;
  909.             if(rest) {
  910.                 isFault = message.isFault() || message.castAsRest().isProblemDetailsForHttpApis_RFC7807();  
  911.                 processFault = modiProperties.isRestSecurityTokenFaultProcessEnabled();
  912.             }
  913.             else {
  914.                 isFault = message.isFault() || message.castAsSoap().hasSOAPFault();
  915.                 processFault = modiProperties.isSoapSecurityTokenFaultProcessEnabled();
  916.             }
  917.             if(isFault && !processFault) {
  918.                 processSecurity = false;
  919.             }
  920.            
  921.         }
  922.        
  923.         return processSecurity;
  924.        
  925.     }
  926.    
  927.     private static List<String> readValues(String v){
  928.         List<String> codici = new ArrayList<>();
  929.         if(v!=null && !StringUtils.isEmpty(v)) {
  930.             if(v.contains(",")) {
  931.                 String [] tmp = v.split(",");
  932.                 for (int i = 0; i < tmp.length; i++) {
  933.                     codici.add(tmp[i].trim());
  934.                 }
  935.             }
  936.             else {
  937.                 codici.add(v.trim());
  938.             }
  939.         }
  940.         return codici;
  941.     }
  942.    
  943.     public static String readPurposeId(IConfigIntegrationReader configIntegrationReader, AccordoServizioParteSpecifica asps, IDSoggetto idFruitore, String azione) throws ProtocolException {
  944.         String tokenPolicy = readTokenPolicy(asps, idFruitore, azione);
  945.         if(tokenPolicy!=null) {
  946.             boolean signedJWT = isTokenPolicySignedJWT(configIntegrationReader, tokenPolicy);
  947.             if(signedJWT) {
  948.                 boolean pdnd = isTokenPolicyPdnd(configIntegrationReader, tokenPolicy);
  949.                 if(pdnd) {
  950.                     return getTokenPolicyPdndPurposeId(configIntegrationReader, tokenPolicy);
  951.                 }
  952.             }
  953.         }
  954.         return null;
  955.     }
  956.     private static String readTokenPolicy(AccordoServizioParteSpecifica asps, IDSoggetto idFruitore, String azione) throws ProtocolException {  
  957.        
  958.         if(asps!=null && idFruitore!=null) {
  959.             try {
  960.                 if(asps.sizeFruitoreList()>0) {
  961.                     for (Fruitore fruitore : asps.getFruitoreList()) {
  962.                         if(fruitore!=null) {
  963.                             IDSoggetto check = new IDSoggetto(fruitore.getTipo(), fruitore.getNome());
  964.                             if(idFruitore.equals(check)) {

  965.                                 if(fruitore.getConfigurazioneAzioneList()!=null && !fruitore.getConfigurazioneAzioneList().isEmpty()) {
  966.                                     for (ConfigurazioneServizioAzione csa : fruitore.getConfigurazioneAzioneList()) {
  967.                                         if(csa!=null &&
  968.                                             csa.getAzioneList()!=null && csa.getAzioneList().contains(azione)) {

  969.                                             if(csa.getConnettore()!=null && !TipiConnettore.DISABILITATO.getNome().equals(csa.getConnettore().getTipo()) &&
  970.                                                     csa.getConnettore().sizePropertyList()>0) {
  971.                                                 for (Property p : csa.getConnettore().getPropertyList()) {
  972.                                                     if(CostantiConnettori.CONNETTORE_TOKEN_POLICY.equals(p.getNome())){
  973.                                                         String tokenPolicy = p.getValore();
  974.                                                         if(tokenPolicy!=null && StringUtils.isNotEmpty(tokenPolicy) && !Costanti.CONSOLE_DEFAULT_VALUE_NON_SELEZIONATO.equals(tokenPolicy)) {
  975.                                                             return tokenPolicy;
  976.                                                         }
  977.                                                     }
  978.                                                 }
  979.                                             }
  980.                                             break;
  981.                                         }
  982.                                     }
  983.                                 }
  984.                                
  985.                                 if(fruitore.getConnettore()!=null && !TipiConnettore.DISABILITATO.getNome().equals(fruitore.getConnettore().getTipo()) &&
  986.                                         fruitore.getConnettore().sizePropertyList()>0) {
  987.                                     for (Property p : fruitore.getConnettore().getPropertyList()) {
  988.                                         if(CostantiConnettori.CONNETTORE_TOKEN_POLICY.equals(p.getNome())){
  989.                                             String tokenPolicy = p.getValore();
  990.                                             if(tokenPolicy!=null && StringUtils.isNotEmpty(tokenPolicy) && !Costanti.CONSOLE_DEFAULT_VALUE_NON_SELEZIONATO.equals(tokenPolicy)) {
  991.                                                 return tokenPolicy;
  992.                                             }
  993.                                         }
  994.                                     }
  995.                                 }
  996.                             }
  997.                         }
  998.                     }
  999.                 }
  1000.             }catch(Exception e) {
  1001.                 throw new ProtocolException(e.getMessage(),e);
  1002.             }
  1003.         }
  1004.         return null;
  1005.     }
  1006.     public static boolean isTokenPolicySignedJWT(IConfigIntegrationReader configIntegrationReader, String tokenPolicy) throws ProtocolException {
  1007.         try {
  1008.             GenericProperties gp = configIntegrationReader.getTokenPolicyNegoziazione(tokenPolicy);
  1009.             return isTokenPolicySignedJWT(gp);
  1010.         }catch(Exception e) {
  1011.             throw new ProtocolException(e.getMessage(),e);
  1012.         }
  1013.     }
  1014.     public static boolean isTokenPolicySignedJWT(GenericProperties gp) {
  1015.         boolean jwt = false;
  1016.         if(gp!=null && gp.sizePropertyList()>0) {
  1017.             for (int i = 0; i < gp.sizePropertyList(); i++) {
  1018.                 if(org.openspcoop2.pdd.core.token.Costanti.POLICY_RETRIEVE_TOKEN_MODE.equals(gp.getProperty(i).getNome())){
  1019.                     String v = gp.getProperty(i).getValore();
  1020.                     jwt = org.openspcoop2.pdd.core.token.Costanti.ID_RETRIEVE_TOKEN_METHOD_RFC_7523_X509.equals(v);
  1021.                 }
  1022.             }
  1023.         }
  1024.         return jwt;
  1025.     }
  1026.     public static boolean isTokenPolicyPdnd(IConfigIntegrationReader configIntegrationReader, String tokenPolicy) throws ProtocolException {
  1027.         try {
  1028.             GenericProperties gp = configIntegrationReader.getTokenPolicyNegoziazione(tokenPolicy);
  1029.             return isTokenPolicyPdnd(gp);
  1030.         }catch(Exception e) {
  1031.             throw new ProtocolException(e.getMessage(),e);
  1032.         }
  1033.     }
  1034.     public static boolean isTokenPolicyPdnd(GenericProperties gp) {
  1035.         boolean pdnd = false;
  1036.         if(gp!=null && gp.sizePropertyList()>0) {
  1037.             for (int i = 0; i < gp.sizePropertyList(); i++) {
  1038.                 if(org.openspcoop2.pdd.core.token.Costanti.POLICY_RETRIEVE_TOKEN_MODE_PDND.equals(gp.getProperty(i).getNome())){
  1039.                     String v = gp.getProperty(i).getValore();
  1040.                     pdnd = isEnabled(v);
  1041.                 }
  1042.             }
  1043.         }
  1044.         return pdnd;
  1045.     }
  1046.     public static String getTokenPolicyPdndPurposeId(IConfigIntegrationReader configIntegrationReader, String tokenPolicy) throws ProtocolException {
  1047.         try {
  1048.             GenericProperties gp = configIntegrationReader.getTokenPolicyNegoziazione(tokenPolicy);
  1049.             if(gp!=null && gp.sizePropertyList()>0) {
  1050.                 for (int i = 0; i < gp.sizePropertyList(); i++) {
  1051.                     if(org.openspcoop2.pdd.core.token.Costanti.POLICY_RETRIEVE_TOKEN_JWT_PURPOSE_ID.equals(gp.getProperty(i).getNome())){
  1052.                         return gp.getProperty(i).getValore();
  1053.                     }
  1054.                 }
  1055.             }
  1056.             return null;
  1057.         }catch(Exception e) {
  1058.             throw new ProtocolException(e.getMessage(),e);
  1059.         }
  1060.     }
  1061.     private static boolean isEnabled(String v) {
  1062.         return "true".equals(v) || "yes".equals(v);
  1063.     }
  1064. }