PorteDelegateControlloAccessi.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.pd;

  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.commons.lang.StringUtils;
  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.config.AutorizzazioneRuoli;
  32. import org.openspcoop2.core.config.AutorizzazioneScope;
  33. import org.openspcoop2.core.config.GenericProperties;
  34. import org.openspcoop2.core.config.GestioneToken;
  35. import org.openspcoop2.core.config.GestioneTokenAutenticazione;
  36. import org.openspcoop2.core.config.PortaDelegata;
  37. import org.openspcoop2.core.config.PortaDelegataAutorizzazioneToken;
  38. import org.openspcoop2.core.config.Proprieta;
  39. import org.openspcoop2.core.config.constants.RuoloTipoMatch;
  40. import org.openspcoop2.core.config.constants.ScopeTipoMatch;
  41. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  42. import org.openspcoop2.core.config.constants.StatoFunzionalitaConWarning;
  43. import org.openspcoop2.core.config.constants.TipoAutenticazione;
  44. import org.openspcoop2.core.config.constants.TipoAutenticazionePrincipal;
  45. import org.openspcoop2.core.config.constants.TipoAutorizzazione;
  46. import org.openspcoop2.core.id.IDServizio;
  47. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  48. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  49. import org.openspcoop2.core.registry.constants.RuoloTipologia;
  50. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  51. import org.openspcoop2.message.constants.ServiceBinding;
  52. import org.openspcoop2.pdd.core.autorizzazione.CostantiAutorizzazione;
  53. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  54. import org.openspcoop2.utils.SortedMap;
  55. import org.openspcoop2.utils.properties.PropertiesUtilities;
  56. import org.openspcoop2.web.ctrlstat.core.AutorizzazioneUtilities;
  57. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  58. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  59. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  60. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  61. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  62. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCore;
  63. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCostanti;
  64. import org.openspcoop2.web.lib.mvc.BinaryParameter;
  65. import org.openspcoop2.web.lib.mvc.Costanti;
  66. import org.openspcoop2.web.lib.mvc.DataElement;
  67. import org.openspcoop2.web.lib.mvc.ForwardParams;
  68. import org.openspcoop2.web.lib.mvc.GeneralData;
  69. import org.openspcoop2.web.lib.mvc.PageData;
  70. import org.openspcoop2.web.lib.mvc.Parameter;
  71. import org.openspcoop2.web.lib.mvc.ServletUtils;
  72. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  73. /***
  74.  *
  75.  * PorteDelegateControlloAccessi
  76.  *
  77.  * @author Giuliano Pintori (pintori@link.it)
  78.  * @author $Author$
  79.  * @version $Rev$, $Date$
  80.  */
  81. public class PorteDelegateControlloAccessi extends Action {

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

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

  85.         // Inizializzo PageData
  86.         PageData pd = new PageData();

  87.         GeneralHelper generalHelper = new GeneralHelper(session);

  88.         // Inizializzo GeneralData
  89.         GeneralData gd = generalHelper.initGeneralData(request);
  90.        
  91.         boolean isPortaDelegata = true;

  92.         try {
  93.             Boolean contaListe = ServletUtils.getContaListeFromSession(session);
  94.             Boolean confPers = ServletUtils.getObjectFromSession(request, session, Boolean.class, CostantiControlStation.SESSION_PARAMETRO_GESTIONE_CONFIGURAZIONI_PERSONALIZZATE);

  95.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  96.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  97.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  98.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  99.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  100.             int idInt = Integer.parseInt(id);
  101.             String idSoggFruitore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  102.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  103.             if(idAsps == null)
  104.                 idAsps = "";
  105.             String idFruizione= porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  106.             if(idFruizione == null)
  107.                 idFruizione = "";
  108.            
  109.             String autenticazione = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE );
  110.             String autenticazioneOpzionale = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_OPZIONALE );
  111.             String autenticazionePrincipalTipo = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_PRINCIPAL_TIPO);
  112.             TipoAutenticazionePrincipal autenticazionePrincipal = TipoAutenticazionePrincipal.toEnumConstant(autenticazionePrincipalTipo, false);
  113.             List<String> autenticazioneParametroList = porteDelegateHelper.convertFromDataElementValue_parametroAutenticazioneList(autenticazione, autenticazionePrincipal);
  114.             String autenticazioneCustom = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_CUSTOM );
  115.             String autorizzazione = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE);
  116.             String autorizzazioneCustom = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_CUSTOM);
  117.            
  118.             String autorizzazioneAutenticati = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_AUTENTICAZIONE);
  119.             String autorizzazioneRuoli = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_RUOLI);
  120.             String autorizzazioneRuoliTipologia = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO_TIPOLOGIA);
  121.             String ruoloMatch = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO_MATCH);
  122.            
  123.             String autorizzazioneAutenticatiToken = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_AUTENTICAZIONE_TOKEN);
  124.             String autorizzazioneRuoliToken = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_RUOLI_TOKEN);
  125.             String autorizzazioneRuoliTipologiaToken = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO_TIPOLOGIA_TOKEN);
  126.             String autorizzazioneRuoliMatchToken = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO_MATCH_TOKEN);
  127.            
  128.             String autorizzazioneContenuti = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI);
  129.             String autorizzazioneContenutiStato = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_STATO);
  130.             String autorizzazioneContenutiProperties = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_PROPERTIES);


  131.             String applicaModificaS = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_APPLICA_MODIFICA);
  132.             boolean applicaModifica = ServletUtils.isCheckBoxEnabled(applicaModificaS);

  133.             String gestioneToken = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN);
  134.             String gestioneTokenPolicy = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_POLICY);
  135.             String gestioneTokenOpzionale = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_OPZIONALE);
  136.             String gestioneTokenValidazioneInput = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_VALIDAZIONE_INPUT);
  137.             String gestioneTokenIntrospection = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_INTROSPECTION);
  138.             String gestioneTokenUserInfo = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_USERINFO);
  139.             String gestioneTokenTokenForward = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_TOKEN_FORWARD);
  140.            
  141.             String autenticazioneTokenIssuer = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_ISSUER);
  142.             String autenticazioneTokenClientId = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_CLIENT_ID);
  143.             String autenticazioneTokenSubject = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_SUBJECT);
  144.             String autenticazioneTokenUsername = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_USERNAME);
  145.             String autenticazioneTokenEMail = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_MAIL);
  146.            
  147.             String autorizzazioneToken = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_TOKEN);
  148.             String autorizzazioneTokenOptions = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_TOKEN_OPTIONS);
  149.             String autorizzazioneScope = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_SCOPE);
  150.             String autorizzazioneScopeMatch = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_SCOPE_MATCH);
  151.            
  152.             BinaryParameter allegatoXacmlPolicy = porteDelegateHelper.getBinaryParameter(CostantiControlStation.PARAMETRO_DOCUMENTO_SICUREZZA_XACML_POLICY);
  153.            
  154.             String identificazioneAttributiStato = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_ATTRIBUTI_STATO);
  155.             String [] attributeAuthoritySelezionate = porteDelegateHelper.getParameterValues(CostantiControlStation.PARAMETRO_PORTE_ATTRIBUTI_AUTHORITY);
  156.             String attributeAuthorityAttributi = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_ATTRIBUTI_AUTHORITY_ATTRIBUTI);
  157.            
  158.             String idTab = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  159.             if(!porteDelegateHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  160.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  161.             }
  162.            
  163.             // Preparo il menu
  164.             porteDelegateHelper.makeMenu();

  165.             // Prendo il nome della porta
  166.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  167.             ConfigurazioneCore confCore = new ConfigurazioneCore(porteDelegateCore);
  168.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  169.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);

  170.             PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  171.             if(portaDelegata==null) {
  172.                 throw new Exception("PortaDelegata con id '"+idInt+"' non trovata");
  173.             }
  174.             String idporta = portaDelegata.getNome();
  175.            
  176.             List<String> ruoli = new ArrayList<>();
  177.             if(portaDelegata!=null && portaDelegata.getRuoli()!=null && portaDelegata.getRuoli().sizeRuoloList()>0){
  178.                 for (int i = 0; i < portaDelegata.getRuoli().sizeRuoloList(); i++) {
  179.                     ruoli.add(portaDelegata.getRuoli().getRuolo(i).getNome());
  180.                 }
  181.             }
  182.            
  183.             int numRuoli = 0;
  184.             if(portaDelegata.getRuoli()!=null){
  185.                 numRuoli = portaDelegata.getRuoli().sizeRuoloList();
  186.             }
  187.             int numScope = 0;
  188.             if(portaDelegata.getScope()!=null){
  189.                 numScope = portaDelegata.getScope().sizeScopeList();
  190.             }
  191.            
  192.             int sizeFruitori = 0;
  193.             if(portaDelegata.getServizioApplicativoList() !=null){
  194.                 sizeFruitori = portaDelegata.sizeServizioApplicativoList();
  195.             }
  196.            
  197.             int numAutenticatiToken = 0;
  198.             if(portaDelegata.getAutorizzazioneToken()!=null && portaDelegata.getAutorizzazioneToken().getServiziApplicativi()!=null){
  199.                 numAutenticatiToken = portaDelegata.getAutorizzazioneToken().getServiziApplicativi().sizeServizioApplicativoList();
  200.             }
  201.            
  202.             int numRuoliToken = 0;
  203.             if(portaDelegata.getAutorizzazioneToken()!=null && portaDelegata.getAutorizzazioneToken().getRuoli()!=null){
  204.                 numRuoliToken = portaDelegata.getAutorizzazioneToken().getRuoli().sizeRuoloList();
  205.             }
  206.            
  207.             int numAutenticazioneCustomPropertiesList = portaDelegata.sizeProprietaAutenticazioneList();
  208.             int numAutorizzazioneCustomPropertiesList = portaDelegata.sizeProprietaAutorizzazioneList();
  209.             int numAutorizzazioneContenutiCustomPropertiesList = portaDelegata.sizeProprietaAutorizzazioneContenutoList();
  210.             String oldAutorizzazioneContenuto = portaDelegata.getAutorizzazioneContenuto() ;
  211.             String oldAutorizzazioneContenutoStato = StatoFunzionalita.DISABILITATO.getValue();
  212.                    
  213.             boolean oldAutenticazioneCustom = portaDelegata.getAutenticazione() != null && !TipoAutenticazione.getValues().contains(portaDelegata.getAutenticazione());
  214.             boolean oldAutorizzazioneContenutiCustom = false;
  215.             if(oldAutorizzazioneContenuto != null) {
  216.                 if(oldAutorizzazioneContenuto.equals(CostantiAutorizzazione.AUTORIZZAZIONE_CONTENUTO_BUILT_IN)) {
  217.                     oldAutorizzazioneContenutoStato = StatoFunzionalita.ABILITATO.getValue();
  218.                 } else { // custom
  219.                     oldAutorizzazioneContenutiCustom = true;
  220.                     oldAutorizzazioneContenutoStato = CostantiControlStation.VALUE_PARAMETRO_PORTE_CONTROLLO_ACCESSI_AUTORIZZAZIONE_CONTENUTI_STATO_CUSTOM;
  221.                 }
  222.             }
  223.            
  224.             IDServizio idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(portaDelegata.getServizio().getTipo(), portaDelegata.getServizio().getNome(),
  225.                     portaDelegata.getSoggettoErogatore().getTipo(), portaDelegata.getSoggettoErogatore().getNome(),
  226.                     portaDelegata.getServizio().getVersione());
  227.             AccordoServizioParteSpecifica asps = apsCore.getServizio(idServizio,false);
  228.             AccordoServizioParteComuneSintetico aspc = apcCore.getAccordoServizioSintetico(porteDelegateHelper.getIDAccordoFromUri(asps.getAccordoServizioParteComune()));
  229.             ServiceBinding serviceBinding = porteDelegateCore.toMessageServiceBinding(aspc.getServiceBinding());

  230.             boolean isSupportatoAutenticazione = true; // sempre nelle porte delegate
  231.            
  232.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idSoggFruitore, idAsps, idFruizione);
  233.            
  234.             String labelPerPorta = null;
  235.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  236.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  237.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CONTROLLO_ACCESSI_CONFIG_DI,
  238.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CONTROLLO_ACCESSI,
  239.                         portaDelegata);
  240.             }
  241.             else {
  242.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CONTROLLO_ACCESSI_CONFIG_DI+idporta;
  243.             }
  244.            
  245.             lstParam.add(new Parameter(labelPerPorta,  null));
  246.            
  247.             // setto la barra del titolo
  248.             ServletUtils.setPageDataTitle(pd, lstParam);
  249.            
  250.             // imposto menu' contestuale
  251.             porteDelegateHelper.impostaComandiMenuContestualePD(idSoggFruitore, idAsps, idFruizione);
  252.            
  253.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  254.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idSoggFruitore);
  255.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  256.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  257.             Parameter pTokenAuthorization = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TOKEN_AUTHORIZATION, true+"");

  258.             Parameter[] urlParmsAutorizzazioneAutenticati = {  pId,pIdSoggetto,pIdAsps,pIdFrizione  };
  259.             Parameter urlAutorizzazioneAutenticatiParam= new Parameter("", PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_SERVIZIO_APPLICATIVO_LIST , urlParmsAutorizzazioneAutenticati);
  260.             String urlAutorizzazioneAutenticati = urlAutorizzazioneAutenticatiParam.getValue();
  261.            
  262.             Parameter[] urlParmsAutorizzazioneRuoli = {  pId,pIdSoggetto,pIdAsps,pIdFrizione };
  263.             Parameter urlAutorizzazioneRuoliParam = new Parameter("", PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_RUOLI_LIST , urlParmsAutorizzazioneRuoli);
  264.             String urlAutorizzazioneRuoli = urlAutorizzazioneRuoliParam.getValue();
  265.            
  266.             Parameter[] urlParmsAutorizzazioneAutenticatiToken = {  pId,pIdSoggetto,pIdAsps,pIdFrizione,pTokenAuthorization  };
  267.             Parameter urlAutorizzazioneAutenticatiParamToken= new Parameter("", PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_SERVIZIO_APPLICATIVO_LIST , urlParmsAutorizzazioneAutenticatiToken);
  268.             String urlAutorizzazioneAutenticatiToken = urlAutorizzazioneAutenticatiParamToken.getValue();
  269.            
  270.             Parameter[] urlParmsAutorizzazioneRuoliToken = {  pId,pIdSoggetto,pIdAsps,pIdFrizione,pTokenAuthorization };
  271.             Parameter urlAutorizzazioneRuoliParamToken = new Parameter("", PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_RUOLI_LIST , urlParmsAutorizzazioneRuoliToken);
  272.             String urlAutorizzazioneRuoliToken = urlAutorizzazioneRuoliParamToken.getValue();
  273.            
  274.             Parameter[] urlParmsAutorizzazioneScope = {  pId,pIdSoggetto,pIdAsps,pIdFrizione };
  275.             Parameter urlAutorizzazioneScopeParam = new Parameter("", PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_SCOPE_LIST , urlParmsAutorizzazioneScope);
  276.             String urlAutorizzazioneScope = urlAutorizzazioneScopeParam.getValue();
  277.            
  278.             Parameter[] urlParmsAutenticazioneCustomProperties = { pId,pIdSoggetto,pIdAsps,pIdFrizione };
  279.             Parameter urlAutenticazioneCustomPropertiesParam = new Parameter("", PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_AUTENTICAZIONE_CUSTOM_PROPERTIES_LIST , urlParmsAutenticazioneCustomProperties);
  280.             String urlAutenticazioneCustomProperties = urlAutenticazioneCustomPropertiesParam.getValue();
  281.            
  282.             Parameter[] urlParmsAutorizzazioneCustomProperties = {  pId,pIdSoggetto,pIdAsps,pIdFrizione };
  283.             Parameter urlAutorizzazioneCustomPropertiesParam = new Parameter("", PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_AUTORIZZAZIONE_CUSTOM_PROPERTIES_LIST , urlParmsAutorizzazioneCustomProperties);
  284.             String urlAutorizzazioneCustomProperties = urlAutorizzazioneCustomPropertiesParam.getValue();
  285.            
  286.             Parameter[] urlParmsAutorizzazioneContenutiCustomProperties = {  pId,pIdSoggetto,pIdAsps, pIdFrizione };
  287.             Parameter urlAutorizzazioneContenutiCustomPropertiesParam = new Parameter("", PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_CUSTOM_PROPERTIES_LIST , urlParmsAutorizzazioneContenutiCustomProperties);
  288.             String urlAutorizzazioneContenutiCustomPropertiesList = urlAutorizzazioneContenutiCustomPropertiesParam.getValue();
  289.            
  290.             String servletChiamante = PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_CONTROLLO_ACCESSI;
  291.            
  292.             // Token Policy
  293.             List<GenericProperties> gestorePolicyTokenList = confCore.gestorePolicyTokenList(null, ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TIPOLOGIA_GESTIONE_POLICY_TOKEN, null);
  294.             String [] policyLabels = new String[gestorePolicyTokenList.size() + 1];
  295.             String [] policyValues = new String[gestorePolicyTokenList.size() + 1];
  296.            
  297.             policyLabels[0] = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  298.             policyValues[0] = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  299.            
  300.             for (int i = 0; i < gestorePolicyTokenList.size(); i++) {
  301.             GenericProperties genericProperties = gestorePolicyTokenList.get(i);
  302.                 policyLabels[(i+1)] = genericProperties.getNome();
  303.                 policyValues[(i+1)] = genericProperties.getNome();
  304.             }
  305.            
  306.             String protocollo = ProtocolFactoryManager.getInstance().getProtocolByServiceType(asps.getTipo());
  307.            
  308.             // La XACML Policy, se definita nella porta delegata può solo essere cambiata, non annullata.
  309.             if(allegatoXacmlPolicy!=null && allegatoXacmlPolicy.getValue()==null &&
  310.                 portaDelegata.getXacmlPolicy()!=null && !"".equals(portaDelegata.getXacmlPolicy())) {
  311.                 allegatoXacmlPolicy.setValue(portaDelegata.getXacmlPolicy().getBytes());
  312.             }
  313.            
  314.             // AttributeAuthority
  315.             List<GenericProperties> attributeAuthorityList = confCore.gestorePolicyTokenList(null, ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TIPOLOGIA_ATTRIBUTE_AUTHORITY, null);
  316.             String [] attributeAuthorityLabels = new String[attributeAuthorityList.size()];
  317.             String [] attributeAuthorityValues = new String[attributeAuthorityList.size()];
  318.             for (int i = 0; i < attributeAuthorityList.size(); i++) {
  319.                 GenericProperties genericProperties = attributeAuthorityList.get(i);
  320.                 attributeAuthorityLabels[i] = genericProperties.getNome();
  321.                 attributeAuthorityValues[i] = genericProperties.getNome();
  322.             }
  323.            
  324.             // postback
  325.             String postBackElementName = porteDelegateHelper.getPostBackElementName();
  326.             if(postBackElementName != null) {
  327.                 if(postBackElementName.equals(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE) &&
  328.                     autenticazione.equals(CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTENTICAZIONE_CUSTOM)) {
  329.                     autenticazioneCustom = "";
  330.                 }
  331.                
  332.                 if(postBackElementName.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_STATO)) {
  333.                     if(autorizzazioneContenutiStato.equals(StatoFunzionalita.DISABILITATO.getValue()) || autorizzazioneContenutiStato.equals(CostantiControlStation.VALUE_PARAMETRO_PORTE_CONTROLLO_ACCESSI_AUTORIZZAZIONE_CONTENUTI_STATO_CUSTOM)) {
  334.                         autorizzazioneContenuti = "";
  335.                     }
  336.                     if(autorizzazioneContenutiStato.equals(StatoFunzionalita.ABILITATO.getValue())) {
  337.                         autorizzazioneContenuti = CostantiAutorizzazione.AUTORIZZAZIONE_CONTENUTO_BUILT_IN;
  338.                     }
  339.                 }
  340.             }
  341.            
  342.             if( porteDelegateHelper.isEditModeInProgress() && !applicaModifica){

  343.                 if (autenticazione == null) {
  344.                     autenticazione = portaDelegata.getAutenticazione();
  345.                     if (autenticazione != null &&
  346.                             !TipoAutenticazione.getValues().contains(autenticazione)) {
  347.                         autenticazioneCustom = autenticazione;
  348.                         autenticazione = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTENTICAZIONE_CUSTOM;
  349.                     }
  350.                    
  351.                     autenticazionePrincipal = porteDelegateCore.getTipoAutenticazionePrincipal(portaDelegata.getProprietaAutenticazioneList());
  352.                     autenticazioneParametroList = porteDelegateCore.getParametroAutenticazione(autenticazione, portaDelegata.getProprietaAutenticazioneList());
  353.                 }
  354.                 if(autenticazioneOpzionale==null){
  355.                     autenticazioneOpzionale = "";
  356.                     if(portaDelegata.getAutenticazioneOpzionale()!=null &&
  357.                         portaDelegata.getAutenticazioneOpzionale().equals(StatoFunzionalita.ABILITATO)) {
  358.                         autenticazioneOpzionale = Costanti.CHECK_BOX_ENABLED;
  359.                     }
  360.                 }
  361.                 if (autorizzazione == null) {
  362.                     if (portaDelegata.getAutorizzazione() != null &&
  363.                             !TipoAutorizzazione.getAllValues().contains(portaDelegata.getAutorizzazione())) {
  364.                         autorizzazioneCustom = portaDelegata.getAutorizzazione();
  365.                         autorizzazione = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTORIZZAZIONE_CUSTOM;
  366.                     }
  367.                     else{
  368.                         autorizzazione = AutorizzazioneUtilities.convertToStato(portaDelegata.getAutorizzazione());
  369.                         if(TipoAutorizzazione.isAuthenticationRequired(portaDelegata.getAutorizzazione()))
  370.                             autorizzazioneAutenticati = Costanti.CHECK_BOX_ENABLED;
  371.                         if(TipoAutorizzazione.isRolesRequired(portaDelegata.getAutorizzazione()))
  372.                             autorizzazioneRuoli = Costanti.CHECK_BOX_ENABLED;
  373.                         autorizzazioneRuoliTipologia = AutorizzazioneUtilities.convertToRuoloTipologia(portaDelegata.getAutorizzazione()).getValue();
  374.                     }
  375.                 }
  376.                
  377.                 if (ruoloMatch == null &&
  378.                     portaDelegata.getRuoli()!=null && portaDelegata.getRuoli().getMatch()!=null){
  379.                     ruoloMatch = portaDelegata.getRuoli().getMatch().getValue();
  380.                 }
  381.                
  382.                 if(autorizzazioneAutenticatiToken==null &&
  383.                     portaDelegata.getAutorizzazioneToken()!=null && portaDelegata.getAutorizzazioneToken().getAutorizzazioneApplicativi()!=null) {
  384.                     autorizzazioneAutenticatiToken = StatoFunzionalita.ABILITATO.equals(portaDelegata.getAutorizzazioneToken().getAutorizzazioneApplicativi()) ? Costanti.CHECK_BOX_ENABLED : Costanti.CHECK_BOX_DISABLED;
  385.                 }
  386.                
  387.                 if(autorizzazioneRuoliToken==null &&
  388.                     portaDelegata.getAutorizzazioneToken()!=null && portaDelegata.getAutorizzazioneToken().getAutorizzazioneRuoli()!=null) {
  389.                     autorizzazioneRuoliToken = StatoFunzionalita.ABILITATO.equals(portaDelegata.getAutorizzazioneToken().getAutorizzazioneRuoli()) ? Costanti.CHECK_BOX_ENABLED : Costanti.CHECK_BOX_DISABLED;
  390.                 }
  391.                 if(autorizzazioneRuoliTipologiaToken==null &&
  392.                     portaDelegata.getAutorizzazioneToken()!=null && portaDelegata.getAutorizzazioneToken().getTipologiaRuoli()!=null) {
  393.                     autorizzazioneRuoliTipologiaToken = portaDelegata.getAutorizzazioneToken().getTipologiaRuoli().getValue();
  394.                 }
  395.                 if (autorizzazioneRuoliMatchToken == null &&
  396.                     portaDelegata.getAutorizzazioneToken()!=null && portaDelegata.getAutorizzazioneToken().getRuoli()!=null && portaDelegata.getAutorizzazioneToken().getRuoli().getMatch()!=null){
  397.                     autorizzazioneRuoliMatchToken = portaDelegata.getAutorizzazioneToken().getRuoli().getMatch().getValue();
  398.                 }
  399.                
  400.                 if(autorizzazioneContenutiStato==null){
  401.                     autorizzazioneContenuti = portaDelegata.getAutorizzazioneContenuto();
  402.                    
  403.                     if(autorizzazioneContenuti == null || "".equals(autorizzazioneContenuti)) {
  404.                         autorizzazioneContenutiStato = StatoFunzionalita.DISABILITATO.getValue();
  405.                     } else if(autorizzazioneContenuti.equals(CostantiAutorizzazione.AUTORIZZAZIONE_CONTENUTO_BUILT_IN)) {
  406.                         autorizzazioneContenutiStato = StatoFunzionalita.ABILITATO.getValue();
  407.                         List<Proprieta> proprietaAutorizzazioneContenutoList = portaDelegata.getProprietaAutorizzazioneContenutoList();
  408.                         SortedMap<List<String>> map = porteDelegateCore.toSortedListMap(proprietaAutorizzazioneContenutoList);
  409.                         autorizzazioneContenutiProperties = PropertiesUtilities.convertSortedListMapToText(map, true);
  410.                     } else { // custom
  411.                         autorizzazioneContenutiStato = CostantiControlStation.VALUE_PARAMETRO_PORTE_CONTROLLO_ACCESSI_AUTORIZZAZIONE_CONTENUTI_STATO_CUSTOM;
  412.                     }
  413.                 }
  414.                
  415.                 if(gestioneToken == null) {
  416.                     if(portaDelegata.getGestioneToken() != null) {
  417.                         gestioneTokenPolicy = portaDelegata.getGestioneToken().getPolicy();
  418.                         if(gestioneTokenPolicy == null) {
  419.                             gestioneToken = StatoFunzionalita.DISABILITATO.getValue();
  420.                             gestioneTokenPolicy = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  421.                         } else {
  422.                             gestioneToken = StatoFunzionalita.ABILITATO.getValue();
  423.                         }
  424.                        
  425.                         StatoFunzionalita tokenOpzionale = portaDelegata.getGestioneToken().getTokenOpzionale();
  426.                         if(tokenOpzionale == null) {
  427.                             gestioneTokenOpzionale = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_OPZIONALE;
  428.                         }else {
  429.                             gestioneTokenOpzionale = tokenOpzionale.getValue();
  430.                         }
  431.                        
  432.                         StatoFunzionalitaConWarning validazione = portaDelegata.getGestioneToken().getValidazione();
  433.                         if(validazione == null) {
  434.                             gestioneTokenValidazioneInput = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_VALIDAZIONE_INPUT;
  435.                         }else {
  436.                             gestioneTokenValidazioneInput = validazione.getValue();
  437.                         }
  438.                        
  439.                         StatoFunzionalitaConWarning introspection = portaDelegata.getGestioneToken().getIntrospection();
  440.                         if(introspection == null) {
  441.                             gestioneTokenIntrospection = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_INTROSPECTION;
  442.                         }else {
  443.                             gestioneTokenIntrospection = introspection.getValue();
  444.                         }
  445.                        
  446.                         StatoFunzionalitaConWarning userinfo = portaDelegata.getGestioneToken().getUserInfo();
  447.                         if(userinfo == null) {
  448.                             gestioneTokenUserInfo = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_USER_INFO;
  449.                         }else {
  450.                             gestioneTokenUserInfo = userinfo.getValue();
  451.                         }
  452.                        
  453.                         StatoFunzionalita tokenForward = portaDelegata.getGestioneToken().getForward();
  454.                         if(tokenForward == null) {
  455.                             gestioneTokenTokenForward = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TOKEN_FORWARD;
  456.                         }else {
  457.                             gestioneTokenTokenForward = tokenForward.getValue();
  458.                         }
  459.                        
  460.                         autorizzazioneTokenOptions = portaDelegata.getGestioneToken().getOptions();
  461.                         if((autorizzazioneTokenOptions!=null && !"".equals(autorizzazioneTokenOptions))) {
  462.                             autorizzazioneToken = Costanti.CHECK_BOX_ENABLED;
  463.                         }
  464.                         else {
  465.                             autorizzazioneToken = Costanti.CHECK_BOX_DISABLED;
  466.                         }
  467.                        
  468.                         if(portaDelegata.getGestioneToken().getAutenticazione() != null) {
  469.                            
  470.                             StatoFunzionalita issuer = portaDelegata.getGestioneToken().getAutenticazione().getIssuer();
  471.                             if(issuer == null) {
  472.                                 autenticazioneTokenIssuer = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_ISSUER;
  473.                             }else {
  474.                                 autenticazioneTokenIssuer = issuer.getValue();
  475.                             }
  476.                            
  477.                             StatoFunzionalita clientId = portaDelegata.getGestioneToken().getAutenticazione().getClientId();
  478.                             if(clientId == null) {
  479.                                 autenticazioneTokenClientId = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_CLIENT_ID;
  480.                             }else {
  481.                                 autenticazioneTokenClientId = clientId.getValue();
  482.                             }
  483.                            
  484.                             StatoFunzionalita subject = portaDelegata.getGestioneToken().getAutenticazione().getSubject();
  485.                             if(subject == null) {
  486.                                 autenticazioneTokenSubject = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_SUBJECT;
  487.                             }else {
  488.                                 autenticazioneTokenSubject = subject.getValue();
  489.                             }
  490.                            
  491.                             StatoFunzionalita username = portaDelegata.getGestioneToken().getAutenticazione().getUsername();
  492.                             if(username == null) {
  493.                                 autenticazioneTokenUsername = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_USERNAME;
  494.                             }else {
  495.                                 autenticazioneTokenUsername = username.getValue();
  496.                             }
  497.                            
  498.                             StatoFunzionalita mailTmp = portaDelegata.getGestioneToken().getAutenticazione().getEmail();
  499.                             if(mailTmp == null) {
  500.                                 autenticazioneTokenEMail = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_EMAIL;
  501.                             }else {
  502.                                 autenticazioneTokenEMail = mailTmp.getValue();
  503.                             }
  504.                            
  505.                         }
  506.                         else {                          
  507.                             autenticazioneTokenIssuer = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_ISSUER;
  508.                             autenticazioneTokenClientId = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_CLIENT_ID;
  509.                             autenticazioneTokenSubject = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_SUBJECT;
  510.                             autenticazioneTokenUsername = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_USERNAME;
  511.                             autenticazioneTokenEMail = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_EMAIL;
  512.                         }
  513.                     }
  514.                     else {
  515.                         gestioneToken = StatoFunzionalita.DISABILITATO.getValue();
  516.                         gestioneTokenPolicy = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  517.                         gestioneTokenOpzionale = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_OPZIONALE;
  518.                        
  519.                         gestioneTokenValidazioneInput = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_VALIDAZIONE_INPUT;
  520.                         gestioneTokenIntrospection = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_INTROSPECTION;
  521.                         gestioneTokenUserInfo = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_USER_INFO;
  522.                         gestioneTokenTokenForward = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TOKEN_FORWARD;
  523.                        
  524.                         autenticazioneTokenIssuer = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_ISSUER;
  525.                         autenticazioneTokenClientId = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_CLIENT_ID;
  526.                         autenticazioneTokenSubject = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_SUBJECT;
  527.                         autenticazioneTokenUsername = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_USERNAME;
  528.                         autenticazioneTokenEMail = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_EMAIL;
  529.                     }
  530.                 }
  531.                
  532.                 if(autorizzazioneScope == null) {
  533.                     if(portaDelegata.getScope() != null) {
  534.                         autorizzazioneScope =  portaDelegata.getScope().getStato().equals(StatoFunzionalita.ABILITATO) ? Costanti.CHECK_BOX_ENABLED : "";
  535.                     } else {
  536.                         autorizzazioneScope = "";
  537.                     }
  538.                 }
  539.                
  540.                 if(autorizzazioneScopeMatch == null &&
  541.                     portaDelegata.getScope()!=null && portaDelegata.getScope().getMatch()!=null){
  542.                     autorizzazioneScopeMatch = portaDelegata.getScope().getMatch().getValue();
  543.                 }
  544.                
  545.                 if(identificazioneAttributiStato==null) {
  546.                     identificazioneAttributiStato = portaDelegata.sizeAttributeAuthorityList()>0 ? StatoFunzionalita.ABILITATO.getValue() : StatoFunzionalita.DISABILITATO.getValue();
  547.                     if(portaDelegata.sizeAttributeAuthorityList()>0) {
  548.                         attributeAuthoritySelezionate = porteDelegateCore.buildAuthorityArrayString(portaDelegata.getAttributeAuthorityList());
  549.                         attributeAuthorityAttributi = porteDelegateCore.buildAttributesStringFromAuthority(portaDelegata.getAttributeAuthorityList());
  550.                     }
  551.                 }

  552.                 // preparo i campi
  553.                 List<DataElement> dati = new ArrayList<>();
  554.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  555.                 porteDelegateHelper.controlloAccessiGestioneToken(dati, TipoOperazione.OTHER, gestioneToken, policyLabels, policyValues,
  556.                         gestioneTokenPolicy,gestioneTokenOpzionale,
  557.                         gestioneTokenValidazioneInput, gestioneTokenIntrospection, gestioneTokenUserInfo, gestioneTokenTokenForward, portaDelegata,protocollo,isPortaDelegata,
  558.                         false);
  559.                
  560.                 porteDelegateHelper.controlloAccessiAutenticazione(dati, TipoOperazione.OTHER, servletChiamante,portaDelegata,protocollo,
  561.                         autenticazione, autenticazioneCustom, autenticazioneOpzionale, autenticazionePrincipal, autenticazioneParametroList, confPers, isSupportatoAutenticazione,isPortaDelegata,
  562.                         gestioneToken, gestioneTokenPolicy, autenticazioneTokenIssuer, autenticazioneTokenClientId, autenticazioneTokenSubject, autenticazioneTokenUsername, autenticazioneTokenEMail,
  563.                         oldAutenticazioneCustom, urlAutenticazioneCustomProperties, numAutenticazioneCustomPropertiesList,
  564.                         false, false);
  565.                
  566.                 // Tipo operazione = CHANGE per evitare di aggiungere if, questa e' a tutti gli effetti una servlet di CHANGE
  567.                 porteDelegateHelper.controlloAccessiAutorizzazione(dati, TipoOperazione.CHANGE, servletChiamante,portaDelegata,protocollo,
  568.                         autenticazione, autenticazioneCustom,
  569.                         autorizzazione, autorizzazioneCustom,
  570.                         autorizzazioneAutenticati, urlAutorizzazioneAutenticati, sizeFruitori, null, null,
  571.                         autorizzazioneRuoli,  urlAutorizzazioneRuoli, numRuoli, null,
  572.                         autorizzazioneRuoliTipologia, ruoloMatch,
  573.                         confPers, isSupportatoAutenticazione, contaListe, isPortaDelegata, false,autorizzazioneScope,urlAutorizzazioneScope,numScope,null,autorizzazioneScopeMatch,
  574.                         gestioneToken, gestioneTokenPolicy,
  575.                         autorizzazioneToken, autorizzazioneTokenOptions,allegatoXacmlPolicy,
  576.                         null, 0,
  577.                         urlAutorizzazioneCustomProperties, numAutorizzazioneCustomPropertiesList,
  578.                         identificazioneAttributiStato, attributeAuthorityLabels, attributeAuthorityValues, attributeAuthoritySelezionate, attributeAuthorityAttributi,
  579.                         autorizzazioneAutenticatiToken, urlAutorizzazioneAutenticatiToken, numAutenticatiToken,
  580.                         autorizzazioneRuoliToken,  urlAutorizzazioneRuoliToken, numRuoliToken, autorizzazioneRuoliTipologiaToken, autorizzazioneRuoliMatchToken
  581.                         );
  582.                
  583.                 porteDelegateHelper.controlloAccessiAutorizzazioneContenuti(dati, TipoOperazione.OTHER, true, portaDelegata,protocollo,
  584.                         autorizzazioneContenutiStato, autorizzazioneContenuti, autorizzazioneContenutiProperties, serviceBinding,
  585.                         oldAutorizzazioneContenutiCustom, urlAutorizzazioneContenutiCustomPropertiesList, numAutorizzazioneContenutiCustomPropertiesList,
  586.                         confPers);
  587.                
  588.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  589.                         idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);

  590.                 pd.setDati(dati);

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

  592.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  593.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CONTROLLO_ACCESSI, ForwardParams.OTHER(""));
  594.             }

  595.             // Controlli sui campi immessi
  596.             boolean isOk = porteDelegateHelper.controlloAccessiCheck(TipoOperazione.OTHER, autenticazione, autenticazioneOpzionale, autenticazionePrincipal, autenticazioneParametroList,  
  597.                     autorizzazione, autorizzazioneAutenticati, autorizzazioneRuoli,
  598.                     autorizzazioneRuoliTipologia, ruoloMatch,
  599.                      isSupportatoAutenticazione, isPortaDelegata, portaDelegata, ruoli,gestioneToken, gestioneTokenPolicy,
  600.                         gestioneTokenValidazioneInput, gestioneTokenIntrospection, gestioneTokenUserInfo, gestioneTokenTokenForward,
  601.                         autorizzazioneAutenticatiToken, autorizzazioneRuoliToken,
  602.                         autorizzazioneToken,autorizzazioneTokenOptions,
  603.                         autorizzazioneScope,autorizzazioneScopeMatch,allegatoXacmlPolicy,
  604.                         autorizzazioneContenutiStato, autorizzazioneContenuti, autorizzazioneContenutiProperties,
  605.                         protocollo,
  606.                         identificazioneAttributiStato, attributeAuthoritySelezionate, attributeAuthorityAttributi);
  607.            
  608.             if (!isOk) {
  609.                 // preparo i campi
  610.                 List<DataElement> dati = new ArrayList<>();

  611.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  612.                
  613.                 porteDelegateHelper.controlloAccessiGestioneToken(dati, TipoOperazione.OTHER, gestioneToken, policyLabels, policyValues,
  614.                         gestioneTokenPolicy, gestioneTokenOpzionale,
  615.                         gestioneTokenValidazioneInput, gestioneTokenIntrospection, gestioneTokenUserInfo, gestioneTokenTokenForward, portaDelegata,protocollo,isPortaDelegata,
  616.                         false);
  617.                
  618.                 porteDelegateHelper.controlloAccessiAutenticazione(dati, TipoOperazione.OTHER, servletChiamante,portaDelegata,protocollo,
  619.                         autenticazione, autenticazioneCustom, autenticazioneOpzionale, autenticazionePrincipal, autenticazioneParametroList, confPers, isSupportatoAutenticazione,isPortaDelegata,
  620.                         gestioneToken, gestioneTokenPolicy, autenticazioneTokenIssuer, autenticazioneTokenClientId, autenticazioneTokenSubject, autenticazioneTokenUsername, autenticazioneTokenEMail,
  621.                         oldAutenticazioneCustom, urlAutenticazioneCustomProperties, numAutenticazioneCustomPropertiesList,
  622.                         false, false);
  623.                
  624.                 // Tipo operazione = CHANGE per evitare di aggiungere if, questa e' a tutti gli effetti una servlet di CHANGE
  625.                 porteDelegateHelper.controlloAccessiAutorizzazione(dati, TipoOperazione.CHANGE, servletChiamante,portaDelegata,protocollo,
  626.                         autenticazione, autenticazioneCustom,
  627.                         autorizzazione, autorizzazioneCustom,
  628.                         autorizzazioneAutenticati, urlAutorizzazioneAutenticati, sizeFruitori, null, null,
  629.                         autorizzazioneRuoli,  urlAutorizzazioneRuoli, numRuoli, null,
  630.                         autorizzazioneRuoliTipologia, ruoloMatch,
  631.                         confPers, isSupportatoAutenticazione, contaListe, isPortaDelegata, false,autorizzazioneScope,urlAutorizzazioneScope,numScope,null,autorizzazioneScopeMatch,
  632.                         gestioneToken, gestioneTokenPolicy,
  633.                         autorizzazioneToken, autorizzazioneTokenOptions,allegatoXacmlPolicy,
  634.                         null, 0,
  635.                         urlAutorizzazioneCustomProperties, numAutorizzazioneCustomPropertiesList,
  636.                         identificazioneAttributiStato, attributeAuthorityLabels, attributeAuthorityValues, attributeAuthoritySelezionate, attributeAuthorityAttributi,
  637.                         autorizzazioneAutenticatiToken, urlAutorizzazioneAutenticatiToken, numAutenticatiToken,
  638.                         autorizzazioneRuoliToken,  urlAutorizzazioneRuoliToken, numRuoliToken, autorizzazioneRuoliTipologiaToken, autorizzazioneRuoliMatchToken);
  639.                
  640.                 porteDelegateHelper.controlloAccessiAutorizzazioneContenuti(dati, TipoOperazione.OTHER, true, portaDelegata,protocollo,
  641.                         autorizzazioneContenutiStato, autorizzazioneContenuti, autorizzazioneContenutiProperties, serviceBinding,
  642.                         oldAutorizzazioneContenutiCustom, urlAutorizzazioneContenutiCustomPropertiesList, numAutorizzazioneContenutiCustomPropertiesList,
  643.                         confPers);
  644.                
  645.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  646.                         idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);

  647.                 pd.setDati(dati);

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

  649.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  650.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CONTROLLO_ACCESSI,
  651.                         ForwardParams.OTHER(""));
  652.             }

  653.            
  654.             if (autenticazione == null || !autenticazione.equals(CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTENTICAZIONE_CUSTOM))
  655.                 portaDelegata.setAutenticazione(autenticazione);
  656.             else {
  657.                 portaDelegata.setAutenticazione(autenticazioneCustom);
  658.                
  659.                 if(!oldAutenticazioneCustom)
  660.                     portaDelegata.getProprietaAutenticazioneList().clear();
  661.             }
  662.             if(autenticazioneOpzionale != null){
  663.                 if(ServletUtils.isCheckBoxEnabled(autenticazioneOpzionale))
  664.                     portaDelegata.setAutenticazioneOpzionale(StatoFunzionalita.ABILITATO);
  665.                 else
  666.                     portaDelegata.setAutenticazioneOpzionale(StatoFunzionalita.DISABILITATO);
  667.             } else
  668.                 portaDelegata.setAutenticazioneOpzionale(null);
  669.             if (autenticazione == null || !autenticazione.equals(CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTENTICAZIONE_CUSTOM)) {
  670.                 portaDelegata.getProprietaAutenticazioneList().clear();
  671.                 List<Proprieta> proprietaAutenticazione = porteDelegateCore.convertToAutenticazioneProprieta(autenticazione, autenticazionePrincipal, autenticazioneParametroList);
  672.                 if(proprietaAutenticazione!=null && !proprietaAutenticazione.isEmpty()) {
  673.                     portaDelegata.getProprietaAutenticazioneList().addAll(proprietaAutenticazione);
  674.                 }
  675.             }
  676.            
  677.             if (autorizzazione == null || !autorizzazione.equals(CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTORIZZAZIONE_CUSTOM)) {
  678.                 portaDelegata.setAutorizzazione(AutorizzazioneUtilities.convertToTipoAutorizzazioneAsString(autorizzazione,
  679.                         ServletUtils.isCheckBoxEnabled(autorizzazioneAutenticati),
  680.                         ServletUtils.isCheckBoxEnabled(autorizzazioneRuoli),
  681.                         ServletUtils.isCheckBoxEnabled(autorizzazioneAutenticatiToken),
  682.                         ServletUtils.isCheckBoxEnabled(autorizzazioneRuoliToken),
  683.                         ServletUtils.isCheckBoxEnabled(autorizzazioneScope),
  684.                         autorizzazioneTokenOptions,
  685.                         RuoloTipologia.toEnumConstant(autorizzazioneRuoliTipologia)));
  686.                 portaDelegata.getProprietaAutorizzazioneList().clear();
  687.             } else {
  688.                 portaDelegata.setAutorizzazione(autorizzazioneCustom);
  689.             }
  690.            
  691.             if(autorizzazione != null && autorizzazione.equals(AutorizzazioneUtilities.STATO_XACML_POLICY) && allegatoXacmlPolicy.getValue() != null) {
  692.                 portaDelegata.setXacmlPolicy(new String(allegatoXacmlPolicy.getValue()));
  693.             } else {
  694.                 portaDelegata.setXacmlPolicy(null);
  695.             }
  696.            
  697.             if(ruoloMatch!=null && !"".equals(ruoloMatch)){
  698.                 RuoloTipoMatch tipoRuoloMatch = RuoloTipoMatch.toEnumConstant(ruoloMatch);
  699.                 if(tipoRuoloMatch!=null){
  700.                     if(portaDelegata.getRuoli()==null){
  701.                         portaDelegata.setRuoli(new AutorizzazioneRuoli());
  702.                     }
  703.                     portaDelegata.getRuoli().setMatch(tipoRuoloMatch);
  704.                 }
  705.             }
  706.            
  707.             if(ServletUtils.isCheckBoxEnabled(autorizzazioneAutenticatiToken ) ) {
  708.                 if(portaDelegata.getAutorizzazioneToken()==null) {
  709.                     portaDelegata.setAutorizzazioneToken(new PortaDelegataAutorizzazioneToken());
  710.                 }
  711.                 portaDelegata.getAutorizzazioneToken().setAutorizzazioneApplicativi(StatoFunzionalita.ABILITATO);
  712.             }
  713.             else {
  714.                 if(portaDelegata.getAutorizzazioneToken()!=null) {
  715.                     portaDelegata.getAutorizzazioneToken().setAutorizzazioneApplicativi(StatoFunzionalita.DISABILITATO);
  716.                     portaDelegata.getAutorizzazioneToken().setServiziApplicativi(null);
  717.                 }
  718.             }
  719.            
  720.             if(ServletUtils.isCheckBoxEnabled(autorizzazioneRuoliToken ) ) {
  721.                 if(portaDelegata.getAutorizzazioneToken()==null) {
  722.                     portaDelegata.setAutorizzazioneToken(new PortaDelegataAutorizzazioneToken());
  723.                 }
  724.                 portaDelegata.getAutorizzazioneToken().setAutorizzazioneRuoli(StatoFunzionalita.ABILITATO);
  725.                
  726.                 if(autorizzazioneRuoliMatchToken!=null && !"".equals(autorizzazioneRuoliMatchToken)){
  727.                     RuoloTipoMatch ruoloTipoMatch = RuoloTipoMatch.toEnumConstant(autorizzazioneRuoliMatchToken);
  728.                     if(ruoloTipoMatch!=null){
  729.                         if(portaDelegata.getAutorizzazioneToken().getRuoli()==null){
  730.                             portaDelegata.getAutorizzazioneToken().setRuoli(new AutorizzazioneRuoli());
  731.                         }
  732.                         portaDelegata.getAutorizzazioneToken().getRuoli().setMatch(ruoloTipoMatch);
  733.                     }
  734.                     else {
  735.                         if(portaDelegata.getAutorizzazioneToken().getRuoli()!=null){
  736.                             portaDelegata.getAutorizzazioneToken().getRuoli().setMatch(null);
  737.                         }
  738.                     }
  739.                 }
  740.                 else {
  741.                     if(portaDelegata.getAutorizzazioneToken().getRuoli()!=null){
  742.                         portaDelegata.getAutorizzazioneToken().getRuoli().setMatch(null);
  743.                     }
  744.                 }
  745.                
  746.                 if(autorizzazioneRuoliTipologiaToken!=null && !"".equals(autorizzazioneRuoliTipologiaToken)){
  747.                     org.openspcoop2.core.config.constants.RuoloTipologia ruoloTipologia = org.openspcoop2.core.config.constants.RuoloTipologia.toEnumConstant(autorizzazioneRuoliTipologiaToken);
  748.                     if(ruoloTipologia!=null){
  749.                         portaDelegata.getAutorizzazioneToken().setTipologiaRuoli(ruoloTipologia);
  750.                     }
  751.                     else {
  752.                         portaDelegata.getAutorizzazioneToken().setTipologiaRuoli(null);
  753.                     }
  754.                 }
  755.                 else {
  756.                     portaDelegata.getAutorizzazioneToken().setTipologiaRuoli(null);
  757.                 }
  758.             }
  759.             else {
  760.                 if(portaDelegata.getAutorizzazioneToken()!=null) {
  761.                     portaDelegata.getAutorizzazioneToken().setAutorizzazioneRuoli(StatoFunzionalita.DISABILITATO);
  762.                     portaDelegata.getAutorizzazioneToken().setRuoli(null);
  763.                 }
  764.             }
  765.            
  766.             if(ServletUtils.isCheckBoxEnabled(autorizzazioneScope )) {
  767.                 if(portaDelegata.getScope() == null)
  768.                     portaDelegata.setScope(new AutorizzazioneScope());
  769.                
  770.                 portaDelegata.getScope().setStato(StatoFunzionalita.ABILITATO);
  771.             }
  772.             else {
  773.                 portaDelegata.setScope(null);
  774.             }
  775.             if(autorizzazioneScopeMatch!=null && !"".equals(autorizzazioneScopeMatch)){
  776.                 ScopeTipoMatch scopeTipoMatch = ScopeTipoMatch.toEnumConstant(autorizzazioneScopeMatch);
  777.                 if(scopeTipoMatch!=null){
  778.                     if(portaDelegata.getScope()==null){
  779.                         portaDelegata.setScope(new AutorizzazioneScope());
  780.                     }
  781.                     portaDelegata.getScope().setMatch(scopeTipoMatch);
  782.                 }
  783.             }
  784.            
  785.             if(autorizzazioneContenutiStato.equals(StatoFunzionalita.DISABILITATO.getValue())) {
  786.                 portaDelegata.setAutorizzazioneContenuto(null);
  787.                 portaDelegata.getProprietaAutorizzazioneContenutoList().clear();
  788.             } else if(autorizzazioneContenutiStato.equals(StatoFunzionalita.ABILITATO.getValue())) {
  789.                 portaDelegata.setAutorizzazioneContenuto(CostantiAutorizzazione.AUTORIZZAZIONE_CONTENUTO_BUILT_IN);
  790.                 portaDelegata.getProprietaAutorizzazioneContenutoList().clear();
  791.                 // Fix: non rispettava l'ordine
  792.                 SortedMap<List<String>> convertTextToProperties = PropertiesUtilities.convertTextToSortedListMap(autorizzazioneContenutiProperties, true);
  793.                 porteDelegateCore.addFromSortedListMap(portaDelegata.getProprietaAutorizzazioneContenutoList(), convertTextToProperties);
  794.             } else {
  795.                 portaDelegata.setAutorizzazioneContenuto(autorizzazioneContenuti);
  796.                 if(!autorizzazioneContenutiStato.equals(oldAutorizzazioneContenutoStato))
  797.                     portaDelegata.getProprietaAutorizzazioneContenutoList().clear();
  798.             }
  799.            
  800.             if(portaDelegata.getGestioneToken() == null)
  801.                 portaDelegata.setGestioneToken(new GestioneToken());
  802.            
  803.             if(gestioneToken.equals(StatoFunzionalita.ABILITATO.getValue())) {
  804.                 portaDelegata.getGestioneToken().setPolicy(gestioneTokenPolicy);
  805.                 if(ServletUtils.isCheckBoxEnabled(gestioneTokenOpzionale)) {
  806.                     portaDelegata.getGestioneToken().setTokenOpzionale(StatoFunzionalita.ABILITATO);
  807.                 }
  808.                 else {
  809.                     portaDelegata.getGestioneToken().setTokenOpzionale(StatoFunzionalita.DISABILITATO);
  810.                 }
  811.                 portaDelegata.getGestioneToken().setValidazione(StatoFunzionalitaConWarning.toEnumConstant(gestioneTokenValidazioneInput));
  812.                 portaDelegata.getGestioneToken().setIntrospection(StatoFunzionalitaConWarning.toEnumConstant(gestioneTokenIntrospection));
  813.                 portaDelegata.getGestioneToken().setUserInfo(StatoFunzionalitaConWarning.toEnumConstant(gestioneTokenUserInfo));
  814.                 portaDelegata.getGestioneToken().setForward(StatoFunzionalita.toEnumConstant(gestioneTokenTokenForward));
  815.                 portaDelegata.getGestioneToken().setOptions(autorizzazioneTokenOptions);
  816.                 if(portaDelegata.getGestioneToken().getAutenticazione()==null) {
  817.                     portaDelegata.getGestioneToken().setAutenticazione(new GestioneTokenAutenticazione());
  818.                 }
  819.                 portaDelegata.getGestioneToken().getAutenticazione().setIssuer(ServletUtils.isCheckBoxEnabled(autenticazioneTokenIssuer) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenIssuer));
  820.                 portaDelegata.getGestioneToken().getAutenticazione().setClientId(ServletUtils.isCheckBoxEnabled(autenticazioneTokenClientId) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenClientId));
  821.                 portaDelegata.getGestioneToken().getAutenticazione().setSubject(ServletUtils.isCheckBoxEnabled(autenticazioneTokenSubject) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenSubject));
  822.                 portaDelegata.getGestioneToken().getAutenticazione().setUsername(ServletUtils.isCheckBoxEnabled(autenticazioneTokenUsername) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenUsername));
  823.                 portaDelegata.getGestioneToken().getAutenticazione().setEmail(ServletUtils.isCheckBoxEnabled(autenticazioneTokenEMail) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenEMail));
  824.             } else {
  825.                 portaDelegata.getGestioneToken().setPolicy(null);
  826.                 portaDelegata.getGestioneToken().setTokenOpzionale(StatoFunzionalita.DISABILITATO);
  827.                 portaDelegata.getGestioneToken().setValidazione(StatoFunzionalitaConWarning.DISABILITATO);
  828.                 portaDelegata.getGestioneToken().setIntrospection(StatoFunzionalitaConWarning.DISABILITATO);
  829.                 portaDelegata.getGestioneToken().setUserInfo(StatoFunzionalitaConWarning.DISABILITATO);
  830.                 portaDelegata.getGestioneToken().setForward(StatoFunzionalita.DISABILITATO);
  831.                 portaDelegata.getGestioneToken().setOptions(null);
  832.                 if(portaDelegata.getGestioneToken().getAutenticazione()!=null) {
  833.                     portaDelegata.getGestioneToken().setAutenticazione(null);
  834.                 }
  835.             }
  836.            
  837.             while (portaDelegata.sizeAttributeAuthorityList()>0) {
  838.                 portaDelegata.removeAttributeAuthority(0);
  839.             }
  840.             if(StatoFunzionalita.ABILITATO.getValue().equals(identificazioneAttributiStato) && attributeAuthoritySelezionate!=null && attributeAuthoritySelezionate.length>0) {
  841.                 for (String aaName : attributeAuthoritySelezionate) {
  842.                     portaDelegata.addAttributeAuthority(porteDelegateCore.buildAttributeAuthority(attributeAuthoritySelezionate.length, aaName, attributeAuthorityAttributi));
  843.                 }
  844.             }
  845.            
  846.             String userLogin = ServletUtils.getUserLoginFromSession(session);

  847.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), portaDelegata);
  848.            
  849.             // cancello i file temporanei
  850.             porteDelegateHelper.deleteBinaryParameters(allegatoXacmlPolicy);
  851.            
  852.             // preparo i campi
  853.             List<DataElement> dati = new ArrayList<>();
  854.            
  855.             portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  856.             if(portaDelegata==null) {
  857.                 throw new Exception("PortaDelegata con id '"+idInt+"' non trovata");
  858.             }
  859.             idporta = portaDelegata.getNome();
  860.            
  861.             ruoli = new ArrayList<>();
  862.             if(portaDelegata!=null && portaDelegata.getRuoli()!=null && portaDelegata.getRuoli().sizeRuoloList()>0){
  863.                 for (int i = 0; i < portaDelegata.getRuoli().sizeRuoloList(); i++) {
  864.                     ruoli.add(portaDelegata.getRuoli().getRuolo(i).getNome());
  865.                 }
  866.             }
  867.            
  868.             numRuoli = 0;
  869.             if(portaDelegata.getRuoli()!=null){
  870.                 numRuoli = portaDelegata.getRuoli().sizeRuoloList();
  871.             }
  872.            
  873.             numScope = 0;
  874.             if(portaDelegata.getScope()!=null){
  875.                 numScope = portaDelegata.getScope().sizeScopeList();
  876.             }
  877.            
  878.             sizeFruitori = 0;
  879.             if(portaDelegata.getServizioApplicativoList() !=null){
  880.                 sizeFruitori = portaDelegata.sizeServizioApplicativoList();
  881.             }
  882.            
  883.             numAutenticatiToken = 0;
  884.             if(portaDelegata.getAutorizzazioneToken()!=null && portaDelegata.getAutorizzazioneToken().getServiziApplicativi()!=null){
  885.                 numAutenticatiToken = portaDelegata.getAutorizzazioneToken().getServiziApplicativi().sizeServizioApplicativoList();
  886.             }
  887.            
  888.             numRuoliToken = 0;
  889.             if(portaDelegata.getAutorizzazioneToken()!=null && portaDelegata.getAutorizzazioneToken().getRuoli()!=null){
  890.                 numRuoliToken = portaDelegata.getAutorizzazioneToken().getRuoli().sizeRuoloList();
  891.             }
  892.            
  893.             numAutenticazioneCustomPropertiesList = portaDelegata.sizeProprietaAutenticazioneList();
  894.             numAutorizzazioneCustomPropertiesList = portaDelegata.sizeProprietaAutorizzazioneList();
  895.             numAutorizzazioneContenutiCustomPropertiesList = portaDelegata.sizeProprietaAutorizzazioneContenutoList();
  896.             oldAutorizzazioneContenutiCustom = portaDelegata.getAutorizzazioneContenuto() != null && !portaDelegata.getAutorizzazioneContenuto().equals(CostantiAutorizzazione.AUTORIZZAZIONE_CONTENUTO_BUILT_IN);
  897.             oldAutenticazioneCustom = portaDelegata.getAutenticazione() != null && !TipoAutenticazione.getValues().contains(portaDelegata.getAutenticazione());
  898.            
  899.             if (autenticazione == null) {
  900.                 autenticazione = portaDelegata.getAutenticazione();
  901.                 if (autenticazione != null &&
  902.                         !TipoAutenticazione.getValues().contains(autenticazione)) {
  903.                     autenticazioneCustom = autenticazione;
  904.                     autenticazione = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTENTICAZIONE_CUSTOM;
  905.                 }
  906.                
  907.                 autenticazionePrincipal = porteDelegateCore.getTipoAutenticazionePrincipal(portaDelegata.getProprietaAutenticazioneList());
  908.                 autenticazioneParametroList = porteDelegateCore.getParametroAutenticazione(autenticazione, portaDelegata.getProprietaAutenticazioneList());
  909.             }
  910.             if(autenticazioneOpzionale==null){
  911.                 autenticazioneOpzionale = "";
  912.                 if(portaDelegata.getAutenticazioneOpzionale()!=null &&
  913.                     portaDelegata.getAutenticazioneOpzionale().equals(StatoFunzionalita.ABILITATO)) {
  914.                     autenticazioneOpzionale = Costanti.CHECK_BOX_ENABLED;
  915.                 }
  916.             }
  917.            
  918.             if (autorizzazione == null) {
  919.                 if (portaDelegata.getAutorizzazione() != null &&
  920.                         !TipoAutorizzazione.getAllValues().contains(portaDelegata.getAutorizzazione())) {
  921.                     autorizzazioneCustom = portaDelegata.getAutorizzazione();
  922.                     autorizzazione = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTORIZZAZIONE_CUSTOM;
  923.                 }
  924.                 else{
  925.                     autorizzazione = AutorizzazioneUtilities.convertToStato(portaDelegata.getAutorizzazione());
  926.                     if(TipoAutorizzazione.isAuthenticationRequired(portaDelegata.getAutorizzazione()))
  927.                         autorizzazioneAutenticati = Costanti.CHECK_BOX_ENABLED;
  928.                     if(TipoAutorizzazione.isRolesRequired(portaDelegata.getAutorizzazione()))
  929.                         autorizzazioneRuoli = Costanti.CHECK_BOX_ENABLED;
  930.                     autorizzazioneRuoliTipologia = AutorizzazioneUtilities.convertToRuoloTipologia(portaDelegata.getAutorizzazione()).getValue();
  931.                 }
  932.             }
  933.            
  934.             if (ruoloMatch == null &&
  935.                 portaDelegata.getRuoli()!=null && portaDelegata.getRuoli().getMatch()!=null){
  936.                 ruoloMatch = portaDelegata.getRuoli().getMatch().getValue();
  937.             }
  938.            
  939.             if(autorizzazioneAutenticatiToken==null &&
  940.                 portaDelegata.getAutorizzazioneToken()!=null && portaDelegata.getAutorizzazioneToken().getAutorizzazioneApplicativi()!=null) {
  941.                 autorizzazioneAutenticatiToken = StatoFunzionalita.ABILITATO.equals(portaDelegata.getAutorizzazioneToken().getAutorizzazioneApplicativi()) ? Costanti.CHECK_BOX_ENABLED : Costanti.CHECK_BOX_DISABLED;
  942.             }
  943.            
  944.             if(autorizzazioneRuoliToken==null &&
  945.                 portaDelegata.getAutorizzazioneToken()!=null && portaDelegata.getAutorizzazioneToken().getAutorizzazioneRuoli()!=null) {
  946.                 autorizzazioneRuoliToken = StatoFunzionalita.ABILITATO.equals(portaDelegata.getAutorizzazioneToken().getAutorizzazioneRuoli()) ? Costanti.CHECK_BOX_ENABLED : Costanti.CHECK_BOX_DISABLED;
  947.             }
  948.             if(autorizzazioneRuoliTipologiaToken==null &&
  949.                 portaDelegata.getAutorizzazioneToken()!=null && portaDelegata.getAutorizzazioneToken().getTipologiaRuoli()!=null) {
  950.                 autorizzazioneRuoliTipologiaToken = portaDelegata.getAutorizzazioneToken().getTipologiaRuoli().getValue();
  951.             }
  952.             if (autorizzazioneRuoliMatchToken == null &&
  953.                 portaDelegata.getAutorizzazioneToken()!=null && portaDelegata.getAutorizzazioneToken().getRuoli()!=null && portaDelegata.getAutorizzazioneToken().getRuoli().getMatch()!=null){
  954.                 autorizzazioneRuoliMatchToken = portaDelegata.getAutorizzazioneToken().getRuoli().getMatch().getValue();
  955.             }
  956.            
  957.             autorizzazioneContenuti = portaDelegata.getAutorizzazioneContenuto();
  958.            
  959.             if(autorizzazioneContenuti == null) {
  960.                 autorizzazioneContenutiStato = StatoFunzionalita.DISABILITATO.getValue();
  961.             } else if(autorizzazioneContenuti.equals(CostantiAutorizzazione.AUTORIZZAZIONE_CONTENUTO_BUILT_IN)) {
  962.                 autorizzazioneContenutiStato = StatoFunzionalita.ABILITATO.getValue();
  963.                 List<Proprieta> proprietaAutorizzazioneContenutoList = portaDelegata.getProprietaAutorizzazioneContenutoList();
  964.                 SortedMap<List<String>> map = porteDelegateCore.toSortedListMap(proprietaAutorizzazioneContenutoList);
  965.                 autorizzazioneContenutiProperties = PropertiesUtilities.convertSortedListMapToText(map, true);
  966.             } else { // custom
  967.                 autorizzazioneContenutiStato = CostantiControlStation.VALUE_PARAMETRO_PORTE_CONTROLLO_ACCESSI_AUTORIZZAZIONE_CONTENUTI_STATO_CUSTOM;
  968.             }
  969.            
  970.             if(portaDelegata.getGestioneToken() != null) {
  971.                 gestioneTokenPolicy = portaDelegata.getGestioneToken().getPolicy();
  972.                 if(gestioneTokenPolicy == null) {
  973.                     gestioneToken = StatoFunzionalita.DISABILITATO.getValue();
  974.                     gestioneTokenPolicy = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  975.                 } else {
  976.                     gestioneToken = StatoFunzionalita.ABILITATO.getValue();
  977.                 }
  978.                
  979.                 StatoFunzionalita tokenOpzionale = portaDelegata.getGestioneToken().getTokenOpzionale();
  980.                 if(tokenOpzionale == null) {
  981.                     gestioneTokenOpzionale = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_OPZIONALE;
  982.                 }else {
  983.                     gestioneTokenOpzionale = tokenOpzionale.getValue();
  984.                 }
  985.                
  986.                 StatoFunzionalitaConWarning validazione = portaDelegata.getGestioneToken().getValidazione();
  987.                 if(validazione == null) {
  988.                     gestioneTokenValidazioneInput = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_VALIDAZIONE_INPUT;
  989.                 }else {
  990.                     gestioneTokenValidazioneInput = validazione.getValue();
  991.                 }
  992.                
  993.                 StatoFunzionalitaConWarning introspection = portaDelegata.getGestioneToken().getIntrospection();
  994.                 if(introspection == null) {
  995.                     gestioneTokenIntrospection = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_INTROSPECTION;
  996.                 }else {
  997.                     gestioneTokenIntrospection = introspection.getValue();
  998.                 }
  999.                
  1000.                 StatoFunzionalitaConWarning userinfo = portaDelegata.getGestioneToken().getUserInfo();
  1001.                 if(userinfo == null) {
  1002.                     gestioneTokenUserInfo = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_USER_INFO;
  1003.                 }else {
  1004.                     gestioneTokenUserInfo = userinfo.getValue();
  1005.                 }
  1006.                
  1007.                 StatoFunzionalita tokenForward = portaDelegata.getGestioneToken().getForward();
  1008.                 if(tokenForward == null) {
  1009.                     gestioneTokenTokenForward = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TOKEN_FORWARD;
  1010.                 }else {
  1011.                     gestioneTokenTokenForward = tokenForward.getValue();
  1012.                 }
  1013.                
  1014.                 autorizzazioneTokenOptions = portaDelegata.getGestioneToken().getOptions();
  1015.                
  1016.                 if(portaDelegata.getGestioneToken().getAutenticazione() != null) {
  1017.                    
  1018.                     StatoFunzionalita issuer = portaDelegata.getGestioneToken().getAutenticazione().getIssuer();
  1019.                     if(issuer == null) {
  1020.                         autenticazioneTokenIssuer = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_ISSUER;
  1021.                     }else {
  1022.                         autenticazioneTokenIssuer = issuer.getValue();
  1023.                     }
  1024.                    
  1025.                     StatoFunzionalita clientId = portaDelegata.getGestioneToken().getAutenticazione().getClientId();
  1026.                     if(clientId == null) {
  1027.                         autenticazioneTokenClientId = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_CLIENT_ID;
  1028.                     }else {
  1029.                         autenticazioneTokenClientId = clientId.getValue();
  1030.                     }
  1031.                    
  1032.                     StatoFunzionalita subject = portaDelegata.getGestioneToken().getAutenticazione().getSubject();
  1033.                     if(subject == null) {
  1034.                         autenticazioneTokenSubject = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_SUBJECT;
  1035.                     }else {
  1036.                         autenticazioneTokenSubject = subject.getValue();
  1037.                     }
  1038.                    
  1039.                     StatoFunzionalita username = portaDelegata.getGestioneToken().getAutenticazione().getUsername();
  1040.                     if(username == null) {
  1041.                         autenticazioneTokenUsername = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_USERNAME;
  1042.                     }else {
  1043.                         autenticazioneTokenUsername = username.getValue();
  1044.                     }
  1045.                    
  1046.                     StatoFunzionalita mailTmp = portaDelegata.getGestioneToken().getAutenticazione().getEmail();
  1047.                     if(mailTmp == null) {
  1048.                         autenticazioneTokenEMail = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_EMAIL;
  1049.                     }else {
  1050.                         autenticazioneTokenEMail = mailTmp.getValue();
  1051.                     }
  1052.                    
  1053.                 }
  1054.                 else {
  1055.                     autenticazioneTokenIssuer = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_ISSUER;
  1056.                     autenticazioneTokenClientId = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_CLIENT_ID;
  1057.                     autenticazioneTokenSubject = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_SUBJECT;
  1058.                     autenticazioneTokenUsername = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_USERNAME;
  1059.                     autenticazioneTokenEMail = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_EMAIL;
  1060.                 }
  1061.             }
  1062.             else {
  1063.                 gestioneToken = StatoFunzionalita.DISABILITATO.getValue();
  1064.                 gestioneTokenPolicy = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  1065.                 gestioneTokenOpzionale = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_OPZIONALE;
  1066.                
  1067.                 gestioneTokenValidazioneInput = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_VALIDAZIONE_INPUT;
  1068.                 gestioneTokenIntrospection = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_INTROSPECTION;
  1069.                 gestioneTokenUserInfo = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_USER_INFO;
  1070.                 gestioneTokenTokenForward = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TOKEN_FORWARD;
  1071.                
  1072.                 autenticazioneTokenIssuer = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_ISSUER;
  1073.                 autenticazioneTokenClientId = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_CLIENT_ID;
  1074.                 autenticazioneTokenSubject = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_SUBJECT;
  1075.                 autenticazioneTokenUsername = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_USERNAME;
  1076.                 autenticazioneTokenEMail = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_EMAIL;
  1077.             }
  1078.            
  1079.             if(autorizzazioneScope == null) {
  1080.                 if(portaDelegata.getScope() != null) {
  1081.                     autorizzazioneScope =  portaDelegata.getScope().getStato().equals(StatoFunzionalita.ABILITATO) ? Costanti.CHECK_BOX_ENABLED : "";
  1082.                 } else {
  1083.                     autorizzazioneScope = "";
  1084.                 }
  1085.             }
  1086.            
  1087.             if(autorizzazioneScopeMatch == null &&
  1088.                 portaDelegata.getScope()!=null && portaDelegata.getScope().getMatch()!=null){
  1089.                 autorizzazioneScopeMatch = portaDelegata.getScope().getMatch().getValue();
  1090.             }
  1091.            
  1092.             if(identificazioneAttributiStato==null) {
  1093.                 identificazioneAttributiStato = portaDelegata.sizeAttributeAuthorityList()>0 ? StatoFunzionalita.ABILITATO.getValue() : StatoFunzionalita.DISABILITATO.getValue();
  1094.                 if(portaDelegata.sizeAttributeAuthorityList()>0) {
  1095.                     attributeAuthoritySelezionate = porteDelegateCore.buildAuthorityArrayString(portaDelegata.getAttributeAuthorityList());
  1096.                     attributeAuthorityAttributi = porteDelegateCore.buildAttributesStringFromAuthority(portaDelegata.getAttributeAuthorityList());
  1097.                 }
  1098.             }
  1099.            
  1100.             asps = apsCore.getAccordoServizioParteSpecifica(Long.parseLong(idAsps),true);
  1101.            
  1102.             porteDelegateHelper.controlloAccessiGestioneToken(dati, TipoOperazione.OTHER, gestioneToken, policyLabels, policyValues,
  1103.                     gestioneTokenPolicy, gestioneTokenOpzionale,
  1104.                     gestioneTokenValidazioneInput, gestioneTokenIntrospection, gestioneTokenUserInfo, gestioneTokenTokenForward, portaDelegata,protocollo,isPortaDelegata,
  1105.                     false);
  1106.            
  1107.             porteDelegateHelper.controlloAccessiAutenticazione(dati, TipoOperazione.OTHER, servletChiamante,portaDelegata,protocollo,
  1108.                     autenticazione, autenticazioneCustom, autenticazioneOpzionale, autenticazionePrincipal, autenticazioneParametroList, confPers, isSupportatoAutenticazione,isPortaDelegata,
  1109.                     gestioneToken, gestioneTokenPolicy, autenticazioneTokenIssuer, autenticazioneTokenClientId, autenticazioneTokenSubject, autenticazioneTokenUsername, autenticazioneTokenEMail,
  1110.                     oldAutenticazioneCustom, urlAutenticazioneCustomProperties, numAutenticazioneCustomPropertiesList,
  1111.                     false, false);
  1112.            
  1113.             // Tipo operazione = CHANGE per evitare di aggiungere if, questa e' a tutti gli effetti una servlet di CHANGE
  1114.             porteDelegateHelper.controlloAccessiAutorizzazione(dati, TipoOperazione.CHANGE, servletChiamante,portaDelegata,protocollo,
  1115.                     autenticazione, autenticazioneCustom,
  1116.                     autorizzazione, autorizzazioneCustom,
  1117.                     autorizzazioneAutenticati, urlAutorizzazioneAutenticati, sizeFruitori, null, null,
  1118.                     autorizzazioneRuoli,  urlAutorizzazioneRuoli, numRuoli, null,
  1119.                     autorizzazioneRuoliTipologia, ruoloMatch,
  1120.                     confPers, isSupportatoAutenticazione, contaListe, isPortaDelegata, false,autorizzazioneScope,urlAutorizzazioneScope,numScope,null,autorizzazioneScopeMatch,
  1121.                     gestioneToken, gestioneTokenPolicy,
  1122.                     autorizzazioneToken, autorizzazioneTokenOptions,allegatoXacmlPolicy,
  1123.                     null, 0,
  1124.                     urlAutorizzazioneCustomProperties, numAutorizzazioneCustomPropertiesList,
  1125.                     identificazioneAttributiStato, attributeAuthorityLabels, attributeAuthorityValues, attributeAuthoritySelezionate, attributeAuthorityAttributi,
  1126.                     autorizzazioneAutenticatiToken, urlAutorizzazioneAutenticatiToken, numAutenticatiToken,
  1127.                     autorizzazioneRuoliToken,  urlAutorizzazioneRuoliToken, numRuoliToken, autorizzazioneRuoliTipologiaToken, autorizzazioneRuoliMatchToken);
  1128.            
  1129.             porteDelegateHelper.controlloAccessiAutorizzazioneContenuti(dati, TipoOperazione.OTHER, true, portaDelegata,protocollo,
  1130.                     autorizzazioneContenutiStato, autorizzazioneContenuti, autorizzazioneContenutiProperties, serviceBinding,
  1131.                     oldAutorizzazioneContenutiCustom, urlAutorizzazioneContenutiCustomPropertiesList, numAutorizzazioneContenutiCustomPropertiesList,
  1132.                     confPers);
  1133.            
  1134.             dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  1135.                     idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);
  1136.            
  1137.             pd.setDati(dati);
  1138.            
  1139.             pd.setMessage(CostantiControlStation.LABEL_AGGIORNAMENTO_EFFETTUATO_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  1140.             dati.add(ServletUtils.getDataElementForEditModeFinished());
  1141.            
  1142.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  1143.             // Forward control to the specified success URI
  1144.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CONTROLLO_ACCESSI,
  1145.                     ForwardParams.OTHER(""));
  1146.            
  1147.         } catch (Exception e) {
  1148.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  1149.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_CONTROLLO_ACCESSI ,
  1150.                     ForwardParams.OTHER(""));
  1151.         }
  1152.     }

  1153. }