PorteApplicativeAdd.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.pa;

  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.PortaApplicativa;
  42. import org.openspcoop2.core.config.PortaApplicativaAzione;
  43. import org.openspcoop2.core.config.PortaApplicativaBehaviour;
  44. import org.openspcoop2.core.config.PortaApplicativaServizio;
  45. import org.openspcoop2.core.config.PortaApplicativaSoggettoVirtuale;
  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.PortaApplicativaAzioneIdentificazione;
  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.IDAccordoFactory;
  66. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  67. import org.openspcoop2.message.constants.ServiceBinding;
  68. import org.openspcoop2.pdd.core.autorizzazione.CostantiAutorizzazione;
  69. import org.openspcoop2.utils.SortedMap;
  70. import org.openspcoop2.utils.properties.PropertiesUtilities;
  71. import org.openspcoop2.web.ctrlstat.core.AutorizzazioneUtilities;
  72. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  73. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  74. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  75. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  76. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  77. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  78. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCore;
  79. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCostanti;
  80. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
  81. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCostanti;
  82. import org.openspcoop2.web.lib.mvc.BinaryParameter;
  83. import org.openspcoop2.web.lib.mvc.Costanti;
  84. import org.openspcoop2.web.lib.mvc.DataElement;
  85. import org.openspcoop2.web.lib.mvc.ForwardParams;
  86. import org.openspcoop2.web.lib.mvc.GeneralData;
  87. import org.openspcoop2.web.lib.mvc.PageData;
  88. import org.openspcoop2.web.lib.mvc.Parameter;
  89. import org.openspcoop2.web.lib.mvc.ServletUtils;
  90. import org.openspcoop2.web.lib.mvc.TipoOperazione;

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

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

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

  105.         // Inizializzo PageData
  106.         PageData pd = new PageData();

  107.         GeneralHelper generalHelper = new GeneralHelper(session);

  108.         // Inizializzo GeneralData
  109.         GeneralData gd = generalHelper.initGeneralData(request);



  110.         try {
  111.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  112.             String nomePorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME_PORTA);
  113.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  114.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  115.             int soggInt = Integer.parseInt(idsogg);
  116.             String descr = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_DESCRIZIONE);
  117.             String statoPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_STATO_PORTA);
  118.             String soggvirt = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_SOGGETTO_VIRTUALE);
  119.             if (soggvirt == null || "".equals(soggvirt)) {
  120.                 soggvirt = "-";
  121.             }
  122.             String servizio = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_SERVIZIO);
  123.             String azione = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_AZIONE);
  124.             String stateless = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_STATELESS);
  125.             String behaviour = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_BEHAVIOUR);
  126.             String gestBody = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_GESTIONE_BODY);
  127.             String gestManifest = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_GESTIONE_MANIFEST);
  128.             String ricsim = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_RICEVUTA_ASINCRONA_SIMMETRICA);
  129.             String ricasim = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_RICEVUTA_ASINCRONA_ASIMMETRICA);
  130.             String statoValidazione = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_XSD);
  131.             String tipoValidazione = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TIPO_VALIDAZIONE);
  132.             String autorizzazioneContenuti = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI);
  133.             String autorizzazioneContenutiStato = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI_STATO);
  134.             String autorizzazioneContenutiProperties = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI_PROPERTIES);
  135.             String applicaMTOM = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_APPLICA_MTOM);

  136.             String autenticazione = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE);
  137.             String autenticazioneOpzionale = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_OPZIONALE);
  138.             String autenticazionePrincipalTipo = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_PRINCIPAL_TIPO);
  139.             TipoAutenticazionePrincipal autenticazionePrincipal = TipoAutenticazionePrincipal.toEnumConstant(autenticazionePrincipalTipo, false);
  140.             List<String> autenticazioneParametroList = porteApplicativeHelper.convertFromDataElementValue_parametroAutenticazioneList(autenticazione, autenticazionePrincipal);
  141.             String autenticazioneCustom = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_CUSTOM);
  142.             String autorizzazione = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE);
  143.             String autorizzazioneCustom = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_CUSTOM);
  144.            
  145.             String autorizzazioneAutenticati = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_AUTENTICAZIONE);
  146.             String autorizzazioneRuoli = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_RUOLI);
  147.             String autorizzazioneRuoliTipologia = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO_TIPOLOGIA);
  148.             String ruoloMatch = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO_MATCH);
  149.            
  150.             String azid = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_AZIONE_ID);
  151.             String modeaz = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_AZIONE);
  152.             String forceWsdlBased = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_FORCE_INTERFACE_BASED);
  153.            
  154.             String serviceBindingS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_SERVICE_BINDING);
  155.             ServiceBinding serviceBinding = null;
  156.             if(StringUtils.isNotEmpty(serviceBindingS))
  157.                 serviceBinding = ServiceBinding.valueOf(serviceBindingS);
  158.            
  159.             if(servizio == null) {
  160.                 servizio = "";
  161.             }
  162.            
  163.             if(modeaz == null) {
  164.                 modeaz = PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_REGISTER_INPUT;
  165.             }
  166.              
  167.             if ((modeaz != null) && !modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_REGISTER_INPUT) && (azione == null)) {
  168.                 azione = "";
  169.             }
  170.            
  171.             String gestioneToken = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN);
  172.             String gestioneTokenPolicy = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_POLICY);
  173.             String gestioneTokenOpzionale = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_OPZIONALE);
  174.             String gestioneTokenValidazioneInput = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_VALIDAZIONE_INPUT);
  175.             String gestioneTokenIntrospection = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_INTROSPECTION);
  176.             String gestioneTokenUserInfo = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_USERINFO);
  177.             String gestioneTokenTokenForward = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_GESTIONE_TOKEN_TOKEN_FORWARD);
  178.            
  179.             String autenticazioneTokenIssuer = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_ISSUER);
  180.             String autenticazioneTokenClientId = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_CLIENT_ID);
  181.             String autenticazioneTokenSubject = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_SUBJECT);
  182.             String autenticazioneTokenUsername = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_USERNAME);
  183.             String autenticazioneTokenEMail = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTENTICAZIONE_TOKEN_MAIL);
  184.            
  185.             String autorizzazioneAutenticatiToken = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_AUTENTICAZIONE_TOKEN);
  186.             String autorizzazioneRuoliToken = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_RUOLI_TOKEN);
  187.             String autorizzazioneRuoliTipologiaToken = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO_TIPOLOGIA_TOKEN);
  188.             String autorizzazioneRuoliMatchToken = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO_MATCH_TOKEN);
  189.            
  190.             String autorizzazioneToken = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_TOKEN);
  191.             String autorizzazioneTokenOptions = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_TOKEN_OPTIONS);
  192.             String autorizzazioneScope = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_AUTORIZZAZIONE_SCOPE);
  193.             String autorizzazioneScopeMatch = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_SCOPE_MATCH);
  194.            
  195.             BinaryParameter allegatoXacmlPolicy = porteApplicativeHelper.getBinaryParameter(CostantiControlStation.PARAMETRO_DOCUMENTO_SICUREZZA_XACML_POLICY);
  196.            
  197.             String identificazioneAttributiStato = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_ATTRIBUTI_STATO);
  198.             String [] attributeAuthoritySelezionate = porteApplicativeHelper.getParameterValues(CostantiControlStation.PARAMETRO_PORTE_ATTRIBUTI_AUTHORITY);
  199.             String attributeAuthorityAttributi = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_PORTE_ATTRIBUTI_AUTHORITY_ATTRIBUTI);
  200.            
  201.             // RateLimiting
  202.             String ctModalitaSincronizzazione = porteApplicativeHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_SINCRONIZZAZIONE);
  203.             String ctImplementazione = porteApplicativeHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_IMPLEMENTAZIONE);
  204.             String ctContatori = porteApplicativeHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_CONTATORI);
  205.             String ctTipologia = porteApplicativeHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_TIPOLOGIA);
  206.             String ctHeaderHttp = porteApplicativeHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP);
  207.             String ctHeaderHttpLimit = porteApplicativeHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_LIMIT);
  208.             String ctHeaderHttpRemaining = porteApplicativeHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_REMAINING);
  209.             String ctHeaderHttpReset = porteApplicativeHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_RESET);
  210.             String ctHeaderHttpRetryAfter = porteApplicativeHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_RETRY_AFTER);
  211.             String ctHeaderHttpRetryAfterBackoff = porteApplicativeHelper.getParameter(org.openspcoop2.core.controllo_traffico.constants.Costanti.MODALITA_GENERAZIONE_HEADER_HTTP_RETRY_AFTER_BACKOFF_SECONDS);
  212.            
  213.             // Preparo il menu
  214.             porteApplicativeHelper.makeMenu();

  215.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  216.             SoggettiCore soggettiCore = new SoggettiCore(porteApplicativeCore);
  217.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
  218.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  219.             ConfigurazioneCore confCore = new ConfigurazioneCore(porteApplicativeCore);

  220.             // Prendo nome, tipo e pdd del soggetto
  221.             String tipoNomeSoggettoProprietario = null;
  222.             String tipoSoggettoProprietario = null;
  223.             String nomeSoggettoProprietario = null;
  224.             if(porteApplicativeCore.isRegistroServiziLocale()){
  225.                 org.openspcoop2.core.registry.Soggetto soggetto = soggettiCore.getSoggettoRegistro(soggInt);
  226.                 tipoNomeSoggettoProprietario = soggetto.getTipo() + "/" + soggetto.getNome();
  227.                 tipoSoggettoProprietario = soggetto.getTipo();
  228.                 nomeSoggettoProprietario = soggetto.getNome();
  229.             }else{
  230.                 org.openspcoop2.core.config.Soggetto soggetto = soggettiCore.getSoggetto(soggInt);
  231.                 tipoNomeSoggettoProprietario = soggetto.getTipo() + "/" + soggetto.getNome();
  232.                 tipoSoggettoProprietario = soggetto.getTipo();
  233.                 nomeSoggettoProprietario = soggetto.getNome();
  234.             }

  235.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(tipoSoggettoProprietario);
  236.             String tmpTitle = porteApplicativeHelper.getLabelNomeSoggetto(protocollo, tipoSoggettoProprietario, nomeSoggettoProprietario);

  237.             boolean isSupportatoAutenticazioneSoggetti = soggettiCore.isSupportatoAutenticazioneSoggetti(protocollo);
  238.            
  239.            
  240.             String postBackElementName = porteApplicativeHelper.getPostBackElementName();
  241.            
  242.             // se ho modificato il soggetto ricalcolo il servizio e il service binding
  243.             if (postBackElementName != null) {
  244.                 if(postBackElementName.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_SOGGETTO_VIRTUALE)) {
  245.                     servizio = null;
  246.                     serviceBinding = null;
  247.                 } else if(postBackElementName.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_SERVIZIO)) {
  248.                     serviceBinding = null;
  249.                 }
  250.             }
  251.            
  252.             List<String> tipiServizioCompatibiliAccordo = new ArrayList<>();
  253.             if(serviceBinding == null) {
  254.                 List<ServiceBinding> serviceBindingListProtocollo = apsCore.getServiceBindingListProtocollo(protocollo);
  255.                
  256.                 if(serviceBindingListProtocollo != null && !serviceBindingListProtocollo.isEmpty()) {
  257.                     for (ServiceBinding serviceBinding2 : serviceBindingListProtocollo) {
  258.                         List<String> tipiServizioCompatibiliAccordoTmp = apsCore.getTipiServiziGestitiProtocollo(protocollo,serviceBinding2);
  259.                        
  260.                         for (String tipoTmp : tipiServizioCompatibiliAccordoTmp) {
  261.                             if(!tipiServizioCompatibiliAccordo.contains(tipoTmp))
  262.                                 tipiServizioCompatibiliAccordo.add(tipoTmp);
  263.                         }
  264.                     }
  265.                 }
  266.             } else {
  267.                 tipiServizioCompatibiliAccordo = apsCore.getTipiServiziGestitiProtocollo(protocollo,serviceBinding);
  268.             }
  269.            
  270.             // Informazioni sul numero di ServiziApplicativi, Correlazione Applicativa e stato Message-Security
  271.             int numSA = 0;
  272.             int numRuoli =0;
  273.             int numScope = 0;
  274.             String statoMessageSecurity  =  "";
  275.             String statoMTOM  = "";
  276.             int numCorrelazioneReq =0;
  277.             int numCorrelazioneRes =0;
  278.             int numProprProt = 0;

  279.             // Prendo la lista di soggetti (tranne il mio) e li metto in un
  280.             // array per la funzione SoggettoVirtuale
  281.             String[] soggettiList = null;
  282.             String[] soggettiListLabel = null;
  283.             Boolean soggVirt = ServletUtils.getObjectFromSession(request, session, Boolean.class, CostantiControlStation.SESSION_PARAMETRO_GESTIONE_SOGGETTI_VIRTUALI);
  284.             if (soggVirt!=null && soggVirt.booleanValue()) {
  285.                 List<IDServizio> list = null;
  286.                 List<IDSoggetto> listSoggetti = new ArrayList<>();
  287.                 List<String> identitaSoggetti = new ArrayList<>();
  288.                 try{
  289.                     list = apsCore.getAllIdServizi(new FiltroRicercaServizi());
  290.                 }catch(DriverRegistroServiziNotFound dNotFound){}
  291.                 if(list!=null){
  292.                     for (int i = 0; i < list.size(); i++) {
  293.                         String idSoggetto = list.get(i).getSoggettoErogatore().toString();
  294.                         if (!idSoggetto.equals(tipoNomeSoggettoProprietario)){ // non aggiungo il soggetto proprietario della porta applicativa
  295.                             if(!identitaSoggetti.contains(idSoggetto)){
  296.                                 identitaSoggetti.add(idSoggetto);
  297.                                 IDSoggetto soggettoErogatore = list.get(i).getSoggettoErogatore();
  298.                                 String protocolloSoggettoErogatore = soggettiCore.getProtocolloAssociatoTipoSoggetto(soggettoErogatore.getTipo());
  299.                                 if(protocolloSoggettoErogatore.equals(protocollo)){
  300.                                     listSoggetti.add(soggettoErogatore);
  301.                                 }
  302.                             }
  303.                         }
  304.                     }
  305.                 }
  306.                 int totEl = listSoggetti.size() + 1;
  307.                 soggettiList = new String[totEl];
  308.                 soggettiListLabel = new String[totEl];
  309.                 soggettiList[0] = "-";
  310.                 soggettiListLabel[0] = "-";
  311.                 Map<String, String> soggettiMapTmp = new HashMap<>();
  312.                 List<String> listSoggettiOrdered = new ArrayList<>();
  313.                 for (IDSoggetto idSoggetto : listSoggetti) {
  314.                     listSoggettiOrdered.add(idSoggetto.getTipo() + "/" + idSoggetto.getNome());
  315.                     soggettiMapTmp.put(idSoggetto.getTipo() + "/" + idSoggetto.getNome(), porteApplicativeHelper.getLabelNomeSoggetto(protocollo,
  316.                             idSoggetto.getTipo(), idSoggetto.getNome()));
  317.                 }
  318.                 Collections.sort(listSoggettiOrdered);
  319.                 int i = 1;
  320.                 for (String idSOrdered : listSoggettiOrdered) {
  321.                     soggettiList[i] = idSOrdered;
  322.                     soggettiListLabel[i] = soggettiMapTmp.get(idSOrdered);
  323.                     i++;
  324.                 }
  325.             }

  326.             // Prendo la lista di servizi e li metto in un array
  327.             String[] serviziList = null;
  328.             String[] serviziListLabel = null;
  329.             FiltroRicercaServizi filtroServizi = new FiltroRicercaServizi();
  330.             if ( (!soggvirt.equals("")) && (!soggvirt.equals("-")) ){
  331.                 filtroServizi.setTipoSoggettoErogatore(soggvirt.split("/")[0]);
  332.                 filtroServizi.setNomeSoggettoErogatore(soggvirt.split("/")[1]);
  333.             }
  334.             else{
  335.                 filtroServizi.setTipoSoggettoErogatore(tipoSoggettoProprietario);
  336.                 filtroServizi.setNomeSoggettoErogatore(nomeSoggettoProprietario);
  337.             }
  338.             List<IDServizio> listaServizi = null;
  339.             try{
  340.                 listaServizi = apsCore.getAllIdServizi(filtroServizi);
  341.             }catch(DriverRegistroServiziNotFound not){
  342.                 // ignore
  343.             }
  344.             if(listaServizi!=null && !listaServizi.isEmpty()){
  345.                 List<String> serviziListTmp = new ArrayList<>();
  346.                 Map<String, IDServizio> serviziMapTmp = new HashMap<>();
  347.                 for (IDServizio idServizio : listaServizi) {
  348.                     if(tipiServizioCompatibiliAccordo.contains(idServizio.getTipo())){
  349.                         String keyServizio = idServizio.getSoggettoErogatore().getTipo() + "/" + idServizio.getSoggettoErogatore().getNome() + " " + idServizio.getTipo() + "/" + idServizio.getNome() + "/" + idServizio.getVersione().intValue();
  350.                         serviziListTmp.add(keyServizio);
  351.                         serviziMapTmp.put(keyServizio, idServizio);
  352.                     }
  353.                 }

  354.                 Collections.sort(serviziListTmp);
  355.                 serviziList = serviziListTmp.toArray(new String[1]);
  356.                 serviziListLabel = new String[serviziList.length];
  357.                 for (int i = 0; i < serviziList.length; i++) {
  358.                     String idServTmp = serviziList[i];
  359.                     serviziListLabel[i] = porteApplicativeHelper.getLabelIdServizio(protocollo, serviziMapTmp.get(idServTmp));
  360.                 }
  361.             }

  362.             IDServizio idServizio = null;
  363.             AccordoServizioParteSpecifica servS = null;
  364.             if (servizio != null) {
  365.                 boolean servizioPresenteInLista  = false;
  366.                 if(serviziList!=null && serviziList.length>0){
  367.                     for (int i = 0; i < serviziList.length; i++) {
  368.                         if(serviziList[i].equals(servizio)){
  369.                             servizioPresenteInLista = true;
  370.                             break;
  371.                         }
  372.                     }
  373.                 }
  374.                 if(servizioPresenteInLista){
  375.                     String [] tmp = servizio.split(" ");
  376.                     idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(tmp[1].split("/")[0],tmp[1].split("/")[1],
  377.                             tmp[0].split("/")[0],tmp[0].split("/")[1],
  378.                             Integer.parseInt(tmp[1].split("/")[2]));
  379.                     try{
  380.                         servS = apsCore.getServizio(idServizio);
  381.                     }catch(DriverRegistroServiziNotFound dNotFound){
  382.                     }
  383.                 }
  384.                 if(servS==null){
  385.                    
  386.                     // è cambiato il soggetto erogatore. non è più valido il servizio
  387.                     servizio = null;
  388.                     idServizio = null;
  389.                     if(serviziList!=null && serviziList.length>0){
  390.                         servizio = serviziList[0];
  391.                         String []tmp = servizio.split(" ");
  392.                         idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(tmp[1].split("/")[0],tmp[1].split("/")[1],
  393.                                 tmp[0].split("/")[0],tmp[0].split("/")[1],
  394.                                 Integer.parseInt(tmp[1].split("/")[2]));
  395.                         try{
  396.                             servS = apsCore.getServizio(idServizio);
  397.                         }catch(DriverRegistroServiziNotFound dNotFound){
  398.                         }
  399.                         if(servS==null){
  400.                             servizio = null;
  401.                             idServizio = null;
  402.                         }
  403.                     }
  404.                 }
  405.             }
  406.            
  407.             AccordoServizioParteComuneSintetico as = null;
  408.             if (servS != null) {
  409.                 IDAccordo idAccordo = IDAccordoFactory.getInstance().getIDAccordoFromUri(servS.getAccordoServizioParteComune());
  410.                 as = apcCore.getAccordoServizioSintetico(idAccordo);
  411.                 if(serviceBinding == null)
  412.                     serviceBinding = apcCore.toMessageServiceBinding(as.getServiceBinding());
  413.             }
  414.            
  415.             String[] azioniList = null;
  416.             String[] azioniListLabel = null;
  417.             boolean addTrattinoSelezioneNonEffettuata = false;
  418.             List<String> filtraAzioniUtilizzate = new ArrayList<>();
  419.             if ((modeaz != null) && modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_REGISTER_INPUT)) {
  420.            
  421.                 Map<String,String> azioni = porteApplicativeCore.getAzioniConLabel(servS, as, addTrattinoSelezioneNonEffettuata , true, filtraAzioniUtilizzate);
  422.                 if(azioni != null && azioni.size() > 0) {
  423.                     azioniList = new String[azioni.size()];
  424.                     azioniListLabel = new String[azioni.size()];
  425.                     int i = 0;
  426.                     for (String string : azioni.keySet()) {
  427.                         azioniList[i] = string;
  428.                         azioniListLabel[i] = azioni.get(string);
  429.                         i++;
  430.                     }
  431.                 }
  432.             }
  433.            
  434.             // Token Policy
  435.             List<GenericProperties> gestorePolicyTokenList = confCore.gestorePolicyTokenList(null, ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TIPOLOGIA_GESTIONE_POLICY_TOKEN, null);
  436.             String [] policyLabels = new String[gestorePolicyTokenList.size() + 1];
  437.             String [] policyValues = new String[gestorePolicyTokenList.size() + 1];
  438.            
  439.             policyLabels[0] = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  440.             policyValues[0] = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  441.            
  442.             for (int i = 0; i < gestorePolicyTokenList.size(); i++) {
  443.             GenericProperties genericProperties = gestorePolicyTokenList.get(i);
  444.                 policyLabels[(i+1)] = genericProperties.getNome();
  445.                 policyValues[(i+1)] = genericProperties.getNome();
  446.             }
  447.            
  448.             // AttributeAuthority
  449.             List<GenericProperties> attributeAuthorityList = confCore.gestorePolicyTokenList(null, ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TIPOLOGIA_ATTRIBUTE_AUTHORITY, null);
  450.             String [] attributeAuthorityLabels = new String[attributeAuthorityList.size()];
  451.             String [] attributeAuthorityValues = new String[attributeAuthorityList.size()];
  452.             for (int i = 0; i < attributeAuthorityList.size(); i++) {
  453.                 GenericProperties genericProperties = attributeAuthorityList.get(i);
  454.                 attributeAuthorityLabels[i] = genericProperties.getNome();
  455.                 attributeAuthorityValues[i] = genericProperties.getNome();
  456.             }
  457.            
  458.             // Se idhid = null, devo visualizzare la pagina per l'inserimento
  459.             // dati
  460.             if (porteApplicativeHelper.isEditModeInProgress()) {
  461.                 // setto la barra del titolo
  462.                 ServletUtils.setPageDataTitle(pd,
  463.                         new Parameter(SoggettiCostanti.LABEL_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST),
  464.                         new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_PORTE_APPLICATIVE_DI + tmpTitle,
  465.                                 PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_LIST ,
  466.                                 new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg)),
  467.                                 ServletUtils.getParameterAggiungi()
  468.                         );
  469.                
  470.                 // preparo i campi
  471.                 List<DataElement> dati = new ArrayList<>();
  472.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  473.                
  474.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta, dati);

  475.                 if (statoValidazione == null &&
  476.                     porteApplicativeCore.isSinglePdD()){
  477.                     Configurazione config = porteApplicativeCore.getConfigurazioneGenerale();
  478.                     if(config.getValidazioneContenutiApplicativi()!=null){
  479.                         if(config.getValidazioneContenutiApplicativi().getStato()!=null)
  480.                             statoValidazione = config.getValidazioneContenutiApplicativi().getStato().toString();
  481.                         if(config.getValidazioneContenutiApplicativi().getTipo()!=null)
  482.                             tipoValidazione = config.getValidazioneContenutiApplicativi().getTipo().toString();
  483.                         if(StatoFunzionalita.ABILITATO.equals(config.getValidazioneContenutiApplicativi().getAcceptMtomMessage())){
  484.                             applicaMTOM = Costanti.CHECK_BOX_ENABLED_ABILITATO;
  485.                         }
  486.                     }
  487.                 }

  488.                 if (statoValidazione == null) {
  489.                     statoValidazione = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_VALIDAZIONE_DISABILITATO;
  490.                 }
  491.                 if (tipoValidazione == null) {
  492.                     tipoValidazione = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_VALIDAZIONE_INTERFACE;
  493.                 }
  494.                 if (applicaMTOM == null) {
  495.                     applicaMTOM = "";
  496.                 }
  497.                 if (stateless == null) {
  498.                     stateless = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_STATELESS_DEFAULT;
  499.                 }
  500.                 if (gestManifest == null) {
  501.                     gestManifest = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_GEST_MANIFEST_DEFAULT;
  502.                 }
  503.                
  504.                 if (autenticazione == null) {
  505.                     autenticazione = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_AUTENTICAZIONE;
  506.                 }
  507.                 if (autorizzazione == null) {
  508.                     String defaultAutorizzazione = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_AUTORIZZAZIONE;
  509.                     if (defaultAutorizzazione != null &&
  510.                             !TipoAutorizzazione.getAllValues().contains(defaultAutorizzazione)) {
  511.                         autorizzazioneCustom = defaultAutorizzazione;
  512.                         autorizzazione = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTORIZZAZIONE_CUSTOM;
  513.                     }
  514.                     else{
  515.                         autorizzazione = AutorizzazioneUtilities.convertToStato(defaultAutorizzazione);
  516.                         if(TipoAutorizzazione.isAuthenticationRequired(defaultAutorizzazione))
  517.                             autorizzazioneAutenticati = Costanti.CHECK_BOX_ENABLED;
  518.                         if(TipoAutorizzazione.isRolesRequired(defaultAutorizzazione))
  519.                             autorizzazioneRuoli = Costanti.CHECK_BOX_ENABLED;
  520.                         autorizzazioneRuoliTipologia = AutorizzazioneUtilities.convertToRuoloTipologia(defaultAutorizzazione).getValue();
  521.                     }
  522.                 }
  523.                
  524.                 if(gestioneToken == null) {
  525.                     gestioneToken = StatoFunzionalita.DISABILITATO.getValue();
  526.                     gestioneTokenPolicy = CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO;
  527.                     gestioneTokenOpzionale = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_OPZIONALE;
  528.                     gestioneTokenValidazioneInput = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_VALIDAZIONE_INPUT;
  529.                     gestioneTokenIntrospection = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_INTROSPECTION;
  530.                     gestioneTokenUserInfo = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_USER_INFO;
  531.                     gestioneTokenTokenForward = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_TOKEN_FORWARD;
  532.                     autenticazioneTokenIssuer = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_ISSUER;
  533.                     autenticazioneTokenClientId = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_CLIENT_ID;
  534.                     autenticazioneTokenSubject = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_SUBJECT;
  535.                     autenticazioneTokenUsername = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_USERNAME;
  536.                     autenticazioneTokenEMail = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_GESTORE_POLICY_TOKEN_AUTENTICAZIONE_EMAIL;
  537.                 }
  538.                
  539.                 if(autorizzazioneScope == null) {
  540.                     autorizzazioneScope = "";
  541.                 }
  542.                
  543.                 if(autorizzazioneContenutiStato == null)
  544.                     autorizzazioneContenutiStato = StatoFunzionalita.DISABILITATO.getValue();
  545.                
  546.                 if(identificazioneAttributiStato==null) {
  547.                     identificazioneAttributiStato = StatoFunzionalita.DISABILITATO.getValue();
  548.                 }

  549.                 dati = porteApplicativeHelper.addPorteAppToDati(TipoOperazione.ADD,dati, nomePorta, descr, soggvirt, soggettiList,
  550.                         soggettiListLabel, servizio, serviziList, serviziListLabel, azione, azioniList, azioniListLabel,
  551.                         stateless, ricsim, ricasim, null, null, statoValidazione, tipoValidazione, gestBody, gestManifest,
  552.                         null,null,null,null,null,0,null,autorizzazioneContenutiStato, autorizzazioneContenuti, autorizzazioneContenutiProperties,protocollo,
  553.                         numSA,numRuoli, ruoloMatch,
  554.                         statoMessageSecurity,statoMTOM,numCorrelazioneReq,numCorrelazioneRes,numProprProt,applicaMTOM,
  555.                         behaviour,null,null,null,
  556.                         autenticazione, autorizzazione,
  557.                         autenticazioneOpzionale, autenticazionePrincipal, autenticazioneParametroList, autenticazioneCustom, autorizzazioneCustom,
  558.                         isSupportatoAutenticazioneSoggetti,autorizzazioneAutenticati,autorizzazioneRuoli,autorizzazioneRuoliTipologia,
  559.                         servS,as,serviceBinding,
  560.                         statoPorta, modeaz,  azid,  azione, forceWsdlBased,false,false,
  561.                         false,null,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, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE,
  577.                         ForwardParams.ADD());

  578.             }

  579.             // Controlli sui campi immessi
  580.             boolean isOk = porteApplicativeHelper.porteAppCheckData(TipoOperazione.ADD, null, isSupportatoAutenticazioneSoggetti, false,
  581.                     serviceBinding);
  582.             if (!isOk) {
  583.                 // setto la barra del titolo
  584.                 ServletUtils.setPageDataTitle(pd,
  585.                         new Parameter(SoggettiCostanti.LABEL_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST),
  586.                         new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_PORTE_APPLICATIVE_DI + tmpTitle,
  587.                                 PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_LIST ,
  588.                                 new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg)),
  589.                                 ServletUtils.getParameterAggiungi()
  590.                         );

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

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

  594.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta, dati);

  595.                 dati = porteApplicativeHelper.addPorteAppToDati(TipoOperazione.ADD,dati, nomePorta, descr, soggvirt, soggettiList,
  596.                         soggettiListLabel, servizio, serviziList,
  597.                         serviziListLabel, azione, azioniList, azioniListLabel, stateless, ricsim, ricasim,
  598.                         null, null, statoValidazione, tipoValidazione, gestBody, gestManifest,null,null,null,null,null,0,null,autorizzazioneContenutiStato, autorizzazioneContenuti, autorizzazioneContenutiProperties,protocollo,
  599.                         numSA,numRuoli, ruoloMatch,
  600.                         statoMessageSecurity,statoMTOM,numCorrelazioneReq,numCorrelazioneRes,numProprProt,applicaMTOM,
  601.                         behaviour,null,null,null,
  602.                         autenticazione, autorizzazione,
  603.                         autenticazioneOpzionale, autenticazionePrincipal, autenticazioneParametroList, autenticazioneCustom, autorizzazioneCustom,
  604.                         isSupportatoAutenticazioneSoggetti,autorizzazioneAutenticati,autorizzazioneRuoli,autorizzazioneRuoliTipologia,
  605.                         servS,as,serviceBinding,
  606.                         statoPorta, modeaz,  azid, azione, forceWsdlBased, false,false,
  607.                         false,null,gestioneToken,policyLabels, policyValues,
  608.                         gestioneTokenPolicy,gestioneTokenOpzionale,
  609.                         gestioneTokenValidazioneInput,gestioneTokenIntrospection,gestioneTokenUserInfo,gestioneTokenTokenForward,
  610.                         autenticazioneTokenIssuer, autenticazioneTokenClientId, autenticazioneTokenSubject, autenticazioneTokenUsername, autenticazioneTokenEMail,
  611.                         autorizzazioneToken, autorizzazioneTokenOptions,
  612.                         autorizzazioneScope,numScope, autorizzazioneScopeMatch,allegatoXacmlPolicy,
  613.                         null,null,
  614.                         identificazioneAttributiStato, null,null, attributeAuthoritySelezionate, attributeAuthorityAttributi,
  615.                         autorizzazioneAutenticatiToken, null, 0,
  616.                         autorizzazioneRuoliToken,  null, 0, autorizzazioneRuoliTipologiaToken, autorizzazioneRuoliMatchToken,
  617.                         ctModalitaSincronizzazione, ctImplementazione, ctContatori, ctTipologia,
  618.                         ctHeaderHttp, ctHeaderHttpLimit, ctHeaderHttpRemaining, ctHeaderHttpReset,
  619.                         ctHeaderHttpRetryAfter, ctHeaderHttpRetryAfterBackoff);

  620.                 pd.setDati(dati);

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

  622.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE,
  623.                         ForwardParams.ADD());
  624.             }

  625.             // Inserisco la porta applicativa nel db
  626.             PortaApplicativa pa = new PortaApplicativa();
  627.             pa.setNome(nomePorta);
  628.             pa.setNomeSoggettoProprietario(nomeSoggettoProprietario);
  629.             pa.setTipoSoggettoProprietario(tipoSoggettoProprietario);
  630.             pa.setDescrizione(descr);
  631.             if(statoPorta==null || "".equals(statoPorta) || CostantiConfigurazione.ABILITATO.toString().equals(statoPorta)){
  632.                 pa.setStato(StatoFunzionalita.ABILITATO);
  633.             }
  634.             else{
  635.                 pa.setStato(StatoFunzionalita.DISABILITATO);
  636.             }
  637.             if(autorizzazioneContenutiStato.equals(StatoFunzionalita.DISABILITATO.getValue())) {
  638.                 pa.setAutorizzazioneContenuto(null);
  639.                 pa.getProprietaAutorizzazioneContenutoList().clear();
  640.             } else if(autorizzazioneContenutiStato.equals(StatoFunzionalita.ABILITATO.getValue())) {
  641.                 pa.setAutorizzazioneContenuto(CostantiAutorizzazione.AUTORIZZAZIONE_CONTENUTO_BUILT_IN);
  642.                 pa.getProprietaAutorizzazioneContenutoList().clear();
  643.                 SortedMap<List<String>> convertTextToProperties = PropertiesUtilities.convertTextToSortedListMap(autorizzazioneContenutiProperties, true);
  644.                 porteApplicativeCore.addFromSortedListMap(pa.getProprietaAutorizzazioneContenutoList(), convertTextToProperties);
  645.             } else {
  646.                 pa.setAutorizzazioneContenuto(autorizzazioneContenuti);
  647.             }
  648.            
  649.             if (autenticazione == null ||
  650.                     !autenticazione.equals(CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTENTICAZIONE_CUSTOM))
  651.                 pa.setAutenticazione(autenticazione);
  652.             else
  653.                 pa.setAutenticazione(autenticazioneCustom);
  654.             if(autenticazioneOpzionale != null){
  655.                 if(ServletUtils.isCheckBoxEnabled(autenticazioneOpzionale))
  656.                     pa.setAutenticazioneOpzionale(StatoFunzionalita.ABILITATO);
  657.                 else
  658.                     pa.setAutenticazioneOpzionale(StatoFunzionalita.DISABILITATO);
  659.             } else
  660.                 pa.setAutenticazioneOpzionale(null);
  661.             List<Proprieta> proprietaAutenticazione = porteApplicativeCore.convertToAutenticazioneProprieta(autenticazione, autenticazionePrincipal, autenticazioneParametroList);
  662.             if(proprietaAutenticazione!=null && !proprietaAutenticazione.isEmpty()) {
  663.                 pa.getProprietaAutenticazioneList().addAll(proprietaAutenticazione);
  664.             }
  665.            
  666.             if (autorizzazione == null ||
  667.                     !autorizzazione.equals(CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PORTE_AUTORIZZAZIONE_CUSTOM))
  668.                 pa.setAutorizzazione(AutorizzazioneUtilities.convertToTipoAutorizzazioneAsString(autorizzazione,
  669.                         ServletUtils.isCheckBoxEnabled(autorizzazioneAutenticati),
  670.                         ServletUtils.isCheckBoxEnabled(autorizzazioneRuoli),
  671.                         ServletUtils.isCheckBoxEnabled(autorizzazioneAutenticatiToken),
  672.                         ServletUtils.isCheckBoxEnabled(autorizzazioneRuoliToken),
  673.                         ServletUtils.isCheckBoxEnabled(autorizzazioneScope),
  674.                         autorizzazioneTokenOptions,
  675.                         RuoloTipologia.toEnumConstant(autorizzazioneRuoliTipologia)));
  676.             else
  677.                 pa.setAutorizzazione(autorizzazioneCustom);
  678.                        
  679.             if(ruoloMatch!=null && !"".equals(ruoloMatch)){
  680.                 RuoloTipoMatch tipoRuoloMatch = RuoloTipoMatch.toEnumConstant(ruoloMatch);
  681.                 if(tipoRuoloMatch!=null){
  682.                     if(pa.getRuoli()==null){
  683.                         pa.setRuoli(new AutorizzazioneRuoli());
  684.                     }
  685.                     pa.getRuoli().setMatch(tipoRuoloMatch);
  686.                 }
  687.             }
  688.             if(ServletUtils.isCheckBoxEnabled(autorizzazioneScope )) {
  689.                 if(pa.getScope() == null)
  690.                     pa.setScope(new AutorizzazioneScope());
  691.                
  692.                 pa.getScope().setStato(StatoFunzionalita.ABILITATO);
  693.             }
  694.             else {
  695.                 pa.setScope(null);
  696.             }
  697.             if(autorizzazioneScopeMatch!=null && !"".equals(autorizzazioneScopeMatch)){
  698.                 ScopeTipoMatch scopeTipoMatch = ScopeTipoMatch.toEnumConstant(autorizzazioneScopeMatch);
  699.                 if(scopeTipoMatch!=null){
  700.                     if(pa.getScope()==null){
  701.                         pa.setScope(new AutorizzazioneScope());
  702.                     }
  703.                     pa.getScope().setMatch(scopeTipoMatch);
  704.                 }
  705.             }
  706.            
  707.             if(pa.getGestioneToken() == null)
  708.                 pa.setGestioneToken(new GestioneToken());
  709.            
  710.             if(gestioneToken.equals(StatoFunzionalita.ABILITATO.getValue())) {
  711.                 pa.getGestioneToken().setPolicy(gestioneTokenPolicy);
  712.                 if(ServletUtils.isCheckBoxEnabled(gestioneTokenOpzionale)) {
  713.                     pa.getGestioneToken().setTokenOpzionale(StatoFunzionalita.ABILITATO);
  714.                 }
  715.                 else {
  716.                     pa.getGestioneToken().setTokenOpzionale(StatoFunzionalita.DISABILITATO);
  717.                 }
  718.                 pa.getGestioneToken().setValidazione(StatoFunzionalitaConWarning.toEnumConstant(gestioneTokenValidazioneInput));
  719.                 pa.getGestioneToken().setIntrospection(StatoFunzionalitaConWarning.toEnumConstant(gestioneTokenIntrospection));
  720.                 pa.getGestioneToken().setUserInfo(StatoFunzionalitaConWarning.toEnumConstant(gestioneTokenUserInfo));
  721.                 pa.getGestioneToken().setForward(StatoFunzionalita.toEnumConstant(gestioneTokenTokenForward));
  722.                 pa.getGestioneToken().setOptions(autorizzazioneTokenOptions);
  723.                 if(pa.getGestioneToken().getAutenticazione()==null) {
  724.                     pa.getGestioneToken().setAutenticazione(new GestioneTokenAutenticazione());
  725.                 }
  726.                 pa.getGestioneToken().getAutenticazione().setIssuer(ServletUtils.isCheckBoxEnabled(autenticazioneTokenIssuer) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenIssuer));
  727.                 pa.getGestioneToken().getAutenticazione().setClientId(ServletUtils.isCheckBoxEnabled(autenticazioneTokenClientId) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenClientId));
  728.                 pa.getGestioneToken().getAutenticazione().setSubject(ServletUtils.isCheckBoxEnabled(autenticazioneTokenSubject) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenSubject));
  729.                 pa.getGestioneToken().getAutenticazione().setUsername(ServletUtils.isCheckBoxEnabled(autenticazioneTokenUsername) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenUsername));
  730.                 pa.getGestioneToken().getAutenticazione().setEmail(ServletUtils.isCheckBoxEnabled(autenticazioneTokenEMail) ? StatoFunzionalita.ABILITATO : StatoFunzionalita.toEnumConstant(autenticazioneTokenEMail));
  731.             } else {
  732.                 pa.getGestioneToken().setPolicy(null);
  733.                 pa.getGestioneToken().setTokenOpzionale(StatoFunzionalita.DISABILITATO);
  734.                 pa.getGestioneToken().setValidazione(StatoFunzionalitaConWarning.DISABILITATO);
  735.                 pa.getGestioneToken().setValidazione(StatoFunzionalitaConWarning.DISABILITATO);
  736.                 pa.getGestioneToken().setIntrospection(StatoFunzionalitaConWarning.DISABILITATO);
  737.                 pa.getGestioneToken().setUserInfo(StatoFunzionalitaConWarning.DISABILITATO);
  738.                 pa.getGestioneToken().setForward(StatoFunzionalita.DISABILITATO);
  739.                 pa.getGestioneToken().setOptions(null);
  740.                 if(pa.getGestioneToken().getAutenticazione()!=null) {
  741.                     pa.getGestioneToken().setAutenticazione(null);
  742.                 }
  743.             }
  744.            
  745.             if (stateless!=null && !stateless.equals(PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_STATELESS_DEFAULT))
  746.                 pa.setStateless(StatoFunzionalita.toEnumConstant(stateless));
  747.             if (PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_GEST_BODY_ALLEGA.equals(gestBody))
  748.                 pa.setAllegaBody(StatoFunzionalita.toEnumConstant(PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_ABILITATO));
  749.             else
  750.                 pa.setAllegaBody(StatoFunzionalita.toEnumConstant(PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_DISABILITATO));
  751.             if (PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_GEST_BODY_SCARTA.equals(gestBody))
  752.                 pa.setScartaBody(StatoFunzionalita.toEnumConstant(PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_ABILITATO));
  753.             else
  754.                 pa.setScartaBody(StatoFunzionalita.toEnumConstant(PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_DISABILITATO));
  755.             if (gestManifest!=null && !gestManifest.equals(PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_GEST_MANIFEST_DEFAULT))
  756.                 pa.setGestioneManifest(StatoFunzionalita.toEnumConstant(gestManifest));
  757.             pa.setRicevutaAsincronaSimmetrica(StatoFunzionalita.toEnumConstant(ricsim));
  758.             pa.setRicevutaAsincronaAsimmetrica(StatoFunzionalita.toEnumConstant(ricasim));
  759.             if ( (!soggvirt.equals("")) && (!soggvirt.equals("-")) ){
  760.                 String tipoSoggVirt = soggvirt.split("/")[0];
  761.                 String nomeSoggVirt = soggvirt.split("/")[1];
  762.                 PortaApplicativaSoggettoVirtuale pasv = new PortaApplicativaSoggettoVirtuale();
  763.                 pasv.setTipo(tipoSoggVirt);
  764.                 pasv.setNome(nomeSoggVirt);
  765.                 pa.setSoggettoVirtuale(pasv);
  766.             }

  767.             if (servizio!=null) {
  768.                 String [] tmp = servizio.split(" ");
  769.                 idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(tmp[1].split("/")[0],tmp[1].split("/")[1],
  770.                         tmp[0].split("/")[0],tmp[0].split("/")[1],
  771.                         Integer.parseInt(tmp[1].split("/")[2]));
  772.                 PortaApplicativaServizio pas = new PortaApplicativaServizio();
  773.                 pas.setTipo(idServizio.getTipo());
  774.                 pas.setNome(idServizio.getNome());
  775.                 pas.setVersione(idServizio.getVersione());
  776.                 pa.setServizio(pas);
  777.             }
  778.            
  779.             // se l azione e' settata allora creo il bean
  780.             if ((!azione.equals("") ||
  781.                             modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_INPUT_BASED) ||
  782.                             modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_SOAP_ACTION_BASED) ||
  783.                             modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_PROTOCOL_BASED) ||
  784.                             modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_INTERFACE_BASED)) ||
  785.                             !azid.equals("")) {
  786.                 PortaApplicativaAzione paa = new PortaApplicativaAzione();

  787.                 if (modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_REGISTER_INPUT)) {
  788.                     azione = azid;
  789.                     if(paa.getId()<=0){
  790.                         paa.setId(-2l);
  791.                     }
  792.                 }
  793.                
  794.                 paa.setIdentificazione(PortaApplicativaAzioneIdentificazione.toEnumConstant(modeaz));
  795.                
  796.                 if (modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_HEADER_BASED) ||
  797.                         modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_URL_BASED) ||
  798.                         modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_CONTENT_BASED)
  799.                         ) {
  800.                     paa.setNome(null);
  801.                     paa.setPattern(azione);
  802.                 }
  803.                 else if (modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_REGISTER_INPUT)
  804.                         ) {
  805.                     paa.setNome(azione);
  806.                     paa.setPattern(null);
  807.                 }
  808.                 else {
  809.                     paa.setNome(null);
  810.                     paa.setPattern(null);
  811.                 }

  812.                 //FORCE WSDL BASED
  813.                 if(!modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_REGISTER_INPUT) &&
  814.                         !modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_PROTOCOL_BASED) &&
  815.                         !modeaz.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MODE_INTERFACE_BASED)){

  816.                     if(forceWsdlBased != null && (ServletUtils.isCheckBoxEnabled(forceWsdlBased))){
  817.                         paa.setForceInterfaceBased(StatoFunzionalita.ABILITATO);
  818.                     }else {
  819.                         paa.setForceInterfaceBased(StatoFunzionalita.DISABILITATO);
  820.                     }
  821.                 }else {
  822.                     paa.setForceInterfaceBased(null);
  823.                 }

  824.                 pa.setAzione(paa);
  825.             } else
  826.                 pa.setAzione(null);

  827.             pa.setStatoMessageSecurity(PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_DISABILITATO);
  828.             pa.setIdSoggetto(Long.valueOf(soggInt));

  829.             ValidazioneContenutiApplicativi vx = new ValidazioneContenutiApplicativi();
  830.             vx.setStato(StatoFunzionalitaConWarning.toEnumConstant(statoValidazione));
  831.             vx.setTipo(ValidazioneContenutiApplicativiTipo.toEnumConstant(tipoValidazione));
  832.            
  833.             if(applicaMTOM != null){
  834.                 if(ServletUtils.isCheckBoxEnabled(applicaMTOM))
  835.                     vx.setAcceptMtomMessage(StatoFunzionalita.ABILITATO);
  836.                 else
  837.                     vx.setAcceptMtomMessage(StatoFunzionalita.DISABILITATO);
  838.             } else
  839.                 vx.setAcceptMtomMessage(null);
  840.            
  841.             pa.setValidazioneContenutiApplicativi(vx);

  842.             if(!porteApplicativeCore.isConnettoriMultipliEnabled()) {
  843.                 if(behaviour!=null && !"".equals(behaviour)) {
  844.                     pa.setBehaviour(new PortaApplicativaBehaviour());
  845.                     pa.getBehaviour().setNome(behaviour);
  846.                 }
  847.                 else
  848.                     pa.setBehaviour(null);
  849.             }
  850.            
  851.             if(autorizzazione != null && autorizzazione.equals(AutorizzazioneUtilities.STATO_XACML_POLICY) && allegatoXacmlPolicy.getValue() != null) {
  852.                 pa.setXacmlPolicy(new String(allegatoXacmlPolicy.getValue()));
  853.             } else {
  854.                 pa.setXacmlPolicy(null);
  855.             }
  856.            
  857.             String userLogin = ServletUtils.getUserLoginFromSession(session);      

  858.             porteApplicativeCore.performCreateOperation(userLogin, porteApplicativeHelper.smista(), pa);
  859.            
  860.             // Preparo la lista
  861.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  862.             int idLista = Liste.PORTE_APPLICATIVE_BY_SOGGETTO;
  863.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  864.             List<PortaApplicativa> lista = porteApplicativeCore.porteAppList(soggInt, ricerca);

  865.             porteApplicativeHelper.preparePorteAppList(ricerca, lista, idLista);

  866.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  867.             // Forward control to the specified success URI
  868.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE,
  869.                     ForwardParams.ADD());

  870.         } catch (Exception e) {
  871.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  872.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE,
  873.                     ForwardParams.ADD());
  874.         }  
  875.     }
  876. }