ConfigurazionePolicyGestioneTokenDel.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.config;

  21. import java.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.List;

  24. import javax.servlet.http.HttpServletRequest;
  25. import javax.servlet.http.HttpServletResponse;
  26. import javax.servlet.http.HttpSession;

  27. import org.apache.struts.action.Action;
  28. import org.apache.struts.action.ActionForm;
  29. import org.apache.struts.action.ActionForward;
  30. import org.apache.struts.action.ActionMapping;
  31. import org.openspcoop2.core.commons.ErrorsHandlerCostant;
  32. import org.openspcoop2.core.commons.Liste;
  33. import org.openspcoop2.core.config.GenericProperties;
  34. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  35. import org.openspcoop2.core.id.IDGenericProperties;
  36. import org.openspcoop2.protocol.engine.utils.DBOggettiInUsoUtils;
  37. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  38. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  39. import org.openspcoop2.web.ctrlstat.core.Utilities;
  40. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  41. import org.openspcoop2.web.lib.mvc.Costanti;
  42. import org.openspcoop2.web.lib.mvc.ForwardParams;
  43. import org.openspcoop2.web.lib.mvc.GeneralData;
  44. import org.openspcoop2.web.lib.mvc.PageData;
  45. import org.openspcoop2.web.lib.mvc.ServletUtils;


  46. /**    
  47.  * ConfigurazionePolicyGestioneTokenDel
  48.  *
  49.  * @author Pintori Giuliano (pintori@link.it)
  50.  * @author $Author$
  51.  * @version $Rev$, $Date$
  52.  */
  53. public class ConfigurazionePolicyGestioneTokenDel extends Action {

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

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

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

  59.         GeneralHelper generalHelper = new GeneralHelper(session);

  60.         // Inizializzo GeneralData
  61.         GeneralData gd = generalHelper.initGeneralData(request);

  62.         String userLogin = ServletUtils.getUserLoginFromSession(session);  
  63.        
  64.         try {
  65.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);

  66.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  67.             // Preparo il menu
  68.             confHelper.makeMenu();

  69.             String infoType = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_TOKEN_POLICY_TIPOLOGIA_INFORMAZIONE);
  70.             if(infoType==null) {
  71.                 infoType = ServletUtils.getObjectFromSession(request, session, String.class, ConfigurazioneCostanti.PARAMETRO_TOKEN_POLICY_TIPOLOGIA_INFORMAZIONE);
  72.             }
  73.             boolean attributeAuthority = ConfigurazioneCostanti.isConfigurazioneAttributeAuthority(infoType);
  74.            
  75.             String objToRemove =confHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);

  76.             // Elimino i filtri dal db
  77.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);

  78.             StringBuilder inUsoMessage = new StringBuilder();
  79.             HashMap<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  80.             boolean normalizeObjectIds = !confHelper.isModalitaCompleta();
  81.             for (int i = 0; i < idsToRemove.size(); i++) {

  82.                 long idGenericProperties = Long.parseLong(idsToRemove.get(i));
  83.                 GenericProperties policy = confCore.getGenericProperties(idGenericProperties);
  84.                
  85.                 IDGenericProperties idGP = new IDGenericProperties();
  86.                 idGP.setNome(policy.getNome());
  87.                 idGP.setTipologia(policy.getTipologia());

  88.                 boolean gpInUso = confCore.isGenericPropertiesInUso(idGP,whereIsInUso,normalizeObjectIds);

  89.                 if (gpInUso) {
  90.                     inUsoMessage.append(DBOggettiInUsoUtils.toString(idGP, whereIsInUso, true, org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE));
  91.                     inUsoMessage.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);

  92.                 } else {
  93.                    
  94.                     if(CostantiConfigurazione.GENERIC_PROPERTIES_TOKEN_TIPOLOGIA_VALIDATION.equals(policy.getTipologia()) && confCore.isPolicyGestioneTokenPDND(policy.getNome())) {
  95.                         String object = "Token Policy";
  96.                         String intestazione = " non eliminabile perch&egrave; :";
  97.                         String separator =  org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE;
  98.                         String msg = object+" '"+idGP.getNome()+"'" + intestazione+separator;
  99.                         inUsoMessage.append(msg+" definisce la policy di validazione dei token ottenuti dalla PDND");
  100.                         inUsoMessage.append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  101.                     }
  102.                     else {
  103.                         confCore.performDeleteOperation(userLogin, confHelper.smista(), policy);
  104.                     }
  105.                 }

  106.             }// chiudo for

  107.             if (inUsoMessage.length()>0) {
  108.                 pd.setMessage(inUsoMessage.toString());
  109.             }
  110.            
  111.             // Preparo la lista
  112.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  113.             int idLista = attributeAuthority ? Liste.CONFIGURAZIONE_GESTIONE_ATTRIBUTE_AUTHORITY : Liste.CONFIGURAZIONE_GESTIONE_POLICY_TOKEN;
  114.            
  115.             ricerca = confHelper.checkSearchParameters(idLista, ricerca);

  116.             List<String> tipologie = new ArrayList<>();
  117.             if(attributeAuthority) {
  118.                 tipologie.add(ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TIPOLOGIA_ATTRIBUTE_AUTHORITY);
  119.             }
  120.             else {
  121.                 tipologie.add(ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TIPOLOGIA_GESTIONE_POLICY_TOKEN);
  122.                 tipologie.add(ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TIPOLOGIA_RETRIEVE_POLICY_TOKEN);
  123.             }
  124.            
  125.             List<GenericProperties> lista = confCore.gestorePolicyTokenList(idLista, tipologie, ricerca);
  126.            
  127.             confHelper.prepareGestorePolicyTokenList(ricerca, lista, idLista);

  128.             // salvo l'oggetto ricerca nella sessione
  129.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);
  130.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  131.             // Forward control to the specified success URI
  132.             return ServletUtils.getStrutsForward (mapping, ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_POLICY_GESTIONE_TOKEN, ForwardParams.DEL());
  133.         } catch (Exception e) {
  134.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  135.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_POLICY_GESTIONE_TOKEN, ForwardParams.DEL());
  136.         }  
  137.     }
  138. }