PorteApplicativeWSRequestChange.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.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.PortaApplicativa;
  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.  * porteAppWSRequestChange
  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 PorteApplicativeWSRequestChange 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.         try {
  68.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  69.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  70.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  71.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  72.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  73.             int idInt = Integer.parseInt(idPorta);
  74.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  75.             String nome = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME);
  76.             String valore = porteApplicativeHelper.getLockedParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_VALORE, false);
  77.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  78.             if(idAsps == null)
  79.                 idAsps = "";
  80.            
  81.             // Wrap value
  82.             valore = porteApplicativeHelper.wrapValoreProprieta(valore);
  83.            
  84.             // Preparo il menu
  85.             porteApplicativeHelper.makeMenu();

  86.             // Prendo il nome della porta applicativa
  87.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  88.            
  89.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  90.             String idporta = pa.getNome();
  91.            
  92.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  93.            
  94.             String labelPerPorta = null;
  95.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  96.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  97.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_CONFIG_DI,
  98.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY,
  99.                         pa);
  100.             }
  101.             else {
  102.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_CONFIG_DI+idporta;
  103.             }
  104.             lstParam.add(new Parameter(labelPerPorta,
  105.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY,
  106.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  107.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  108.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)));
  109.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST_FLOW_DI, // + idporta,
  110.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST_LIST,
  111.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  112.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  113.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)));
  114.             lstParam.add(new Parameter(nome, null));


  115.             // Se valore = null, devo visualizzare la pagina per la
  116.             // modifica dati
  117.             if (porteApplicativeHelper.isEditModeInProgress()) {
  118.                
  119.                 // setto la barra del titolo
  120.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  134.                 // preparo i campi
  135.                 List<DataElement> dati = new ArrayList<>();
  136.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  137.                 DataElement dataElement = new DataElement();
  138.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  139.                 dataElement.setType(DataElementType.TITLE);
  140.                 dati.add(dataElement);
  141.                
  142.                 dati = porteApplicativeHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.CHANGE, dati, nome, valore, false);

  143.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg,idPorta, idAsps, dati);
  144.                
  145.                 pd.setDati(dati);

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

  147.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST,
  148.                         ForwardParams.CHANGE());
  149.             }

  150.             // Controlli sui campi immessi
  151.             boolean isOk = porteApplicativeHelper.porteAppMessageSecurityRequestCheckData(TipoOperazione.CHANGE);
  152.             if (!isOk) {
  153.                 // setto la barra del titolo
  154.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  157.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  158.                
  159.                 DataElement dataElement = new DataElement();
  160.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  161.                 dataElement.setType(DataElementType.TITLE);
  162.                 dati.add(dataElement);
  163.                
  164.                 dati = porteApplicativeHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.CHANGE, dati, nome, valore,  false);

  165.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg,idPorta, idAsps, dati);

  166.                 pd.setDati(dati);

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

  168.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST,
  169.                         ForwardParams.CHANGE());
  170.             }

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

  183.             MessageSecurityFlowParameter wsrfp = new MessageSecurityFlowParameter();
  184.             wsrfp.setNome(nome);
  185.             wsrfp.setValore(valore);
  186.             if(ws.getRequestFlow()==null){
  187.                 ws.setRequestFlow(new MessageSecurityFlow());
  188.             }
  189.             ws.getRequestFlow().addParameter(wsrfp);
  190.             pa.setMessageSecurity(ws);

  191.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  192.            
  193.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);

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

  196.             int idLista = Liste.PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST;

  197.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);

  198.             List<MessageSecurityFlowParameter> lista = porteApplicativeCore.porteAppMessageSecurityRequestList(idInt, ricerca);

  199.             porteApplicativeHelper.preparePorteAppMessageSecurityRequestList(idporta, ricerca, lista);

  200.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  201.             // Forward control to the specified success URI
  202.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST,
  203.                     ForwardParams.CHANGE());
  204.         } catch (Exception e) {
  205.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  206.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST,
  207.                     ForwardParams.CHANGE());
  208.         }
  209.     }
  210. }