PorteApplicativeWSRequestPropertiesConfig.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.  * PorteApplicativeWSRequestPropertiesConfig
  52.  *
  53.  * @author Pintori Giuliano (pintori@link.it)
  54.  * @author $Author$
  55.  * @version $Rev$, $Date$
  56.  */
  57. public class PorteApplicativeWSRequestPropertiesConfig  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.            
  81.             // Stato [si usa per capire se sono entrato per la prima volta nella schermata]    
  82.             boolean first = porteApplicativeHelper.isFirstTimeFromHttpParameters(CostantiControlStation.PARAMETRO_CONTROLLO_FIRST_TIME);

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

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

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

  113.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  114.            
  115.             String labelPerPorta = null;
  116.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  117.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  118.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_CONFIG_DI,
  119.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY,
  120.                         pa);
  121.             }
  122.             else {
  123.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_CONFIG_DI+idPorta;
  124.             }

  125.             lstParam.add(new Parameter(labelPerPorta,
  126.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY, urlParms));

  127.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST_FLOW_PROPERTIES_CONFIG + " " + configurazione.getLabel() ,null));

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

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

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

  143.                 pd.setDati(dati);

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

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

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

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

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

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

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

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

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

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