PorteDelegateAdd.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.Collections;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;

  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpServletResponse;
  28. import javax.servlet.http.HttpSession;

  29. import org.apache.commons.lang.StringUtils;
  30. import org.apache.struts.action.Action;
  31. import org.apache.struts.action.ActionForm;
  32. import org.apache.struts.action.ActionForward;
  33. import org.apache.struts.action.ActionMapping;
  34. import org.openspcoop2.core.commons.Liste;
  35. import org.openspcoop2.core.config.AutorizzazioneRuoli;
  36. import org.openspcoop2.core.config.AutorizzazioneScope;
  37. import org.openspcoop2.core.config.Configurazione;
  38. import org.openspcoop2.core.config.GenericProperties;
  39. import org.openspcoop2.core.config.GestioneToken;
  40. import org.openspcoop2.core.config.GestioneTokenAutenticazione;
  41. import org.openspcoop2.core.config.PortaDelegata;
  42. import org.openspcoop2.core.config.PortaDelegataAzione;
  43. import org.openspcoop2.core.config.PortaDelegataLocalForward;
  44. import org.openspcoop2.core.config.PortaDelegataServizio;
  45. import org.openspcoop2.core.config.PortaDelegataSoggettoErogatore;
  46. import org.openspcoop2.core.config.Proprieta;
  47. import org.openspcoop2.core.config.ValidazioneContenutiApplicativi;
  48. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  49. import org.openspcoop2.core.config.constants.PortaDelegataAzioneIdentificazione;
  50. import org.openspcoop2.core.config.constants.RuoloTipoMatch;
  51. import org.openspcoop2.core.config.constants.ScopeTipoMatch;
  52. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  53. import org.openspcoop2.core.config.constants.StatoFunzionalitaConWarning;
  54. import org.openspcoop2.core.config.constants.TipoAutenticazionePrincipal;
  55. import org.openspcoop2.core.config.constants.TipoAutorizzazione;
  56. import org.openspcoop2.core.config.constants.ValidazioneContenutiApplicativiTipo;
  57. import org.openspcoop2.core.id.IDAccordo;
  58. import org.openspcoop2.core.id.IDServizio;
  59. import org.openspcoop2.core.id.IDSoggetto;
  60. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  61. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  62. import org.openspcoop2.core.registry.constants.RuoloTipologia;
  63. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  64. import org.openspcoop2.core.registry.driver.FiltroRicercaServizi;
  65. import org.openspcoop2.core.registry.driver.FiltroRicercaSoggetti;
  66. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  67. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  68. import org.openspcoop2.message.constants.ServiceBinding;
  69. import org.openspcoop2.pdd.core.autorizzazione.CostantiAutorizzazione;
  70. import org.openspcoop2.utils.SortedMap;
  71. import org.openspcoop2.utils.properties.PropertiesUtilities;
  72. import org.openspcoop2.web.ctrlstat.core.AutorizzazioneUtilities;
  73. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  74. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  75. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  76. import org.openspcoop2.web.ctrlstat.dao.SoggettoCtrlStat;
  77. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  78. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  79. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  80. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCore;
  81. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCostanti;
  82. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
  83. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCostanti;
  84. import org.openspcoop2.web.lib.mvc.BinaryParameter;
  85. import org.openspcoop2.web.lib.mvc.Costanti;
  86. import org.openspcoop2.web.lib.mvc.DataElement;
  87. import org.openspcoop2.web.lib.mvc.ForwardParams;
  88. import org.openspcoop2.web.lib.mvc.GeneralData;
  89. import org.openspcoop2.web.lib.mvc.PageData;
  90. import org.openspcoop2.web.lib.mvc.Parameter;
  91. import org.openspcoop2.web.lib.mvc.ServletUtils;
  92. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  93. /**
  94.  * porteDelegateAdd
  95.  *
  96.  * @author Andrea Poli (apoli@link.it)
  97.  * @author Stefano Corallo (corallo@link.it)
  98.  * @author Sandra Giangrandi (sandra@link.it)
  99.  * @author $Author$
  100.  * @version $Rev$, $Date$
  101.  *
  102.  */
  103. public final class PorteDelegateAdd extends Action {

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

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

  107.         // Inizializzo PageData
  108.         PageData pd = new PageData();

  109.         GeneralHelper generalHelper = new GeneralHelper(session);

  110.         // Inizializzo GeneralData
  111.         GeneralData gd = generalHelper.initGeneralData(request);

  112.         try {
  113.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  114.             String nomePD = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME_PORTA);
  115.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  116.             int soggInt = Integer.parseInt(idsogg);
  117.             String descr = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_DESCRIZIONE);
  118.             String statoPorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_STATO_PORTA);
  119.             String autenticazione = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE);
  120.             String autenticazioneOpzionale = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_OPZIONALE);
  121.             String autenticazionePrincipalTipo = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_PRINCIPAL_TIPO);
  122.             TipoAutenticazionePrincipal autenticazionePrincipal = TipoAutenticazionePrincipal.toEnumConstant(autenticazionePrincipalTipo, false);
  123.             List<String> autenticazioneParametroList = porteDelegateHelper.convertFromDataElementValue_parametroAutenticazioneList(autenticazione, autenticazionePrincipal);
  124.             String autenticazioneCustom = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_CUSTOM);
  125.             String autorizzazione = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE);
  126.             String autorizzazioneCustom = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_CUSTOM);
  127.             String soggid = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SOGGETTO_ID);
  128.             String tiposp = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TIPO_SP);
  129.             String sp = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SP);
  130.             String servid = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SERVIZIO_ID);
  131.             String tiposervizio = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TIPO_SERVIZIO);
  132.             String servizio = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SERVIZIO);
  133.             String versioneServizio = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_VERSIONE_SERVIZIO);
  134.             String azid = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_AZIONE_ID);
  135.             String modeaz = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_AZIONE);
  136.             String azione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_AZIONE);
  137.             String stateless = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_STATELESS);
  138.             String localForward = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_LOCAL_FORWARD);
  139.             String paLocalForward = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_LOCAL_FORWARD_PA);
  140.             String gestBody = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_GESTIONE_BODY);
  141.             String gestManifest = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_GESTIONE_MANIFEST);
  142.             String ricsim = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_RICEVUTA_ASINCRONA_SIMMETRICA);
  143.             String ricasim = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_RICEVUTA_ASINCRONA_ASIMMETRICA);
  144.             String statoValidazione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_XSD);
  145.             String tipoValidazione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TIPO_VALIDAZIONE);
  146.             String autorizzazioneContenuti = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_AUTORIZZAZIONE_CONTENUTI);
  147.             String autorizzazioneContenutiStato = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_STATO);
  148.             String autorizzazioneContenutiProperties = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_AUTORIZZAZIONE_CONTENUTI_PROPERTIES);
  149.             String forceWsdlBased = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_FORCE_INTERFACE_BASED);
  150.             String applicaMTOM = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_APPLICA_MTOM);

  151.             String autorizzazioneAutenticati = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_AUTENTICAZIONE);
  152.             String autorizzazioneRuoli = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_RUOLI);
  153.             String autorizzazioneRuoliTipologia = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO_TIPOLOGIA);
  154.             String ruoloMatch = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO_MATCH);
  155.            
  156.             String gestioneToken = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN);
  157.             String gestioneTokenPolicy = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_POLICY);
  158.             String gestioneTokenOpzionale = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_OPZIONALE);
  159.             String gestioneTokenValidazioneInput = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_VALIDAZIONE_INPUT);
  160.             String gestioneTokenIntrospection = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_INTROSPECTION);
  161.             String gestioneTokenUserInfo = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_USERINFO);
  162.             String gestioneTokenTokenForward = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_TOKEN_FORWARD);
  163.            
  164.             String autenticazioneTokenIssuer = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_ISSUER);
  165.             String autenticazioneTokenClientId = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_CLIENT_ID);
  166.             String autenticazioneTokenSubject = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_SUBJECT);
  167.             String autenticazioneTokenUsername = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_USERNAME);
  168.             String autenticazioneTokenEMail = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_MAIL);
  169.            
  170.             String autorizzazioneAutenticatiToken = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_AUTENTICAZIONE_TOKEN);
  171.             String autorizzazioneRuoliToken = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_RUOLI_TOKEN);
  172.             String autorizzazioneRuoliTipologiaToken = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO_TIPOLOGIA_TOKEN);
  173.             String autorizzazioneRuoliMatchToken = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO_MATCH_TOKEN);
  174.            
  175.             String autorizzazioneToken = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_TOKEN);
  176.             String autorizzazioneTokenOptions = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_TOKEN_OPTIONS);
  177.             String autorizzazioneScope = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_SCOPE);
  178.             String autorizzazioneScopeMatch = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_SCOPE_MATCH);
  179.            
  180.             BinaryParameter allegatoXacmlPolicy = porteDelegateHelper.getBinaryParameter(CostantiControlStation.PARAMETRO_DOCUMENTO_SICUREZZA_XACML_POLICY);
  181.            
  182.             String identificazioneAttributiStato = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_ATTRIBUTI_STATO);
  183.             String [] attributeAuthoritySelezionate = porteDelegateHelper.getParameterValues(CostantiControlStation.PARAMETRO_PORTE_ATTRIBUTI_AUTHORITY);
  184.             String attributeAuthorityAttributi = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_ATTRIBUTI_AUTHORITY_ATTRIBUTI);
  185.            
  186.             // RateLimiting
  187.             String ctModalitaSincronizzazione = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_SINCRONIZZAZIONE);
  188.             String ctImplementazione = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_IMPLEMENTAZIONE);
  189.             String ctContatori = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_CONTATORI);
  190.             String ctTipologia = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_TIPOLOGIA);
  191.             String ctHeaderHttp = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP);
  192.             String ctHeaderHttpLimit = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_LIMIT);
  193.             String ctHeaderHttpRemaining = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_REMAINING);
  194.             String ctHeaderHttpReset = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_RESET);
  195.             String ctHeaderHttpRetryAfter = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_RETRY_AFTER);
  196.             String ctHeaderHttpRetryAfterBackoff = porteDelegateHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_RETRY_AFTER_BACKOFF_SECONDS);

  197.             if(sp == null) {
  198.                 tiposp = "";
  199.                 sp = "";
  200.             }
  201.            
  202.             if(servizio == null) {
  203.                 tiposervizio = "";
  204.                 servizio = "";
  205.             }
  206.            
  207.             if(modeaz == null) {
  208.                 modeaz = PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT;
  209.             }
  210.              
  211.             if ((modeaz != null) && !modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT) && (azione == null)) {
  212.                 azione = "";
  213.             }
  214.            
  215.             String serviceBindingS = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SERVICE_BINDING);
  216.             ServiceBinding serviceBinding = null;
  217.             if(StringUtils.isNotEmpty(serviceBindingS))
  218.                 serviceBinding = ServiceBinding.valueOf(serviceBindingS);

  219.             // Informazioni sul numero di ServiziApplicativi, Correlazione Applicativa e stato Message-Security
  220.             int numSA =0;
  221.             int numRuoli =0;
  222.             int numScope = 0;
  223.             String statoMessageSecurity  = "";
  224.             String statoMTOM  = "";
  225.             int numCorrelazioneReq =0;
  226.             int numCorrelazioneRes =0;

  227.             // Preparo il menu
  228.             porteDelegateHelper.makeMenu();

  229.             // Prendo nome e tipo del soggetto
  230.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore( );
  231.             SoggettiCore soggettiCore = new SoggettiCore(porteDelegateCore);
  232.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);
  233.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  234.             ConfigurazioneCore confCore = new ConfigurazioneCore(porteDelegateCore);

  235.             String tmpTitle = null;
  236.             String protocollo = null;
  237.             if(porteDelegateCore.isRegistroServiziLocale()){
  238.                 org.openspcoop2.core.registry.Soggetto soggetto = soggettiCore.getSoggettoRegistro(soggInt);
  239.                 protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(soggetto.getTipo());
  240.                 tmpTitle = porteDelegateHelper.getLabelNomeSoggetto(protocollo, soggetto.getTipo() , soggetto.getNome());
  241.             }else{
  242.                 org.openspcoop2.core.config.Soggetto tmpSogg = soggettiCore.getSoggetto(soggInt);
  243.                 protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(tmpSogg.getTipo());
  244.                 tmpTitle = porteDelegateHelper.getLabelNomeSoggetto(protocollo, tmpSogg.getTipo() , tmpSogg.getNome());
  245.             }

  246.             String postBackElementName = porteDelegateHelper.getPostBackElementName();
  247.            
  248.             // se ho modificato il soggetto ricalcolo il servizio e il service binding
  249.             if (postBackElementName != null) {
  250.                 if(postBackElementName.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SOGGETTO_ID)) {
  251.                     servid = null;
  252.                     serviceBinding = null;
  253.                 } else if(postBackElementName.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_SERVIZIO_ID)) {
  254.                     serviceBinding = null;
  255.                 }
  256.             }
  257.            
  258.             List<String> tipiServizioCompatibiliAccordo = new ArrayList<>();
  259.             if(serviceBinding == null) {
  260.                 List<ServiceBinding> serviceBindingListProtocollo = apsCore.getServiceBindingListProtocollo(protocollo);
  261.                
  262.                 if(serviceBindingListProtocollo != null && !serviceBindingListProtocollo.isEmpty()) {
  263.                     for (ServiceBinding serviceBinding2 : serviceBindingListProtocollo) {
  264.                         List<String> tipiServizioCompatibiliAccordoTmp = apsCore.getTipiServiziGestitiProtocollo(protocollo,serviceBinding2);
  265.                        
  266.                         for (String tipoTmp : tipiServizioCompatibiliAccordoTmp) {
  267.                             if(!tipiServizioCompatibiliAccordo.contains(tipoTmp))
  268.                                 tipiServizioCompatibiliAccordo.add(tipoTmp);
  269.                         }
  270.                     }
  271.                 }
  272.             } else {
  273.                 tipiServizioCompatibiliAccordo = apsCore.getTipiServiziGestitiProtocollo(protocollo,serviceBinding);
  274.             }

  275.             // Se modesp = register-input, prendo la lista di tutti i soggetti
  276.             // e la metto in un array
  277.             String[] soggettiList = null;
  278.             String[] soggettiListLabel = null;

  279.             List<String> tipiSoggettiCompatibiliAccordo = soggettiCore.getTipiSoggettiGestitiProtocollo(protocollo);

  280.             List<IDSoggetto> list = soggettiCore.getAllIdSoggettiRegistro(new FiltroRicercaSoggetti());
  281.             if (list!=null && !list.isEmpty()) {

  282.                 List<String> soggettiListTmp = new ArrayList<>();
  283.                 Map<String, String> soggettiMapTmp = new HashMap<>();
  284.                
  285.                 for (IDSoggetto soggetto : list) {
  286.                     if(tipiSoggettiCompatibiliAccordo.contains(soggetto.getTipo())){
  287.                         String keyIdSog = soggetto.getTipo() + "/" + soggetto.getNome();
  288.                         soggettiListTmp.add(keyIdSog);
  289.                         soggettiMapTmp.put(keyIdSog, porteDelegateHelper.getLabelNomeSoggetto(protocollo, soggetto.getTipo(), soggetto.getNome()));
  290.                     }
  291.                 }
  292.                 Collections.sort(soggettiListTmp);
  293.                 soggettiList = soggettiListTmp.toArray(new String[1]);
  294.                 soggettiListLabel = new String[soggettiList.length];
  295.                
  296.                 for (int i = 0; i < soggettiList.length; i++) {
  297.                     String keyIdSog = soggettiList[i];
  298.                     soggettiListLabel[i] = soggettiMapTmp.get(keyIdSog);
  299.                 }
  300.             }

  301.             // Se modeservizio = register-input, prendo la lista di tutti i servizi
  302.             // e la metto in un array
  303.             String[] serviziList = null;
  304.             String[] serviziListLabel = null;
  305.             if ( (soggid != null && !"".equals(soggid) && soggid.contains("/")) ) {
  306.                 IDSoggetto idSoggetto = new IDSoggetto(soggid.split("/")[0], soggid.split("/")[1]);
  307.                 FiltroRicercaServizi filtro = new FiltroRicercaServizi();
  308.                 filtro.setTipoSoggettoErogatore(idSoggetto.getTipo());
  309.                 filtro.setNomeSoggettoErogatore(idSoggetto.getNome());
  310.                 List<IDServizio> listServTmp = null;
  311.                 try{
  312.                     listServTmp = apsCore.getAllIdServizi(filtro);
  313.                 }catch(DriverRegistroServiziNotFound dNotFound){
  314.                     // ignore
  315.                 }
  316.                 if(listServTmp!=null && !listServTmp.isEmpty()){
  317.                     List<String> serviziListTmp = new ArrayList<>();
  318.                     Map<String, IDServizio> serviziMapTmp = new HashMap<>();
  319.                     for (IDServizio idServizio : listServTmp) {
  320.                         if(tipiServizioCompatibiliAccordo.contains(idServizio.getTipo())){
  321.                             String keyServizio = idServizio.getTipo() + "/" + idServizio.getNome() + "/" + idServizio.getVersione();
  322.                             serviziListTmp.add(keyServizio);
  323.                             serviziMapTmp.put(keyServizio, idServizio);
  324.                         }
  325.                     }

  326.                     Collections.sort(serviziListTmp);
  327.                     serviziList = serviziListTmp.toArray(new String[1]);
  328.                     serviziListLabel = new String[serviziList.length];
  329.                     for (int i = 0; i < serviziList.length; i++) {
  330.                         String idServTmp = serviziList[i];
  331.                         serviziListLabel[i] = porteDelegateHelper.getLabelIdServizio(protocollo, serviziMapTmp.get(idServTmp));
  332.                     }
  333.                 }
  334.             }
  335.            
  336.            
  337.             IDSoggetto idSoggetto = null;
  338.             IDServizio idServizio = null;
  339.             AccordoServizioParteSpecifica servS = null;
  340.             if (    (servid != null && !"".equals(servid) && servid.contains("/"))
  341.                     &&
  342.                     (soggid != null && !"".equals(soggid) && soggid.contains("/"))
  343.                     ) {
  344.                 idSoggetto = new IDSoggetto(soggid.split("/")[0], soggid.split("/")[1]);
  345.                 idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(servid.split("/")[0], servid.split("/")[1], idSoggetto,
  346.                         Integer.parseInt(servid.split("/")[2]));
  347.                 try{
  348.                     servS = apsCore.getServizio(idServizio);
  349.                 }catch(DriverRegistroServiziNotFound dNotFound){
  350.                     // ignore
  351.                 }
  352.                 if(servS==null){
  353.                     // è cambiato il soggetto erogatore. non è più valido il servizio
  354.                     servid = null;
  355.                     idServizio = null;
  356.                     if(serviziList!=null && serviziList.length>0){
  357.                         servid = serviziList[0];
  358.                         idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(servid.split("/")[0], servid.split("/")[1], idSoggetto,
  359.                                 Integer.parseInt(servid.split("/")[2]));
  360.                         try{
  361.                             servS = apsCore.getServizio(idServizio);
  362.                         }catch(DriverRegistroServiziNotFound dNotFound){
  363.                             // ignore
  364.                         }
  365.                         if(servS==null){
  366.                             servid = null;
  367.                             idServizio = null;
  368.                         }
  369.                     }
  370.                 }
  371.             }
  372.            
  373.             AccordoServizioParteComuneSintetico as = null;
  374.             if ( servS!=null ) {
  375.                 IDAccordo idAccordo = IDAccordoFactory.getInstance().getIDAccordoFromUri(servS.getAccordoServizioParteComune());
  376.                 as = apcCore.getAccordoServizioSintetico(idAccordo);
  377.                
  378.                 if(serviceBinding == null) {
  379.                     serviceBinding = porteDelegateCore.toMessageServiceBinding(as.getServiceBinding());
  380.                 }
  381.                
  382.             }
  383.            
  384.             // Se modeaz = register-input, prendo la lista delle azioni
  385.             // associate a servid e la metto in un array
  386.             String[] azioniList = null;
  387.             String[] azioniListLabel = null;
  388.             boolean addTrattinoSelezioneNonEffettuata = false;
  389.             List<String> filtraAzioniUtilizzate = new ArrayList<>();
  390.             if ((modeaz != null) && modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT)) {
  391.            
  392.                 Map<String,String> azioni = porteDelegateCore.getAzioniConLabel(servS, as, addTrattinoSelezioneNonEffettuata , true, filtraAzioniUtilizzate);
  393.                 if(azioni != null && azioni.size() > 0) {
  394.                     azioniList = new String[azioni.size()];
  395.                     azioniListLabel = new String[azioni.size()];
  396.                     int i = 0;
  397.                     for (String string : azioni.keySet()) {
  398.                         azioniList[i] = string;
  399.                         azioniListLabel[i] = azioni.get(string);
  400.                         i++;
  401.                     }
  402.                 }
  403.             }
  404.             int numAzioni = 0;
  405.             if (azioniList != null)
  406.                 numAzioni = azioniList.length;
  407.            
  408.             // Token Policy
  409.             List<GenericProperties> gestorePolicyTokenList = confCore.gestorePolicyTokenList(null, ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TIPOLOGIA_GESTIONE_POLICY_TOKEN, null);
  410.             String [] policyLabels = new String[gestorePolicyTokenList.size() + 1];
  411.             String [] policyValues = new String[gestorePolicyTokenList.size() + 1];
  412.            
  413.             policyLabels[0] = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  414.             policyValues[0] = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  415.            
  416.             for (int i = 0; i < gestorePolicyTokenList.size(); i++) {
  417.             GenericProperties genericProperties = gestorePolicyTokenList.get(i);
  418.                 policyLabels[(i+1)] = genericProperties.getNome();
  419.                 policyValues[(i+1)] = genericProperties.getNome();
  420.             }

  421.             // AttributeAuthority
  422.             List<GenericProperties> attributeAuthorityList = confCore.gestorePolicyTokenList(null, ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TIPOLOGIA_ATTRIBUTE_AUTHORITY, null);
  423.             String [] attributeAuthorityLabels = new String[attributeAuthorityList.size()];
  424.             String [] attributeAuthorityValues = new String[attributeAuthorityList.size()];
  425.             for (int i = 0; i < attributeAuthorityList.size(); i++) {
  426.                 GenericProperties genericProperties = attributeAuthorityList.get(i);
  427.                 attributeAuthorityLabels[i] = genericProperties.getNome();
  428.                 attributeAuthorityValues[i] = genericProperties.getNome();
  429.             }
  430.            
  431.             // Se idhid = null, devo visualizzare la pagina per l'inserimento
  432.             // dati
  433.             if (porteDelegateHelper.isEditModeInProgress()) {

  434.                 // setto la barra del titolo
  435.                 ServletUtils.setPageDataTitle(pd,
  436.                         new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST),
  437.                         new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_PORTE_DELEGATE_DI + tmpTitle,
  438.                                 PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_LIST,
  439.                                 new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO,idsogg)
  440.                                 ),
  441.                                 ServletUtils.getParameterAggiungi()
  442.                         );

  443.                 // preparo i campi
  444.                 List<DataElement> dati = new ArrayList<>();
  445.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  446.                 if (nomePD == null) {
  447.                     nomePD = "";
  448.                 }
  449.                 if (descr == null) {
  450.                     descr = "";
  451.                 }
  452.                 if (autenticazione == null) {
  453.                     autenticazione = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_AUTENTICAZIONE;
  454.                 }
  455.                 if (autorizzazione == null) {
  456.                     String defaultAutorizzazione = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_AUTORIZZAZIONE;
  457.                     if (defaultAutorizzazione != null &&
  458.                             !TipoAutorizzazione.getAllValues().contains(defaultAutorizzazione)) {
  459.                         autorizzazioneCustom = defaultAutorizzazione;
  460.                         autorizzazione = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTORIZZAZIONE_CUSTOM;
  461.                     }
  462.                     else{
  463.                         autorizzazione = AutorizzazioneUtilities.convertToStato(defaultAutorizzazione);
  464.                         if(TipoAutorizzazione.isAuthenticationRequired(defaultAutorizzazione))
  465.                             autorizzazioneAutenticati = Costanti.CHECK_BOX_ENABLED;
  466.                         if(TipoAutorizzazione.isRolesRequired(defaultAutorizzazione))
  467.                             autorizzazioneRuoli = Costanti.CHECK_BOX_ENABLED;
  468.                         autorizzazioneRuoliTipologia = AutorizzazioneUtilities.convertToRuoloTipologia(defaultAutorizzazione).getValue();
  469.                     }      
  470.                 }
  471.                 if (stateless == null) {
  472.                     stateless = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_STATELESS_DEFAULT;
  473.                 }
  474.                 if (localForward == null) {
  475.                     localForward = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_LOCAL_FORWARD_DISABILITATO;
  476.                 }
  477.                 if (gestBody == null) {
  478.                     gestBody =  PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_GEST_BODY_NONE;
  479.                 }
  480.                 if (gestManifest == null) {
  481.                     gestManifest = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_GEST_MANIFEST_DEFAULT;
  482.                 }
  483.                 if (ricsim == null) {
  484.                     ricsim =  PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_RICEVUTA_ASINCRONA_SIMMETRICA_ABILITATO;
  485.                 }
  486.                 if (ricasim == null) {
  487.                     ricasim = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_RICEVUTA_ASINCRONA_ASIMMETRICA_ABILITATO;
  488.                 }

  489.                 if (statoValidazione == null &&
  490.                     porteDelegateCore.isSinglePdD()){
  491.                     Configurazione config = porteDelegateCore.getConfigurazioneGenerale();
  492.                     if(config.getValidazioneContenutiApplicativi()!=null){
  493.                         if(config.getValidazioneContenutiApplicativi().getStato()!=null){
  494.                             statoValidazione = config.getValidazioneContenutiApplicativi().getStato().toString();
  495.                         }
  496.                         if(config.getValidazioneContenutiApplicativi().getTipo()!=null){
  497.                             tipoValidazione = config.getValidazioneContenutiApplicativi().getTipo().toString();
  498.                         }
  499.                         if(StatoFunzionalita.ABILITATO.equals(config.getValidazioneContenutiApplicativi().getAcceptMtomMessage())){
  500.                             applicaMTOM = Costanti.CHECK_BOX_ENABLED_ABILITATO;
  501.                         }
  502.                     }
  503.                 }

  504.                 if (statoValidazione == null) {
  505.                     statoValidazione = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_VALIDAZIONE_DISABILITATO;
  506.                 }
  507.                 if (tipoValidazione == null) {
  508.                     tipoValidazione = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_VALIDAZIONE_INTERFACE;
  509.                 }

  510.                 if (applicaMTOM == null) {
  511.                     applicaMTOM = "";
  512.                 }
  513.                
  514.                 if(gestioneToken == null) {
  515.                     gestioneToken = StatoFunzionalita.DISABILITATO.getValue();
  516.                     gestioneTokenPolicy = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  517.                     gestioneTokenOpzionale = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_OPZIONALE;
  518.                     gestioneTokenValidazioneInput = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_VALIDAZIONE_INPUT;
  519.                     gestioneTokenIntrospection = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_INTROSPECTION;
  520.                     gestioneTokenUserInfo = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_USER_INFO;
  521.                     gestioneTokenTokenForward = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TOKEN_FORWARD;
  522.                     autenticazioneTokenIssuer = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_ISSUER;
  523.                     autenticazioneTokenClientId = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_CLIENT_ID;
  524.                     autenticazioneTokenSubject = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_SUBJECT;
  525.                     autenticazioneTokenUsername = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_USERNAME;
  526.                     autenticazioneTokenEMail = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_EMAIL;
  527.                 }
  528.                
  529.                 if(autorizzazioneScope == null) {
  530.                     autorizzazioneScope = "";
  531.                 }
  532.                
  533.                 if(autorizzazioneContenutiStato == null)
  534.                     autorizzazioneContenutiStato = StatoFunzionalita.DISABILITATO.getValue();

  535.                 if(identificazioneAttributiStato==null) {
  536.                     identificazioneAttributiStato = StatoFunzionalita.DISABILITATO.getValue();
  537.                 }
  538.                
  539.                 // i pattern sono i nomi
  540.                 dati = porteDelegateHelper.addPorteDelegateToDati(TipoOperazione.ADD,
  541.                         PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_NEW_ID,
  542.                         nomePD,
  543.                         dati, PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_NEW_ID,
  544.                         descr, autenticazione, autorizzazione,
  545.                         soggid, soggettiList, soggettiListLabel,
  546.                         sp, tiposp, sp, servid, serviziList,
  547.                         serviziListLabel, servizio, tiposervizio, versioneServizio, servizio,
  548.                         modeaz, azid, azioniListLabel, azioniList, azione,
  549.                         azione, numAzioni,  stateless, localForward, paLocalForward, ricsim, ricasim,
  550.                         statoValidazione, tipoValidazione, 0, "", gestBody, gestManifest,
  551.                         null,null,null,null,null, autenticazioneOpzionale, autenticazionePrincipal, autenticazioneParametroList, autenticazioneCustom,
  552.                         autorizzazioneCustom,autorizzazioneAutenticati,autorizzazioneRuoli,autorizzazioneRuoliTipologia,
  553.                         autorizzazioneContenutiStato, autorizzazioneContenuti,autorizzazioneContenutiProperties,
  554.                         idsogg,protocollo,
  555.                         numSA,numRuoli, ruoloMatch,
  556.                         statoMessageSecurity,statoMTOM,numCorrelazioneReq,numCorrelazioneRes,
  557.                         forceWsdlBased,applicaMTOM,false,
  558.                         servS,as,serviceBinding,
  559.                         statoPorta,false,false,
  560.                         false,null,
  561.                         gestioneToken,policyLabels, policyValues,
  562.                         gestioneTokenPolicy,gestioneTokenOpzionale,
  563.                         gestioneTokenValidazioneInput,gestioneTokenIntrospection,gestioneTokenUserInfo,gestioneTokenTokenForward,
  564.                         autenticazioneTokenIssuer, autenticazioneTokenClientId, autenticazioneTokenSubject, autenticazioneTokenUsername, autenticazioneTokenEMail,
  565.                         autorizzazioneToken, autorizzazioneTokenOptions,
  566.                         autorizzazioneScope,numScope, autorizzazioneScopeMatch,allegatoXacmlPolicy,
  567.                         null, null,
  568.                         identificazioneAttributiStato, attributeAuthorityLabels, attributeAuthorityValues, attributeAuthoritySelezionate, attributeAuthorityAttributi,
  569.                         autorizzazioneAutenticatiToken, null, 0,
  570.                         autorizzazioneRuoliToken,  null, 0, autorizzazioneRuoliTipologiaToken, autorizzazioneRuoliMatchToken,
  571.                         ctModalitaSincronizzazione, ctImplementazione, ctContatori, ctTipologia,
  572.                         ctHeaderHttp, ctHeaderHttpLimit, ctHeaderHttpRemaining, ctHeaderHttpReset,
  573.                         ctHeaderHttpRetryAfter, ctHeaderHttpRetryAfterBackoff);

  574.                 pd.setDati(dati);


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

  576.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE, ForwardParams.ADD());
  577.             }
  578.             // Controlli sui campi immessi
  579.             boolean isOk = porteDelegateHelper.porteDelegateCheckData(TipoOperazione.ADD, "", false,
  580.                     serviceBinding);
  581.             if (!isOk) {

  582.                 // setto la barra del titolo
  583.                 ServletUtils.setPageDataTitle(pd,
  584.                         new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST),
  585.                         new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_PORTE_DELEGATE_DI + tmpTitle,
  586.                                 PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_LIST,
  587.                                 new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO,idsogg)
  588.                                 ),
  589.                                 ServletUtils.getParameterAggiungi()
  590.                         );

  591.                 // preparo i campi
  592.                 List<DataElement> dati = new ArrayList<>();

  593.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  594.                 dati = porteDelegateHelper.addPorteDelegateToDati(TipoOperazione.ADD,
  595.                         PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_NEW_ID,
  596.                         nomePD,
  597.                         dati, PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_NEW_ID,
  598.                         descr, autenticazione, autorizzazione,
  599.                         soggid, soggettiList, soggettiListLabel,
  600.                         sp, tiposp, sp, servid, serviziList,
  601.                         serviziListLabel, servizio, tiposervizio,versioneServizio, servizio,
  602.                         modeaz, azid, azioniListLabel, azioniList, azione,
  603.                         azione, numAzioni, stateless, localForward, paLocalForward, ricsim, ricasim,
  604.                         statoValidazione, tipoValidazione, 0, "", gestBody, gestManifest,
  605.                         null,null,null,null,null, autenticazioneOpzionale, autenticazionePrincipal, autenticazioneParametroList, autenticazioneCustom,
  606.                         autorizzazioneCustom,autorizzazioneAutenticati,autorizzazioneRuoli,autorizzazioneRuoliTipologia,
  607.                         autorizzazioneContenutiStato, autorizzazioneContenuti,autorizzazioneContenutiProperties,
  608.                         idsogg,protocollo,
  609.                         numSA,numRuoli, ruoloMatch,
  610.                         statoMessageSecurity,statoMTOM,numCorrelazioneReq,numCorrelazioneRes,
  611.                         forceWsdlBased,applicaMTOM,false,
  612.                         servS,as,serviceBinding,
  613.                         statoPorta,false,false,
  614.                         false,null,
  615.                         gestioneToken,policyLabels, policyValues,
  616.                         gestioneTokenPolicy,gestioneTokenOpzionale,
  617.                         gestioneTokenValidazioneInput,gestioneTokenIntrospection,gestioneTokenUserInfo,gestioneTokenTokenForward,
  618.                         autenticazioneTokenIssuer, autenticazioneTokenClientId, autenticazioneTokenSubject, autenticazioneTokenUsername, autenticazioneTokenEMail,
  619.                         autorizzazioneToken, autorizzazioneTokenOptions,
  620.                         autorizzazioneScope,numScope, autorizzazioneScopeMatch,allegatoXacmlPolicy,
  621.                         null, null,
  622.                         identificazioneAttributiStato, attributeAuthorityLabels, attributeAuthorityValues, attributeAuthoritySelezionate, attributeAuthorityAttributi,
  623.                         autorizzazioneAutenticatiToken, null, 0,
  624.                         autorizzazioneRuoliToken,  null, 0, autorizzazioneRuoliTipologiaToken, autorizzazioneRuoliMatchToken,
  625.                         ctModalitaSincronizzazione, ctImplementazione, ctContatori, ctTipologia,
  626.                         ctHeaderHttp, ctHeaderHttpLimit, ctHeaderHttpRemaining, ctHeaderHttpReset,
  627.                         ctHeaderHttpRetryAfter, ctHeaderHttpRetryAfterBackoff);

  628.                 pd.setDati(dati);

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

  630.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE, ForwardParams.ADD());
  631.             }

  632.             // Inserisco la porta delegata nel db
  633.             sp = soggid.split("/")[1];
  634.             tiposp = soggid.split("/")[0];

  635.             versioneServizio = servid.split("/")[2];
  636.             servizio = servid.split("/")[1];
  637.             tiposervizio = servid.split("/")[0];
  638.            
  639.             if (modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT)) {
  640.                 azione = "";
  641.             } else {
  642.                 azid = "";
  643.             }

  644.             PortaDelegata portaDelegata = new PortaDelegata();
  645.             portaDelegata.setNome(nomePD);
  646.             portaDelegata.setDescrizione(descr);
  647.             if(statoPorta==null || "".equals(statoPorta) || CostantiConfigurazione.ABILITATO.toString().equals(statoPorta)){
  648.                 portaDelegata.setStato(StatoFunzionalita.ABILITATO);
  649.             }
  650.             else{
  651.                 portaDelegata.setStato(StatoFunzionalita.DISABILITATO);
  652.             }
  653.            
  654.             if(autorizzazioneContenutiStato.equals(StatoFunzionalita.DISABILITATO.getValue())) {
  655.                 portaDelegata.setAutorizzazioneContenuto(null);
  656.                 portaDelegata.getProprietaAutorizzazioneContenutoList().clear();
  657.             } else if(autorizzazioneContenutiStato.equals(StatoFunzionalita.ABILITATO.getValue())) {
  658.                 portaDelegata.setAutorizzazioneContenuto(CostantiAutorizzazione.AUTORIZZAZIONE_CONTENUTO_BUILT_IN);
  659.                 portaDelegata.getProprietaAutorizzazioneContenutoList().clear();
  660.                 // Fix: non rispettava l'ordine
  661.                 SortedMap<List<String>> convertTextToProperties = PropertiesUtilities.convertTextToSortedListMap(autorizzazioneContenutiProperties, true);
  662.                 porteDelegateCore.addFromSortedListMap(portaDelegata.getProprietaAutorizzazioneContenutoList(), convertTextToProperties);
  663.             } else {
  664.                 portaDelegata.setAutorizzazioneContenuto(autorizzazioneContenuti);
  665.             }
  666.            
  667.             if (autenticazione == null ||
  668.                     !autenticazione.equals(CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTENTICAZIONE_CUSTOM))
  669.                 portaDelegata.setAutenticazione(autenticazione);
  670.             else
  671.                 portaDelegata.setAutenticazione(autenticazioneCustom);
  672.             if(autenticazioneOpzionale != null){
  673.                 if(ServletUtils.isCheckBoxEnabled(autenticazioneOpzionale))
  674.                     portaDelegata.setAutenticazioneOpzionale(StatoFunzionalita.ABILITATO);
  675.                 else
  676.                     portaDelegata.setAutenticazioneOpzionale(StatoFunzionalita.DISABILITATO);
  677.             } else
  678.                 portaDelegata.setAutenticazioneOpzionale(null);
  679.             List<Proprieta> proprietaAutenticazione = porteDelegateCore.convertToAutenticazioneProprieta(autenticazione, autenticazionePrincipal, autenticazioneParametroList);
  680.             if(proprietaAutenticazione!=null && !proprietaAutenticazione.isEmpty()) {
  681.                 portaDelegata.getProprietaAutenticazioneList().addAll(proprietaAutenticazione);
  682.             }
  683.            
  684.             if (autorizzazione == null ||
  685.                     !autorizzazione.equals(CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTORIZZAZIONE_CUSTOM))
  686.                 portaDelegata.setAutorizzazione(AutorizzazioneUtilities.convertToTipoAutorizzazioneAsString(autorizzazione,
  687.                         ServletUtils.isCheckBoxEnabled(autorizzazioneAutenticati),
  688.                         ServletUtils.isCheckBoxEnabled(autorizzazioneRuoli),
  689.                         ServletUtils.isCheckBoxEnabled(autorizzazioneAutenticatiToken),
  690.                         ServletUtils.isCheckBoxEnabled(autorizzazioneRuoliToken),
  691.                         ServletUtils.isCheckBoxEnabled(autorizzazioneScope),
  692.                         autorizzazioneTokenOptions,
  693.                         RuoloTipologia.toEnumConstant(autorizzazioneRuoliTipologia)));
  694.             else
  695.                 portaDelegata.setAutorizzazione(autorizzazioneCustom);
  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.             if(ServletUtils.isCheckBoxEnabled(autorizzazioneScope )) {
  707.                 if(portaDelegata.getScope() == null)
  708.                     portaDelegata.setScope(new AutorizzazioneScope());
  709.                
  710.                 portaDelegata.getScope().setStato(StatoFunzionalita.ABILITATO);
  711.             }
  712.             else {
  713.                 portaDelegata.setScope(null);
  714.             }
  715.             if(autorizzazioneScopeMatch!=null && !"".equals(autorizzazioneScopeMatch)){
  716.                 ScopeTipoMatch scopeTipoMatch = ScopeTipoMatch.toEnumConstant(autorizzazioneScopeMatch);
  717.                 if(scopeTipoMatch!=null){
  718.                     if(portaDelegata.getScope()==null){
  719.                         portaDelegata.setScope(new AutorizzazioneScope());
  720.                     }
  721.                     portaDelegata.getScope().setMatch(scopeTipoMatch);
  722.                 }
  723.             }
  724.            
  725.             if(portaDelegata.getGestioneToken() == null)
  726.                 portaDelegata.setGestioneToken(new GestioneToken());
  727.            
  728.             if(gestioneToken.equals(StatoFunzionalita.ABILITATO.getValue())) {
  729.                 portaDelegata.getGestioneToken().setPolicy(gestioneTokenPolicy);
  730.                 if(ServletUtils.isCheckBoxEnabled(gestioneTokenOpzionale)) {
  731.                     portaDelegata.getGestioneToken().setTokenOpzionale(StatoFunzionalita.ABILITATO);
  732.                 }
  733.                 else {
  734.                     portaDelegata.getGestioneToken().setTokenOpzionale(StatoFunzionalita.DISABILITATO);
  735.                 }
  736.                 portaDelegata.getGestioneToken().setValidazione(StatoFunzionalitaConWarning.toEnumConstant(gestioneTokenValidazioneInput));
  737.                 portaDelegata.getGestioneToken().setIntrospection(StatoFunzionalitaConWarning.toEnumConstant(gestioneTokenIntrospection));
  738.                 portaDelegata.getGestioneToken().setUserInfo(StatoFunzionalitaConWarning.toEnumConstant(gestioneTokenUserInfo));
  739.                 portaDelegata.getGestioneToken().setForward(StatoFunzionalita.toEnumConstant(gestioneTokenTokenForward));
  740.                 portaDelegata.getGestioneToken().setOptions(autorizzazioneTokenOptions);
  741.                 if(portaDelegata.getGestioneToken().getAutenticazione()==null) {
  742.                     portaDelegata.getGestioneToken().setAutenticazione(new GestioneTokenAutenticazione());
  743.                 }
  744.                 portaDelegata.getGestioneToken().getAutenticazione().setIssuer(ServletUtils.isCheckBoxEnabled(autenticazioneTokenIssuer) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenIssuer));
  745.                 portaDelegata.getGestioneToken().getAutenticazione().setClientId(ServletUtils.isCheckBoxEnabled(autenticazioneTokenClientId) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenClientId));
  746.                 portaDelegata.getGestioneToken().getAutenticazione().setSubject(ServletUtils.isCheckBoxEnabled(autenticazioneTokenSubject) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenSubject));
  747.                 portaDelegata.getGestioneToken().getAutenticazione().setUsername(ServletUtils.isCheckBoxEnabled(autenticazioneTokenUsername) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenUsername));
  748.                 portaDelegata.getGestioneToken().getAutenticazione().setEmail(ServletUtils.isCheckBoxEnabled(autenticazioneTokenEMail) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenEMail));
  749.             } else {
  750.                 portaDelegata.getGestioneToken().setPolicy(null);
  751.                 portaDelegata.getGestioneToken().setTokenOpzionale(StatoFunzionalita.DISABILITATO);
  752.                 portaDelegata.getGestioneToken().setValidazione(StatoFunzionalitaConWarning.DISABILITATO);
  753.                 portaDelegata.getGestioneToken().setIntrospection(StatoFunzionalitaConWarning.DISABILITATO);
  754.                 portaDelegata.getGestioneToken().setUserInfo(StatoFunzionalitaConWarning.DISABILITATO);
  755.                 portaDelegata.getGestioneToken().setForward(StatoFunzionalita.DISABILITATO);
  756.                 portaDelegata.getGestioneToken().setOptions(null);
  757.                 if(portaDelegata.getGestioneToken().getAutenticazione()!=null) {
  758.                     portaDelegata.getGestioneToken().setAutenticazione(null);
  759.                 }
  760.             }
  761.            
  762.             if (stateless !=null && !stateless.equals(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_STATELESS_DEFAULT))
  763.                 portaDelegata.setStateless(StatoFunzionalita.toEnumConstant(stateless));
  764.             if (PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_GEST_BODY_ALLEGA.equals(gestBody))
  765.                 portaDelegata.setAllegaBody(StatoFunzionalita.toEnumConstant(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_ABILITATO));
  766.             else
  767.                 portaDelegata.setAllegaBody(StatoFunzionalita.toEnumConstant(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_DISABILITATO));
  768.             if (PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_GEST_BODY_SCARTA.equals(gestBody))
  769.                 portaDelegata.setScartaBody(StatoFunzionalita.toEnumConstant(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_ABILITATO));
  770.             else
  771.                 portaDelegata.setScartaBody(StatoFunzionalita.toEnumConstant(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_DISABILITATO));
  772.             if (gestManifest !=null && !gestManifest.equals(PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_STATELESS_DEFAULT))
  773.                 portaDelegata.setGestioneManifest(StatoFunzionalita.toEnumConstant(gestManifest));
  774.             portaDelegata.setRicevutaAsincronaSimmetrica(StatoFunzionalita.toEnumConstant(ricsim));
  775.             portaDelegata.setRicevutaAsincronaAsimmetrica(StatoFunzionalita.toEnumConstant(ricasim));
  776.             if(localForward!=null){
  777.                 portaDelegata.setLocalForward(new PortaDelegataLocalForward());
  778.                 portaDelegata.getLocalForward().setStato(StatoFunzionalita.toEnumConstant(localForward));
  779.                 portaDelegata.getLocalForward().setPortaApplicativa(paLocalForward);
  780.             }

  781.             PortaDelegataSoggettoErogatore pdSogg = new PortaDelegataSoggettoErogatore();
  782.             IDSoggetto idSoggettoErogatore = new IDSoggetto(tiposp, sp);
  783.            
  784.             pdSogg.setId(soggettiCore.getSoggettoRegistro(idSoggettoErogatore).getId());
  785.             if(pdSogg.getId()<=0){
  786.                 pdSogg.setId(-2l);
  787.             }
  788.            
  789.             pdSogg.setNome(sp);
  790.             pdSogg.setTipo(tiposp);

  791.             portaDelegata.setSoggettoErogatore(pdSogg);

  792.             PortaDelegataServizio pdServizio = new PortaDelegataServizio();
  793.             AccordoServizioParteSpecifica asps = null;
  794.             idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(tiposervizio, servizio, idSoggettoErogatore, Integer.parseInt(versioneServizio));
  795.             try{
  796.                 asps = apsCore.getServizio(idServizio);
  797.                 pdServizio.setId(asps.getId());
  798.             }catch(DriverRegistroServiziNotFound dNotFound){
  799.                 // ignore
  800.             }
  801.             if(pdServizio.getId()<=0){
  802.                 pdServizio.setId(-2l);
  803.             }
  804.             pdServizio.setNome(servizio);
  805.             pdServizio.setTipo(tiposervizio);

  806.             portaDelegata.setServizio(pdServizio);

  807.             // se l azione e' settata allora creo il bean
  808.             if ((!azione.equals("") ||
  809.                             modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_INPUT_BASED) ||
  810.                             modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_SOAP_ACTION_BASED) ||
  811.                             modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_INTERFACE_BASED)) ||
  812.                             !azid.equals("")) {
  813.                 PortaDelegataAzione pdAzione = new PortaDelegataAzione();

  814.                 if (modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT)) {
  815.                     azione = azid;
  816. /**                 IDAccordo idAccordo = IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune());
  817. //                  as = apcCore.getAccordoServizio(idAccordo);
  818. //
  819. //                  if(asps.getPortType()!=null){
  820. //                      // Bisogna prendere le operations del port type
  821. //                      PortType pt = null;
  822. //                      for (int i = 0; i < as.sizePortTypeList(); i++) {
  823. //                          if(as.getPortType(i).getNome().equals(asps.getPortType())){
  824. //                              pt = as.getPortType(i);
  825. //                              break;
  826. //                          }
  827. //                      }
  828. //                      if(pt==null){
  829. //                          throw new Exception("Accordo di servizio parte specifica ["+idServizio.toString()+"] possiede un port type ["+asps.getPortType()+"] che non risulta essere registrato nell'accordo di servizio parte comune ["+asps.getAccordoServizioParteComune()+"]");
  830. //                      }
  831. //                      if(pt.sizeAzioneList()>0){
  832. //                          for (int i = 0; i < pt.sizeAzioneList(); i++) {
  833. //                              if(pt.getAzione(i).getNome().equals(azione)){
  834. //                                  pdAzione.setId(pt.getAzione(i).getId());
  835. //                                  break;
  836. //                              }
  837. //                          }
  838. //                      }
  839. //                  }else{
  840. //                      if(as.sizeAzioneList()>0){
  841. //                          for (int i = 0; i < as.sizeAzioneList(); i++) {
  842. //                              if(as.getAzione(i).getNome().equals(azione)){
  843. //                                  pdAzione.setId(as.getAzione(i).getId());
  844. //                                  break;
  845. //                              }
  846. //                          }
  847. //                      }
  848. //                  }*/

  849.                     if(pdAzione.getId()<=0){
  850.                         pdAzione.setId(-2l);
  851.                     }
  852.                 }
  853.                 pdAzione.setNome(azione);
  854.                 pdAzione.setIdentificazione(PortaDelegataAzioneIdentificazione.toEnumConstant(modeaz));
  855.                 pdAzione.setPattern(azione);

  856.                 //FORCE WSDL BASED
  857.                 if(!modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_REGISTER_INPUT) &&
  858.                         !modeaz.equals(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MODE_INTERFACE_BASED)){

  859.                     if(forceWsdlBased != null && (ServletUtils.isCheckBoxEnabled(forceWsdlBased))){
  860.                         pdAzione.setForceInterfaceBased(StatoFunzionalita.ABILITATO);
  861.                     }else {
  862.                         pdAzione.setForceInterfaceBased(StatoFunzionalita.DISABILITATO);
  863.                     }
  864.                 }else {
  865.                     pdAzione.setForceInterfaceBased(null);
  866.                 }

  867.                 portaDelegata.setAzione(pdAzione);
  868.             }

  869.             // soggetto proprietario
  870.             SoggettoCtrlStat soggettoCS = soggettiCore.getSoggettoCtrlStat(soggInt);
  871.             portaDelegata.setIdSoggetto(soggettoCS.getId());
  872.             portaDelegata.setTipoSoggettoProprietario(soggettoCS.getTipo());
  873.             portaDelegata.setNomeSoggettoProprietario(soggettoCS.getNome());

  874.             ValidazioneContenutiApplicativi vx = new ValidazioneContenutiApplicativi();
  875.             vx.setStato(StatoFunzionalitaConWarning.toEnumConstant(statoValidazione));
  876.             vx.setTipo(ValidazioneContenutiApplicativiTipo.toEnumConstant(tipoValidazione));
  877.             if(applicaMTOM != null){
  878.                 if(ServletUtils.isCheckBoxEnabled(applicaMTOM))
  879.                     vx.setAcceptMtomMessage(StatoFunzionalita.ABILITATO);
  880.                 else
  881.                     vx.setAcceptMtomMessage(StatoFunzionalita.DISABILITATO);
  882.             } else
  883.                 vx.setAcceptMtomMessage(null);
  884.            
  885.             portaDelegata.setValidazioneContenutiApplicativi(vx);

  886.             portaDelegata.setAutorizzazioneContenuto(autorizzazioneContenuti);
  887.            
  888.             if(autorizzazione != null && autorizzazione.equals(AutorizzazioneUtilities.STATO_XACML_POLICY) && allegatoXacmlPolicy.getValue() != null) {
  889.                 portaDelegata.setXacmlPolicy(new String(allegatoXacmlPolicy.getValue()));
  890.             } else {
  891.                 portaDelegata.setXacmlPolicy(null);
  892.             }

  893.             String userLogin = ServletUtils.getUserLoginFromSession(session);

  894.             porteDelegateCore.performCreateOperation(userLogin, porteDelegateHelper.smista(), portaDelegata);

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

  897.             int idLista = Liste.PORTE_DELEGATE_BY_SOGGETTO;
  898.             ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  899.             List<PortaDelegata> lista = porteDelegateCore.porteDelegateList(soggInt, ricerca);

  900.             porteDelegateHelper.preparePorteDelegateList(ricerca, lista,idLista);

  901.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  902.             // Forward control to the specified success URI
  903.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE, ForwardParams.ADD());

  904.         } catch (Exception e) {
  905.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  906.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE,
  907.                     ForwardParams.ADD());
  908.         }  
  909.     }
  910. }