PorteApplicativeWSResponsePropertiesConfig.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.pa;

  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.Properties;

  25. import javax.servlet.http.HttpServletRequest;
  26. import javax.servlet.http.HttpServletResponse;
  27. import javax.servlet.http.HttpSession;

  28. import org.apache.struts.action.Action;
  29. import org.apache.struts.action.ActionForm;
  30. import org.apache.struts.action.ActionForward;
  31. import org.apache.struts.action.ActionMapping;
  32. import org.openspcoop2.core.config.MessageSecurityFlowParameter;
  33. import org.openspcoop2.core.config.PortaApplicativa;
  34. import org.openspcoop2.core.mvc.properties.Config;
  35. import org.openspcoop2.core.mvc.properties.utils.ConfigManager;
  36. import org.openspcoop2.core.mvc.properties.utils.DBPropertiesUtils;
  37. import org.openspcoop2.core.mvc.properties.utils.PropertiesSourceConfiguration;
  38. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  39. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  40. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  41. import org.openspcoop2.web.lib.mvc.Costanti;
  42. import org.openspcoop2.web.lib.mvc.DataElement;
  43. import org.openspcoop2.web.lib.mvc.ForwardParams;
  44. import org.openspcoop2.web.lib.mvc.GeneralData;
  45. import org.openspcoop2.web.lib.mvc.PageData;
  46. import org.openspcoop2.web.lib.mvc.Parameter;
  47. import org.openspcoop2.web.lib.mvc.ServletUtils;
  48. import org.openspcoop2.web.lib.mvc.TipoOperazione;
  49. import org.openspcoop2.web.lib.mvc.properties.beans.ConfigBean;

  50. /**    
  51.  * PorteApplicativeWSResponsePropertiesConfig
  52.  *
  53.  * @author Pintori Giuliano (pintori@link.it)
  54.  * @author $Author$
  55.  * @version $Rev$, $Date$
  56.  */
  57. public class PorteApplicativeWSResponsePropertiesConfig  extends Action {

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

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

  61.         // Inizializzo PageData
  62.         PageData pd = new PageData();

  63.         GeneralHelper generalHelper = new GeneralHelper(session);

  64.         // Inizializzo GeneralData
  65.         GeneralData gd = generalHelper.initGeneralData(request);
  66.        
  67.         TipoOperazione tipoOperazione = TipoOperazione.OTHER;

  68.         try {
  69.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  70.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  71.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  72.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;

  73.             String configName = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_PROPERTIES_CONFIG_NAME);
  74.             String id = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  75.             int idInt = Integer.parseInt(id);
  76.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  77.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  78.             if(idAsps == null)
  79.                 idAsps = "";

  80.             // Stato [si usa per capire se sono entrato per la prima volta nella schermata]    
  81.             boolean first = porteApplicativeHelper.isFirstTimeFromHttpParameters(CostantiControlStation.PARAMETRO_CONTROLLO_FIRST_TIME);

  82.             // Preparo il menu
  83.             porteApplicativeHelper.makeMenu();
  84.            
  85.             // Prendo il nome della porta
  86.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();

  87.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  88.             String idPorta = pa.getNome();
  89.            
  90.             PropertiesSourceConfiguration propertiesSourceConfiguration = porteApplicativeCore.getMessageSecurityPropertiesSourceConfiguration();
  91.             ConfigManager configManager = ConfigManager.getinstance(ControlStationCore.getLog());
  92.             Config configurazione = configManager.getConfigurazione(propertiesSourceConfiguration, configName);
  93.            
  94.             Map<String, Properties> mappaDB = porteApplicativeCore.readMessageSecurityResponsePropertiesConfiguration(pa.getId());
  95.            
  96.             ConfigBean configurazioneBean = porteApplicativeCore.leggiConfigurazione(configurazione, mappaDB);
  97.            
  98.             if(!first) { // la prima volta non sovrascrivo la configurazione con i valori letti dai parametri
  99.                 porteApplicativeHelper.aggiornaConfigurazioneProperties(configurazioneBean);
  100.             } else {
  101.                 // reset di eventuali configurazioni salvate in sessione
  102.                 ServletUtils.removeConfigurazioneBeanFromSession(request, session, configurazioneBean.getId());
  103.             }
  104.            
  105.             configurazioneBean.updateConfigurazione(configurazione);
  106.             ServletUtils.saveConfigurazioneBeanIntoSession(request, session, configurazioneBean, configurazioneBean.getId());

  107.             Parameter pId = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, id);
  108.             Parameter pIdSoggetto = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg);
  109.             Parameter pIdAsps = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps);
  110.             Parameter pIdPropertiesConfigReq= new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_PROPERTIES_CONFIG_NAME, configName);
  111.             Parameter[] urlParms = { pId,pIdSoggetto,pIdAsps,pIdPropertiesConfigReq };

  112.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);

  113.             String labelPerPorta = null;
  114.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  115.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  116.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_CONFIG_DI,
  117.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY,
  118.                         pa);
  119.             }
  120.             else {
  121.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_CONFIG_DI+idPorta;
  122.             }
  123.             lstParam.add(new Parameter(labelPerPorta,
  124.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY, urlParms));

  125.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_FLOW_PROPERTIES_CONFIG + " " + configurazione.getLabel() ,null));

  126.             // imposta menu' contestuale
  127.             porteApplicativeHelper.impostaComandiMenuContestualePA(idsogg, idAsps);
  128.            
  129.             if(porteApplicativeHelper.isEditModeInProgress()){
  130.                 // setto la barra del titolo
  131.                 ServletUtils.setPageDataTitle(pd, lstParam);

  132.                 // preparo i campi
  133.                 List<DataElement> dati = new ArrayList<>();
  134.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  135.                
  136.                 dati = porteApplicativeHelper.addPropertiesConfigToDati(tipoOperazione,dati, configName, configurazioneBean);

  137.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.OTHER, id, idsogg, null, idAsps, dati);
  138.                
  139.                 // Set First Time == false
  140.                 porteApplicativeHelper.addToDatiFirstTimeDisabled(dati,CostantiControlStation.PARAMETRO_CONTROLLO_FIRST_TIME);

  141.                 pd.setDati(dati);

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

  143.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_PROPERTIES_CONFIG, ForwardParams.OTHER(""));
  144.             }
  145.            
  146.             // Controlli sui campi immessi
  147.             boolean isOk = porteApplicativeHelper.checkPropertiesConfigurationData(tipoOperazione, configurazioneBean, null, null, configurazione);
  148.             if(!isOk){
  149.                 // setto la barra del titolo
  150.                 ServletUtils.setPageDataTitle(pd, lstParam);

  151.                 // preparo i campi
  152.                 List<DataElement> dati = new ArrayList<>();
  153.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  154.                
  155.                 dati = porteApplicativeHelper.addPropertiesConfigToDati(tipoOperazione,dati, configName, configurazioneBean);

  156.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.OTHER, id, idsogg, null, idAsps, dati);
  157.                
  158.                 // Set First Time == false
  159.                 porteApplicativeHelper.addToDatiFirstTimeDisabled(dati,CostantiControlStation.PARAMETRO_CONTROLLO_FIRST_TIME);
  160.                
  161.                 pd.setDati(dati);

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

  163.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_PROPERTIES_CONFIG, ForwardParams.OTHER(""));
  164.             }
  165.            
  166.             Map<String, Properties> mappaDestinazione = configurazioneBean.getPropertiesMap();  
  167.             Map<String, String> map = DBPropertiesUtils.toMap(mappaDestinazione);
  168.            
  169.             if(pa.getMessageSecurity().getResponseFlow().getParameterList() == null)
  170.                 pa.getMessageSecurity().getResponseFlow().setParameterList(new ArrayList<>());
  171.            
  172.             pa.getMessageSecurity().getResponseFlow().getParameterList().clear();
  173.            
  174.             for (String propKey : map.keySet()) {
  175.                 MessageSecurityFlowParameter parameter = new MessageSecurityFlowParameter();
  176.                 parameter.setNome(propKey);
  177.                 parameter.setValore(map.get(propKey));
  178.                
  179.                 pa.getMessageSecurity().getResponseFlow().addParameter(parameter);
  180.             }
  181.            
  182.             String userLogin = ServletUtils.getUserLoginFromSession(session);

  183.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);
  184.            
  185.             mappaDB = porteApplicativeCore.readMessageSecurityResponsePropertiesConfiguration(pa.getId());
  186.            
  187.             configurazioneBean = porteApplicativeCore.leggiConfigurazione(configurazione, mappaDB);
  188.            
  189.             // setto la barra del titolo
  190.             ServletUtils.setPageDataTitle(pd, lstParam);
  191.            
  192.             // preparo i campi
  193.             List<DataElement> dati = new ArrayList<>();
  194.             dati.add(ServletUtils.getDataElementForEditModeFinished());
  195.            
  196.             configurazioneBean.updateConfigurazione(configurazione);
  197.             ServletUtils.saveConfigurazioneBeanIntoSession(request, session, configurazioneBean, configurazioneBean.getId());

  198.             dati = porteApplicativeHelper.addPropertiesConfigToDati(tipoOperazione,dati, configName, configurazioneBean);

  199.             dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.OTHER, id, idsogg, null, idAsps, dati);
  200.            
  201.             // Set First Time == false
  202.             porteApplicativeHelper.addToDatiFirstTimeDisabled(dati,CostantiControlStation.PARAMETRO_CONTROLLO_FIRST_TIME);
  203.            
  204.             pd.setDati(dati);
  205.            
  206.             pd.setMessage(CostantiControlStation.LABEL_AGGIORNAMENTO_CONFIGURAZIONE_PROPERTIES_EFFETTUATO_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);

  207.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  208.            
  209.             // Forward control to the specified success URI
  210.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_PROPERTIES_CONFIG, ForwardParams.OTHER(""));
  211.         } catch (Exception e) {
  212.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  213.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_PROPERTIES_CONFIG,
  214.                     ForwardParams.OTHER(""));
  215.         }  
  216.     }
  217. }