PorteDelegateWS.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.web.ctrlstat.servlet.pd;

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

  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import javax.servlet.http.HttpSession;

  26. import org.apache.commons.lang.StringUtils;
  27. import org.apache.struts.action.Action;
  28. import org.apache.struts.action.ActionForm;
  29. import org.apache.struts.action.ActionForward;
  30. import org.apache.struts.action.ActionMapping;
  31. import org.openspcoop2.core.config.MessageSecurity;
  32. import org.openspcoop2.core.config.MessageSecurityFlow;
  33. import org.openspcoop2.core.config.PortaDelegata;
  34. import org.openspcoop2.core.config.TrasformazioneRegola;
  35. import org.openspcoop2.core.config.constants.MTOMProcessorType;
  36. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  37. import org.openspcoop2.core.mvc.properties.utils.ConfigManager;
  38. import org.openspcoop2.core.mvc.properties.utils.PropertiesSourceConfiguration;
  39. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  40. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  41. import org.openspcoop2.message.constants.ServiceBinding;
  42. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  43. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  44. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  45. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  46. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  47. import org.openspcoop2.web.lib.mvc.Costanti;
  48. import org.openspcoop2.web.lib.mvc.DataElement;
  49. import org.openspcoop2.web.lib.mvc.ForwardParams;
  50. import org.openspcoop2.web.lib.mvc.GeneralData;
  51. import org.openspcoop2.web.lib.mvc.PageData;
  52. import org.openspcoop2.web.lib.mvc.Parameter;
  53. import org.openspcoop2.web.lib.mvc.ServletUtils;
  54. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  55. /**
  56.  * porteDelegateWS
  57.  *
  58.  * @author Andrea Poli (apoli@link.it)
  59.  * @author Stefano Corallo (corallo@link.it)
  60.  * @author Sandra Giangrandi (sandra@link.it)
  61.  * @author $Author$
  62.  * @version $Rev$, $Date$
  63.  *
  64.  */
  65. public final class PorteDelegateWS extends Action {

  66.     @Override
  67.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

  68.         HttpSession session = request.getSession(true);

  69.         // Inizializzo PageData
  70.         PageData pd = new PageData();

  71.         GeneralHelper generalHelper = new GeneralHelper(session);

  72.         // Inizializzo GeneralData
  73.         GeneralData gd = generalHelper.initGeneralData(request);

  74.         try {
  75.             Boolean contaListe = ServletUtils.getContaListeFromSession(session);

  76.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  77.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  78.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  79.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  80.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  81.             int idInt = Integer.parseInt(id);
  82.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  83.             String statoMessageSecurity = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY);
  84.             String applicaMTOMRichiesta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_APPLICA_MTOM_RICHIESTA);
  85.             String applicaMTOMRisposta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_APPLICA_MTOM_RISPOSTA);
  86.             String applicaModificaS = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_APPLICA_MODIFICA);
  87.             boolean applicaModifica = ServletUtils.isCheckBoxEnabled(applicaModificaS);
  88.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  89.             if(idAsps == null)
  90.                 idAsps = "";
  91.            
  92.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  93.             if(idFruizione == null)
  94.                 idFruizione = "";
  95.            
  96.             String idPropertiesConfigReq = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_FLOW_PROPERTIES_CONFIG_NAME);
  97.             String idPropertiesConfigRes = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_FLOW_PROPERTIES_CONFIG_NAME);
  98.            
  99.             String idTab = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  100.             if(!porteDelegateHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  101.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  102.             }
  103.            
  104.             // Preparo il menu
  105.             porteDelegateHelper.makeMenu();

  106.             // modalitaInterfaccia
  107.             boolean isModalitaAvanzata = porteDelegateHelper.isModalitaAvanzata();

  108.             // Prendo il nome della porta
  109.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  110.             AccordiServizioParteSpecificaCore aspsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  111.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(aspsCore);

  112.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);
  113.             if(pde==null) {
  114.                 throw new Exception("PortaDelegata con id '"+idInt+"' non trovata");
  115.             }
  116.             String idporta = pde.getNome();
  117.            
  118.             AccordoServizioParteSpecifica asps = aspsCore.getAccordoServizioParteSpecifica(Long.parseLong(idAsps));
  119.             AccordoServizioParteComuneSintetico as = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  120.             ServiceBinding serviceBindingAPI = apcCore.toMessageServiceBinding(as.getServiceBinding());

  121.             // Calcolo lo stato MTOM
  122.             boolean isMTOMAbilitatoReq = false;
  123.             boolean isMTOMAbilitatoRes= false;

  124.             MTOMProcessorType mtomReqTmp = null;
  125.             MTOMProcessorType mtomResTmp = null;

  126.             if(pde.getMtomProcessor()!= null){
  127.                 if(pde.getMtomProcessor().getRequestFlow() != null){
  128.                     mtomReqTmp = pde.getMtomProcessor().getRequestFlow().getMode();
  129.                 }

  130.                 if(pde.getMtomProcessor().getResponseFlow() != null){
  131.                     mtomResTmp = pde.getMtomProcessor().getResponseFlow().getMode();
  132.                 }
  133.             }

  134.             // calcolo lo stato di richiesta e risposta
  135.             if(isModalitaAvanzata && mtomReqTmp!= null && !mtomReqTmp.equals(MTOMProcessorType.DISABLE) && !mtomReqTmp.equals(MTOMProcessorType.VERIFY))
  136.                 isMTOMAbilitatoReq = true;

  137.             if(isModalitaAvanzata && mtomResTmp!= null && !mtomResTmp.equals(MTOMProcessorType.DISABLE ) && !mtomResTmp.equals(MTOMProcessorType.VERIFY))
  138.                 isMTOMAbilitatoRes = true;

  139.             // Conto i ws-request ed i ws-response
  140.             MessageSecurity pdeMessageSecurity = pde.getMessageSecurity();
  141.             int numMessageSecurityReq = 0;
  142.             int numMessageSecurityRes = 0;
  143.             String oldIdPropertiesConfigReq = null;
  144.             String oldIdPropertiesConfigRes = null;
  145.             if (pdeMessageSecurity != null) {
  146.                 if(pdeMessageSecurity.getRequestFlow()!=null){
  147.                     numMessageSecurityReq = pdeMessageSecurity.getRequestFlow().sizeParameterList();
  148.                     oldIdPropertiesConfigReq = pdeMessageSecurity.getRequestFlow().getMode();
  149.                 }
  150.                 if(pdeMessageSecurity.getResponseFlow()!=null){
  151.                     numMessageSecurityRes = pdeMessageSecurity.getResponseFlow().sizeParameterList();
  152.                     oldIdPropertiesConfigRes = pdeMessageSecurity.getResponseFlow().getMode();
  153.                 }
  154.             }

  155.             if(statoMessageSecurity == null)
  156.                 statoMessageSecurity = pde.getStatoMessageSecurity();
  157.            
  158.             // imposto lo stato iniziale del mode scelto
  159.             if(idPropertiesConfigReq == null)
  160.                 idPropertiesConfigReq = oldIdPropertiesConfigReq;
  161.            
  162.             if(idPropertiesConfigRes == null)
  163.                 idPropertiesConfigRes = oldIdPropertiesConfigRes;
  164.            
  165.             if(idPropertiesConfigReq == null)
  166.                 idPropertiesConfigReq = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_FLOW_PROPERTIES_CONFIG_NAME_NESSUNO;
  167.            
  168.             if(idPropertiesConfigRes == null)
  169.                 idPropertiesConfigRes = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_FLOW_PROPERTIES_CONFIG_NAME_NESSUNO;
  170.            
  171.            
  172.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  173.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  174.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  175.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  176.             Parameter pIdPropertiesConfigReq= new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_PROPERTIES_CONFIG_NAME, idPropertiesConfigReq);
  177.             Parameter pIdPropertiesConfigRes= new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_PROPERTIES_CONFIG_NAME, idPropertiesConfigRes);
  178.            
  179.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  180.            
  181.             String labelPerPorta = null;
  182.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  183.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  184.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_CONFIG_DI,
  185.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY,
  186.                         pde);
  187.             }
  188.             else {
  189.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_CONFIG_DI+idporta;
  190.             }
  191.             lstParam.add(new Parameter(labelPerPorta,  null));

  192.             Parameter[] urlReqParms = { pId,pIdSoggetto,pIdAsps,pIdFrizione,pIdPropertiesConfigReq };
  193.             Parameter[] urlResParms = { pId,pIdSoggetto,pIdAsps,pIdFrizione,pIdPropertiesConfigRes };
  194.             // setto la barra del titolo
  195.             ServletUtils.setPageDataTitle(pd, lstParam);
  196.            
  197.             // imposto menu' contestuale
  198.             porteDelegateHelper.impostaComandiMenuContestualePD(idsogg, idAsps, idFruizione);

  199.             String servletNameRequestList =  idPropertiesConfigReq.equals(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_FLOW_PROPERTIES_CONFIG_NAME)
  200.                     ? PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_LIST : PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_PROPERTIES_CONFIG;
  201.             String servletNameResponseList = idPropertiesConfigRes.equals(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_FLOW_PROPERTIES_CONFIG_NAME)
  202.                     ? PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_LIST  : PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_PROPERTIES_CONFIG;
  203.            
  204.             Parameter urlRequestList = new Parameter("", servletNameRequestList , urlReqParms);
  205.             Parameter urlResponseList = new Parameter("", servletNameResponseList , urlResParms);
  206.            
  207.             PropertiesSourceConfiguration propertiesSourceConfiguration = porteDelegateCore.getMessageSecurityPropertiesSourceConfiguration();
  208.            
  209.             ConfigManager configManager = ConfigManager.getinstance(ControlStationCore.getLog());
  210.             configManager.leggiConfigurazioni(propertiesSourceConfiguration, true);
  211.            
  212.             ServiceBinding serviceBindingSecurityTransformazioni = null;
  213.             // se ci sono delle trasformazioni abilitate posso dover modificare il binding (Solo nelle fruizioni)
  214.             if(pde!=null && pde.getTrasformazioni()!=null && pde.getTrasformazioni().sizeRegolaList()>0) {
  215.                 for (int i = 0; i < pde.getTrasformazioni().sizeRegolaList(); i++) {
  216.                     TrasformazioneRegola tr = pde.getTrasformazioni().getRegola(i);
  217.                     if(StatoFunzionalita.ABILITATO.equals(tr.getStato()) &&
  218.                         tr.getRichiesta()!=null) {
  219.                         if(ServiceBinding.REST.equals(serviceBindingAPI)) {
  220.                             if(tr.getRichiesta().getTrasformazioneSoap()!=null) {
  221.                                 serviceBindingSecurityTransformazioni = ServiceBinding.SOAP;
  222.                                 break;
  223.                             }
  224.                         }
  225.                         else {
  226.                             if(tr.getRichiesta().getTrasformazioneRest()!=null) {
  227.                                 serviceBindingSecurityTransformazioni = ServiceBinding.REST;
  228.                                 break;
  229.                             }
  230.                         }
  231.                     }
  232.                 }
  233.             }
  234.            
  235.             List<String> nomiConfigurazioniReq = configManager.getNomiConfigurazioni(propertiesSourceConfiguration,serviceBindingAPI.name(),PorteDelegateCostanti.TAG_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST,PorteDelegateCostanti.TAG_PORTE_DELEGATE_MESSAGE_SECURITY_PD);
  236.             if(serviceBindingSecurityTransformazioni!=null) {
  237.                 List<String> nomiConfigurazioniReqTrasformazioni = configManager.getNomiConfigurazioni(propertiesSourceConfiguration,serviceBindingSecurityTransformazioni.name(),PorteDelegateCostanti.TAG_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST,PorteDelegateCostanti.TAG_PORTE_DELEGATE_MESSAGE_SECURITY_PD);
  238.                 if(nomiConfigurazioniReqTrasformazioni!=null && !nomiConfigurazioniReqTrasformazioni.isEmpty()) {
  239.                     nomiConfigurazioniReq.addAll(nomiConfigurazioniReqTrasformazioni);
  240.                 }
  241.             }
  242.             List<String> labelConfigurazioniReq = configManager.convertToLabel(propertiesSourceConfiguration, nomiConfigurazioniReq);
  243.            
  244.             List<String> propConfigReqLabelListTmp = new ArrayList<>();
  245.             propConfigReqLabelListTmp.add(PorteDelegateCostanti.LABEL_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_FLOW_PROPERTIES_CONFIG_NAME_NESSUNO);
  246.             propConfigReqLabelListTmp.addAll(labelConfigurazioniReq);
  247.             if(porteDelegateHelper.isModalitaAvanzata())
  248.                 propConfigReqLabelListTmp.add(PorteDelegateCostanti.LABEL_DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_FLOW_PROPERTIES_CONFIG_NAME);
  249.            
  250.            
  251.             List<String>  propConfigReqListTmp = new ArrayList<>();
  252.             propConfigReqListTmp.add(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_FLOW_PROPERTIES_CONFIG_NAME_NESSUNO);
  253.             propConfigReqListTmp.addAll(nomiConfigurazioniReq);
  254.             if(porteDelegateHelper.isModalitaAvanzata())
  255.                 propConfigReqListTmp.add(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_FLOW_PROPERTIES_CONFIG_NAME);
  256.            
  257.            
  258.             List<String> nomiConfigurazioniRes = configManager.getNomiConfigurazioni(propertiesSourceConfiguration,serviceBindingAPI.name(),PorteDelegateCostanti.TAG_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE,PorteDelegateCostanti.TAG_PORTE_DELEGATE_MESSAGE_SECURITY_PD);
  259.             if(serviceBindingSecurityTransformazioni!=null) {
  260.                 List<String> nomiConfigurazioniResTrasformazioni = configManager.getNomiConfigurazioni(propertiesSourceConfiguration,serviceBindingSecurityTransformazioni.name(),PorteDelegateCostanti.TAG_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE,PorteDelegateCostanti.TAG_PORTE_DELEGATE_MESSAGE_SECURITY_PD);
  261.                 if(nomiConfigurazioniResTrasformazioni!=null && !nomiConfigurazioniResTrasformazioni.isEmpty()) {
  262.                     nomiConfigurazioniRes.addAll(nomiConfigurazioniResTrasformazioni);
  263.                 }
  264.             }
  265.             List<String> labelConfigurazioniRes = configManager.convertToLabel(propertiesSourceConfiguration, nomiConfigurazioniRes);
  266.            
  267.             List<String>  propConfigResLabelListTmp = new ArrayList<>();
  268.             propConfigResLabelListTmp.add(PorteDelegateCostanti.LABEL_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_FLOW_PROPERTIES_CONFIG_NAME_NESSUNO);
  269.             propConfigResLabelListTmp.addAll(labelConfigurazioniRes);
  270.             if(porteDelegateHelper.isModalitaAvanzata())
  271.                 propConfigResLabelListTmp.add(PorteDelegateCostanti.LABEL_DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_FLOW_PROPERTIES_CONFIG_NAME);
  272.            
  273.            
  274.             List<String>  propConfigResListTmp = new ArrayList<>();
  275.             propConfigResListTmp.add(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_FLOW_PROPERTIES_CONFIG_NAME_NESSUNO);
  276.             propConfigResListTmp.addAll(nomiConfigurazioniRes);
  277.             if(porteDelegateHelper.isModalitaAvanzata())
  278.                 propConfigResListTmp.add(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_FLOW_PROPERTIES_CONFIG_NAME);

  279.            
  280.             String[] propConfigReqLabelList = propConfigReqLabelListTmp.toArray(new String[propConfigReqLabelListTmp.size()]);
  281.             String[] propConfigReqList= propConfigReqListTmp.toArray(new String[propConfigReqListTmp.size()]);
  282.            
  283.             String[] propConfigResLabelList= propConfigResLabelListTmp.toArray(new String[propConfigResLabelListTmp.size()]);
  284.             String[] propConfigResList= propConfigResListTmp.toArray(new String[propConfigResListTmp.size()]);
  285.            
  286.             // controllo postback
  287.             String postBackElementName = porteDelegateHelper.getPostBackElementName();
  288.             if(postBackElementName != null) {
  289.                 if(postBackElementName.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_FLOW_PROPERTIES_CONFIG_NAME)) {
  290.                     applicaModifica = false;
  291.                 }
  292.                 if(postBackElementName.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_FLOW_PROPERTIES_CONFIG_NAME)) {
  293.                     applicaModifica = false;
  294.                 }
  295.                 if(postBackElementName.equals(CostantiControlStation.PARAMETRO_MESSAGE_SECURITY)) {
  296.                     applicaModifica = false;
  297.                 }
  298.             }


  299.             // Se idhid = null, devo visualizzare la pagina per la
  300.             // modifica dati
  301.             if( porteDelegateHelper.isEditModeInProgress() && !applicaModifica){

  302.                 // preparo i campi
  303.                 List<DataElement> dati = new ArrayList<>();
  304.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  305.                 if (pdeMessageSecurity != null) {
  306.                     if(pdeMessageSecurity.getRequestFlow()!=null){
  307.                         StatoFunzionalita applyToMtomRich = pdeMessageSecurity.getRequestFlow().getApplyToMtom();
  308.                         if(applicaMTOMRichiesta == null) {
  309.                             if(applyToMtomRich != null && applyToMtomRich.equals(StatoFunzionalita.ABILITATO) && isMTOMAbilitatoReq)
  310.                                 applicaMTOMRichiesta = "yes";
  311.                             else
  312.                                 applicaMTOMRichiesta = "";
  313.                         }
  314.                     }
  315.                     if(pdeMessageSecurity.getResponseFlow()!=null){
  316.                         StatoFunzionalita applyToMtomRich = pdeMessageSecurity.getResponseFlow().getApplyToMtom();
  317.                         if(applicaMTOMRisposta == null) {
  318.                             if(applyToMtomRich != null && applyToMtomRich.equals(StatoFunzionalita.ABILITATO) && isMTOMAbilitatoRes)
  319.                                 applicaMTOMRisposta = "yes";
  320.                             else
  321.                                 applicaMTOMRisposta = "";
  322.                         }
  323.                     }
  324.                 }

  325.                 if(applicaMTOMRichiesta == null){
  326.                     applicaMTOMRichiesta = "";
  327.                 }

  328.                 if(applicaMTOMRisposta == null){
  329.                     applicaMTOMRisposta = "";
  330.                 }
  331.                
  332.                 dati = porteDelegateHelper.addMessageSecurityToDati(dati,  true, idInt, statoMessageSecurity, urlRequestList.getValue(), urlResponseList.getValue() , contaListe, numMessageSecurityReq, numMessageSecurityRes,
  333.                         isMTOMAbilitatoReq, applicaMTOMRichiesta, isMTOMAbilitatoRes, applicaMTOMRisposta,idPropertiesConfigReq,idPropertiesConfigRes,propConfigReqLabelList, propConfigReqList,  propConfigResLabelList, propConfigResList,
  334.                         oldIdPropertiesConfigReq,oldIdPropertiesConfigRes);

  335.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER, id, idsogg, null, idAsps,
  336.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  337.                 pd.setDati(dati);

  338.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  339.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  340.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY, ForwardParams.OTHER(""));
  341.             }

  342.             // Controlli sui campi immessi
  343.             boolean isOk = porteDelegateHelper.WSCheckData(TipoOperazione.OTHER);
  344.             if (!isOk) {
  345.                 // preparo i campi
  346.                 List<DataElement> dati = new ArrayList<>();

  347.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  348.                 dati = porteDelegateHelper.addMessageSecurityToDati(dati, true, idInt, statoMessageSecurity, urlRequestList.getValue(), urlResponseList.getValue() , contaListe, numMessageSecurityReq, numMessageSecurityRes,
  349.                         isMTOMAbilitatoReq, applicaMTOMRichiesta, isMTOMAbilitatoRes, applicaMTOMRisposta,idPropertiesConfigReq,idPropertiesConfigRes,propConfigReqLabelList, propConfigReqList,  propConfigResLabelList, propConfigResList,
  350.                         oldIdPropertiesConfigReq,oldIdPropertiesConfigRes);

  351.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER, id, idsogg, null, idAsps,
  352.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  353.                 pd.setDati(dati);

  354.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  355.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  356.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY,
  357.                         ForwardParams.OTHER(""));
  358.             }

  359.             // Modifico i dati della porta delegata nel db
  360.             pde.setStatoMessageSecurity(statoMessageSecurity);

  361.             if (pde.getMessageSecurity() == null)
  362.                 pde.setMessageSecurity(new MessageSecurity());

  363.             if(pde.getMessageSecurity().getRequestFlow()==null){
  364.                 pde.getMessageSecurity().setRequestFlow(new MessageSecurityFlow());
  365.             }
  366.             if(pde.getMessageSecurity().getResponseFlow() ==null){
  367.                 pde.getMessageSecurity().setResponseFlow(new MessageSecurityFlow());
  368.             }
  369.             String oldRequestMode = pde.getMessageSecurity().getRequestFlow().getMode();
  370.             String oldResponseMode = pde.getMessageSecurity().getResponseFlow().getMode();
  371.            
  372.             String newRequestMode = !idPropertiesConfigReq.equals(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_FLOW_PROPERTIES_CONFIG_NAME_NESSUNO) ? idPropertiesConfigReq : null;
  373.             String newResponseMode = !idPropertiesConfigRes.equals(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_FLOW_PROPERTIES_CONFIG_NAME_NESSUNO) ? idPropertiesConfigRes : null;
  374.            
  375.             // salvataggio della configurazione delle properties
  376.             pde.getMessageSecurity().getRequestFlow().setMode(newRequestMode);
  377.             pde.getMessageSecurity().getResponseFlow().setMode(newResponseMode);
  378.            
  379.             // se ho cambiato la modalita' di configurazione della sicurezza resetto la vecchia configurazione
  380.             if(oldRequestMode!= null && !oldRequestMode.equals(idPropertiesConfigReq)) {
  381.                 pde.getMessageSecurity().getRequestFlow().getParameterList().clear();
  382.             }
  383.             if(oldResponseMode!= null && !oldResponseMode.equals(idPropertiesConfigRes)) {
  384.                 pde.getMessageSecurity().getResponseFlow().getParameterList().clear();
  385.             }

  386.             if(isMTOMAbilitatoReq){
  387.                 if(applicaMTOMRichiesta != null && (ServletUtils.isCheckBoxEnabled(applicaMTOMRichiesta))){
  388.                     pde.getMessageSecurity().getRequestFlow().setApplyToMtom(StatoFunzionalita.ABILITATO);
  389.                 }else {
  390.                     pde.getMessageSecurity().getRequestFlow().setApplyToMtom(StatoFunzionalita.DISABILITATO);
  391.                 }
  392.             }else
  393.                 pde.getMessageSecurity().getRequestFlow().setApplyToMtom(null);

  394.             if(isMTOMAbilitatoRes){
  395.                 if(applicaMTOMRisposta  != null && (ServletUtils.isCheckBoxEnabled(applicaMTOMRisposta))){
  396.                     pde.getMessageSecurity().getResponseFlow().setApplyToMtom(StatoFunzionalita.ABILITATO);
  397.                 }else {
  398.                     pde.getMessageSecurity().getResponseFlow().setApplyToMtom(StatoFunzionalita.DISABILITATO);
  399.                 }
  400.             }else
  401.                 pde.getMessageSecurity().getResponseFlow().setApplyToMtom(null);

  402.             if(!CostantiControlStation.DEFAULT_VALUE_PARAMETRO_MESSAGE_SECURITY_ABILITATO.equals(statoMessageSecurity)) {
  403.                 // Devo annullare altrimenti si possono creare inconsistenze tra link accesso alla configurazione della sicurezza e non salvataggio reale dello stato generale (se si abilita la sicurezza e precedentemente esisteva giĆ  una config per la request o response)
  404.                 pde.getMessageSecurity().setRequestFlow(null);
  405.                 pde.getMessageSecurity().setResponseFlow(null);
  406.             }
  407.                        
  408.             String userLogin = ServletUtils.getUserLoginFromSession(session);

  409.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), pde);

  410.             // preparo i campi
  411.             List<DataElement> dati = new ArrayList<>();

  412.             // Aggiorno valori MessageSecurity request e response
  413.             pde = porteDelegateCore.getPortaDelegata(idInt);
  414.             pdeMessageSecurity = pde.getMessageSecurity();

  415.             applicaMTOMRichiesta = null;
  416.             applicaMTOMRisposta = null;

  417.             if (pdeMessageSecurity != null) {
  418.                 if(pdeMessageSecurity.getRequestFlow()!=null){
  419.                     numMessageSecurityReq = pdeMessageSecurity.getRequestFlow().sizeParameterList();
  420.                     oldIdPropertiesConfigReq = pdeMessageSecurity.getRequestFlow().getMode();
  421.                     StatoFunzionalita applyToMtomRich = pdeMessageSecurity.getRequestFlow().getApplyToMtom();

  422.                     if(applicaMTOMRichiesta == null) {
  423.                         if(applyToMtomRich != null && applyToMtomRich.equals(StatoFunzionalita.ABILITATO) && isMTOMAbilitatoReq)
  424.                             applicaMTOMRichiesta = "yes";
  425.                         else
  426.                             applicaMTOMRichiesta = "";
  427.                     }
  428.                 }
  429.                 if(pdeMessageSecurity.getResponseFlow()!=null){
  430.                     numMessageSecurityRes = pdeMessageSecurity.getResponseFlow().sizeParameterList();
  431.                     oldIdPropertiesConfigRes = pdeMessageSecurity.getResponseFlow().getMode();
  432.                     StatoFunzionalita applyToMtomRich = pdeMessageSecurity.getResponseFlow().getApplyToMtom();

  433.                     if(applicaMTOMRisposta ==null) {
  434.                         if(applyToMtomRich != null && applyToMtomRich.equals(StatoFunzionalita.ABILITATO) && isMTOMAbilitatoRes)
  435.                             applicaMTOMRisposta = "yes";
  436.                         else
  437.                             applicaMTOMRisposta = "";
  438.                     }
  439.                 }
  440.             }
  441.            
  442.             if(applicaMTOMRichiesta == null){
  443.                 applicaMTOMRichiesta = "";
  444.             }

  445.             if(applicaMTOMRisposta == null){
  446.                 applicaMTOMRisposta = "";
  447.             }

  448.             dati = porteDelegateHelper.addMessageSecurityToDati(dati,  true, idInt, statoMessageSecurity, urlRequestList.getValue(), urlResponseList.getValue() ,
  449.                     contaListe, numMessageSecurityReq, numMessageSecurityRes,isMTOMAbilitatoReq, applicaMTOMRichiesta, isMTOMAbilitatoRes, applicaMTOMRisposta,
  450.                     idPropertiesConfigReq,idPropertiesConfigRes,propConfigReqLabelList, propConfigReqList,  propConfigResLabelList, propConfigResList,
  451.                     oldIdPropertiesConfigReq,oldIdPropertiesConfigRes);

  452.             dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER, id, idsogg, null, idAsps,
  453.                     idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  454.             pd.setDati(dati);
  455.            
  456.             pd.setMessage(CostantiControlStation.LABEL_AGGIORNAMENTO_EFFETTUATO_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  457.             dati.add(ServletUtils.getDataElementForEditModeFinished());
  458.            
  459.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  460.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY,
  461.                     ForwardParams.OTHER(""));
  462.         } catch (Exception e) {
  463.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  464.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY,
  465.                     ForwardParams.OTHER(""));
  466.         }  
  467.     }
  468. }