PorteDelegateProprietaAutenticazioneAdd.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 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.PortaDelegata;
  32. import org.openspcoop2.core.config.Proprieta;
  33. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  34. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.lib.mvc.DataElement;
  37. import org.openspcoop2.web.lib.mvc.ForwardParams;
  38. import org.openspcoop2.web.lib.mvc.GeneralData;
  39. import org.openspcoop2.web.lib.mvc.PageData;
  40. import org.openspcoop2.web.lib.mvc.Parameter;
  41. import org.openspcoop2.web.lib.mvc.ServletUtils;
  42. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  43. /**
  44.  * PorteDelegateProprietaAutenticazioneAdd
  45.  *
  46.  * @author Andrea Poli (apoli@link.it)
  47.  * @author Giuliano Pintori (pintori@link.it)
  48.  * @author $Author$
  49.  * @version $Rev$, $Date$
  50.  *
  51.  */
  52. public final class PorteDelegateProprietaAutenticazioneAdd extends Action {

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

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

  56.         // Inizializzo PageData
  57.         PageData pd = new PageData();

  58.         GeneralHelper generalHelper = new GeneralHelper(session);

  59.         // Inizializzo GeneralData
  60.         GeneralData gd = generalHelper.initGeneralData(request);
  61.  
  62.         try {
  63.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  64.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  65.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  66.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  67.             String idPorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  68.             int idInt = Integer.parseInt(idPorta);
  69.             String nome = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME);
  70.             String valore = porteDelegateHelper.getLockedParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_VALORE, false);
  71.             String idSoggFruitore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  72.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  73.             if(idAsps == null)
  74.                 idAsps = "";
  75.             String idFruizione= porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  76.             if(idFruizione == null)
  77.                 idFruizione = "";
  78.            
  79.             // Wrap value
  80.             valore = porteDelegateHelper.wrapValoreProprieta(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_VALORE, valore);
  81.            
  82.             // Preparo il menu
  83.             porteDelegateHelper.makeMenu();

  84.             // Prendo nome, tipo e pdd del soggetto
  85.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();

  86.             // Prendo nome della porta applicativa
  87.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);
  88.             String idporta = pde.getNome();
  89.            
  90.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, "" + pde.getId());
  91.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, pde.getIdSoggetto() + "");
  92.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  93.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  94.             Parameter[] urlParms = { pId,pIdSoggetto,pIdAsps,pIdFrizione };
  95.            
  96.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idSoggFruitore, idAsps, idFruizione);
  97.            
  98.             String labelPerPorta = null;
  99.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  100.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  101.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CONTROLLO_ACCESSI_CONFIG_DI,
  102.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CONTROLLO_ACCESSI,
  103.                         pde);
  104.             }
  105.             else {
  106.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CONTROLLO_ACCESSI_CONFIG_DI+idporta;
  107.             }
  108.            
  109.             lstParam.add(new Parameter(labelPerPorta, PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_CONTROLLO_ACCESSI,
  110.                     new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, "" + pde.getId()),
  111.                     new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME_PORTA, pde.getNome()),
  112.                     new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, pde.getIdSoggetto() + ""),
  113.                     pIdAsps, new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione+ "")));
  114.            
  115.             String labelPagLista = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_AUTENTICAZIONE_PROPRIETA;
  116.            
  117.             lstParam.add(new Parameter(labelPagLista,
  118.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_AUTENTICAZIONE_CUSTOM_PROPERTIES_LIST,urlParms));
  119.             lstParam.add(ServletUtils.getParameterAggiungi());
  120.            
  121.             // Se nome = null, devo visualizzare la pagina per l'inserimento
  122.             // dati
  123.             if (porteDelegateHelper.isEditModeInProgress()) {
  124.                 // setto la barra del titolo
  125.                 ServletUtils.setPageDataTitle(pd, lstParam);

  126.                 // preparo i campi
  127.                 List<DataElement> dati = new ArrayList<>();
  128.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  129.                 dati = porteDelegateHelper.addProprietaAutenticazioneCustomToDati(dati, TipoOperazione.ADD, nome ,valore);

  130.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idSoggFruitore,  null,idAsps,
  131.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  132.                 pd.setDati(dati);

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

  134.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AUTENTICAZIONE_CUSTOM_PROPERTIES,
  135.                         ForwardParams.ADD());
  136.             }

  137.             // Controlli sui campi immessi
  138.             boolean isOk = porteDelegateHelper.proprietaAutenticazioneCheckData(TipoOperazione.ADD, idPorta, nome, valore);
  139.             if (!isOk) {
  140.                 // setto la barra del titolo
  141.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  144.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  145.                
  146.                 dati = porteDelegateHelper.addProprietaAutenticazioneCustomToDati(dati, TipoOperazione.ADD, nome ,valore);

  147.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idSoggFruitore,  null,idAsps,
  148.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  149.                 pd.setDati(dati);

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

  151.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AUTENTICAZIONE_CUSTOM_PROPERTIES,
  152.                         ForwardParams.ADD());
  153.             }

  154.             // Inserisco la property della porta applicativa nel db
  155.             Proprieta ssp = new Proprieta();
  156.             ssp.setNome(nome);
  157.             ssp.setValore(valore);
  158.             pde.addProprietaAutenticazione(ssp);

  159.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  160.            
  161.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), pde);

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

  164.             int idLista = Liste.PORTE_DELEGATE_PROPRIETA_AUTENTICAZIONE;

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

  166.             List<Proprieta> lista = porteDelegateCore.porteDelegateAutenticazioneCustomPropList(Integer.parseInt(idPorta), ricerca);

  167.             porteDelegateHelper.preparePorteDelegateAutenticazioneCustomPropList(idporta, ricerca, lista);

  168.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  169.             // Forward control to the specified success URI
  170.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AUTENTICAZIONE_CUSTOM_PROPERTIES,
  171.                     ForwardParams.ADD());
  172.         } catch (Exception e) {
  173.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  174.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AUTENTICAZIONE_CUSTOM_PROPERTIES,
  175.                     ForwardParams.ADD());
  176.         }  
  177.     }

  178.    
  179. }