SoggettiCredenzialiDel.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.soggetti;

  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.registry.Soggetto;
  31. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  32. import org.openspcoop2.web.ctrlstat.core.Utilities;
  33. import org.openspcoop2.web.ctrlstat.dao.SoggettoCtrlStat;
  34. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  35. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriCostanti;
  36. import org.openspcoop2.web.lib.mvc.Costanti;
  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.ServletUtils;

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

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

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

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

  56.         GeneralHelper generalHelper = new GeneralHelper(session);

  57.         // Inizializzo GeneralData
  58.         GeneralData gd = generalHelper.initGeneralData(request);

  59.         try {
  60.             SoggettiHelper soggettiHelper = new SoggettiHelper(request, pd, session);
  61.            
  62.             String id = soggettiHelper.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID);
  63.             int idSogg = Integer.parseInt(id);
  64.             String nomeprov = soggettiHelper.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME);
  65.             String tipoprov = soggettiHelper.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO);
  66.            
  67.             // ctrlstatHelper ch = new ctrlstatHelper(request, pd, con, session);
  68.             String objToRemove = soggettiHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);

  69.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  70.             // // Elimino i soggetti dal db
  71.             // StringTokenizer objTok = new StringTokenizer(objToRemove, ",");
  72.             // int[] idToRemove = new int[objTok.countTokens()];
  73.             //
  74.             // int k = 0;
  75.             // while (objTok.hasMoreElements()) {
  76.             // idToRemove[k++] = Integer.parseInt(objTok.nextToken());
  77.             // }
  78.    
  79.             // String soggInUsoServizioApplicativo = "", soggInUsoServ = "",
  80.             // soggInUsoPorteDel = "";
  81.             // String nomeprov = "", tipoprov = "";
  82.            
  83.             soggettiHelper.makeMenu();
  84.    
  85.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  86.    
  87.             SoggettiCore soggettiCore = new SoggettiCore();
  88.            
  89.             Soggetto soggettoRegistry = null;
  90.             org.openspcoop2.core.config.Soggetto soggettoConfig = null;
  91.            
  92.             if(soggettiCore.isRegistroServiziLocale()){
  93.                 soggettoRegistry = soggettiCore.getSoggettoRegistro(idSogg);// core.getSoggettoRegistro(new
  94.                 // IDSoggetto(tipoprov,nomeprov));
  95.             }

  96.             soggettoConfig = soggettiCore.getSoggetto(idSogg);// core.getSoggetto(new
  97.            
  98.             boolean isPrincipale = false;
  99.             for (int i = idsToRemove.size() -1; i >=0; i--) {
  100.                 int idEliminare = Integer.parseInt(idsToRemove.get(i));
  101.                 if(idEliminare != 0) {
  102.                     if(soggettoRegistry!=null) {
  103.                         soggettoRegistry.removeCredenziali(Integer.parseInt(idsToRemove.get(i)));
  104.                     }
  105.                 }
  106.                 else {
  107.                     isPrincipale = true;
  108.                 }
  109.             }
  110.            
  111.             SoggettoCtrlStat sog = new SoggettoCtrlStat(soggettoRegistry, soggettoConfig);
  112.             sog.setOldNomeForUpdate(nomeprov);
  113.             sog.setOldTipoForUpdate(tipoprov);

  114.             // eseguo l'aggiornamento
  115.             List<Object> listOggettiDaAggiornare = SoggettiUtilities.getOggettiDaAggiornare(soggettiCore, nomeprov, nomeprov, tipoprov, tipoprov, sog);
  116.             soggettiCore.performUpdateOperation(userLogin, soggettiHelper.smista(), listOggettiDaAggiornare.toArray());
  117.            
  118.             soggettoRegistry = soggettiCore.getSoggettoRegistro(idSogg);
  119.            
  120.             soggettiHelper.prepareSoggettiCredenzialiList(soggettoRegistry, id);
  121.            
  122.             if(isPrincipale) {
  123.                 pd.setMessage(ConnettoriCostanti.MESSAGGIO_NON_ELIMINABILE_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_ALIAS_CERTIFICATO_PRINCIPALE);
  124.             }
  125.            
  126.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  127.            
  128.             return ServletUtils.getStrutsForward(mapping, SoggettiCostanti.OBJECT_NAME_SOGGETTI_CREDENZIALI, ForwardParams.DEL());
  129.            
  130.         } catch (Exception e) {
  131.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  132.                     SoggettiCostanti.OBJECT_NAME_SOGGETTI_CREDENZIALI, ForwardParams.DEL());
  133.         }
  134.     }
  135. }