PorteDelegateWSRequestChange.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.List;
  22. import java.util.ArrayList;

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

  26. import org.apache.struts.action.Action;
  27. import org.apache.struts.action.ActionForm;
  28. import org.apache.struts.action.ActionForward;
  29. import org.apache.struts.action.ActionMapping;
  30. import org.openspcoop2.core.commons.Liste;
  31. import org.openspcoop2.core.config.MessageSecurity;
  32. import org.openspcoop2.core.config.MessageSecurityFlow;
  33. import org.openspcoop2.core.config.MessageSecurityFlowParameter;
  34. import org.openspcoop2.core.config.PortaDelegata;
  35. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  36. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCostanti;
  39. import org.openspcoop2.web.lib.mvc.DataElement;
  40. import org.openspcoop2.web.lib.mvc.DataElementType;
  41. import org.openspcoop2.web.lib.mvc.ForwardParams;
  42. import org.openspcoop2.web.lib.mvc.GeneralData;
  43. import org.openspcoop2.web.lib.mvc.PageData;
  44. import org.openspcoop2.web.lib.mvc.Parameter;
  45. import org.openspcoop2.web.lib.mvc.ServletUtils;
  46. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  47. /**
  48.  * porteDelegateWSRequestChange
  49.  *
  50.  * @author Andrea Poli (apoli@link.it)
  51.  * @author Stefano Corallo (corallo@link.it)
  52.  * @author Sandra Giangrandi (sandra@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  *
  56.  */
  57. public final class PorteDelegateWSRequestChange 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.         try {
  67.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  68.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  69.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  70.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  71.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  72.             int idInt = Integer.parseInt(id);
  73.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  74.             String nome = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME);
  75.             String valore = porteDelegateHelper.getLockedParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_VALORE, false);
  76.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  77.             if(idAsps == null)
  78.                 idAsps = "";
  79.            
  80.             // Wrap value
  81.             valore = porteDelegateHelper.wrapValoreProprieta(valore);
  82.            
  83.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  84.             if(idFruizione == null)
  85.                 idFruizione = "";
  86.            
  87.             // Preparo il menu
  88.             porteDelegateHelper.makeMenu();

  89.             // Prendo il nome della porta applicativa
  90.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();

  91.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);
  92.             String idporta = pde.getNome();

  93.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  94.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  95.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  96.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  97.            
  98.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  99.            
  100.             Parameter[] urlParms = { pId,pIdSoggetto,pIdAsps,pIdFrizione };
  101.            
  102.             String labelPerPorta = null;
  103.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  104.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  105.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_CONFIG_DI,
  106.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY,
  107.                         pde);
  108.             }
  109.             else {
  110.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_CONFIG_DI+idporta;
  111.             }
  112.             lstParam.add(new Parameter(labelPerPorta,
  113.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MESSAGE_SECURITY, urlParms));
  114.            
  115.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_FLOW_DI, // + idporta,
  116.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST_LIST, urlParms  
  117.             ));
  118.            
  119.             lstParam.add(new Parameter(nome, null));
  120.            
  121.             if( porteDelegateHelper.isEditModeInProgress()){
  122.                 // setto la barra del titolo
  123.                 ServletUtils.setPageDataTitle(pd, lstParam);

  124.                 if(valore==null) {
  125.                     MessageSecurity ws = pde.getMessageSecurity();
  126.                     if(ws.getRequestFlow()!=null){
  127.                         List<MessageSecurityFlowParameter> wsrfpArray = ws.getRequestFlow().getParameterList();
  128.                         for (int i = 0; i < wsrfpArray.size(); i++) {
  129.                             MessageSecurityFlowParameter wsrfp = wsrfpArray.get(i);
  130.                             if (nome.equals(wsrfp.getNome())) {
  131.                                 valore = wsrfp.getValore();
  132.                                 break;
  133.                             }
  134.                         }
  135.                     }
  136.                 }

  137.                 // preparo i campi
  138.                 List<DataElement> dati = new ArrayList<>();
  139.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  140.                 DataElement dataElement = new DataElement();
  141.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  142.                 dataElement.setType(DataElementType.TITLE);
  143.                 dati.add(dataElement);
  144.                
  145.                 dati = porteDelegateHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.CHANGE,dati, nome, valore,false);

  146.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, idsogg, null, idAsps,
  147.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  148.                 pd.setDati(dati);

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

  150.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  151.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST, ForwardParams.CHANGE());
  152.             }

  153.             // Controlli sui campi immessi
  154.             boolean isOk = porteDelegateHelper.porteDelegateMessageSecurityRequestCheckData(TipoOperazione.CHANGE);
  155.             if (!isOk) {
  156.                 // setto la barra del titolo
  157.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  161.                 DataElement dataElement = new DataElement();
  162.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  163.                 dataElement.setType(DataElementType.TITLE);
  164.                 dati.add(dataElement);
  165.                
  166.                 dati = porteDelegateHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.CHANGE,dati, nome, valore,false);

  167.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, idsogg, null, idAsps,
  168.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  169.                 pd.setDati(dati);

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

  171.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  172.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST,
  173.                         ForwardParams.CHANGE());
  174.             }

  175.             // Modifico i dati del message-security della porta delegata nel db
  176.             MessageSecurity ws = pde.getMessageSecurity();
  177.             if(ws.getRequestFlow()!=null){
  178.                 List<MessageSecurityFlowParameter> wsrfpArray = ws.getRequestFlow().getParameterList();
  179.                 for (int i = 0; i < wsrfpArray.size(); i++) {
  180.                     MessageSecurityFlowParameter wsrfp = wsrfpArray.get(i);
  181.                     if (nome.equals(wsrfp.getNome())) {
  182.                         ws.getRequestFlow().removeParameter(i);
  183.                         break;
  184.                     }
  185.                 }
  186.             }

  187.             MessageSecurityFlowParameter wsrfp = new MessageSecurityFlowParameter();
  188.             wsrfp.setNome(nome);
  189.             wsrfp.setValore(valore);
  190.             if(ws.getRequestFlow()==null){
  191.                 ws.setRequestFlow(new MessageSecurityFlow());
  192.             }
  193.             ws.getRequestFlow().addParameter(wsrfp);
  194.             pde.setMessageSecurity(ws);

  195.             String userLogin = ServletUtils.getUserLoginFromSession(session);

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

  197.             // Preparo la lista
  198.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  199.             int idLista = Liste.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST;

  200.             ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);

  201.             List<MessageSecurityFlowParameter> lista = porteDelegateCore.porteDelegateMessageSecurityRequestList(Integer.parseInt(id), ricerca);

  202.             porteDelegateHelper.preparePorteDelegateMessageSecurityRequestList(idporta, ricerca, lista);

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

  204.             // Forward control to the specified success URI
  205.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST,
  206.                     ForwardParams.CHANGE());
  207.         } catch (Exception e) {
  208.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  209.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST,
  210.                     ForwardParams.CHANGE());
  211.         }
  212.     }
  213. }