ConfigurazionePolicyGestioneTokenList.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.List;
  23. import java.util.Properties;

  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.Liste;
  32. import org.openspcoop2.core.config.GenericProperties;
  33. import org.openspcoop2.core.mvc.properties.Config;
  34. import org.openspcoop2.core.mvc.properties.utils.ConfigManager;
  35. import org.openspcoop2.core.mvc.properties.utils.PropertiesSourceConfiguration;
  36. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  37. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  38. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  39. import org.openspcoop2.web.lib.mvc.ForwardParams;
  40. import org.openspcoop2.web.lib.mvc.GeneralData;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;

  43. /**    
  44.  * ConfigurazionePolicyGestioneTokenList
  45.  *
  46.  * @author Pintori Giuliano (pintori@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  */
  50. public class ConfigurazionePolicyGestioneTokenList 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.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);

  61.             ConfigurazioneCore confCore = new ConfigurazioneCore();
  62.            
  63.             // Preparo il menu
  64.             confHelper.makeMenu();

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

  67.             String infoType = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_TOKEN_POLICY_TIPOLOGIA_INFORMAZIONE);
  68.             String infoTypeSession = ServletUtils.getObjectFromSession(request, session, String.class, ConfigurazioneCostanti.PARAMETRO_TOKEN_POLICY_TIPOLOGIA_INFORMAZIONE);
  69.             if(infoType==null) {
  70.                 infoType = infoTypeSession;
  71.             }
  72.             else {
  73.                 ServletUtils.setObjectIntoSession(request, session, infoType, ConfigurazioneCostanti.PARAMETRO_TOKEN_POLICY_TIPOLOGIA_INFORMAZIONE);
  74.             }
  75.             boolean attributeAuthority = ConfigurazioneCostanti.isConfigurazioneAttributeAuthority(infoType);
  76.            
  77.             // reset di eventuali configurazioni salvate in sessione
  78.             Properties mapId = attributeAuthority ?
  79.                     confCore.getAttributeAuthorityTipologia() :
  80.                     confCore.getTokenPolicyTipologia();
  81.             if(mapId!=null && !mapId.isEmpty()) {
  82.                 PropertiesSourceConfiguration propertiesSourceConfiguration = attributeAuthority ?
  83.                         confCore.getAttributeAuthorityPropertiesSourceConfiguration() :
  84.                         confCore.getPolicyGestioneTokenPropertiesSourceConfiguration();
  85.                 ConfigManager configManager = ConfigManager.getinstance(ControlStationCore.getLog());
  86.                 configManager.leggiConfigurazioni(propertiesSourceConfiguration, true);
  87.                 for (Object oTipo : mapId.keySet()) {
  88.                     if(oTipo instanceof String) {
  89.                         String tipo = (String) oTipo;
  90.                         Config config = configManager.getConfigurazione(propertiesSourceConfiguration, tipo);
  91.                         ServletUtils.removeConfigurazioneBeanFromSession(request, session, config.getId());
  92.                     }
  93.                 }
  94.             }
  95.            
  96.             int idLista = attributeAuthority ? Liste.CONFIGURAZIONE_GESTIONE_ATTRIBUTE_AUTHORITY : Liste.CONFIGURAZIONE_GESTIONE_POLICY_TOKEN;
  97.            
  98.             ricerca = confHelper.checkSearchParameters(idLista, ricerca);

  99.             List<String> tipologie = new ArrayList<>();
  100.             if(attributeAuthority) {
  101.                 tipologie.add(ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TIPOLOGIA_ATTRIBUTE_AUTHORITY);
  102.             }
  103.             else {
  104.                 tipologie.add(ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TIPOLOGIA_GESTIONE_POLICY_TOKEN);
  105.                 tipologie.add(ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TIPOLOGIA_RETRIEVE_POLICY_TOKEN);
  106.             }
  107.            
  108.             List<GenericProperties> lista = confCore.gestorePolicyTokenList(idLista, tipologie, ricerca);
  109.            
  110.             confHelper.prepareGestorePolicyTokenList(ricerca, lista, idLista);
  111.            
  112.             // salvo l'oggetto ricerca nella sessione
  113.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);
  114.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  115.            
  116.             // Forward control to the specified success URI
  117.             return ServletUtils.getStrutsForward (mapping, ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_POLICY_GESTIONE_TOKEN,
  118.                     ForwardParams.LIST());
  119.         } catch (Exception e) {
  120.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  121.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_POLICY_GESTIONE_TOKEN, ForwardParams.LIST());
  122.         }  
  123.     }
  124.    
  125. }