ModiApiApiHelper.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.core.config.rs.server.api.impl.api;

  21. import java.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.Optional;

  26. import org.apache.commons.lang.StringUtils;
  27. import org.openspcoop2.core.commons.CoreException;
  28. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  29. import org.openspcoop2.core.config.rs.server.api.impl.ProtocolPropertiesHelper;
  30. import org.openspcoop2.core.config.rs.server.model.Api;
  31. import org.openspcoop2.core.config.rs.server.model.ApiAzione;
  32. import org.openspcoop2.core.config.rs.server.model.ApiModI;
  33. import org.openspcoop2.core.config.rs.server.model.ApiModIAzioneSoap;
  34. import org.openspcoop2.core.config.rs.server.model.ApiModIPatternInterazioneCorrelazioneRest;
  35. import org.openspcoop2.core.config.rs.server.model.ApiModIPatternInterazioneCorrelazioneSoap;
  36. import org.openspcoop2.core.config.rs.server.model.ApiModIPatternInterazioneRest;
  37. import org.openspcoop2.core.config.rs.server.model.ApiModIPatternInterazioneSoap;
  38. import org.openspcoop2.core.config.rs.server.model.ApiModIRisorsaRest;
  39. import org.openspcoop2.core.config.rs.server.model.ApiModISicurezzaCanale;
  40. import org.openspcoop2.core.config.rs.server.model.ApiModISicurezzaMessaggio;
  41. import org.openspcoop2.core.config.rs.server.model.ApiModISicurezzaMessaggioApplicabilitaCustom;
  42. import org.openspcoop2.core.config.rs.server.model.ApiModISicurezzaMessaggioOperazione;
  43. import org.openspcoop2.core.config.rs.server.model.ApiModISicurezzaMessaggioOperazioneRidefinito;
  44. import org.openspcoop2.core.config.rs.server.model.ApiRisorsa;
  45. import org.openspcoop2.core.config.rs.server.model.HttpMethodEnum;
  46. import org.openspcoop2.core.config.rs.server.model.ModIPatternInterazioneEnum;
  47. import org.openspcoop2.core.config.rs.server.model.ModIPatternInterazioneFunzioneEnum;
  48. import org.openspcoop2.core.config.rs.server.model.ModIPatternInterazioneTipoEnum;
  49. import org.openspcoop2.core.config.rs.server.model.ModISicurezzaCanaleEnum;
  50. import org.openspcoop2.core.config.rs.server.model.ModISicurezzaMessaggioApplicabilitaCustomEnum;
  51. import org.openspcoop2.core.config.rs.server.model.ModISicurezzaMessaggioApplicabilitaEnum;
  52. import org.openspcoop2.core.config.rs.server.model.ModISicurezzaMessaggioEnum;
  53. import org.openspcoop2.core.config.rs.server.model.ModISicurezzaMessaggioGenerazioneTokenEnum;
  54. import org.openspcoop2.core.config.rs.server.model.ModISicurezzaMessaggioOperazioneEnum;
  55. import org.openspcoop2.core.config.rs.server.model.ModISicurezzaMessaggioPatternAuditEnum;
  56. import org.openspcoop2.core.config.rs.server.model.ModISicurezzaMessaggioRestHeaderEnum;
  57. import org.openspcoop2.core.config.rs.server.model.TipoApiEnum;
  58. import org.openspcoop2.core.id.IDAccordo;
  59. import org.openspcoop2.core.id.IDPortType;
  60. import org.openspcoop2.core.id.IDPortTypeAzione;
  61. import org.openspcoop2.core.id.IDResource;
  62. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  63. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  64. import org.openspcoop2.core.registry.Operation;
  65. import org.openspcoop2.core.registry.PortType;
  66. import org.openspcoop2.core.registry.Resource;
  67. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  68. import org.openspcoop2.core.registry.constants.FormatoSpecifica;
  69. import org.openspcoop2.core.registry.constants.HttpMethod;
  70. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  71. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  72. import org.openspcoop2.protocol.engine.utils.AzioniUtils;
  73. import org.openspcoop2.protocol.modipa.config.ModIAuditConfig;
  74. import org.openspcoop2.protocol.modipa.config.ModIProperties;
  75. import org.openspcoop2.protocol.modipa.constants.ModIConsoleCostanti;
  76. import org.openspcoop2.protocol.modipa.constants.ModICostanti;
  77. import org.openspcoop2.protocol.modipa.properties.ModIProfiliInterazioneRESTConfig;
  78. import org.openspcoop2.protocol.sdk.ProtocolException;
  79. import org.openspcoop2.protocol.sdk.constants.ConsoleOperationType;
  80. import org.openspcoop2.protocol.sdk.properties.AbstractProperty;
  81. import org.openspcoop2.protocol.sdk.properties.ConsoleConfiguration;
  82. import org.openspcoop2.protocol.sdk.properties.ProtocolProperties;
  83. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesFactory;
  84. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesUtils;
  85. import org.openspcoop2.protocol.sdk.registry.IRegistryReader;
  86. import org.openspcoop2.protocol.sdk.registry.RegistryException;
  87. import org.openspcoop2.protocol.sdk.registry.RegistryNotFound;
  88. import org.openspcoop2.utils.UtilsException;
  89. import org.openspcoop2.utils.service.beans.ProfiloEnum;
  90. import org.openspcoop2.utils.service.fault.jaxrs.FaultCode;

  91. /**
  92.  * ApiApiHelper
  93.  *
  94.  * @author $Author$
  95.  * @version $Rev$, $Date$
  96.  *
  97.  */
  98. public class ModiApiApiHelper {
  99.    
  100.     private ModiApiApiHelper() {}


  101.     private static final String SPECIFICARE_CONFIGURAZIONE_MODI = "Specificare la configurazione 'ModI'";
  102.    
  103.     private static String getErroreAuditPatternSpecificatoConPattern(ModISicurezzaMessaggioPatternAuditEnum auditPattern, ModISicurezzaMessaggioEnum pattern) {
  104.         return "sicurezza_messaggio.informazioni_utente (audit-pattern: "+auditPattern+") specificato con pattern " + pattern;
  105.     }
  106.     private static String getErroreAuditPatternSpecificatoConApplicabilita(ModISicurezzaMessaggioApplicabilitaEnum applicabilita) {
  107.         return "sicurezza_messaggio.informazioni_utente specificato con applicabilità " + applicabilita;
  108.     }
  109.     private static String getErroreAuditPatternRichiedeTokenNonLocale(ModISicurezzaMessaggioPatternAuditEnum auditPattern) {
  110.         return "sicurezza_messaggio.informazioni_utente con audit-pattern '"+auditPattern+"' richiede la generazione di un token oauth o pdnd";
  111.     }
  112.     private static String getErroreDigestRichiestaSpecificatoConPatternApplicabilita(ModISicurezzaMessaggioEnum pattern, ModISicurezzaMessaggioApplicabilitaEnum applicabilita) {
  113.         return "sicurezza_messaggio.digest_richiesta specificato con pattern " + pattern + " o applicabilita " + applicabilita;
  114.     }

  115.     public static void populateApiAzioneWithProtocolInfo(AccordoServizioParteComune as, Operation az, ApiEnv env, ApiAzione ret) throws CoreException, DriverRegistroServiziException, ProtocolException, DriverConfigurazioneException, UtilsException {

  116.         Map<String, AbstractProperty<?>> p = new HashMap<>();
  117.         Optional<PortType> portType = as.getPortTypeList().stream().filter(pt -> pt.getId().equals(az.getIdPortType())).findAny();
  118.                
  119.         if(!portType.isPresent()) {
  120.             throw FaultCode.ERRORE_INTERNO.toException("Port type non trovato");
  121.         }
  122.         IDAccordo idAccordoFromAccordo = env.idAccordoFactory.getIDAccordoFromAccordo(as);
  123.         IDPortTypeAzione idPortTypeAzione = new IDPortTypeAzione();
  124.         IDPortType idPortType = new IDPortType();
  125.         idPortType.setIdAccordo(idAccordoFromAccordo);
  126.         idPortType.setNome(portType.get().getNome());
  127.         idPortTypeAzione.setIdPortType(idPortType);
  128.         idPortTypeAzione.setNome(az.getNome());
  129.         ConsoleConfiguration consoleConf = ApiApiHelper.getConsoleConfiguration(env, idPortTypeAzione);

  130.         ProtocolProperties prop = env.apcHelper.estraiProtocolPropertiesDaRequest(consoleConf, ConsoleOperationType.CHANGE);
  131.         ProtocolPropertiesUtils.mergeProtocolPropertiesRegistry(prop, az.getProtocolPropertyList(), ConsoleOperationType.CHANGE);

  132.         for(int i =0; i < prop.sizeProperties(); i++) {
  133.             p.put(prop.getIdProperty(i), prop.getProperty(i));
  134.         }

  135.         ApiModIAzioneSoap apimodi = new ApiModIAzioneSoap();

  136.         ApiModIPatternInterazioneSoap interazione = new ApiModIPatternInterazioneSoap();

  137.         if(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE, true).equals(ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_CRUD)) {
  138.             interazione.setPattern(ModIPatternInterazioneEnum.CRUD);
  139.         } else if(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE, true).equals(ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_BLOCCANTE)) {
  140.             interazione.setPattern(ModIPatternInterazioneEnum.BLOCCANTE);
  141.         } else if(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE, true).equals(ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE)) {

  142.             ModIPatternInterazioneTipoEnum tipo = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA, true).equals(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PULL) ?
  143.                     ModIPatternInterazioneTipoEnum.PULL : ModIPatternInterazioneTipoEnum.PUSH;
  144.            
  145.             interazione.setTipo(tipo);

  146.             ModIPatternInterazioneFunzioneEnum funzione = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO, true).equals(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA) ?
  147.                     ModIPatternInterazioneFunzioneEnum.RICHIESTA: ModIPatternInterazioneFunzioneEnum.RISPOSTA;
  148.            
  149.             interazione.setFunzione(funzione);
  150.            
  151.             if(funzione.equals(ModIPatternInterazioneFunzioneEnum.RISPOSTA)) {
  152.                 interazione.setAzioneCorrelata(getAzioneCorrelata(p, env));
  153.             }
  154.            
  155.             interazione.setPattern(ModIPatternInterazioneEnum.NON_BLOCCANTE);
  156.         }

  157.         apimodi.setInterazione(interazione);


  158.         if(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_ACTION_MODE, true).equals(ModICostanti.MODIPA_PROFILO_DEFAULT)) {
  159.             ApiModISicurezzaMessaggioOperazione op = new ApiModISicurezzaMessaggioOperazione();
  160.             op.setStato(ModISicurezzaMessaggioOperazioneEnum.API);
  161.             apimodi.setSicurezzaMessaggio(op);
  162.         } else {

  163.             ApiModISicurezzaMessaggioOperazioneRidefinito rid = new ApiModISicurezzaMessaggioOperazioneRidefinito();
  164.             rid.setStato(ModISicurezzaMessaggioOperazioneEnum.RIDEFINITO);
  165.             rid.setConfigurazione(getSicurezzaMessaggio(p, true));

  166.             apimodi.setSicurezzaMessaggio(rid);
  167.         }

  168.         ret.setModi(apimodi);

  169.     }


  170.     public static void populateApiRisorsaWithProtocolInfo(AccordoServizioParteComune as, Resource res, ApiEnv env, ApiRisorsa ret) throws DriverRegistroServiziException, ProtocolException, DriverConfigurazioneException, CoreException, RegistryNotFound, RegistryException, UtilsException {

  171.         Map<String, AbstractProperty<?>> p = new HashMap<>();
  172.         IDAccordo idAccordoFromAccordo = env.idAccordoFactory.getIDAccordoFromAccordo(as);
  173.         IDResource idres = new IDResource();
  174.         idres.setIdAccordo(idAccordoFromAccordo);
  175.         idres.setNome(res.getNome());
  176.         ConsoleConfiguration consoleConf = ApiApiHelper.getConsoleConfiguration(env, idres, res.getMethod() != null ? res.getMethod().toString() : null, res.getPath());

  177.         ProtocolProperties prop = env.apcHelper.estraiProtocolPropertiesDaRequest(consoleConf, ConsoleOperationType.CHANGE);
  178.         ProtocolPropertiesUtils.mergeProtocolPropertiesRegistry(prop, res.getProtocolPropertyList(), ConsoleOperationType.CHANGE);

  179.         for(int i =0; i < prop.sizeProperties(); i++) {
  180.             p.put(prop.getIdProperty(i), prop.getProperty(i));
  181.         }

  182.         ApiModIRisorsaRest apimodi = new ApiModIRisorsaRest();

  183.         ApiModIPatternInterazioneRest interazione = new ApiModIPatternInterazioneRest();

  184.         if(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE, true).equals(ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_CRUD)) {
  185.             interazione.setPattern(ModIPatternInterazioneEnum.CRUD);
  186.         } else if(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE, true).equals(ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_BLOCCANTE)) {
  187.             interazione.setPattern(ModIPatternInterazioneEnum.BLOCCANTE);
  188.         } else if(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE, true).equals(ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE)) {

  189.             ModIPatternInterazioneTipoEnum tipo = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA, true).equals(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PULL) ?
  190.                     ModIPatternInterazioneTipoEnum.PULL : ModIPatternInterazioneTipoEnum.PUSH;
  191.            
  192.             interazione.setTipo(tipo);

  193.             ModIPatternInterazioneFunzioneEnum funzione = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO, true).equals(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA) ?
  194.                     ModIPatternInterazioneFunzioneEnum.RICHIESTA: ModIPatternInterazioneFunzioneEnum.RISPOSTA;
  195.            
  196.             interazione.setFunzione(funzione);
  197.            
  198.             if(funzione.equals(ModIPatternInterazioneFunzioneEnum.RISPOSTA)) {
  199.                 interazione.setRisorsaCorrelata(getRisorsaCorrelata(p, env));
  200.             }
  201.            
  202.             interazione.setPattern(ModIPatternInterazioneEnum.NON_BLOCCANTE);
  203.         }

  204.         apimodi.setInterazione(interazione);


  205.         if(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_ACTION_MODE, true).equals(ModICostanti.MODIPA_PROFILO_DEFAULT)) {
  206.             ApiModISicurezzaMessaggioOperazione op = new ApiModISicurezzaMessaggioOperazione();
  207.             op.setStato(ModISicurezzaMessaggioOperazioneEnum.API);
  208.             apimodi.setSicurezzaMessaggio(op);
  209.         } else {

  210.             ApiModISicurezzaMessaggioOperazioneRidefinito rid = new ApiModISicurezzaMessaggioOperazioneRidefinito();
  211.             rid.setStato(ModISicurezzaMessaggioOperazioneEnum.RIDEFINITO);

  212.             rid.setConfigurazione(getSicurezzaMessaggio(p, false));
  213.             apimodi.setSicurezzaMessaggio(rid);
  214.         }

  215.         ret.setModi(apimodi);

  216.     }

  217.     private static ApiModIPatternInterazioneCorrelazioneRest getRisorsaCorrelata(Map<String, AbstractProperty<?>> p, ApiEnv env) throws DriverRegistroServiziException, CoreException, RegistryNotFound, RegistryException, DriverConfigurazioneException {
  218.         IDAccordo idAccordoFromAccordo = env.idAccordoFactory.getIDAccordoFromUri(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA, true));
  219.         IDResource id = new IDResource();
  220.         id.setIdAccordo(idAccordoFromAccordo);
  221.         id.setNome(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA, true));
  222.         IRegistryReader registryReader = env.soggettiCore.getRegistryReader(env.protocolFactory);
  223.         Resource resource = registryReader.getResourceAccordo(id);

  224.         ApiModIPatternInterazioneCorrelazioneRest risorsaCorrelata = new ApiModIPatternInterazioneCorrelazioneRest();
  225.         risorsaCorrelata.setApiNome(idAccordoFromAccordo.getNome());
  226.         risorsaCorrelata.setApiVersione(idAccordoFromAccordo.getVersione());
  227.        
  228.         HttpMethodEnum method = HttpMethodEnum.QUALSIASI;          
  229.        
  230.         if(resource.getMethod()!=null) {
  231.             switch(resource.getMethod()) {
  232.             case DELETE: method = HttpMethodEnum.DELETE;
  233.                 break;
  234.             case GET: method = HttpMethodEnum.GET;
  235.                 break;
  236.             case HEAD: method = HttpMethodEnum.HEAD;
  237.                 break;
  238.             case LINK: method = HttpMethodEnum.LINK;
  239.                 break;
  240.             case OPTIONS: method = HttpMethodEnum.OPTIONS;
  241.                 break;
  242.             case PATCH: method = HttpMethodEnum.PATCH;
  243.                 break;
  244.             case POST: method = HttpMethodEnum.POST;
  245.                 break;
  246.             case PUT: method = HttpMethodEnum.PUT;
  247.                 break;
  248.             case TRACE: method = HttpMethodEnum.TRACE;
  249.                 break;
  250.             case UNLINK: method = HttpMethodEnum.UNLINK;
  251.                 break;}
  252.         }
  253.        
  254.         risorsaCorrelata.setRisorsaHttpMethod(method);
  255.         risorsaCorrelata.setRisorsaPath(resource.getPath());
  256.        
  257.         return risorsaCorrelata;
  258.     }

  259.     private static ApiModIPatternInterazioneCorrelazioneSoap getAzioneCorrelata(Map<String, AbstractProperty<?>> p, ApiEnv env) throws DriverRegistroServiziException, CoreException {

  260.         IDAccordo idAccordoFromAccordo = env.idAccordoFactory.getIDAccordoFromUri(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA, true));

  261.         ApiModIPatternInterazioneCorrelazioneSoap risorsaCorrelata = new ApiModIPatternInterazioneCorrelazioneSoap();
  262.         risorsaCorrelata.setApiNome(idAccordoFromAccordo.getNome());
  263.         risorsaCorrelata.setApiVersione(idAccordoFromAccordo.getVersione());
  264.        
  265.         risorsaCorrelata.setServizio(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_SERVIZIO_RICHIESTA_CORRELATA, true));
  266.         risorsaCorrelata.setAzione(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA, true));
  267.        
  268.         return risorsaCorrelata;
  269.     }


  270.     public static ApiModI getApiModI(AccordoServizioParteComune as, ProfiloEnum profilo, ApiEnv env) throws DriverRegistroServiziException, ProtocolException, DriverConfigurazioneException, CoreException, UtilsException {
  271.         if(profilo == null || (!profilo.equals(ProfiloEnum.MODI) && !profilo.equals(ProfiloEnum.MODIPA))) {
  272.             throw FaultCode.RICHIESTA_NON_VALIDA.toException("Operazione utilizzabile solamente con Profilo 'ModI'");
  273.         }

  274.         Map<String, AbstractProperty<?>> p = new HashMap<>();
  275.         IDAccordo idAccordoFromAccordo = env.idAccordoFactory.getIDAccordoFromAccordo(as);
  276.         ConsoleConfiguration consoleConf = ApiApiHelper.getConsoleConfiguration(env, idAccordoFromAccordo);

  277.         ProtocolProperties prop = env.apcHelper.estraiProtocolPropertiesDaRequest(consoleConf, ConsoleOperationType.CHANGE);
  278.         ProtocolPropertiesUtils.mergeProtocolPropertiesRegistry(prop, as.getProtocolPropertyList(), ConsoleOperationType.CHANGE);

  279.         for(int i =0; i < prop.sizeProperties(); i++) {
  280.             p.put(prop.getIdProperty(i), prop.getProperty(i));
  281.         }


  282.         ApiModI apimodi = new ApiModI();

  283.         ApiModISicurezzaCanale sicurezzaCanale = new ApiModISicurezzaCanale();

  284.         String sicurezzaCanalePatternString = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_SICUREZZA_CANALE, true);

  285.         sicurezzaCanale.setPattern(sicurezzaCanalePatternString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_CANALE_VALUE_IDAC01) ? ModISicurezzaCanaleEnum.AUTH01:ModISicurezzaCanaleEnum.AUTH02);
  286.         apimodi.setSicurezzaCanale(sicurezzaCanale);

  287.         apimodi.setSicurezzaMessaggio(getSicurezzaMessaggio(p, as.getServiceBinding().equals(org.openspcoop2.core.registry.constants.ServiceBinding.SOAP)));

  288.         return apimodi;
  289.     }

  290.     private static ApiModISicurezzaMessaggio getSicurezzaMessaggio(Map<String, AbstractProperty<?>> p, boolean isSOAP) throws CoreException {
  291.         ApiModISicurezzaMessaggio sicurezzaMessaggio = new ApiModISicurezzaMessaggio();

  292.         String sicurezzaMessaggioPatternString = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO, true);

  293.         ModISicurezzaMessaggioEnum profiloSicurezzaMessaggioPattern = null;
  294.         if(sicurezzaMessaggioPatternString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM01)) {
  295.             profiloSicurezzaMessaggioPattern = ModISicurezzaMessaggioEnum.AUTH01;
  296.         } else if(sicurezzaMessaggioPatternString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM02)) {
  297.             profiloSicurezzaMessaggioPattern = ModISicurezzaMessaggioEnum.AUTH02;
  298.         } else if(sicurezzaMessaggioPatternString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_UNDEFINED)) {
  299.             profiloSicurezzaMessaggioPattern = ModISicurezzaMessaggioEnum.DISABILITATO;
  300.         } else if(sicurezzaMessaggioPatternString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0301)) {
  301.             profiloSicurezzaMessaggioPattern = ModISicurezzaMessaggioEnum.INTEGRITY01_AUTH01;
  302.         } else if(sicurezzaMessaggioPatternString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0302)) {
  303.             profiloSicurezzaMessaggioPattern = ModISicurezzaMessaggioEnum.INTEGRITY01_AUTH02;
  304.         } else if(sicurezzaMessaggioPatternString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0401)) {
  305.             profiloSicurezzaMessaggioPattern = ModISicurezzaMessaggioEnum.INTEGRITY02_AUTH01;
  306.         } else if(sicurezzaMessaggioPatternString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0402)) {
  307.             profiloSicurezzaMessaggioPattern = ModISicurezzaMessaggioEnum.INTEGRITY02_AUTH02;
  308.         }
  309.         sicurezzaMessaggio.setPattern(profiloSicurezzaMessaggioPattern);

  310.         String sicurezzaMessaggioGnerazioneTokenString = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH, false);
  311.         if(sicurezzaMessaggioGnerazioneTokenString!=null && StringUtils.isNotEmpty(sicurezzaMessaggioGnerazioneTokenString)) {
  312.             ModISicurezzaMessaggioGenerazioneTokenEnum generazioneToken = null;
  313.             if(sicurezzaMessaggioGnerazioneTokenString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_LOCALE)) {
  314.                 generazioneToken = ModISicurezzaMessaggioGenerazioneTokenEnum.LOCALE;
  315.             } else if(sicurezzaMessaggioGnerazioneTokenString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_PDND)) {
  316.                 generazioneToken = ModISicurezzaMessaggioGenerazioneTokenEnum.PDND;
  317.             } else if(sicurezzaMessaggioGnerazioneTokenString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_OAUTH)) {
  318.                 generazioneToken = ModISicurezzaMessaggioGenerazioneTokenEnum.OAUTH;
  319.             }
  320.             sicurezzaMessaggio.setGenerazioneToken(generazioneToken);
  321.         }
  322.        
  323.         if(profiloSicurezzaMessaggioPattern!=null && !profiloSicurezzaMessaggioPattern.equals(ModISicurezzaMessaggioEnum.DISABILITATO)) {
  324.             if(isSOAP) {
  325.                 populateSicurezzaMessaggioSOAP(p, sicurezzaMessaggio);
  326.             } else {
  327.                 populateSicurezzaMessaggioREST(p, sicurezzaMessaggio);
  328.             }

  329.             sicurezzaMessaggio.setDigestRichiesta(ProtocolPropertiesHelper.getBooleanProperty(p, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_REQUEST_DIGEST, true));
  330.             sicurezzaMessaggio.setInformazioniUtente(ProtocolPropertiesHelper.getBooleanProperty(p, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA, true));
  331.             if(sicurezzaMessaggio.isInformazioniUtente()!=null && sicurezzaMessaggio.isInformazioniUtente().booleanValue()) {
  332.                
  333.                 String sicurezzaMessaggioInformazioniUtentePatternString = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN, false);
  334.                 if(sicurezzaMessaggioInformazioniUtentePatternString!=null && StringUtils.isNotEmpty(sicurezzaMessaggioInformazioniUtentePatternString)) {
  335.                     ModISicurezzaMessaggioPatternAuditEnum patternAudit = null;
  336.                     if(sicurezzaMessaggioInformazioniUtentePatternString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD)) {
  337.                         patternAudit = ModISicurezzaMessaggioPatternAuditEnum.LEGACY;
  338.                     } else if(sicurezzaMessaggioInformazioniUtentePatternString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_AUDIT_REST_01)) {
  339.                         patternAudit = ModISicurezzaMessaggioPatternAuditEnum.REST01;
  340.                     } else if(sicurezzaMessaggioInformazioniUtentePatternString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_AUDIT_REST_02)) {
  341.                         patternAudit = ModISicurezzaMessaggioPatternAuditEnum.REST02;
  342.                     }
  343.                     sicurezzaMessaggio.setPatternAudit(patternAudit);
  344.                 }
  345.                
  346.                 String sicurezzaMessaggioInformazioniUtenteSchemaString = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_SCHEMA, false);
  347.                 if(sicurezzaMessaggioInformazioniUtenteSchemaString!=null && StringUtils.isNotEmpty(sicurezzaMessaggioInformazioniUtenteSchemaString)) {
  348.                     sicurezzaMessaggio.setSchemaAudit(sicurezzaMessaggioInformazioniUtenteSchemaString);
  349.                 }
  350.             }

  351.         } else {
  352.             sicurezzaMessaggio.setInformazioniUtente(false);
  353.             sicurezzaMessaggio.setDigestRichiesta(false);
  354.             sicurezzaMessaggio.setSoapFirmaAllegati(false);
  355.         }
  356.        
  357.         return sicurezzaMessaggio;

  358.     }

  359.     private static void populateSicurezzaMessaggioSOAP(Map<String, AbstractProperty<?>> p, ApiModISicurezzaMessaggio sicurezzaMessaggio) throws CoreException {
  360.         ModISicurezzaMessaggioApplicabilitaEnum applicabilita = null;

  361.         String sicurezzaMessaggioApplicabilitaString = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE, true);

  362.         if(sicurezzaMessaggioApplicabilitaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_ENTRAMBI_CON_ATTACHMENTS)) {
  363.             applicabilita = ModISicurezzaMessaggioApplicabilitaEnum.QUALSIASI;
  364.             sicurezzaMessaggio.setSoapFirmaAllegati(true);
  365.         } else if(sicurezzaMessaggioApplicabilitaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RICHIESTA_CON_ATTACHMENTS)) {
  366.             applicabilita = ModISicurezzaMessaggioApplicabilitaEnum.RICHIESTA;
  367.             sicurezzaMessaggio.setSoapFirmaAllegati(true);
  368.         } else if(sicurezzaMessaggioApplicabilitaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RISPOSTA_CON_ATTACHMENTS)) {
  369.             applicabilita = ModISicurezzaMessaggioApplicabilitaEnum.RISPOSTA;
  370.             sicurezzaMessaggio.setSoapFirmaAllegati(true);
  371.         } else if(sicurezzaMessaggioApplicabilitaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_ENTRAMBI)) {
  372.             applicabilita = ModISicurezzaMessaggioApplicabilitaEnum.QUALSIASI;
  373.         } else if(sicurezzaMessaggioApplicabilitaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RICHIESTA)) {
  374.             applicabilita = ModISicurezzaMessaggioApplicabilitaEnum.RICHIESTA;
  375.         } else if(sicurezzaMessaggioApplicabilitaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RISPOSTA)) {
  376.             applicabilita = ModISicurezzaMessaggioApplicabilitaEnum.RISPOSTA;
  377.         }
  378.         sicurezzaMessaggio.setApplicabilita(applicabilita);
  379.        
  380.     }

  381.     private static void populateSicurezzaMessaggioREST(Map<String, AbstractProperty<?>> p, ApiModISicurezzaMessaggio sicurezzaMessaggio) throws CoreException {
  382.         ModISicurezzaMessaggioRestHeaderEnum restHeader = null;
  383.         String restHeaderString = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER, true);

  384.         boolean custom = false;
  385.         if(restHeaderString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_MODIPA)) {
  386.             restHeader = ModISicurezzaMessaggioRestHeaderEnum.AGID;
  387.         } else if(restHeaderString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION)) {
  388.             restHeader = ModISicurezzaMessaggioRestHeaderEnum.BEARER;
  389.         } else if(restHeaderString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_MODIPA)) {
  390.             restHeader = ModISicurezzaMessaggioRestHeaderEnum.AGID_BEARER_REQUEST;
  391.         } else if(restHeaderString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_MODIPA_AUTH_IN_RESPONSE)) {
  392.             restHeader = ModISicurezzaMessaggioRestHeaderEnum.AGID_BEARER;
  393.         } else if(restHeaderString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_CUSTOM)) {
  394.             restHeader = ModISicurezzaMessaggioRestHeaderEnum.CUSTOM;
  395.             custom = true;
  396.         } else if(restHeaderString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_CUSTOM)) {
  397.             restHeader = ModISicurezzaMessaggioRestHeaderEnum.CUSTOM_BEARER_REQUEST;
  398.             custom = true;
  399.         } else if(restHeaderString.equals(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_CUSTOM_AUTH_IN_RESPONSE)) {
  400.             restHeader = ModISicurezzaMessaggioRestHeaderEnum.CUSTOM_BEARER;
  401.             custom = true;
  402.         }
  403.         sicurezzaMessaggio.setRestHeader(restHeader);
  404.        
  405.         if(custom) {
  406.             String restHeaderCustomString = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM, true);
  407.             sicurezzaMessaggio.setRestHeaderCustom(restHeaderCustomString);
  408.         }

  409.         ModISicurezzaMessaggioApplicabilitaEnum applicabilita = null;

  410.         String sicurezzaMessaggioApplicabilitaString = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE, true);

  411.         if(sicurezzaMessaggioApplicabilitaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_ENTRAMBI)) {
  412.             applicabilita = ModISicurezzaMessaggioApplicabilitaEnum.QUALSIASI;
  413.         } else if(sicurezzaMessaggioApplicabilitaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RICHIESTA)) {
  414.             applicabilita = ModISicurezzaMessaggioApplicabilitaEnum.RICHIESTA;
  415.         } else if(sicurezzaMessaggioApplicabilitaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RISPOSTA)) {
  416.             applicabilita = ModISicurezzaMessaggioApplicabilitaEnum.RISPOSTA;
  417.         } else if(sicurezzaMessaggioApplicabilitaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_PERSONALIZZATO)) {
  418.             applicabilita = ModISicurezzaMessaggioApplicabilitaEnum.CUSTOM;

  419.             ApiModISicurezzaMessaggioApplicabilitaCustom appCustom = new ApiModISicurezzaMessaggioApplicabilitaCustom();
  420.             appCustom.setApplicabilita(applicabilita);
  421.             String applicabilitaCustomRichiestaString = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE, true);
  422.             ModISicurezzaMessaggioApplicabilitaCustomEnum applicabilitaCustomRichiesta = null;

  423.             if(applicabilitaCustomRichiestaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE_VALUE_ABILITATO)) {
  424.                 applicabilitaCustomRichiesta = ModISicurezzaMessaggioApplicabilitaCustomEnum.ABILITATO;
  425.             } else if(applicabilitaCustomRichiestaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE_VALUE_DISABILITATO)) {
  426.                 applicabilitaCustomRichiesta = ModISicurezzaMessaggioApplicabilitaCustomEnum.DISABILITATO;
  427.             } else if(applicabilitaCustomRichiestaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE_VALUE_PERSONALIZZATO)) {
  428.                 applicabilitaCustomRichiesta = ModISicurezzaMessaggioApplicabilitaCustomEnum.CUSTOM;
  429.                 appCustom.setRichiestaContentType(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_CONTENT_TYPE_MODE_ID, true));
  430.             }

  431.             appCustom.setRichiesta(applicabilitaCustomRichiesta);


  432.             String applicabilitaCustomRispostaString = ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE, true);
  433.             ModISicurezzaMessaggioApplicabilitaCustomEnum applicabilitaCustomRisposta = null;

  434.             if(applicabilitaCustomRispostaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE_VALUE_ABILITATO)) {
  435.                 applicabilitaCustomRisposta = ModISicurezzaMessaggioApplicabilitaCustomEnum.ABILITATO;
  436.             } else if(applicabilitaCustomRispostaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE_VALUE_DISABILITATO)) {
  437.                 applicabilitaCustomRisposta = ModISicurezzaMessaggioApplicabilitaCustomEnum.DISABILITATO;
  438.             } else if(applicabilitaCustomRispostaString.equals(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE_VALUE_PERSONALIZZATO)) {
  439.                 applicabilitaCustomRisposta = ModISicurezzaMessaggioApplicabilitaCustomEnum.CUSTOM;

  440.                 appCustom.setRispostaContentType(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_CONTENT_TYPE_MODE_ID, true));
  441.                 appCustom.setRispostaCodice(ProtocolPropertiesHelper.getStringProperty(p, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_ID, true));
  442.             }

  443.             appCustom.setRisposta(applicabilitaCustomRisposta);

  444.             sicurezzaMessaggio.setApplicabilitaCustom(appCustom);
  445.         }
  446.        
  447.         sicurezzaMessaggio.setApplicabilita(applicabilita);


  448.     }

  449.     public static ProtocolProperties getProtocolProperties(ApiAzione body, AccordoServizioParteComune as, Operation op, ApiEnv env) throws DriverRegistroServiziException, DriverConfigurazioneException, RegistryNotFound, RegistryException {
  450.         return getSOAPModiProtocolProperties(body.getModi(), as, op, env);
  451.     }


  452.     public static ProtocolProperties getProtocolProperties(ApiRisorsa body, Resource res, ApiEnv env) throws DriverRegistroServiziException, DriverConfigurazioneException, DriverRegistroServiziNotFound, RegistryNotFound, RegistryException {
  453.         return getRESTModiProtocolProperties(body.getModi(), res, env);
  454.     }

  455.     public static ProtocolProperties getRESTModiProtocolProperties(ApiModIRisorsaRest modi, Resource res, ApiEnv env) throws DriverRegistroServiziException, DriverConfigurazioneException, DriverRegistroServiziNotFound, RegistryNotFound, RegistryException {

  456.         if(modi == null) {
  457.             throw FaultCode.RICHIESTA_NON_VALIDA.toException(SPECIFICARE_CONFIGURAZIONE_MODI);
  458.         }
  459.        
  460.         ModIProfiliInterazioneRESTConfig config = null;
  461.         ModIProperties modIProperties = null;
  462.         try {
  463.             modIProperties = ModIProperties.getInstance();
  464.             config = new ModIProfiliInterazioneRESTConfig(modIProperties,  res.getMethod() != null ? res.getMethod().toString() : null, res);
  465.         } catch (ProtocolException e) {
  466.             throw FaultCode.ERRORE_INTERNO.toException(e.getMessage());
  467.         }

  468.         ProtocolProperties p = new ProtocolProperties();

  469.         if(modi.getInterazione().getPattern().equals(ModIPatternInterazioneEnum.BLOCCANTE)) {
  470.             if(!config.isCompatibileBloccante()) {
  471.                 throw FaultCode.RICHIESTA_NON_VALIDA.toException("Pattern "+modi.getInterazione().getPattern()+" non compatibile");
  472.             }

  473.             p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE, ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_BLOCCANTE);

  474.         } else if(modi.getInterazione().getPattern().equals(ModIPatternInterazioneEnum.NON_BLOCCANTE)) {

  475.             boolean isPull = modi.getInterazione().getTipo().equals(ModIPatternInterazioneTipoEnum.PULL);
  476.             boolean isRichiesta = modi.getInterazione().getFunzione().equals(ModIPatternInterazioneFunzioneEnum.RICHIESTA);
  477.            
  478.             if(isPull) {
  479.                 if(!config.isCompatibileNonBloccantePull()) {
  480.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("Pattern "+modi.getInterazione().getPattern()+" non compatibile");
  481.                 }

  482.                 p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PULL);
  483.                
  484.                 if(isRichiesta) {
  485.                     if(!config.isCompatibileNonBloccantePullRequest()) {
  486.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException("Pattern "+modi.getInterazione().getPattern()+" non compatibile");
  487.                     }
  488.                    
  489.                     p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA);
  490.                 } else {
  491.                     if(!config.isCompatibileNonBloccantePullResponse()) {
  492.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException("Pattern "+modi.getInterazione().getPattern()+" non compatibile");
  493.                     }
  494.                    
  495.                     p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RISPOSTA);
  496.                 }
  497.             } else {
  498.                 if(!config.isCompatibileNonBloccantePush()) {
  499.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("Pattern "+modi.getInterazione().getPattern()+" non compatibile");
  500.                 }
  501.                
  502.                 p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH);
  503.                
  504.                
  505.                 if(isRichiesta) {
  506.                     if(!config.isCompatibileNonBloccantePushRequest()) {
  507.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException("Pattern "+modi.getInterazione().getPattern()+" non compatibile");
  508.                     }
  509.                    
  510.                     p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA);
  511.                 } else {
  512.                     if(!config.isCompatibileNonBloccantePushResponse()) {
  513.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException("Pattern "+modi.getInterazione().getPattern()+" non compatibile");
  514.                     }
  515.                    
  516.                     p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RISPOSTA);
  517.                 }
  518.                
  519.             }

  520.             if(!isRichiesta) {
  521.                 addRisorsaCorrelata(modi.getInterazione().getRisorsaCorrelata(), env, p, isPull);
  522.             }

  523.             p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE, ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE);
  524.            
  525.         } else if(modi.getInterazione().getPattern().equals(ModIPatternInterazioneEnum.CRUD)) {
  526.             p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE, ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_CRUD);
  527.         }


  528.         if(modi.getSicurezzaMessaggio().getStato().equals(ModISicurezzaMessaggioOperazioneEnum.API)) {
  529.             p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_ACTION_MODE, ModICostanti.MODIPA_PROFILO_DEFAULT);
  530.         } else {
  531.             p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_ACTION_MODE, ModICostanti.MODIPA_PROFILO_RIDEFINISCI);
  532.             ApiModISicurezzaMessaggioOperazioneRidefinito rid = ((ApiModISicurezzaMessaggioOperazioneRidefinito)modi.getSicurezzaMessaggio());

  533.             if(!rid.getConfigurazione().getPattern().equals(ModISicurezzaMessaggioEnum.DISABILITATO)) {
  534.                 getRESTProperties(rid.getConfigurazione(), p, modIProperties);
  535.             }
  536.         }

  537.         return p;
  538.     }


  539.     private static void addRisorsaCorrelata(ApiModIPatternInterazioneCorrelazioneRest corr, ApiEnv env, ProtocolProperties p, boolean isPull) throws DriverRegistroServiziException, DriverConfigurazioneException, DriverRegistroServiziNotFound, RegistryNotFound, RegistryException {

  540.         IDAccordo idAccordoFromAccordo = env.idAccordoFactory.getIDAccordoFromValues(corr.getApiNome(), env.idSoggetto.getTipo(),env.idSoggetto.getNome(),corr.getApiVersione());
  541.         IRegistryReader registryReader = env.soggettiCore.getRegistryReader(env.protocolFactory);
  542.         AccordoServizioParteComune accordoServizioFull = env.apcCore.getAccordoServizioFull(idAccordoFromAccordo);
  543.         Resource found = null;
  544.        
  545.         HttpMethod method = null;
  546.        
  547.         switch(corr.getRisorsaHttpMethod()) {
  548.         case DELETE: method = HttpMethod.DELETE;
  549.             break;
  550.         case GET:method = HttpMethod.GET;
  551.             break;
  552.         case HEAD:method = HttpMethod.HEAD;
  553.             break;
  554.         case LINK:method = HttpMethod.LINK;
  555.             break;
  556.         case OPTIONS:method = HttpMethod.OPTIONS;
  557.             break;
  558.         case PATCH:method = HttpMethod.PATCH;
  559.             break;
  560.         case POST:method = HttpMethod.POST;
  561.             break;
  562.         case PUT:method = HttpMethod.PUT;
  563.             break;
  564.         case TRACE: method = HttpMethod.TRACE;
  565.             break;
  566.         case UNLINK:method = HttpMethod.UNLINK;
  567.             break;
  568.         default:
  569.             break;
  570.         }
  571.         for(Resource r: accordoServizioFull.getResourceList()) {
  572.             if(sameResource(r, method, corr.getRisorsaPath())) {
  573.                 found = r;
  574.             }
  575.         }
  576.        
  577.         if(found == null) {
  578.             throw FaultCode.RICHIESTA_NON_VALIDA.toException("Azione non trovata");            
  579.         }
  580.        
  581.         String nomeRisorsa = found.getNome();
  582.         checkAzione(idAccordoFromAccordo, null, nomeRisorsa, isPull, registryReader);

  583.         p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA, idAccordoFromAccordo.toString());
  584.         p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA, nomeRisorsa);
  585.         p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_SERVIZIO_RICHIESTA_CORRELATA, ModIConsoleCostanti.MODIPA_LABEL_UNDEFINED);

  586.     }


  587.     private static boolean sameResource(Resource r, HttpMethod method, String path) {
  588.        
  589.         boolean equalsMethod = false;
  590.         if(r.getMethod() == null) {
  591.             equalsMethod = method == null;
  592.         } else {
  593.             equalsMethod = r.getMethod().equals(method);
  594.         }
  595.        
  596.         return equalsMethod && r.getPath().equals(path);
  597.     }


  598.     public static ProtocolProperties getSOAPModiProtocolProperties(ApiModIAzioneSoap modi, AccordoServizioParteComune as, Operation op, ApiEnv env) throws DriverRegistroServiziException, DriverConfigurazioneException, RegistryNotFound, RegistryException {

  599.         if(modi == null) {
  600.             throw FaultCode.RICHIESTA_NON_VALIDA.toException(SPECIFICARE_CONFIGURAZIONE_MODI);
  601.         }

  602.         ModIProperties modIProperties = null;
  603.         try {
  604.             modIProperties = ModIProperties.getInstance();
  605.         } catch (ProtocolException e) {
  606.             throw FaultCode.ERRORE_INTERNO.toException(e.getMessage());
  607.         }
  608.        
  609.         ProtocolProperties p = new ProtocolProperties();

  610.         if(modi.getInterazione().getPattern().equals(ModIPatternInterazioneEnum.BLOCCANTE)) {

  611.             if(modi.getInterazione().getTipo()!= null) {
  612.                 throw FaultCode.RICHIESTA_NON_VALIDA.toException("Impossibile specificare interazione.tipo con pattern " + modi.getInterazione().getPattern());
  613.             }

  614.             if(modi.getInterazione().getFunzione()!= null) {
  615.                 throw FaultCode.RICHIESTA_NON_VALIDA.toException("Impossibile specificare interazione.funzione con pattern " + modi.getInterazione().getPattern());
  616.             }
  617.            
  618.             if(modi.getInterazione().getAzioneCorrelata()!=null) {
  619.                 throw FaultCode.RICHIESTA_NON_VALIDA.toException("Impossibile specificare interazione.azione_correlata con funzione " + modi.getInterazione().getFunzione());
  620.             }

  621.             p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE, ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_BLOCCANTE);

  622.         } else if(modi.getInterazione().getPattern().equals(ModIPatternInterazioneEnum.NON_BLOCCANTE)) {
  623.            
  624.             boolean isPull = modi.getInterazione().getTipo().equals(ModIPatternInterazioneTipoEnum.PULL);
  625.             boolean isRichiesta = modi.getInterazione().getFunzione().equals(ModIPatternInterazioneFunzioneEnum.RICHIESTA);
  626.            
  627.             if(isPull) {
  628.                 p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PULL);
  629.                
  630.                 if(isRichiesta) {
  631.                     p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA);
  632.                 } else {
  633.                     p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RISPOSTA);
  634.                 }
  635.             } else {
  636.                 p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PUSH);
  637.                
  638.                
  639.                 if(isRichiesta) {
  640.                     p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA);
  641.                 } else {
  642.                     p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO, ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RISPOSTA);
  643.                 }
  644.             }

  645.             if(!isRichiesta) {
  646.                 addAzioneCorrelata(modi.getInterazione().getAzioneCorrelata(), env, p, isPull);
  647.             }

  648.             p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE, ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE);
  649.            
  650.         } else if(modi.getInterazione().getPattern().equals(ModIPatternInterazioneEnum.CRUD)) {
  651.             throw FaultCode.RICHIESTA_NON_VALIDA.toException("Pattern interazione CRUD non permesso per servizi SOAP");
  652.         }


  653.         if(modi.getSicurezzaMessaggio().getStato().equals(ModISicurezzaMessaggioOperazioneEnum.API)) {
  654.             p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_ACTION_MODE, ModICostanti.MODIPA_PROFILO_DEFAULT);
  655.         } else {
  656.             ApiModISicurezzaMessaggioOperazioneRidefinito rid = ((ApiModISicurezzaMessaggioOperazioneRidefinito)modi.getSicurezzaMessaggio());
  657.             p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_ACTION_MODE, ModICostanti.MODIPA_PROFILO_RIDEFINISCI);
  658.             getSOAPProperties(rid.getConfigurazione(), p, modIProperties);

  659.         }

  660.         return p;
  661.     }

  662.     private static void addAzioneCorrelata(ApiModIPatternInterazioneCorrelazioneSoap azioneCorrelata, ApiEnv env,
  663.             ProtocolProperties p, boolean isPull) throws DriverRegistroServiziException, DriverConfigurazioneException, RegistryNotFound, RegistryException {
  664.        
  665.         IDAccordo idAccordoFromAccordo = env.idAccordoFactory.getIDAccordoFromValues(azioneCorrelata.getApiNome(), env.idSoggetto.getTipo(),env.idSoggetto.getNome(),azioneCorrelata.getApiVersione());
  666.         IRegistryReader registryReader = env.soggettiCore.getRegistryReader(env.protocolFactory);
  667.        
  668.         checkAzione(idAccordoFromAccordo, azioneCorrelata.getServizio(), azioneCorrelata.getAzione(), isPull, registryReader);

  669.         p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_API_RICHIESTA_CORRELATA, idAccordoFromAccordo.toString());
  670.         p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_SERVIZIO_RICHIESTA_CORRELATA, azioneCorrelata.getServizio());
  671.         p.addProperty(ModICostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_AZIONE_RICHIESTA_CORRELATA, azioneCorrelata.getAzione());

  672.     }


  673.     private static void checkAzione(IDAccordo idAccordoFromAccordo, String servizio, String azione, boolean isPull, IRegistryReader registryReader) throws RegistryNotFound, RegistryException, DriverConfigurazioneException {
  674.        
  675.         AccordoServizioParteSpecifica asps = new AccordoServizioParteSpecifica();
  676.         asps.setTipoSoggettoErogatore(idAccordoFromAccordo.getSoggettoReferente().getTipo());
  677.         asps.setNomeSoggettoErogatore(idAccordoFromAccordo.getSoggettoReferente().getNome());
  678.         asps.setNome(idAccordoFromAccordo.getNome());
  679.         asps.setVersione(idAccordoFromAccordo.getVersione());
  680.         asps.setPortType(servizio);
  681.         AccordoServizioParteComune as = registryReader.getAccordoServizioParteComune(idAccordoFromAccordo,false,false);

  682.         AccordoServizioParteComuneSintetico aspc = new AccordoServizioParteComuneSintetico(as);

  683.         Map<String,String> azioni = AzioniUtils.getAzioniConLabel(asps, aspc, false, false,
  684.         new ArrayList<>(), ModIConsoleCostanti.MODIPA_VALUE_UNDEFINED, ModIConsoleCostanti.MODIPA_LABEL_UNDEFINED, org.slf4j.LoggerFactory.getLogger(ApiApiServiceImpl.class));
  685.        
  686.        
  687.        
  688.         if(azioni!=null && !azioni.isEmpty()) {
  689.            
  690.             for (String azioneId : azioni.keySet()) {
  691.                 String tmpInterazione = AzioniUtils.getProtocolPropertyStringValue(as, servizio, azioneId, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ID);
  692.                 if(!ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE.equals(tmpInterazione)) {
  693.                     continue;
  694.                 }
  695.                 String tmpRuolo = AzioniUtils.getProtocolPropertyStringValue(as, servizio, azioneId, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_ID);
  696.                 if(isPull != ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_VALUE_PULL.equals(tmpRuolo)) {
  697.                     continue;
  698.                 }
  699.                 String tmpRelazione = AzioniUtils.getProtocolPropertyStringValue(as, servizio, azioneId, ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_ID);
  700.                 if(!ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_ASINCRONA_RUOLO_VALUE_RICHIESTA.equals(tmpRelazione)) {
  701.                     continue;
  702.                 }
  703.                
  704.                 if(azioneId.equals(azione)) {
  705.                     return;
  706.                 }
  707.             }
  708.         }

  709.         throw FaultCode.RICHIESTA_NON_VALIDA.toException("Azione non correlabile");            
  710.        
  711.     }


  712.     public static ProtocolProperties getProtocolProperties(Api body) {
  713.         return getModiProtocolProperties(body.getModi(), body.getTipoInterfaccia().getProtocollo());
  714.     }

  715.     public static ProtocolProperties updateModiProtocolProperties(AccordoServizioParteComune as, ProfiloEnum profilo, ApiModI modi) {
  716.         if(profilo == null || (!profilo.equals(ProfiloEnum.MODI) && !profilo.equals(ProfiloEnum.MODIPA))) {
  717.             throw FaultCode.RICHIESTA_NON_VALIDA.toException("Operazione utilizzabile solamente con Profilo 'ModI'");
  718.         }

  719.         TipoApiEnum protocollo = as.getFormatoSpecifica().equals(FormatoSpecifica.WSDL_11) ? TipoApiEnum.SOAP: TipoApiEnum.REST;
  720.         return getModiProtocolProperties(modi, protocollo);

  721.     }

  722.     private static ProtocolProperties getModiProtocolProperties(ApiModI modi, TipoApiEnum protocollo) {

  723.         if(modi == null) {
  724.             throw FaultCode.RICHIESTA_NON_VALIDA.toException(SPECIFICARE_CONFIGURAZIONE_MODI);
  725.         }

  726.         ProtocolProperties p = new ProtocolProperties();

  727.         String chan = modi.getSicurezzaCanale().getPattern().equals(ModISicurezzaCanaleEnum.AUTH01) ? ModICostanti.MODIPA_PROFILO_SICUREZZA_CANALE_VALUE_IDAC01 : ModICostanti.MODIPA_PROFILO_SICUREZZA_CANALE_VALUE_IDAC02;
  728.         p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_CANALE, chan);

  729.         ModIProperties modIProperties = null;
  730.         try {
  731.             modIProperties = ModIProperties.getInstance();
  732.         } catch (ProtocolException e) {
  733.             throw FaultCode.ERRORE_INTERNO.toException(e.getMessage());
  734.         }
  735.        
  736.         if(protocollo.equals(TipoApiEnum.SOAP)) {
  737.             getSOAPProperties(modi.getSicurezzaMessaggio(), p, modIProperties);
  738.         } else if(protocollo.equals(TipoApiEnum.REST)) {
  739.             getRESTProperties(modi.getSicurezzaMessaggio(), p, modIProperties);
  740.         }


  741.         return p;
  742.     }


  743.     private static void getRESTProperties(ApiModISicurezzaMessaggio sicurezzaMessaggio, ProtocolProperties p, ModIProperties modIProperties) {
  744.    
  745.         String profiloSicurezzaMessaggio = null;

  746.         switch(sicurezzaMessaggio.getPattern()) {
  747.         case AUTH01: profiloSicurezzaMessaggio = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM01;
  748.         break;
  749.         case AUTH02: profiloSicurezzaMessaggio = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM02;
  750.         break;
  751.         case DISABILITATO: profiloSicurezzaMessaggio = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_UNDEFINED;
  752.         break;
  753.         case INTEGRITY01_AUTH01: profiloSicurezzaMessaggio = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0301;
  754.         break;
  755.         case INTEGRITY01_AUTH02: profiloSicurezzaMessaggio = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0302;
  756.         break;
  757.         case INTEGRITY02_AUTH01: profiloSicurezzaMessaggio = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0401;
  758.         break;
  759.         case INTEGRITY02_AUTH02: profiloSicurezzaMessaggio = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0402;
  760.         break;
  761.         }


  762.         p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO, profiloSicurezzaMessaggio);
  763.        
  764.         boolean cornicePropValue = false;
  765.         boolean digestPropValue = false;


  766.         if(sicurezzaMessaggio.isSoapFirmaAllegati()!= null &&
  767.                 sicurezzaMessaggio.isSoapFirmaAllegati()) {
  768.             throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.soap_firma_allegati specificato con servizio di tipo REST");
  769.         }

  770.         if(!sicurezzaMessaggio.getPattern().equals(ModISicurezzaMessaggioEnum.DISABILITATO)) {

  771.             boolean integrityX509 = sicurezzaMessaggio.getPattern().equals(ModISicurezzaMessaggioEnum.INTEGRITY01_AUTH01) ||
  772.                     sicurezzaMessaggio.getPattern().equals(ModISicurezzaMessaggioEnum.INTEGRITY01_AUTH02);
  773.             boolean integrityKid = sicurezzaMessaggio.getPattern().equals(ModISicurezzaMessaggioEnum.INTEGRITY02_AUTH01) ||
  774.                     sicurezzaMessaggio.getPattern().equals(ModISicurezzaMessaggioEnum.INTEGRITY02_AUTH02);
  775.             boolean integrity = integrityX509 || integrityKid;
  776.            
  777.             boolean sorgenteLocale = true;
  778.            
  779.             if(sicurezzaMessaggio.getGenerazioneToken()!=null) {
  780.                 String sorgenteToken = null;
  781.                 switch(sicurezzaMessaggio.getGenerazioneToken()) {
  782.                 case LOCALE: sorgenteToken = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_LOCALE;
  783.                 if(integrityKid) {
  784.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.generazione_token, valorizzato con '"+sicurezzaMessaggio.getGenerazioneToken()+"', non è compatibile con il pattern '" + sicurezzaMessaggio.getPattern()+"'");
  785.                 }
  786.                 break;
  787.                 case PDND: sorgenteToken = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_PDND; sorgenteLocale = false;
  788.                 break;
  789.                 case OAUTH: sorgenteToken = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_OAUTH; sorgenteLocale = false;
  790.                 break;
  791.                 }
  792.                 p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH, sorgenteToken);    
  793.             }
  794.             else {
  795.                 // default locale
  796.                 if(integrityKid) {
  797.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.generazione_token deve essere valorizzato con il pattern '" + sicurezzaMessaggio.getPattern()+"'");
  798.                 }
  799.             }
  800.            
  801.             if(sicurezzaMessaggio.getRestHeader() == null) {
  802.                 throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.rest_header deve essere specificato con servizio di tipo REST e pattern " + sicurezzaMessaggio.getPattern());
  803.             }


  804.             boolean applicabilitaInfoUtente = false;
  805.             boolean applicabilitaDigest = false;


  806.             String headerHTTPREST = "";
  807.             boolean custom = false;
  808.             boolean dueHeaderInRequest = false;
  809.             switch(sicurezzaMessaggio.getRestHeader()) {
  810.                 case AGID: headerHTTPREST = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_MODIPA;
  811.                 break;
  812.                 case BEARER: headerHTTPREST = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION;
  813.                 break;
  814.                 case AGID_BEARER_REQUEST: headerHTTPREST = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_MODIPA; dueHeaderInRequest = true;
  815.                 break;
  816.                 case AGID_BEARER: headerHTTPREST = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_MODIPA_AUTH_IN_RESPONSE;
  817.                 break;
  818.                 case CUSTOM: headerHTTPREST = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_CUSTOM;
  819.                 custom=true;
  820.                 break;
  821.                 case CUSTOM_BEARER_REQUEST: headerHTTPREST = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_CUSTOM; dueHeaderInRequest = true;
  822.                 custom=true;
  823.                 break;
  824.                 case CUSTOM_BEARER: headerHTTPREST = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_VALUE_AUTHORIZATION_CUSTOM_AUTH_IN_RESPONSE;
  825.                 custom=true;
  826.                 break;
  827.             }
  828.             p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER, headerHTTPREST);
  829.            
  830.             if(custom && sicurezzaMessaggio.getRestHeaderCustom()!=null) {
  831.                 p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER_CUSTOM, sicurezzaMessaggio.getRestHeaderCustom());
  832.             }

  833.             String erroreTokenNonLocaleConPatternSicurezza = "con una generazione token non locale e un pattern di sicurezza";
  834.            
  835.             if(!sorgenteLocale && integrity && !dueHeaderInRequest) {
  836.                 throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.rest_header deve essere definita come '"+
  837.                         ModISicurezzaMessaggioRestHeaderEnum.AGID_BEARER_REQUEST.toString()+"' o '"+ModISicurezzaMessaggioRestHeaderEnum.CUSTOM_BEARER_REQUEST.toString()+"' "+erroreTokenNonLocaleConPatternSicurezza+" '"+sicurezzaMessaggio.getPattern()+"'");
  838.             }

  839.             String applicabilita = "";
  840.            
  841.             if(!sorgenteLocale && !integrity) {
  842.                 if(sicurezzaMessaggio.getApplicabilita()==null) {
  843.                     sicurezzaMessaggio.setApplicabilita(ModISicurezzaMessaggioApplicabilitaEnum.RICHIESTA);
  844.                 }
  845.                 else if(!sicurezzaMessaggio.getApplicabilita().equals(ModISicurezzaMessaggioApplicabilitaEnum.RICHIESTA)) {
  846.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.applicabilita deve essere definita come '"+ModISicurezzaMessaggioApplicabilitaEnum.RICHIESTA.toString()+"' "+erroreTokenNonLocaleConPatternSicurezza+" '"+sicurezzaMessaggio.getPattern()+"'");
  847.                 }
  848.             }
  849.             else {
  850.                 if(sicurezzaMessaggio.getApplicabilita() == null) {
  851.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.applicabilita deve essere specificato");
  852.                 }
  853.             }
  854.            
  855.             if(sicurezzaMessaggio.getApplicabilita().equals(ModISicurezzaMessaggioApplicabilitaEnum.CUSTOM)) {

  856.                 p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_PERSONALIZZATO);

  857.                 if(sicurezzaMessaggio.getApplicabilitaCustom() == null) {
  858.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.applicabilita_custom deve essere specificato con servizio di tipo REST e applicabilita " + sicurezzaMessaggio.getApplicabilita());
  859.                 }

  860.                 ApiModISicurezzaMessaggioApplicabilitaCustom appCustom = sicurezzaMessaggio.getApplicabilitaCustom();

  861.                 String sicurezzaRichiesta = "";
  862.                 boolean requireContentTypeRequest = false;
  863.                 switch(appCustom.getRichiesta()) {
  864.                 case ABILITATO: sicurezzaRichiesta = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE_VALUE_ABILITATO;
  865.                 break;
  866.                 case CUSTOM:sicurezzaRichiesta = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE_VALUE_PERSONALIZZATO; requireContentTypeRequest = true;
  867.                 break;
  868.                 case DISABILITATO:sicurezzaRichiesta = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE_VALUE_DISABILITATO;
  869.                 break;}

  870.                 p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE, sicurezzaRichiesta);

  871.                 if(appCustom.getRichiestaContentType()!=null) {
  872.                     if(!requireContentTypeRequest) {
  873.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.applicabilita_custom.richiesta_content_type non deve essere specificato con servizio di tipo REST e applicabilita_custom.richiesta " + appCustom.getRichiesta());
  874.                     }
  875.                     p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_CONTENT_TYPE_MODE_ID, appCustom.getRichiestaContentType());
  876.                 } else {
  877.                     if(requireContentTypeRequest) {
  878.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.applicabilita_custom.richiesta_content_type deve essere specificato con servizio di tipo REST e applicabilita_custom.richiesta " + appCustom.getRichiesta());
  879.                     }
  880.                 }

  881.                 String sicurezzaRisposta = "";
  882.                 boolean requireContentTypeAndReturnCodeResponse = false;
  883.                 switch(appCustom.getRisposta()) {
  884.                 case ABILITATO: sicurezzaRisposta = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE_VALUE_ABILITATO;
  885.                 break;
  886.                 case CUSTOM:sicurezzaRisposta = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE_VALUE_PERSONALIZZATO; requireContentTypeAndReturnCodeResponse = true;
  887.                 break;
  888.                 case DISABILITATO:sicurezzaRisposta = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE_VALUE_DISABILITATO;
  889.                 break;}

  890.                 p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE, sicurezzaRisposta);


  891.                 if(appCustom.getRispostaContentType()!=null && appCustom.getRispostaCodice()!=null) {
  892.                     if(!requireContentTypeAndReturnCodeResponse) {
  893.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.applicabilita_custom.risposta_content_type e sicurezza_messaggio.applicabilita_custom.risposta_codice non devono essere specificati con servizio di tipo REST e applicabilita_custom.risposta " + appCustom.getRisposta());
  894.                     }
  895.                     p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_CONTENT_TYPE_MODE_ID, appCustom.getRispostaContentType());
  896.                     p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_ID, appCustom.getRispostaCodice());
  897.                 } else {
  898.                     if(requireContentTypeAndReturnCodeResponse) {
  899.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.applicabilita_custom.risposta_content_type e sicurezza_messaggio.applicabilita_custom.risposta_codice devono essere specificati con servizio di tipo REST e applicabilita_custom.risposta " + appCustom.getRisposta());
  900.                     }
  901.                 }

  902.                 applicabilitaDigest = true;
  903.                 applicabilitaInfoUtente= true;

  904.                 if((sicurezzaMessaggio.isInformazioniUtente() != null && sicurezzaMessaggio.isInformazioniUtente().booleanValue())) {

  905.                     cornicePropValue =  sicurezzaMessaggio.isInformazioniUtente().booleanValue();
  906.                    
  907.                     if(!integrity || !applicabilitaInfoUtente) {
  908.                         // il pattern legacy richiede l'integrita'
  909.                         if(!integrity) {
  910.                             if(sicurezzaMessaggio.getPatternAudit()==null || ModISicurezzaMessaggioPatternAuditEnum.LEGACY.equals(sicurezzaMessaggio.getPatternAudit())) {
  911.                                 ModISicurezzaMessaggioPatternAuditEnum auditPattern = sicurezzaMessaggio.getPatternAudit()!=null ? sicurezzaMessaggio.getPatternAudit() : ModISicurezzaMessaggioPatternAuditEnum.LEGACY;
  912.                                 throw FaultCode.RICHIESTA_NON_VALIDA.toException(getErroreAuditPatternSpecificatoConPattern(auditPattern,sicurezzaMessaggio.getPattern()));
  913.                             }
  914.                         }
  915.                         // qualsiasi pattern deve essere applicabile
  916.                         else {
  917.                             throw FaultCode.RICHIESTA_NON_VALIDA.toException(getErroreAuditPatternSpecificatoConApplicabilita(sicurezzaMessaggio.getApplicabilita()));
  918.                         }
  919.                     }
  920.                    
  921.                     if(sorgenteLocale && sicurezzaMessaggio.getPatternAudit()!=null && ModISicurezzaMessaggioPatternAuditEnum.REST02.equals(sicurezzaMessaggio.getPatternAudit())) {
  922.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException(getErroreAuditPatternRichiedeTokenNonLocale(sicurezzaMessaggio.getPatternAudit()));
  923.                     }
  924.                 }

  925.                 if((sicurezzaMessaggio.isDigestRichiesta() != null && sicurezzaMessaggio.isDigestRichiesta())) {

  926.                     if(integrity && applicabilitaDigest) {
  927.                         digestPropValue = sicurezzaMessaggio.isDigestRichiesta();
  928.                     } else {
  929.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException(getErroreDigestRichiestaSpecificatoConPatternApplicabilita(sicurezzaMessaggio.getPattern(),sicurezzaMessaggio.getApplicabilita()));
  930.                     }
  931.                 }

  932.             } else {

  933.                 if(sicurezzaMessaggio.getApplicabilitaCustom() != null) {
  934.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.applicabilita_custom non deve essere specificato con servizio di tipo REST e applicabilita " + sicurezzaMessaggio.getApplicabilita());
  935.                 }

  936.                 switch(sicurezzaMessaggio.getApplicabilita()) {
  937.                 case CUSTOM: //gestito nell'altro ramo if
  938.                     break;
  939.                 case QUALSIASI: applicabilita = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_ENTRAMBI; applicabilitaDigest = true; applicabilitaInfoUtente= true;
  940.                 break;
  941.                 case RICHIESTA: applicabilita = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RICHIESTA; applicabilitaInfoUtente= true;
  942.                 break;
  943.                 case RISPOSTA: applicabilita = ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RISPOSTA;
  944.                 break;
  945.                 }

  946.                 p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE, applicabilita);

  947.                 if((sicurezzaMessaggio.isInformazioniUtente() != null && sicurezzaMessaggio.isInformazioniUtente().booleanValue())) {

  948.                     cornicePropValue =  sicurezzaMessaggio.isInformazioniUtente().booleanValue();
  949.                    
  950.                     if(!integrity || !applicabilitaInfoUtente) {
  951.                         // il pattern legacy richiede l'integrita'
  952.                         if(!integrity) {
  953.                             if(sicurezzaMessaggio.getPatternAudit()==null || ModISicurezzaMessaggioPatternAuditEnum.LEGACY.equals(sicurezzaMessaggio.getPatternAudit())) {
  954.                                 ModISicurezzaMessaggioPatternAuditEnum auditPattern = sicurezzaMessaggio.getPatternAudit()!=null ? sicurezzaMessaggio.getPatternAudit() : ModISicurezzaMessaggioPatternAuditEnum.LEGACY;
  955.                                 throw FaultCode.RICHIESTA_NON_VALIDA.toException(getErroreAuditPatternSpecificatoConPattern(auditPattern,sicurezzaMessaggio.getPattern()));
  956.                             }
  957.                         }
  958.                         // qualsiasi pattern deve essere applicabile
  959.                         else {
  960.                             throw FaultCode.RICHIESTA_NON_VALIDA.toException(getErroreAuditPatternSpecificatoConApplicabilita(sicurezzaMessaggio.getApplicabilita()));
  961.                         }
  962.                     }
  963.                    
  964.                     if(sorgenteLocale && sicurezzaMessaggio.getPatternAudit()!=null && ModISicurezzaMessaggioPatternAuditEnum.REST02.equals(sicurezzaMessaggio.getPatternAudit())) {
  965.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException(getErroreAuditPatternRichiedeTokenNonLocale(sicurezzaMessaggio.getPatternAudit()));
  966.                     }
  967.                 }

  968.                 if((sicurezzaMessaggio.isDigestRichiesta() != null && sicurezzaMessaggio.isDigestRichiesta())) {

  969.                     if(integrity && applicabilitaDigest) {
  970.                         digestPropValue = sicurezzaMessaggio.isDigestRichiesta();
  971.                     } else {
  972.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException(getErroreDigestRichiestaSpecificatoConPatternApplicabilita(sicurezzaMessaggio.getPattern(),sicurezzaMessaggio.getApplicabilita()));
  973.                     }
  974.                 }

  975.             }
  976.             p.addProperty(ProtocolPropertiesFactory.newProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_REQUEST_DIGEST, digestPropValue));
  977.             p.addProperty(ProtocolPropertiesFactory.newProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA, cornicePropValue));
  978.             if(cornicePropValue) {
  979.                
  980.                 String patternAudit = null;
  981.                 boolean schemaRequired = false;
  982.                 if(sicurezzaMessaggio.getPatternAudit()!=null) {
  983.                     switch(sicurezzaMessaggio.getPatternAudit()) {
  984.                     case LEGACY: patternAudit = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD;
  985.                     break;
  986.                     case REST01: patternAudit = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_AUDIT_REST_01; schemaRequired=true;
  987.                     break;
  988.                     case REST02: patternAudit = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_AUDIT_REST_02; schemaRequired=true;
  989.                     break;
  990.                     }
  991.                     p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN, patternAudit);
  992.                 }
  993.                
  994.                 if( (sicurezzaMessaggio.getSchemaAudit()!=null && StringUtils.isNotEmpty(sicurezzaMessaggio.getSchemaAudit()))
  995.                         ||
  996.                         schemaRequired) {
  997.                    
  998.                     List<ModIAuditConfig> l = null;
  999.                     String schemaAudit = null;
  1000.                     try {
  1001.                         l = modIProperties.getAuditConfig();
  1002.                        
  1003.                         if( (sicurezzaMessaggio.getSchemaAudit()!=null && StringUtils.isNotEmpty(sicurezzaMessaggio.getSchemaAudit()))) {
  1004.                             schemaAudit = sicurezzaMessaggio.getSchemaAudit();
  1005.                             boolean find = false;
  1006.                             if(l!=null && !l.isEmpty()) {
  1007.                                 for (ModIAuditConfig modIAuditConfig : l) {
  1008.                                     if(schemaAudit.equals(modIAuditConfig.getNome())) {
  1009.                                         find = true;
  1010.                                         break;
  1011.                                     }
  1012.                                 }
  1013.                             }
  1014.                             if(!find) {
  1015.                                 throw new CoreException("lo schema indicato non risultato configurato");
  1016.                             }
  1017.                         }
  1018.                         else {
  1019.                             // schemaRequired
  1020.                             if(l==null || l.isEmpty() || (l.size()==1 && l.get(0)==null)) {
  1021.                                 throw new CoreException("Nella configurazione ModI non è stato definito uno schema utilizzabile con il pattern di audit '"+patternAudit+"'");
  1022.                             }
  1023.                             if(l.size()>1) {
  1024.                                 throw new CoreException("Nella configurazione ModI sono stati definito più schemi utilizzabile con il pattern di audit '"+patternAudit+"'; indicare lo schema da associare tramite il claim 'schema_audit'");
  1025.                             }
  1026.                             schemaAudit = l.get(0).getNome();
  1027.                         }
  1028.                            
  1029.                     }catch(Exception e) {
  1030.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.schema_audit specificato '"+sicurezzaMessaggio.getSchemaAudit()+"' con pattern di audit '" + sicurezzaMessaggio.getPatternAudit() + "' non valido: "+e.getMessage());
  1031.                     }
  1032.                    
  1033.                     p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_SCHEMA, schemaAudit);  
  1034.                 }
  1035.             }

  1036.         } else {
  1037.             p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_HEADER, "");
  1038.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE, "");

  1039.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE, "");
  1040.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_CONTENT_TYPE_MODE_ID, "");
  1041.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE, "");
  1042.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_CONTENT_TYPE_MODE_ID, "");
  1043.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_ID, "");
  1044.         }
  1045.     }


  1046.     private static void getSOAPProperties(ApiModISicurezzaMessaggio sicurezzaMessaggio, ProtocolProperties p, ModIProperties modIProperties) {
  1047.        
  1048.         String profiloSicurezzaMessaggio = null;

  1049.         switch(sicurezzaMessaggio.getPattern()) {
  1050.         case AUTH01: profiloSicurezzaMessaggio = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM01;
  1051.         break;
  1052.         case AUTH02: profiloSicurezzaMessaggio = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM02;
  1053.         break;
  1054.         case DISABILITATO: profiloSicurezzaMessaggio = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_UNDEFINED;
  1055.         break;
  1056.         case INTEGRITY01_AUTH01: profiloSicurezzaMessaggio = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0301;
  1057.         break;
  1058.         case INTEGRITY01_AUTH02: profiloSicurezzaMessaggio = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0302;
  1059.         break;
  1060.         case INTEGRITY02_AUTH01:
  1061.         case INTEGRITY02_AUTH02:
  1062.             throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.pattern '"+sicurezzaMessaggio.getPattern()+"' non utilizzabile con API SOAP");
  1063.         }


  1064.         p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO, profiloSicurezzaMessaggio);

  1065.         boolean cornicePropValue = false;
  1066.         boolean digestPropValue = false;

  1067.         if(sicurezzaMessaggio.getRestHeader() != null) {
  1068.             throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.rest_header specificato con servizio di tipo SOAP");
  1069.         }


  1070.         if(!sicurezzaMessaggio.getPattern().equals(ModISicurezzaMessaggioEnum.DISABILITATO)) {

  1071.             boolean integrityX509 = sicurezzaMessaggio.getPattern().equals(ModISicurezzaMessaggioEnum.INTEGRITY01_AUTH01) ||
  1072.                     sicurezzaMessaggio.getPattern().equals(ModISicurezzaMessaggioEnum.INTEGRITY01_AUTH02);
  1073.             boolean integrityKid = sicurezzaMessaggio.getPattern().equals(ModISicurezzaMessaggioEnum.INTEGRITY02_AUTH01) ||
  1074.                     sicurezzaMessaggio.getPattern().equals(ModISicurezzaMessaggioEnum.INTEGRITY02_AUTH02);
  1075.             boolean integrity = integrityX509 || integrityKid;
  1076.            
  1077.             if(integrityKid) {
  1078.                 throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.pattern '"+sicurezzaMessaggio.getPattern()+"' non utilizzabile con API SOAP");
  1079.             }
  1080.            
  1081.             boolean sorgenteLocale = true;
  1082.            
  1083.             if(sicurezzaMessaggio.getGenerazioneToken()!=null) {
  1084.                 String sorgenteToken = null;
  1085.                 switch(sicurezzaMessaggio.getGenerazioneToken()) {
  1086.                 case LOCALE: sorgenteToken = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_LOCALE;
  1087.                 break;
  1088.                 case PDND: sorgenteToken = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_PDND; sorgenteLocale = false;
  1089.                 break;
  1090.                 case OAUTH: sorgenteToken = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH_VALUE_OAUTH; sorgenteLocale = false;
  1091.                 break;
  1092.                 }
  1093.                 p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH, sorgenteToken);    
  1094.             }
  1095.            
  1096.             String applicabilita = "";

  1097.             boolean isSoapFirmaAllegati = sicurezzaMessaggio.isSoapFirmaAllegati()!=null && sicurezzaMessaggio.isSoapFirmaAllegati().booleanValue();
  1098.            
  1099.             if(isSoapFirmaAllegati && !integrity) {
  1100.                 throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.soap_firma_allegati specificato con pattern " + sicurezzaMessaggio.getPattern());
  1101.             }

  1102.             boolean applicabilitaInfoUtente = false;
  1103.             boolean applicabilitaDigest = false;

  1104.             if(!sorgenteLocale && !integrity) {
  1105.                 if(sicurezzaMessaggio.getApplicabilita()==null) {
  1106.                     sicurezzaMessaggio.setApplicabilita(ModISicurezzaMessaggioApplicabilitaEnum.RICHIESTA);
  1107.                 }
  1108.                 else if(!sicurezzaMessaggio.getApplicabilita().equals(ModISicurezzaMessaggioApplicabilitaEnum.RICHIESTA)) {
  1109.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.applicabilita deve essere definita come '"+ModISicurezzaMessaggioApplicabilitaEnum.RICHIESTA.toString()+"' con una generazione token non locale e un pattern di sicurezza '"+sicurezzaMessaggio.getPattern()+"'");
  1110.                 }
  1111.             }
  1112.            
  1113.             if(sicurezzaMessaggio.getApplicabilita()!=null) {
  1114.                 switch(sicurezzaMessaggio.getApplicabilita()) {
  1115.                 case CUSTOM: throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.applicabilita custom specificato con servizio di tipo SOAP");
  1116.                 case QUALSIASI: applicabilita = isSoapFirmaAllegati ? ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_ENTRAMBI_CON_ATTACHMENTS : ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_ENTRAMBI; applicabilitaInfoUtente = true; applicabilitaDigest = true;
  1117.                 break;
  1118.                 case RICHIESTA: applicabilita = isSoapFirmaAllegati ? ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RICHIESTA_CON_ATTACHMENTS : ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RICHIESTA; applicabilitaInfoUtente = true;
  1119.                 break;
  1120.                 case RISPOSTA: applicabilita = isSoapFirmaAllegati ? ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RISPOSTA_CON_ATTACHMENTS : ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_RISPOSTA;
  1121.                 break;
  1122.                 }
  1123.                 p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE, applicabilita);
  1124.             } else {
  1125.                 p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE, ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE_VALUE_DEFAULT);
  1126.                 applicabilitaInfoUtente = true;
  1127.                 applicabilitaDigest = true;
  1128.             }

  1129.             if((sicurezzaMessaggio.isInformazioniUtente() != null && sicurezzaMessaggio.isInformazioniUtente().booleanValue())) {

  1130.                 cornicePropValue =  sicurezzaMessaggio.isInformazioniUtente().booleanValue();
  1131.                
  1132.                 if(!integrity || !applicabilitaInfoUtente) {

  1133.                     // il pattern legacy richiede l'integrita'
  1134.                     if(!integrity) {
  1135.                         if(sicurezzaMessaggio.getPatternAudit()==null || ModISicurezzaMessaggioPatternAuditEnum.LEGACY.equals(sicurezzaMessaggio.getPatternAudit())) {
  1136.                             ModISicurezzaMessaggioPatternAuditEnum auditPattern = sicurezzaMessaggio.getPatternAudit()!=null ? sicurezzaMessaggio.getPatternAudit() : ModISicurezzaMessaggioPatternAuditEnum.LEGACY;
  1137.                             throw FaultCode.RICHIESTA_NON_VALIDA.toException(getErroreAuditPatternSpecificatoConPattern(auditPattern,sicurezzaMessaggio.getPattern()));
  1138.                         }
  1139.                     }
  1140.                     // qualsiasi pattern deve essere applicabile
  1141.                     else {
  1142.                         throw FaultCode.RICHIESTA_NON_VALIDA.toException(getErroreAuditPatternSpecificatoConApplicabilita(sicurezzaMessaggio.getApplicabilita()));
  1143.                     }
  1144.                 }
  1145.                
  1146.                 if(sorgenteLocale && sicurezzaMessaggio.getPatternAudit()!=null && ModISicurezzaMessaggioPatternAuditEnum.REST02.equals(sicurezzaMessaggio.getPatternAudit())) {
  1147.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException(getErroreAuditPatternRichiedeTokenNonLocale(sicurezzaMessaggio.getPatternAudit()));
  1148.                 }
  1149.             }

  1150.             if((sicurezzaMessaggio.isDigestRichiesta() != null && sicurezzaMessaggio.isDigestRichiesta())) {

  1151.                 if(integrity && applicabilitaDigest) {
  1152.                     digestPropValue = sicurezzaMessaggio.isDigestRichiesta();
  1153.                 } else {
  1154.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException(getErroreDigestRichiestaSpecificatoConPatternApplicabilita(sicurezzaMessaggio.getPattern(),sicurezzaMessaggio.getApplicabilita()));
  1155.                 }
  1156.             }

  1157.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE, "");
  1158.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_CONTENT_TYPE_MODE_ID, "");
  1159.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE, "");
  1160.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_CONTENT_TYPE_MODE_ID, "");
  1161.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_ID, "");
  1162.         } else {
  1163.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_MESSAGGIO_MODE, "");

  1164.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_MODE, "");
  1165.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RICHIESTA_CONTENT_TYPE_MODE_ID, "");
  1166.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_MODE, "");
  1167.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_CONTENT_TYPE_MODE_ID, "");
  1168.             p.addProperty(ModICostanti.MODIPA_CONFIGURAZIONE_SICUREZZA_RISPOSTA_RETURN_CODE_MODE_ID, "");
  1169.         }

  1170.         p.addProperty(ProtocolPropertiesFactory.newProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_RISPOSTA_REQUEST_DIGEST, digestPropValue));
  1171.         p.addProperty(ProtocolPropertiesFactory.newProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA, cornicePropValue));
  1172.        
  1173.         if(cornicePropValue) {
  1174.            
  1175.             String patternAudit = null;
  1176.             boolean schemaRequired = false;
  1177.             if(sicurezzaMessaggio.getPatternAudit()!=null) {
  1178.                 switch(sicurezzaMessaggio.getPatternAudit()) {
  1179.                 case LEGACY: patternAudit = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_OLD;
  1180.                 break;
  1181.                 case REST01: patternAudit = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_AUDIT_REST_01; schemaRequired=true;
  1182.                 break;
  1183.                 case REST02: patternAudit = ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN_VALUE_AUDIT_REST_02; schemaRequired=true;
  1184.                 break;
  1185.                 }
  1186.                 p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_PATTERN, patternAudit);
  1187.             }
  1188.            
  1189.             if( (sicurezzaMessaggio.getSchemaAudit()!=null && StringUtils.isNotEmpty(sicurezzaMessaggio.getSchemaAudit()))
  1190.                     ||
  1191.                     schemaRequired) {
  1192.                
  1193.                 List<ModIAuditConfig> l = null;
  1194.                 String schemaAudit = null;
  1195.                 try {
  1196.                     l = modIProperties.getAuditConfig();
  1197.                    
  1198.                     if( (sicurezzaMessaggio.getSchemaAudit()!=null && StringUtils.isNotEmpty(sicurezzaMessaggio.getSchemaAudit()))) {
  1199.                         schemaAudit = sicurezzaMessaggio.getSchemaAudit();
  1200.                         boolean find = false;
  1201.                         if(l!=null && !l.isEmpty()) {
  1202.                             for (ModIAuditConfig modIAuditConfig : l) {
  1203.                                 if(schemaAudit.equals(modIAuditConfig.getNome())) {
  1204.                                     find = true;
  1205.                                     break;
  1206.                                 }
  1207.                             }
  1208.                         }
  1209.                         if(!find) {
  1210.                             throw new CoreException("lo schema indicato non risultato configurato");
  1211.                         }
  1212.                     }
  1213.                     else {
  1214.                         // schemaRequired
  1215.                         if(l==null || l.isEmpty() || (l.size()==1 && l.get(0)==null)) {
  1216.                             throw new CoreException("Nella configurazione ModI non è stato definito uno schema utilizzabile con il pattern di audit '"+patternAudit+"'");
  1217.                         }
  1218.                         if(l.size()>1) {
  1219.                             throw new CoreException("Nella configurazione ModI sono stati definito più schemi utilizzabile con il pattern di audit '"+patternAudit+"'; indicare lo schema da associare tramite il claim 'schema_audit'");
  1220.                         }
  1221.                         schemaAudit = l.get(0).getNome();
  1222.                     }
  1223.                    
  1224.                 }catch(Exception e) {
  1225.                     throw FaultCode.RICHIESTA_NON_VALIDA.toException("sicurezza_messaggio.schema_audit specificato '"+sicurezzaMessaggio.getSchemaAudit()+"' con pattern di audit '" + sicurezzaMessaggio.getPatternAudit() + "' non valido: "+e.getMessage());
  1226.                 }
  1227.                
  1228.                 p.addProperty(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_SCHEMA, schemaAudit);  
  1229.             }
  1230.         }
  1231.     }
  1232. }