PorteDelegateWSRequestPropertiesConfig.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 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.PortaDelegata;
  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.  * PorteDelegateWSRequestPropertiesConfig
  52.  *
  53.  * @author Pintori Giuliano (pintori@link.it)
  54.  * @author $Author$
  55.  * @version $Rev$, $Date$
  56.  */
  57. public class PorteDelegateWSRequestPropertiesConfig  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.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  70.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  71.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  72.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;

  73.             String configName = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_PROPERTIES_CONFIG_NAME);
  74.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  75.             int idInt = Integer.parseInt(id);
  76.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  77.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  78.             if(idAsps == null)
  79.                 idAsps = "";

  80.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  81.             if(idFruizione == null)
  82.                 idFruizione = "";
  83.            
  84.             // Stato [si usa per capire se sono entrato per la prima volta nella schermata]    
  85.             boolean first = porteDelegateHelper.isFirstTimeFromHttpParameters(CostantiControlStation.PARAMETRO_CONTROLLO_FIRST_TIME);

  86.             // Preparo il menu
  87.             porteDelegateHelper.makeMenu();
  88.            
  89.             // Prendo il nome della porta
  90.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();

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

  111.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  112.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  113.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  114.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  115.             Parameter pIdPropertiesConfigReq= new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_PROPERTIES_CONFIG_NAME, configName);
  116.             Parameter[] urlParms = { pId,pIdSoggetto,pIdAsps,pIdFrizione,pIdPropertiesConfigReq };

  117.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);

  118.             String labelPerPorta = null;
  119.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  120.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  121.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_CONFIG_DI,
  122.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY,
  123.                         pde);
  124.             }
  125.             else {
  126.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_CONFIG_DI+idporta;
  127.             }
  128.             lstParam.add(new Parameter(labelPerPorta,
  129.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MESSAGE_SECURITY, urlParms));

  130.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_FLOW_PROPERTIES_CONFIG + " " + configurazione.getLabel() ,null));

  131.             // imposto menu' contestuale
  132.             porteDelegateHelper.impostaComandiMenuContestualePD(idsogg, idAsps, idFruizione);
  133.            
  134.             if(porteDelegateHelper.isEditModeInProgress()){
  135.                 // setto la barra del titolo
  136.                 ServletUtils.setPageDataTitle(pd, lstParam);

  137.                 // preparo i campi
  138.                 List<DataElement> dati = new ArrayList<>();
  139.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  140.                
  141.                 dati = porteDelegateHelper.addPropertiesConfigToDati(tipoOperazione,dati, configName, configurazioneBean);

  142.                 dati = porteDelegateHelper.addHiddenFieldsToDati(tipoOperazione, id, idsogg, null, idAsps,
  143.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);
  144.                
  145.                 // Set First Time == false
  146.                 porteDelegateHelper.addToDatiFirstTimeDisabled(dati,CostantiControlStation.PARAMETRO_CONTROLLO_FIRST_TIME);

  147.                 pd.setDati(dati);

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

  149.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_PROPERTIES_CONFIG, ForwardParams.OTHER(""));
  150.             }
  151.            
  152.             // Controlli sui campi immessi
  153.             boolean isOk = porteDelegateHelper.checkPropertiesConfigurationData(tipoOperazione, configurazioneBean, null, null, configurazione);
  154.             if(!isOk){
  155.                 // setto la barra del titolo
  156.                 ServletUtils.setPageDataTitle(pd, lstParam);

  157.                 // preparo i campi
  158.                 List<DataElement> dati = new ArrayList<>();
  159.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  160.                
  161.                 dati = porteDelegateHelper.addPropertiesConfigToDati(tipoOperazione,dati, configName, configurazioneBean);

  162.                 dati = porteDelegateHelper.addHiddenFieldsToDati(tipoOperazione, id, idsogg, null, idAsps,
  163.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);
  164.                
  165.                 // Set First Time == false
  166.                 porteDelegateHelper.addToDatiFirstTimeDisabled(dati,CostantiControlStation.PARAMETRO_CONTROLLO_FIRST_TIME);
  167.                
  168.                 pd.setDati(dati);

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

  170.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_PROPERTIES_CONFIG, ForwardParams.OTHER(""));
  171.             }
  172.            
  173.             Map<String, Properties> mappaDestinazione = configurazioneBean.getPropertiesMap();  
  174.             Map<String, String> map = DBPropertiesUtils.toMap(mappaDestinazione);
  175.            
  176.             if(pde.getMessageSecurity().getRequestFlow().getParameterList() == null)
  177.                 pde.getMessageSecurity().getRequestFlow().setParameterList(new ArrayList<>());
  178.            
  179.             pde.getMessageSecurity().getRequestFlow().getParameterList().clear();
  180.            
  181.             for (String propKey : map.keySet()) {
  182.                 MessageSecurityFlowParameter parameter = new MessageSecurityFlowParameter();
  183.                 parameter.setNome(propKey);
  184.                 parameter.setValore(map.get(propKey));
  185.                
  186.                 pde.getMessageSecurity().getRequestFlow().addParameter(parameter);
  187.             }
  188.            
  189.             String userLogin = ServletUtils.getUserLoginFromSession(session);

  190.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), pde);
  191.            
  192.             mappaDB = porteDelegateCore.readMessageSecurityRequestPropertiesConfiguration(pde.getId());
  193.            
  194.             configurazioneBean = porteDelegateCore.leggiConfigurazione(configurazione, mappaDB);
  195.            
  196.             // setto la barra del titolo
  197.             ServletUtils.setPageDataTitle(pd, lstParam);
  198.            
  199.             // preparo i campi
  200.             List<DataElement> dati = new ArrayList<>();
  201.             dati.add(ServletUtils.getDataElementForEditModeFinished());
  202.            
  203.             configurazioneBean.updateConfigurazione(configurazione);
  204.             ServletUtils.saveConfigurazioneBeanIntoSession(request, session, configurazioneBean, configurazioneBean.getId());

  205.             dati = porteDelegateHelper.addPropertiesConfigToDati(tipoOperazione,dati, configName, configurazioneBean);

  206.             dati = porteDelegateHelper.addHiddenFieldsToDati(tipoOperazione, id, idsogg, null, idAsps,
  207.                     idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);
  208.            
  209.             // Set First Time == false
  210.             porteDelegateHelper.addToDatiFirstTimeDisabled(dati,CostantiControlStation.PARAMETRO_CONTROLLO_FIRST_TIME);
  211.            
  212.             pd.setDati(dati);
  213.            
  214.             pd.setMessage(CostantiControlStation.LABEL_AGGIORNAMENTO_CONFIGURAZIONE_PROPERTIES_EFFETTUATO_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);

  215.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  216.            
  217.             // Forward control to the specified success URI
  218.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_PROPERTIES_CONFIG, ForwardParams.OTHER(""));
  219.         } catch (Exception e) {
  220.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  221.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_PROPERTIES_CONFIG,
  222.                     ForwardParams.OTHER(""));
  223.         }  
  224.     }
  225. }