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

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

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

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

  972.                                 if(fruitore.getConfigurazioneAzioneList()!=null && !fruitore.getConfigurazioneAzioneList().isEmpty()) {
  973.                                     for (ConfigurazioneServizioAzione csa : fruitore.getConfigurazioneAzioneList()) {
  974.                                         if(csa!=null &&
  975.                                             csa.getAzioneList()!=null && csa.getAzioneList().contains(azione)) {

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