ServiziApplicativiCredenzialiDel.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.sa;

  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.config.ServizioApplicativo;
  31. import org.openspcoop2.core.id.IDServizioApplicativo;
  32. import org.openspcoop2.core.id.IDSoggetto;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.core.Utilities;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriCostanti;
  37. import org.openspcoop2.web.lib.mvc.Costanti;
  38. import org.openspcoop2.web.lib.mvc.ForwardParams;
  39. import org.openspcoop2.web.lib.mvc.GeneralData;
  40. import org.openspcoop2.web.lib.mvc.PageData;
  41. import org.openspcoop2.web.lib.mvc.ServletUtils;

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

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

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

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

  57.         GeneralHelper generalHelper = new GeneralHelper(session);

  58.         // Inizializzo GeneralData
  59.         GeneralData gd = generalHelper.initGeneralData(request);
  60.        
  61.         try {
  62.             ServiziApplicativiHelper saHelper = new ServiziApplicativiHelper(request, pd, session);
  63.            
  64.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione
  65.             Integer parentSA = ServletUtils.getIntegerAttributeFromSession(ServiziApplicativiCostanti.ATTRIBUTO_SERVIZI_APPLICATIVI_PARENT, session, request);
  66.             if(parentSA == null) parentSA = ServiziApplicativiCostanti.ATTRIBUTO_SERVIZI_APPLICATIVI_PARENT_NONE;
  67.            
  68.             String id = saHelper.getParameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_ID);
  69.             int idServizioApplicativo = Integer.parseInt(id);
  70.            
  71.             String objToRemove = saHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  72.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);

  73.             ServiziApplicativiCore saCore = new ServiziApplicativiCore();
  74.            
  75.             ServizioApplicativo sa = saCore.getServizioApplicativo(idServizioApplicativo);
  76.             String oldNome = sa.getNome();
  77.             IDSoggetto oldIdSoggetto = new IDSoggetto(sa.getTipoSoggettoProprietario(), sa.getNomeSoggettoProprietario());
  78.             IDServizioApplicativo oldIdServizioApplicativo = new IDServizioApplicativo();
  79.             oldIdServizioApplicativo.setIdSoggettoProprietario(oldIdSoggetto);
  80.             oldIdServizioApplicativo.setNome(oldNome);
  81.            
  82.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  83.            
  84.             boolean isPrincipale = false;
  85.             for (int i = idsToRemove.size() -1; i >=0; i--) {
  86.                 int idEliminare = Integer.parseInt(idsToRemove.get(i));
  87.                 if(idEliminare != 0) {
  88.                     sa.getInvocazionePorta().removeCredenziali(Integer.parseInt(idsToRemove.get(i)));
  89.                 }
  90.                 else {
  91.                     isPrincipale = true;
  92.                 }
  93.             }

  94.             // Preparo il menu
  95.             saHelper.makeMenu();
  96.            
  97.             List<Object> listOggettiDaAggiornare = ServiziApplicativiUtilities.getOggettiDaAggiornare(saCore, oldIdServizioApplicativo, sa);
  98.             saCore.performUpdateOperation(userLogin, saHelper.smista(), listOggettiDaAggiornare.toArray());

  99.             sa = saCore.getServizioApplicativo(idServizioApplicativo);

  100.             saHelper.prepareServizioApplicativoCredenzialiList(sa, id);

  101.             if(isPrincipale) {
  102.                 pd.setMessage(ConnettoriCostanti.MESSAGGIO_NON_ELIMINABILE_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_ALIAS_CERTIFICATO_PRINCIPALE);
  103.             }
  104.            
  105.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  106.             return ServletUtils.getStrutsForward(mapping, ServiziApplicativiCostanti.OBJECT_NAME_SERVIZI_APPLICATIVI_CREDENZIALI, ForwardParams.DEL());
  107.            
  108.         } catch (Exception e) {
  109.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  110.                     ServiziApplicativiCostanti.OBJECT_NAME_SERVIZI_APPLICATIVI_CREDENZIALI, ForwardParams.DEL());
  111.         }
  112.     }
  113. }