PorteApplicativeProprietaAutenticazioneChange.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 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.PortaApplicativa;
  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.  * PorteApplicativeProprietaAutenticazioneAdd
  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 PorteApplicativeProprietaAutenticazioneChange 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.         try {
  62.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  63.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  64.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  65.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  66.            
  67.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  68.             int idInt = Integer.parseInt(idPorta);
  69.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  70.             String nome = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME);
  71.             String valore = porteApplicativeHelper.getLockedParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_VALORE, false);
  72.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  73.             if(idAsps == null)
  74.                 idAsps = "";
  75.            
  76.             // Wrap value
  77.             valore = porteApplicativeHelper.wrapValoreProprieta(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_VALORE, valore);
  78.            
  79.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();

  80.             // Preparo il menu
  81.             porteApplicativeHelper.makeMenu();

  82.             // Prendo nome della porta applicativa
  83.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  84.             String nomePorta = pa.getNome();
  85.            
  86.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  87.            
  88.             String labelPerPorta = null;
  89.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  90.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  91.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONTROLLO_ACCESSI_CONFIG_DI,
  92.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONTROLLO_ACCESSI,
  93.                         pa);
  94.             }
  95.             else {
  96.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONTROLLO_ACCESSI_CONFIG_DI+nomePorta;
  97.             }
  98.            
  99.             lstParam.add(new Parameter(labelPerPorta, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CONTROLLO_ACCESSI,
  100.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  101.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  102.                     new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)));
  103.            
  104.             String labelPagLista = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_AUTENTICAZIONE_PROPRIETA;
  105.            
  106.             lstParam.add(new Parameter(labelPagLista,
  107.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_AUTENTICAZIONE_CUSTOM_PROPERTIES_LIST,
  108.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  109.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  110.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)
  111.                     ));
  112.             lstParam.add(new Parameter(nome, null));

  113.             // Se servizioApplicativohid = null, devo visualizzare la pagina per
  114.             // l'inserimento dati
  115.             if (porteApplicativeHelper.isEditModeInProgress()) {
  116.                 // setto la barra del titolo
  117.                 ServletUtils.setPageDataTitle(pd, lstParam);
  118.                
  119.                 if(valore==null){
  120.                     for (int i = 0; i < pa.sizeProprietaAutenticazioneList(); i++) {
  121.                         Proprieta ssp = pa.getProprietaAutenticazione(i);
  122.                         if (nome.equals(ssp.getNome())) {
  123.                             if(ssp.getValore()!=null){
  124.                                 valore = ssp.getValore();
  125.                             }
  126.                             break;
  127.                         }
  128.                     }
  129.                 }

  130.                 // preparo i campi
  131.                 List<DataElement> dati = new ArrayList<>();
  132.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  133.                 dati = porteApplicativeHelper.addProprietaAutenticazioneCustomToDati(dati, TipoOperazione.CHANGE, nome, valore);
  134.                
  135.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta,idAsps,  dati);

  136.                 pd.setDati(dati);

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

  138.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AUTENTICAZIONE_CUSTOM_PROPERTIES,
  139.                         ForwardParams.CHANGE());
  140.             }

  141.             // Controlli sui campi immessi
  142.             boolean isOk = porteApplicativeHelper.proprietaAutenticazioneCheckData(TipoOperazione.CHANGE, idPorta, nome, valore);
  143.             if (!isOk) {
  144.                
  145.                 // setto la barra del titolo
  146.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  149.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  150.                
  151.                 dati = porteApplicativeHelper.addProprietaAutenticazioneCustomToDati(dati, TipoOperazione.CHANGE, nome, valore);
  152.                
  153.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta, idAsps, dati);

  154.                 pd.setDati(dati);

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

  156.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AUTENTICAZIONE_CUSTOM_PROPERTIES,
  157.                         ForwardParams.CHANGE());
  158.             }

  159.             // rimuovo la vecchia proprieta'
  160.             for (int i = 0; i < pa.sizeProprietaAutenticazioneList(); i++) {
  161.                 Proprieta ssp = pa.getProprietaAutenticazione(i);
  162.                 if (nome.equals(ssp.getNome())) {
  163.                     pa.removeProprietaAutenticazione(i);
  164.                     break;
  165.                 }
  166.             }
  167.            
  168.             // inserisco la nuova proprieta
  169.             Proprieta prop = new Proprieta();
  170.             prop.setNome(nome);
  171.             prop.setValore(valore);
  172.             pa.addProprietaAutenticazione(prop);

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

  174.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);

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

  177.             int idLista = Liste.PORTE_APPLICATIVE_PROPRIETA_AUTENTICAZIONE;

  178.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  179.            
  180.             List<Proprieta> lista = porteApplicativeCore.porteApplicativeAutenticazioneCustomPropList(idInt, ricerca);

  181.             porteApplicativeHelper.preparePorteApplicativeAutenticazioneCustomPropList(nomePorta, ricerca, lista);

  182.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  183.             // Forward control to the specified success URI
  184.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AUTENTICAZIONE_CUSTOM_PROPERTIES,
  185.                     ForwardParams.CHANGE());
  186.         } catch (Exception e) {
  187.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  188.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AUTENTICAZIONE_CUSTOM_PROPERTIES,
  189.                     ForwardParams.CHANGE());
  190.         }
  191.     }
  192.    
  193. }