SoggettiHelper.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.soggetti;

  21. import java.text.MessageFormat;
  22. import java.util.ArrayList;
  23. import java.util.Date;
  24. import java.util.Iterator;
  25. import java.util.List;

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

  28. import org.apache.commons.lang.StringEscapeUtils;
  29. import org.apache.commons.lang.StringUtils;
  30. import org.openspcoop2.core.commons.Filtri;
  31. import org.openspcoop2.core.commons.ISearch;
  32. import org.openspcoop2.core.commons.Liste;
  33. import org.openspcoop2.core.commons.SearchUtils;
  34. import org.openspcoop2.core.config.Credenziali;
  35. import org.openspcoop2.core.config.PortaApplicativa;
  36. import org.openspcoop2.core.config.ServizioApplicativo;
  37. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  38. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  39. import org.openspcoop2.core.config.driver.DriverConfigurazioneNotFound;
  40. import org.openspcoop2.core.config.driver.FiltroRicercaPorteApplicative;
  41. import org.openspcoop2.core.constants.TipiConnettore;
  42. import org.openspcoop2.core.constants.TipoPdD;
  43. import org.openspcoop2.core.id.IDPortaApplicativa;
  44. import org.openspcoop2.core.id.IDSoggetto;
  45. import org.openspcoop2.core.registry.CredenzialiSoggetto;
  46. import org.openspcoop2.core.registry.Proprieta;
  47. import org.openspcoop2.core.registry.Ruolo;
  48. import org.openspcoop2.core.registry.Soggetto;
  49. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  50. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  51. import org.openspcoop2.protocol.engine.ConfigurazioneFiltroServiziApplicativi;
  52. import org.openspcoop2.protocol.sdk.constants.ArchiveType;
  53. import org.openspcoop2.utils.certificate.ArchiveLoader;
  54. import org.openspcoop2.utils.certificate.Certificate;
  55. import org.openspcoop2.utils.certificate.byok.BYOKManager;
  56. import org.openspcoop2.utils.regexp.RegularExpressionEngine;
  57. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  58. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  59. import org.openspcoop2.web.ctrlstat.core.Utilities;
  60. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  61. import org.openspcoop2.web.ctrlstat.costanti.InUsoType;
  62. import org.openspcoop2.web.ctrlstat.dao.PdDControlStation;
  63. import org.openspcoop2.web.ctrlstat.driver.DriverControlStationException;
  64. import org.openspcoop2.web.ctrlstat.driver.DriverControlStationNotFound;
  65. import org.openspcoop2.web.ctrlstat.plugins.ExtendedConnettore;
  66. import org.openspcoop2.web.ctrlstat.servlet.archivi.ExporterUtils;
  67. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriCostanti;
  68. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriHelper;
  69. import org.openspcoop2.web.ctrlstat.servlet.pa.PorteApplicativeCostanti;
  70. import org.openspcoop2.web.ctrlstat.servlet.pd.PorteDelegateCostanti;
  71. import org.openspcoop2.web.ctrlstat.servlet.pdd.PddCostanti;
  72. import org.openspcoop2.web.ctrlstat.servlet.ruoli.RuoliCostanti;
  73. import org.openspcoop2.web.ctrlstat.servlet.sa.ServiziApplicativiCostanti;
  74. import org.openspcoop2.web.lib.mvc.AreaBottoni;
  75. import org.openspcoop2.web.lib.mvc.BinaryParameter;
  76. import org.openspcoop2.web.lib.mvc.Costanti;
  77. import org.openspcoop2.web.lib.mvc.DataElement;
  78. import org.openspcoop2.web.lib.mvc.DataElementType;
  79. import org.openspcoop2.web.lib.mvc.PageData;
  80. import org.openspcoop2.web.lib.mvc.Parameter;
  81. import org.openspcoop2.web.lib.mvc.ServletUtils;
  82. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  83. /**
  84.  * SoggettiHelper
  85.  *
  86.  * @author Poli Andrea (apoli@link.it)
  87.  * @author $Author$
  88.  * @version $Rev$, $Date$
  89.  */
  90. public class SoggettiHelper extends ConnettoriHelper {

  91.     public SoggettiHelper(HttpServletRequest request, PageData pd,
  92.             HttpSession session) throws Exception {
  93.         super(request, pd,  session);
  94.     }
  95.     public SoggettiHelper(ControlStationCore core, HttpServletRequest request, PageData pd,
  96.             HttpSession session) throws Exception {
  97.         super(core, request, pd,  session);
  98.     }

  99.     public List<DataElement> addSoggettiToDati(TipoOperazione tipoOp,List<DataElement> dati, String nomeprov, String tipoprov, String portadom, String descr,
  100.             boolean isRouter, List<String> tipiSoggetti, String profilo, boolean privato, String codiceIpa, List<String> versioni,
  101.             boolean isSupportatoCodiceIPA, boolean isSupportatoIdentificativoPorta,
  102.             String [] pddList,String[] pddEsterneList,String nomePddGestioneLocale, String pdd,
  103.             List<String> listaTipiProtocollo, String protocollo,
  104.             boolean isSupportatoAutenticazioneSoggetti, String utente,String password, String subject, String principal, String tipoauth,
  105.             boolean isPddEsterna,String tipologia, String dominio,
  106.             String tipoCredenzialiSSLSorgente, org.openspcoop2.utils.certificate.ArchiveType tipoCredenzialiSSLTipoArchivio, BinaryParameter tipoCredenzialiSSLFileCertificato, String tipoCredenzialiSSLFileCertificatoPassword,
  107.             List<String> listaAliasEstrattiCertificato, String tipoCredenzialiSSLAliasCertificato,  String tipoCredenzialiSSLAliasCertificatoSubject, String tipoCredenzialiSSLAliasCertificatoIssuer,
  108.             String tipoCredenzialiSSLAliasCertificatoType, String tipoCredenzialiSSLAliasCertificatoVersion, String tipoCredenzialiSSLAliasCertificatoSerialNumber, String tipoCredenzialiSSLAliasCertificatoSelfSigned,
  109.             String tipoCredenzialiSSLAliasCertificatoNotBefore, String tipoCredenzialiSSLAliasCertificatoNotAfter, String tipoCredenzialiSSLVerificaTuttiICampi, String tipoCredenzialiSSLConfigurazioneManualeSelfSigned,
  110.             String issuer,String tipoCredenzialiSSLStatoElaborazioneCertificato,
  111.             String changepwd,
  112.             String multipleApiKey, String appId, String apiKey,
  113.             boolean visualizzaModificaCertificato, boolean visualizzaAddCertificato, String servletCredenzialiList, List<Parameter> parametersServletCredenzialiList, Integer numeroCertificati, String servletCredenzialiAdd) throws Exception  {
  114.         return addSoggettiToDati(tipoOp, dati, nomeprov, tipoprov, portadom, descr,
  115.                 isRouter, tipiSoggetti, profilo, privato, codiceIpa, versioni,
  116.                 isSupportatoCodiceIPA, isSupportatoIdentificativoPorta,
  117.                 pddList, pddEsterneList, nomePddGestioneLocale, pdd,
  118.                 null,null,null,null,
  119.                 -1,null,-1,null,listaTipiProtocollo,protocollo,
  120.                 isSupportatoAutenticazioneSoggetti, utente, password, subject, principal, tipoauth,
  121.                 isPddEsterna, tipologia, dominio,
  122.                 tipoCredenzialiSSLSorgente, tipoCredenzialiSSLTipoArchivio, tipoCredenzialiSSLFileCertificato, tipoCredenzialiSSLFileCertificatoPassword, listaAliasEstrattiCertificato,
  123.                 tipoCredenzialiSSLAliasCertificato, tipoCredenzialiSSLAliasCertificatoSubject, tipoCredenzialiSSLAliasCertificatoIssuer,
  124.                 tipoCredenzialiSSLAliasCertificatoType, tipoCredenzialiSSLAliasCertificatoVersion, tipoCredenzialiSSLAliasCertificatoSerialNumber,
  125.                 tipoCredenzialiSSLAliasCertificatoSelfSigned, tipoCredenzialiSSLAliasCertificatoNotBefore, tipoCredenzialiSSLAliasCertificatoNotAfter,
  126.                 tipoCredenzialiSSLVerificaTuttiICampi, tipoCredenzialiSSLConfigurazioneManualeSelfSigned, issuer,tipoCredenzialiSSLStatoElaborazioneCertificato,
  127.                 changepwd,
  128.                 multipleApiKey, appId, apiKey,
  129.                 visualizzaModificaCertificato, visualizzaAddCertificato, servletCredenzialiList, parametersServletCredenzialiList, numeroCertificati, servletCredenzialiAdd, 0);
  130.     }
  131.     public List<DataElement> addSoggettiToDati(TipoOperazione tipoOp,List<DataElement> dati, String nomeprov, String tipoprov, String portadom, String descr,
  132.             boolean isRouter, List<String> tipiSoggetti, String profilo, boolean privato, String codiceIpa, List<String> versioni,
  133.             boolean isSupportatoCodiceIPA, boolean isSupportatoIdentificativoPorta,
  134.             String [] pddList,String[] pddEsterneList,String nomePddGestioneLocale,String pdd,
  135.             String id, String oldnomeprov, String oldtipoprov, org.openspcoop2.core.registry.Connettore connettore,
  136.             long numPD,String pdUrlPrefixRewriter,long numPA, String paUrlPrefixRewriter, List<String> listaTipiProtocollo, String protocollo,
  137.             boolean isSupportatoAutenticazioneSoggetti, String utente,String password, String subject, String principal, String tipoauth,
  138.             boolean isPddEsterna,String tipologia, String dominio,String tipoCredenzialiSSLSorgente, org.openspcoop2.utils.certificate.ArchiveType tipoCredenzialiSSLTipoArchivio, BinaryParameter tipoCredenzialiSSLFileCertificato, String tipoCredenzialiSSLFileCertificatoPassword,
  139.             List<String> listaAliasEstrattiCertificato, String tipoCredenzialiSSLAliasCertificato,  String tipoCredenzialiSSLAliasCertificatoSubject, String tipoCredenzialiSSLAliasCertificatoIssuer,
  140.             String tipoCredenzialiSSLAliasCertificatoType, String tipoCredenzialiSSLAliasCertificatoVersion, String tipoCredenzialiSSLAliasCertificatoSerialNumber, String tipoCredenzialiSSLAliasCertificatoSelfSigned,
  141.             String tipoCredenzialiSSLAliasCertificatoNotBefore, String tipoCredenzialiSSLAliasCertificatoNotAfter, String tipoCredenzialiSSLVerificaTuttiICampi, String tipoCredenzialiSSLConfigurazioneManualeSelfSigned,
  142.             String issuer,String tipoCredenzialiSSLStatoElaborazioneCertificato,
  143.             String changepwd,
  144.             String multipleApiKey, String appId, String apiKey,
  145.             boolean visualizzaModificaCertificato, boolean visualizzaAddCertificato, String servletCredenzialiList, List<Parameter> parametersServletCredenzialiList, Integer numeroCertificati, String servletCredenzialiAdd, int numeroProprieta) throws Exception {

  146.         Soggetto soggetto = null;
  147.         if(TipoOperazione.CHANGE.equals(tipoOp) &&
  148.                 oldtipoprov!=null && !"".equals(oldtipoprov) &&
  149.                 oldnomeprov!=null && !"".equals(oldnomeprov)) {
  150.             IDSoggetto idSoggetto = new IDSoggetto(oldtipoprov, oldnomeprov);
  151.             soggetto = this.soggettiCore.getSoggettoRegistro(idSoggetto);
  152.         }

  153.         if(TipoOperazione.CHANGE.equals(tipoOp)){
  154.             String labelSoggetto = this.getLabelNomeSoggetto(protocollo, tipoprov, nomeprov);
  155.            
  156.             List<Parameter> listaParametriChange = new ArrayList<>();
  157.             listaParametriChange.add(new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,id));
  158.             listaParametriChange.add(new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME,nomeprov));
  159.             listaParametriChange.add(new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO,tipoprov));
  160.            
  161.             // In Uso Button
  162.             this.addComandoInUsoButton(labelSoggetto,
  163.                     id,
  164.                     InUsoType.SOGGETTO);
  165.            
  166.             // Verifica Certificati
  167.             if(this.core.isSoggettiVerificaCertificati()) {
  168.                 // Verifica certificati visualizzato solo se il soggetto ha credenziali https
  169.                 boolean ssl = false;
  170.                 if(org.openspcoop2.core.registry.constants.CredenzialeTipo.SSL.equals(tipoauth)) {
  171.                         //&& c.getCertificate()!=null) { non viene ritornato dalla lista
  172.                     ssl = true;
  173.                 }
  174.                 if(ssl) {
  175.                     this.pd.addComandoVerificaCertificatiElementoButton(SoggettiCostanti.SERVLET_NAME_SOGGETTI_VERIFICA_CERTIFICATI, listaParametriChange);
  176.                 }
  177.             }
  178.            
  179.             // se e' abilitata l'opzione reset cache per elemento, visualizzo il comando nell'elenco dei comandi disponibili nella lista
  180.             if(this.core.isElenchiVisualizzaComandoResetCacheSingoloElemento()){
  181.                 listaParametriChange.add(new Parameter(CostantiControlStation.PARAMETRO_ELIMINA_ELEMENTO_DALLA_CACHE, "true"));
  182.                 this.pd.addComandoResetCacheElementoButton(SoggettiCostanti.SERVLET_NAME_SOGGETTI_CHANGE, listaParametriChange);
  183.             }
  184.            
  185.             // Proprieta Button
  186.             if(this.existsProprietaOggetto(soggetto.getProprietaOggetto(), soggetto.getDescrizione())) {
  187.                 this.addComandoProprietaOggettoButton(labelSoggetto,id, InUsoType.SOGGETTO);
  188.             }
  189.         }
  190.        

  191.        
  192.        
  193.         Boolean contaListe = ServletUtils.getContaListeFromSession(this.session);
  194.        
  195.         if(TipoOperazione.CHANGE.equals(tipoOp)){
  196.             DataElement de = new DataElement();
  197.             de.setLabel(SoggettiCostanti.PARAMETRO_SOGGETTO_ID);
  198.             de.setValue(id);
  199.             de.setType(DataElementType.HIDDEN);
  200.             de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_ID);
  201.             dati.add(de);
  202.         }

  203.        
  204.         DataElement de = new DataElement();
  205.         de.setLabel(SoggettiCostanti.LABEL_SOGGETTO);
  206.         de.setType(DataElementType.TITLE);
  207.         dati.add(de);
  208.        
  209.         boolean gestionePdd = true;
  210.         if(this.core.isSinglePdD() &&
  211.             !this.core.isGestionePddAbilitata(this)) {
  212.             gestionePdd = false;
  213.         }
  214.        
  215.         boolean multiTenant = this.core.isMultitenant();
  216.         boolean hiddenDatiDominioInterno = false;
  217.         if(!multiTenant &&
  218.             !gestionePdd) {
  219.             hiddenDatiDominioInterno = SoggettiCostanti.SOGGETTO_DOMINIO_OPERATIVO_VALUE.equals(dominio);
  220.         }
  221.        
  222.         if(gestionePdd) {
  223.            
  224.             if(TipoOperazione.ADD.equals(tipoOp)){
  225.                
  226.                 if(this.core.isRegistroServiziLocale()){
  227.                     de = new DataElement();
  228.                     de.setLabel(PddCostanti.LABEL_PORTA_DI_DOMINIO);
  229.                     de.setType(DataElementType.SELECT);
  230.                     de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_PDD);
  231.                     if(this.soggettiCore.isMultitenant()) {
  232.                         de.setValues(pddList);
  233.                     }
  234.                     else {
  235.                         de.setValues(pddEsterneList);
  236.                     }
  237.                     de.setSelected(pdd);
  238.                     de.setPostBack(isSupportatoAutenticazioneSoggetti);
  239.                     if (this.core.isSinglePdD()) {
  240.                         if(
  241.                                 (pdd==null || "".equals(pdd))
  242.                                 &&
  243.                                 nomePddGestioneLocale!=null
  244.                             ){
  245.                             de.setSelected(nomePddGestioneLocale);
  246.                         }
  247.                     }else{
  248.                         de.setRequired(true);
  249.                     }
  250.                     dati.add(de);
  251.                 }
  252.             }
  253.             else{      
  254.                 if(this.core.isSinglePdD()){
  255.                     if(this.core.isRegistroServiziLocale()){
  256.                         de = new DataElement();
  257.                         de.setLabel(PddCostanti.LABEL_PORTA_DI_DOMINIO);
  258.                         de.setType(DataElementType.SELECT);
  259.                         de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_PDD);
  260.                         if(this.soggettiCore.isMultitenant()) {
  261.                             de.setValues(pddList);
  262.                         }
  263.                         else {
  264.                             de.setValues(pddEsterneList);
  265.                         }
  266.                         de.setSelected(pdd);
  267.                         de.setPostBack(isSupportatoAutenticazioneSoggetti);
  268.                         dati.add(de);
  269.                     }
  270.                 }else{
  271.                     de = new DataElement();
  272.                     de.setLabel(PddCostanti.LABEL_PORTA_DI_DOMINIO);
  273.                     de.setType(DataElementType.TEXT);
  274.                     de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_PDD);
  275.                     de.setValue(pdd);
  276.                     dati.add(de);
  277.                 }
  278.             }
  279.         }
  280.         else {
  281.             boolean listOperativoSolamente = false;
  282.             if(pddList!=null && pddList.length==1 && pddList[0].equals(nomePddGestioneLocale)) {
  283.                 listOperativoSolamente = true;
  284.             }
  285.            
  286.             de = new DataElement();
  287.             de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_DOMINIO);
  288.             de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_DOMINIO);
  289.             if(!multiTenant) {
  290.                 de.setType(DataElementType.HIDDEN);
  291.                 de.setValue(dominio);
  292.             }
  293.             else if(TipoOperazione.CHANGE.equals(tipoOp) && listOperativoSolamente){
  294.                 de.setType(DataElementType.HIDDEN);
  295.                 de.setValue(dominio);
  296.                 dati.add(de);
  297.                
  298.                 de = new DataElement();
  299.                 de.setType(DataElementType.TEXT);
  300.                 de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_DOMINIO);
  301.                 de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_DOMINIO+CostantiControlStation.PARAMETRO_SUFFIX_LABEL);
  302.                 String valueDom = dominio;
  303.                 String [] sdValues = SoggettiCostanti.getSoggettiDominiValue();
  304.                 String [] sdLabels = SoggettiCostanti.getSoggettiDominiLabel();
  305.                 for (int i = 0; i < sdValues.length; i++) {
  306.                     if(sdValues[i].equals(dominio)) {
  307.                         valueDom = sdLabels[i];
  308.                         break;
  309.                     }
  310.                 }
  311.                 de.setValue(valueDom);
  312.             }
  313.             else {
  314.                 de.setType(DataElementType.SELECT);
  315.                 de.setValues(SoggettiCostanti.getSoggettiDominiValue());
  316.                 de.setLabels(SoggettiCostanti.getSoggettiDominiLabel());
  317.                 de.setSelected(dominio);
  318.                 de.setPostBack(isSupportatoAutenticazioneSoggetti);
  319.             }
  320.             dati.add(de);
  321.         }


  322.         de = new DataElement();
  323.         de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_PROTOCOLLO);
  324.         if(TipoOperazione.ADD.equals(tipoOp)){
  325.             if(listaTipiProtocollo != null && listaTipiProtocollo.size() > 1){
  326.                 de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_PROTOCOLLO);
  327.                 de.setValues(listaTipiProtocollo);
  328.                 de.setLabels(this.getLabelsProtocolli(listaTipiProtocollo));
  329.                 de.setSelected(protocollo);
  330.                 de.setType(DataElementType.SELECT);
  331.                 de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_PROTOCOLLO);
  332.                 de.setPostBack(true);
  333.             } else {
  334.                 de.setValue(protocollo);
  335.                 de.setType(DataElementType.HIDDEN);
  336.                 de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_PROTOCOLLO);
  337.             }
  338.         } else {
  339.             if(listaTipiProtocollo != null && listaTipiProtocollo.size() > 1){
  340.                
  341.                 DataElement deLABEL = new DataElement();
  342.                 deLABEL.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_PROTOCOLLO);
  343.                 deLABEL.setType(DataElementType.TEXT);
  344.                 deLABEL.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_PROTOCOLLO+CostantiControlStation.PARAMETRO_SUFFIX_LABEL);
  345.                 deLABEL.setValue(this.getLabelProtocollo(protocollo));
  346.                 dati.add(deLABEL);
  347.                
  348.                 de.setValue(protocollo);
  349.                 de.setType(DataElementType.HIDDEN);
  350.                 de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_PROTOCOLLO);
  351.             } else {
  352.                 de.setValue(protocollo);
  353.                 de.setType(DataElementType.HIDDEN);
  354.                 de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_PROTOCOLLO);
  355.             }
  356.         }
  357.         de.setSize(this.getSize());
  358.         dati.add(de);

  359.         String[] tipiLabel = new String[tipiSoggetti.size()];
  360.         for (int i = 0; i < tipiSoggetti.size(); i++) {
  361.             String nomeTipo = tipiSoggetti.get(i);
  362.             tipiLabel[i] = nomeTipo;
  363.         }

  364.         String[] versioniLabel = new String[versioni.size()];
  365.         for (int i = 0; i < versioni.size(); i++) {
  366.             String versione = versioni.get(i);
  367.             versioniLabel[i] = versione;
  368.         }

  369.         de = new DataElement();
  370.         de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_TIPO);
  371.         de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO);
  372.         if(tipiLabel!=null && tipiLabel.length>1) {
  373.             de.setType(DataElementType.SELECT);
  374.             de.setValues(tipiLabel);
  375.             de.setSelected(tipoprov);
  376.         }
  377.         else {
  378.             de.setType(DataElementType.HIDDEN);
  379.             if(
  380.                     ((tipoprov==null || "".equals(tipoprov)) && tipiLabel!=null && tipiLabel.length>0)
  381.                     ||
  382.                     (tipoprov!=null && tipiLabel!=null && tipiLabel.length>0 && !tipoprov.equals(tipiLabel[0])) // fix per cambio protocollo
  383.             ) {
  384.                 tipoprov = tipiLabel[0];
  385.             }
  386.             de.setValue(tipoprov);
  387.         }
  388.         de.setSize(this.getSize());
  389.         de.setPostBack(true);
  390.         dati.add(de);

  391.         de = new DataElement();
  392.         de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_NOME);
  393.         de.setValue(nomeprov);
  394.         de.setType(DataElementType.TEXT_EDIT);
  395.         de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME);
  396.         de.setSize(this.getSize());
  397.         de.setRequired(true);
  398.         dati.add(de);
  399.        
  400.         if(TipoOperazione.ADD.equals(tipoOp)){
  401.             de = new DataElement();
  402.             de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_TIPOLOGIA);
  403.             de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPOLOGIA);
  404.             if(isPddEsterna && isSupportatoAutenticazioneSoggetti){
  405.                 de.setValue(tipologia);
  406.                 de.setSelected(tipologia);
  407.                 de.setType(DataElementType.SELECT);
  408.                 de.setValues(SoggettiCostanti.getSoggettiRuoli());
  409.                 de.setPostBack(true);
  410.             }
  411.             else{
  412.                 de.setValue("");
  413.                 de.setType(DataElementType.HIDDEN);
  414.             }
  415.             de.setSize(this.getSize());
  416.             dati.add(de);
  417.         }
  418.        

  419.         de = new DataElement();
  420.         de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_CODICE_PORTA);
  421.         de.setValue(portadom);
  422.         if (!isSupportatoIdentificativoPorta) {
  423.             de.setType(DataElementType.HIDDEN);
  424.         }else{
  425.             de.setType(DataElementType.TEXT_EDIT);
  426.         }
  427.         de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_CODICE_PORTA);
  428.         de.setSize(this.getSize());
  429.         dati.add(de);

  430.         de = new DataElement();
  431.         de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_CODICE_IPA);
  432.         de.setValue(codiceIpa);
  433.         if (!isSupportatoCodiceIPA) {
  434.             de.setType(DataElementType.HIDDEN);
  435.         }else{
  436.             if(this.core.isRegistroServiziLocale()){
  437.                 de.setType(DataElementType.TEXT_EDIT);
  438.             }else{
  439.                 de.setType(DataElementType.HIDDEN);
  440.             }
  441.         }
  442.         de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_CODICE_IPA);
  443.         de.setSize(this.getSize());
  444.         dati.add(de);

  445.         de = new DataElement();
  446.         de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_DESCRIZIONE);
  447.         de.setValue(descr);
  448.         de.setType(DataElementType.TEXT_AREA);
  449.         de.setRows(2);
  450.         de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_DESCRIZIONE);
  451.         de.setSize(this.getSize());
  452.         dati.add(de);


  453.         de = new DataElement();
  454.         de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_VERSIONE_PROTOCOLLO);
  455.         de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_VERSIONE_PROTOCOLLO);
  456.         boolean showVersioneProtocollo = this.core.isRegistroServiziLocale() && (this.apsCore.getVersioniProtocollo(protocollo).size()>1);
  457.         if(showVersioneProtocollo){
  458.             de.setValues(versioniLabel);
  459.             de.setSelected(profilo);
  460.             de.setType(DataElementType.SELECT);
  461.         }
  462.         else{
  463.             de.setValue(profilo);
  464.             de.setType(DataElementType.HIDDEN);
  465.         }
  466.         de.setSize(this.getSize());
  467.         dati.add(de);

  468.         de = new DataElement();
  469.         de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_IS_PRIVATO);
  470.         if (this.core.isShowFlagPrivato() && this.isModalitaAvanzata() && this.core.isRegistroServiziLocale() ) {
  471.             de.setType(DataElementType.CHECKBOX);
  472.         } else {
  473.             de.setType(DataElementType.HIDDEN);
  474.         }
  475.         de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_IS_PRIVATO);
  476.         de.setSelected(privato ? "yes" : "");
  477.         de.setSize(this.getSize());
  478.         dati.add(de);

  479.         de = new DataElement();
  480.         de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_IS_ROUTER);
  481.         de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_IS_ROUTER);
  482.         // Un router lo si puo' voler creare anche in singlePdD.
  483.         if (this.isModalitaAvanzata() && this.core.isShowGestioneSoggettiRouter()) {
  484.             de.setType(DataElementType.CHECKBOX);
  485.             if (isRouter) {
  486.                 de.setSelected(true);
  487.             }
  488.         } else {
  489.             de.setType(DataElementType.HIDDEN);
  490.             de.setValue(Costanti.CHECK_BOX_DISABLED);
  491.         }
  492.         dati.add(de);


  493.         if(TipoOperazione.CHANGE.equals(tipoOp)){

  494.             boolean showConnettore = this.core.isRegistroServiziLocale() && this.isModalitaCompleta();
  495.                        
  496.             if(showConnettore){
  497.                
  498.                 de = new DataElement();
  499.                 de.setType(DataElementType.LINK);
  500.                 de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_ENDPOINT,
  501.                         new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,id),
  502.                         new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME,oldnomeprov),
  503.                         new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO,oldtipoprov));
  504.                 Utilities.setDataElementLabelTipoConnettore(de, connettore);
  505.                 dati.add(de);
  506.                
  507.             }
  508.        
  509.         }
  510.        
  511.         // link proprieta
  512.         if(TipoOperazione.CHANGE.equals(tipoOp)){
  513.             de = new DataElement();
  514.             de.setType(DataElementType.LINK);
  515.            
  516.             List<Parameter> parametersServletSoggettoChange = new ArrayList<>();
  517.             Parameter pIdSoggetto = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID, id);
  518.             Parameter pNomeSoggetto = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME, nomeprov);
  519.             Parameter pTipoSoggetto = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO, tipoprov);
  520.             parametersServletSoggettoChange.add(pIdSoggetto);
  521.             parametersServletSoggettoChange.add(pNomeSoggetto);
  522.             parametersServletSoggettoChange.add(pTipoSoggetto);
  523.            
  524.             de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_PROPRIETA_LIST, parametersServletSoggettoChange.toArray(new Parameter[parametersServletSoggettoChange.size()]));
  525.             if (contaListe!=null && contaListe.booleanValue()) {
  526.                 de.setValue(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROPRIETA+"(" + numeroProprieta + ")");
  527.             } else {
  528.                 de.setValue(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROPRIETA);
  529.             }
  530.            
  531.             dati.add(de);
  532.            
  533.         }
  534.        
  535.         // Credenziali di accesso
  536.         if(isSupportatoAutenticazioneSoggetti){
  537.             if (utente == null) {
  538.                 utente = "";
  539.             }
  540.             if (password == null) {
  541.                 password = "";
  542.             }
  543.             if (subject == null) {
  544.                 subject = "";
  545.             }
  546.             if (principal == null) {
  547.                 principal = "";
  548.             }
  549.             String servlet = null;
  550.             if(TipoOperazione.ADD.equals(tipoOp)){
  551.                 servlet = SoggettiCostanti.SERVLET_NAME_SOGGETTI_ADD;
  552.             }
  553.             else{
  554.                 servlet = SoggettiCostanti.SERVLET_NAME_SOGGETTI_CHANGE;
  555.             }
  556.            
  557.             boolean autenticazioneNessunaAbilitata = true;
  558.             boolean showCredenziali = true;
  559.             if(this.pddCore.isPddEsterna(pdd)){
  560.                 if(SoggettiCostanti.SOGGETTO_RUOLO_FRUITORE.equals(tipologia) || SoggettiCostanti.SOGGETTO_RUOLO_ENTRAMBI.equals(tipologia)){
  561.                     autenticazioneNessunaAbilitata = this.saCore.isSupportatoAutenticazioneApplicativiEsterniErogazione(protocollo);
  562.                 }
  563.                 if(SoggettiCostanti.SOGGETTO_RUOLO_EROGATORE.equals(tipologia)){
  564.                     showCredenziali = false;
  565.                 }
  566.             }
  567.             else{
  568.                 if(hiddenDatiDominioInterno) {
  569.                     showCredenziali = false;
  570.                 }
  571.                 else if(TipoOperazione.ADD.equals(tipoOp)){
  572.                     showCredenziali = this.isModalitaAvanzata();
  573.                 }
  574.             }
  575.            
  576.             if(showCredenziali){
  577.                
  578.                 String oldtipoauth = null;
  579.                 if(isSupportatoAutenticazioneSoggetti && TipoOperazione.CHANGE.equals(tipoOp) &&
  580.                         soggetto!=null) {
  581.                    
  582.                     // prendo il primo
  583.                     org.openspcoop2.core.registry.constants.CredenzialeTipo tipo = null;
  584.                     if(soggetto.sizeCredenzialiList()>0) {
  585.                         tipo = soggetto.getCredenziali(0).getTipo();
  586.                     }
  587.                     if(tipo!=null) {
  588.                         oldtipoauth = tipo.getValue();
  589.                     }
  590.                     else {
  591.                         oldtipoauth = ConnettoriCostanti.AUTENTICAZIONE_TIPO_NESSUNA;
  592.                     }
  593.                 }
  594.                
  595.                 boolean postBackViaPost = false;
  596.                
  597.                 dati = this.addCredenzialiToDati(tipoOp, dati, tipoauth, oldtipoauth, utente, password, subject, principal, servlet, true, null, false, true, null, autenticazioneNessunaAbilitata,
  598.                         tipoCredenzialiSSLSorgente, tipoCredenzialiSSLTipoArchivio, tipoCredenzialiSSLFileCertificato, tipoCredenzialiSSLFileCertificatoPassword, listaAliasEstrattiCertificato,
  599.                         tipoCredenzialiSSLAliasCertificato, tipoCredenzialiSSLAliasCertificatoSubject, tipoCredenzialiSSLAliasCertificatoIssuer,
  600.                         tipoCredenzialiSSLAliasCertificatoType, tipoCredenzialiSSLAliasCertificatoVersion, tipoCredenzialiSSLAliasCertificatoSerialNumber,
  601.                         tipoCredenzialiSSLAliasCertificatoSelfSigned, tipoCredenzialiSSLAliasCertificatoNotBefore, tipoCredenzialiSSLAliasCertificatoNotAfter,
  602.                         tipoCredenzialiSSLVerificaTuttiICampi, tipoCredenzialiSSLConfigurazioneManualeSelfSigned, issuer,tipoCredenzialiSSLStatoElaborazioneCertificato,
  603.                         changepwd,
  604.                         multipleApiKey, appId, apiKey, visualizzaModificaCertificato, visualizzaAddCertificato, servletCredenzialiList, parametersServletCredenzialiList, numeroCertificati, servletCredenzialiAdd,
  605.                         false, null, null, false,
  606.                         SoggettiCostanti.SOGGETTO_DOMINIO_ESTERNO_VALUE.equals(dominio), protocollo,
  607.                         postBackViaPost);
  608.             }
  609.         }
  610.        
  611.         if(TipoOperazione.CHANGE.equals(tipoOp)){

  612.             de = new DataElement();
  613.             de.setLabel(RuoliCostanti.LABEL_RUOLI);
  614.             de.setType(DataElementType.TITLE);
  615.             dati.add(de);
  616.            
  617.             de = new DataElement();
  618.             de.setType(DataElementType.LINK);
  619.             if(this.isModalitaCompleta()) {
  620.                 de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_RUOLI_LIST,
  621.                         new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,id+""));
  622.             }
  623.             else {
  624.                 // Imposto Accesso da Change!
  625.                 de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_RUOLI_LIST,
  626.                         new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,id+""),
  627.                         new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_RUOLI_ACCESSO_DA_CHANGE,Costanti.CHECK_BOX_ENABLED));
  628.             }
  629.             if (contaListe) {
  630.                 // BugFix OP-674
  631.                 /**List<String> lista1 = this.soggettiCore.soggettiRuoliList(Long.parseLong(id),new Search(true));*/
  632.                 ConsoleSearch searchForCount = new ConsoleSearch(true,1);
  633.                 this.soggettiCore.soggettiRuoliList(Long.parseLong(id),searchForCount);
  634.                 int numRuoli = searchForCount.getNumEntries(Liste.SOGGETTI_RUOLI);
  635.                 ServletUtils.setDataElementCustomLabel(de,RuoliCostanti.LABEL_RUOLI,Long.valueOf(numRuoli));
  636.             } else{
  637.                 ServletUtils.setDataElementCustomLabel(de,RuoliCostanti.LABEL_RUOLI);
  638.             }
  639.             dati.add(de);
  640.            
  641.         }

  642.        
  643.         if(TipoOperazione.CHANGE.equals(tipoOp) && !this.pddCore.isPddEsterna(pdd)){
  644.            
  645.             if (this.isModalitaCompleta()) {    
  646.                 de = new DataElement();
  647.                 de.setLabel(SoggettiCostanti.LABEL_CLIENT);
  648.                 de.setType(DataElementType.TITLE);
  649.                 dati.add(de);
  650.             }

  651.             de = new DataElement();
  652.             de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_PD_URL_PREFIX_REWRITER);
  653.             if (this.isModalitaCompleta()) {    
  654.                 de.setType(DataElementType.TEXT_EDIT);
  655.             }else{
  656.                 de.setType(DataElementType.HIDDEN);
  657.             }
  658.             de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_PD_URL_PREFIX_REWRITER);
  659.             de.setValue(pdUrlPrefixRewriter);
  660.             de.setSize(this.getSize());
  661.             dati.add(de);
  662.            
  663.             if (this.isModalitaCompleta()) {    
  664.                 de = new DataElement();
  665.                 de.setType(DataElementType.LINK);
  666.                 de.setUrl(PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_LIST,
  667.                         new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO,id+""),
  668.                         new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME_SOGGETTO,oldnomeprov),
  669.                         new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TIPO_SOGGETTO,oldtipoprov));
  670.                 if (contaListe) {
  671.                     ServletUtils.setDataElementVisualizzaLabel(de,numPD);
  672.                 } else
  673.                     ServletUtils.setDataElementVisualizzaLabel(de);
  674.                 dati.add(de);
  675.             }

  676.             if (this.isModalitaCompleta()) {    
  677.                 de = new DataElement();
  678.                 de.setLabel(SoggettiCostanti.LABEL_SERVER);
  679.                 de.setType(DataElementType.TITLE);
  680.                 dati.add(de);
  681.             }

  682.             de = new DataElement();
  683.             de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_PA_URL_PREFIX_REWRITER);
  684.             if (this.isModalitaCompleta()) {    
  685.                 de.setType(DataElementType.TEXT_EDIT);
  686.             }else{
  687.                 de.setType(DataElementType.HIDDEN);
  688.             }
  689.             de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_PA_URL_PREFIX_REWRITER);
  690.             de.setValue(paUrlPrefixRewriter);
  691.             de.setSize(this.getSize());
  692.             dati.add(de);
  693.            
  694.             if (this.isModalitaCompleta()) {    
  695.                 de = new DataElement();
  696.                 de.setType(DataElementType.LINK);
  697.                 de.setUrl(PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_LIST,
  698.                         new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO,id+""),
  699.                         new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME_SOGGETTO,oldnomeprov),
  700.                         new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TIPO_SOGGETTO,oldtipoprov));
  701.                 if (contaListe) {
  702.                     ServletUtils.setDataElementVisualizzaLabel(de,numPA);
  703.                 } else
  704.                     ServletUtils.setDataElementVisualizzaLabel(de);
  705.                 dati.add(de);
  706.             }
  707.         }

  708.         return dati;
  709.     }

  710.     public boolean soggettiCheckData(TipoOperazione tipoOp, String id, String tipoprov, String nomeprov, String codiceIpa, String pdUrlPrefixRewriter, String paUrlPrefixRewriter,
  711.             Soggetto soggettoOld, boolean isSupportatoAutenticazioneSoggetti, String descrizione, String portadom) throws Exception {
  712.         try {

  713.             int idInt = 0;
  714.             if (tipoOp.equals(TipoOperazione.CHANGE)) {
  715.                 idInt = Integer.parseInt(id);
  716.             }


  717.             // Campi obbligatori
  718.             if (nomeprov.equals("") || tipoprov.equals("") ) {
  719.                 String tmpElenco = "";
  720.                 if (nomeprov.equals("")) {
  721.                     tmpElenco = SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_NOME;
  722.                 }
  723.                 if (tipoprov.equals("")) {
  724.                     if (tmpElenco.equals("")) {
  725.                         tmpElenco = SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_TIPO;
  726.                     } else {
  727.                         tmpElenco = tmpElenco + ", "+SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_TIPO;
  728.                     }
  729.                 }
  730.                 this.pd.setMessage("Dati incompleti. &Egrave; necessario indicare: " + tmpElenco);
  731.                 return false;
  732.             }

  733.             // Controllo che non ci siano spazi nei campi di testo
  734.             if ((nomeprov.indexOf(" ") != -1) || (tipoprov.indexOf(" ") != -1)) {
  735.                 this.pd.setMessage("Non inserire spazi nei campi di testo");
  736.                 return false;
  737.             }

  738.             // Il tipo deve contenere solo lettere e numeri
  739.             if(!this.checkSimpleName(tipoprov, SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_TIPO)){
  740.                 return false;
  741.             }
  742.            
  743.             String protocollo = this.soggettiCore.getProtocolloAssociatoTipoSoggetto(tipoprov);
  744.            
  745.             boolean dominioEsternoModI = false;
  746.             if(portadom!=null) {
  747.                 dominioEsternoModI = this.isProfiloModIPA(protocollo) && this.pddCore.isPddEsterna(portadom);
  748.             }
  749.                        
  750.             // Il nome deve contenere solo lettere e numeri e -
  751.             if(this.soggettiCore.isSupportatoTrattinoNomeSoggetto(protocollo)) {
  752.                 if(!this.checkSimpleNamePath(nomeprov, SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_NOME)){
  753.                     return false;
  754.                 }
  755.             }
  756.             else {
  757.                 if(!this.checkSimpleName(nomeprov, SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_NOME)){
  758.                     return false;
  759.                 }
  760.             }
  761.            
  762.             // check lunghezza NOTA: Si usa una lunghezza inferiore di 20 al limite massimo della colonna
  763.             // per poter salvaguardare poi il 255 delle colonne per codice ipa e identificativo porta calcolate in base al nome del soggetto
  764.             int maxLength = 255 - 20;
  765.             if(this.soggettiCore.getSoggettiNomeMaxLength()!=null && this.soggettiCore.getSoggettiNomeMaxLength()>0) {
  766.                 maxLength = this.soggettiCore.getSoggettiNomeMaxLength();
  767.             }
  768.             if(!this.checkLength(nomeprov, SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_NOME, -1, maxLength)) {
  769.                 return false;
  770.             }
  771.             if(descrizione!=null && !"".equals(descrizione)) {
  772.                 if(this.checkLength4000(descrizione, SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_DESCRIZIONE)==false) {
  773.                     return false;
  774.                 }
  775.             }

  776.            
  777.             // check Codice IPA
  778.             /**try{
  779.                 if(codiceIpa!=null && !"".equals(codiceIpa)){
  780.                     SICAtoOpenSPCoopUtilities.validateIDSoggettoSICA(codiceIpa);
  781.                 }
  782.             }catch(Exception e){
  783.                 this.pd.setMessage("Codice IPA non corretto: " + e.getMessage());
  784.                 return false;
  785.             }*/

  786.             // Controllo che eventuali PdUrlPrefixRewriter o PaUrlPrefixRewriter rispettino l'espressione regolare: [A-Za-z]+:\/\/(.*)
  787.             if(pdUrlPrefixRewriter!=null && !"".equals(pdUrlPrefixRewriter) &&
  788.                 !RegularExpressionEngine.isMatch(pdUrlPrefixRewriter, "[A-Za-z]+:\\/\\/(.*)")){
  789.                 this.pd.setMessage("Il campo UrlPrefix rewriter del profilo client contiene un valore errato. Il valore atteso deve seguire la sintassi: "+
  790.                         StringEscapeUtils.escapeHtml("protocol://hostname[:port][/*]"));
  791.                 return false;
  792.             }
  793.             if(paUrlPrefixRewriter!=null && !"".equals(paUrlPrefixRewriter) &&
  794.                 !RegularExpressionEngine.isMatch(paUrlPrefixRewriter, "[A-Za-z]+:\\/\\/(.*)")){
  795.                 this.pd.setMessage("Il campo UrlPrefix rewriter del profilo server contiene un valore errato. Il valore atteso deve seguire la sintassi: "+
  796.                         StringEscapeUtils.escapeHtml("protocol://hostname[:port][/*]"));
  797.                 return false;
  798.             }

  799.             IDSoggetto ids = new IDSoggetto(tipoprov, nomeprov);
  800.             String labelSoggetto = this.getLabelNomeSoggetto(ids);
  801.            
  802.             // Se tipoOp = add o tipoOp = change, controllo che non esistano
  803.             // altri soggetti con stessi nome e tipo
  804.             // Se tipoOp = change, devo fare attenzione a non escludere nome e
  805.             // tipo del soggetto selezionato
  806.             if (tipoOp.equals(TipoOperazione.ADD) || tipoOp.equals(TipoOperazione.CHANGE)) {
  807.                 int idSogg = 0;
  808.                 boolean existsSogg = this.soggettiCore.existsSoggetto(ids);
  809.                 if (existsSogg) {
  810.                     if(this.core.isRegistroServiziLocale()){
  811.                         Soggetto mySogg = this.soggettiCore.getSoggettoRegistro(ids);
  812.                         idSogg = mySogg.getId().intValue();
  813.                     }else{
  814.                         org.openspcoop2.core.config.Soggetto mySogg = this.soggettiCore.getSoggetto(ids);
  815.                         idSogg = mySogg.getId().intValue();
  816.                     }
  817.                 }
  818.                 if ((idSogg != 0) && (tipoOp.equals(TipoOperazione.ADD) || (tipoOp.equals(TipoOperazione.CHANGE) && (idInt != idSogg)))) {
  819.                     this.pd.setMessage("Esiste gi&agrave; un soggetto "+labelSoggetto);
  820.                     return false;
  821.                 }

  822.                 // Controllo che il codiceIPA non sia gia utilizzato. Il fatto che non esista in base al nome, e' gia garantito rispetto all'univocita' del nome.
  823.                 if(this.core.isRegistroServiziLocale() &&
  824.                     codiceIpa!=null && !"".equals(codiceIpa)){
  825.                     if(tipoOp.equals(TipoOperazione.ADD)){
  826.                         if(this.soggettiCore.existsSoggetto(codiceIpa)){
  827.                             this.pd.setMessage("Esiste gi&agrave; un soggetto con Codice IPA: " + codiceIpa);
  828.                             return false;
  829.                         }
  830.                     }
  831.                     else{
  832.                         Soggetto mySogg = null;
  833.                         try{
  834.                             mySogg = this.soggettiCore.getSoggettoByCodiceIPA(codiceIpa);
  835.                         }catch(DriverRegistroServiziNotFound dnot){
  836.                             // ignore
  837.                         }
  838.                         if(mySogg!=null &&
  839.                             mySogg.getId()!=idInt){
  840.                             this.pd.setMessage("Esiste gi&agrave; un soggetto con Codice IPA: " + codiceIpa);
  841.                             return false;
  842.                         }
  843.                     }
  844.                 }
  845.             }

  846.             if (tipoOp.equals(TipoOperazione.CHANGE)) {
  847.                
  848.                 String oldTipoAuth = null;
  849.                 if(isSupportatoAutenticazioneSoggetti &&
  850.                         soggettoOld!=null) {
  851.                     // prendo il primo
  852.                     org.openspcoop2.core.registry.constants.CredenzialeTipo tipo = null;
  853.                     if(soggettoOld.sizeCredenzialiList()>0) {
  854.                         tipo = soggettoOld.getCredenziali(0).getTipo();
  855.                     }
  856.                     if(tipo!=null) {
  857.                         oldTipoAuth = tipo.getValue();
  858.                     }
  859.                     else {
  860.                         oldTipoAuth = ConnettoriCostanti.AUTENTICAZIONE_TIPO_NESSUNA;
  861.                     }
  862.                 }
  863.                
  864.                 String tipoauth = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_TIPO_AUTENTICAZIONE);
  865.                
  866.                 if(oldTipoAuth!=null && !oldTipoAuth.equals(tipoauth)) {
  867.                     // controllo che non sia usato in qualche PD
  868.                    
  869.                     FiltroRicercaPorteApplicative filtro = new FiltroRicercaPorteApplicative();
  870.                     filtro.setIdSoggettoAutorizzato(ids);
  871.                     List<IDPortaApplicativa> list = this.porteApplicativeCore.getAllIdPorteApplicative(filtro);
  872.                    
  873.                     if(org.openspcoop2.protocol.engine.constants.Costanti.SPCOOP_PROTOCOL_NAME.equals(protocollo)) {
  874.                         // verifico che non sia utilizzato in porte applicative dove è abilitata l'autenticazione
  875.                         int count = 0;
  876.                         if(list!=null && !list.isEmpty()) {
  877.                             for (IDPortaApplicativa idPortaApplicativa : list) {
  878.                                 PortaApplicativa pa = this.porteApplicativeCore.getPortaApplicativa(idPortaApplicativa);
  879.                                 if(!CostantiConfigurazione.AUTENTICAZIONE_NONE.equalsIgnoreCase(pa.getAutenticazione()) &&
  880.                                         !CostantiConfigurazione.DISABILITATO.toString().equalsIgnoreCase(pa.getAutenticazione())) {
  881.                                     count++; // default ssl se non impostata
  882.                                 }
  883.                             }
  884.                         }
  885.                         if(count>0) {
  886.                             this.pd.setMessage("Non &egrave; possibile modificare il tipo di credenziali poich&egrave; il soggetto viene utilizzato all'interno del controllo degli accessi di "+
  887.                                     list.size()+" configurazioni di erogazione di servizio con autenticazione trasporto abilitata");
  888.                             return false;
  889.                         }
  890.                     }
  891.                     else {
  892.                         if(list!=null && !list.isEmpty()) {
  893.                             this.pd.setMessage("Non &egrave; possibile modificare il tipo di credenziali poich&egrave; il soggetto viene utilizzato all'interno del controllo degli accessi di "+
  894.                                     list.size()+" configurazioni di erogazione di servizio");
  895.                             return false;
  896.                         }
  897.                     }
  898.                 }
  899.                
  900.             }
  901.            

  902.             boolean oldPasswordCifrata = false;
  903.             if(soggettoOld!=null && soggettoOld.sizeCredenzialiList()>0 && soggettoOld.getCredenziali(0).isCertificateStrictVerification()) {
  904.                 oldPasswordCifrata = true;
  905.             }
  906.             boolean encryptEnabled = this.saCore.isSoggettiPasswordEncryptEnabled();
  907.             if(this.credenzialiCheckData(tipoOp,oldPasswordCifrata, encryptEnabled, this.soggettiCore.getSoggettiPasswordVerifier())==false){
  908.                 return false;
  909.             }

  910.             String tipoauth = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_TIPO_AUTENTICAZIONE);
  911.             if (tipoauth == null) {
  912.                 tipoauth = ConnettoriCostanti.DEFAULT_AUTENTICAZIONE_TIPO;
  913.             }
  914.             String utente = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_USERNAME);
  915.             String password = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_PASSWORD);

  916.             String subject = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_SUBJECT);
  917.             String issuer = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_ISSUER);
  918.             if("".equals(issuer)) {
  919.                 issuer = null;
  920.             }
  921.             String principal = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_PRINCIPAL);
  922.            
  923.             // Se sono presenti credenziali, controllo che non siano gia'
  924.             // utilizzate da altri soggetti
  925.             if (tipoauth.equals(ConnettoriCostanti.AUTENTICAZIONE_TIPO_BASIC)) {
  926.                 // recupero soggetto con stesse credenziali
  927.                 boolean checkPassword = this.soggettiCore.isSoggettiCredenzialiBasicCheckUniqueUsePassword(); // la password non viene utilizzata per riconoscere se l'username e' già utilizzato.
  928.                 Soggetto soggettoAutenticato = this.soggettiCore.soggettoWithCredenzialiBasic(utente, password, checkPassword);
  929.                
  930.                 if(soggettoAutenticato!=null && tipoOp.equals(TipoOperazione.CHANGE)){
  931.                     if(idInt == soggettoAutenticato.getId()){
  932.                         soggettoAutenticato = null;
  933.                     }
  934.                 }

  935.                 // Messaggio di errore
  936.                 if(soggettoAutenticato!=null){
  937.                     String labelSoggettoAutenticato = this.getLabelNomeSoggetto(new IDSoggetto(soggettoAutenticato.getTipo(), soggettoAutenticato.getNome()));
  938.                     this.pd.setMessage("Il soggetto "+labelSoggettoAutenticato+" possiede già l'utente (http-basic) indicato");
  939.                     return false;
  940.                 }
  941.                
  942.                 if(!this.soggettiCore.isSoggettiApplicativiCredenzialiBasicPermitSameCredentials()) {
  943.                     // Verifico applicativi
  944.                    
  945.                     // recupera lista servizi applicativi con stesse credenziali
  946.                     boolean checkPasswordSA = this.saCore.isApplicativiCredenzialiBasicCheckUniqueUsePassword(); // la password non viene utilizzata per riconoscere se l'username e' già utilizzato.
  947.                     List<ServizioApplicativo> saList = this.saCore.servizioApplicativoWithCredenzialiBasicList(utente, password, checkPasswordSA);
  948.                    
  949.                     for (int i = 0; i < saList.size(); ) {
  950.                         ServizioApplicativo sa = saList.get(i);

  951.                         // Messaggio di errore
  952.                         String labelSoggettoGiaEsistente = this.getLabelNomeSoggetto(new IDSoggetto(sa.getTipoSoggettoProprietario(), sa.getNomeSoggettoProprietario()));
  953.                         if(sa.getTipo()!=null && StringUtils.isNotEmpty(sa.getTipo())) {
  954.                             this.pd.setMessage("L'applicativo "+sa.getNome()+" (soggetto: "+labelSoggettoGiaEsistente+") possiede già l'utente (http-basic) indicato");
  955.                         }
  956.                         else {
  957.                             this.pd.setMessage("L'erogazione "+sa.getNome()+" possiede già l'utente (http-basic) indicato per il servizio '"+ServiziApplicativiCostanti.LABEL_SERVIZIO_MESSAGE_BOX+"'");
  958.                         }
  959.                         return false; // ne basta uno
  960.                     }
  961.                 }
  962.                
  963.             }
  964.             else if (tipoauth.equals(ConnettoriCostanti.AUTENTICAZIONE_TIPO_APIKEY)) {
  965.                 // Univocita garantita dal meccanismo di generazione delle chiavi
  966.                 /*
  967.                 // Viene calcolato String appId = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_APP_ID);
  968.                 String multipleApiKeys = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_MULTIPLE_API_KEYS);
  969.                            
  970.                 // recupero soggetto con stesse credenziali
  971.                 //Soggetto soggettoAutenticato = this.soggettiCore.getSoggettoRegistroAutenticatoBasic(utente, password);
  972.                 boolean multipleApiKeysEnabled = ServletUtils.isCheckBoxEnabled(multipleApiKeys);
  973.                 String appId = this.soggettiCore.toAppId(this.soggettiCore.getProtocolloAssociatoTipoSoggetto(ids.getTipo()), ids, multipleApiKeysEnabled);
  974.                 Soggetto soggettoAutenticato = this.soggettiCore.soggettoWithCredenzialiApiKey(appId, multipleApiKeysEnabled);
  975.                
  976.                 if(soggettoAutenticato!=null && tipoOp.equals(TipoOperazione.CHANGE)){
  977.                     if(idInt == soggettoAutenticato.getId()){
  978.                         soggettoAutenticato = null;
  979.                     }
  980.                 }

  981.                 // Messaggio di errore
  982.                 if(soggettoAutenticato!=null){
  983.                     String labelSoggettoAutenticato = this.getLabelNomeSoggetto(new IDSoggetto(soggettoAutenticato.getTipo(), soggettoAutenticato.getNome()));
  984.                     String tipoCredenzialiApiKey = ServletUtils.isCheckBoxEnabled(multipleApiKeys) ? ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_MULTIPLE_API_KEYS_DESCR : ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_API_KEY;
  985.                     this.pd.setMessage("Il soggetto "+labelSoggettoAutenticato+" possiede già una credenziale '"+tipoCredenzialiApiKey+"' con identico '"+ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_APP_ID+"'");
  986.                     return false;
  987.                 }
  988.                 */
  989.             }
  990.             else if (tipoauth.equals(ConnettoriCostanti.AUTENTICAZIONE_TIPO_SSL)) {
  991.                 String tipoCredenzialiSSLSorgente = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL);
  992.                 if(tipoCredenzialiSSLSorgente == null) {
  993.                     tipoCredenzialiSSLSorgente = ConnettoriCostanti.VALUE_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_CONFIGURAZIONE_MANUALE;
  994.                 }
  995.                 String tipoCredenzialiSSLConfigurazioneManualeSelfSigned= this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_MANUALE_SELF_SIGNED);
  996.                 if (tipoCredenzialiSSLConfigurazioneManualeSelfSigned == null) {
  997.                     tipoCredenzialiSSLConfigurazioneManualeSelfSigned = Costanti.CHECK_BOX_ENABLED;
  998.                 }
  999.                
  1000.                 String details = "";
  1001.                 Soggetto soggettoAutenticato = null;
  1002.                 String tipoSsl = null;
  1003.                 Certificate cSelezionato = null;
  1004.                 boolean strictVerifier = false;
  1005.                
  1006.                 if(tipoCredenzialiSSLSorgente.equals(ConnettoriCostanti.VALUE_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_CONFIGURAZIONE_MANUALE)) {
  1007.            
  1008.                     // recupero soggetto con stesse credenziali
  1009.                     soggettoAutenticato = this.soggettiCore.getSoggettoRegistroAutenticatoSsl(subject, issuer);
  1010.                     tipoSsl = "subject/issuer";
  1011.            
  1012.                 } else {
  1013.                    
  1014.                     BinaryParameter tipoCredenzialiSSLFileCertificato = this.getBinaryParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_FILE_CERTIFICATO);
  1015.                     String tipoCredenzialiSSLVerificaTuttiICampi = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_VERIFICA_TUTTI_CAMPI);
  1016.                     strictVerifier = ServletUtils.isCheckBoxEnabled(tipoCredenzialiSSLVerificaTuttiICampi);
  1017.                     String tipoCredenzialiSSLTipoArchivioS = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_TIPO_ARCHIVIO);
  1018.                     String tipoCredenzialiSSLFileCertificatoPassword = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_FILE_CERTIFICATO_PASSWORD);
  1019.                     String tipoCredenzialiSSLAliasCertificato = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_ALIAS_CERTIFICATO);
  1020.                     if (tipoCredenzialiSSLAliasCertificato == null) {
  1021.                         tipoCredenzialiSSLAliasCertificato = "";
  1022.                     }
  1023.                     org.openspcoop2.utils.certificate.ArchiveType tipoCredenzialiSSLTipoArchivio= null;
  1024.                     if(tipoCredenzialiSSLTipoArchivioS == null) {
  1025.                         tipoCredenzialiSSLTipoArchivio = org.openspcoop2.utils.certificate.ArchiveType.CER;
  1026.                     } else {
  1027.                         tipoCredenzialiSSLTipoArchivio = org.openspcoop2.utils.certificate.ArchiveType.valueOf(tipoCredenzialiSSLTipoArchivioS);
  1028.                     }
  1029.                     byte [] archivio = tipoCredenzialiSSLFileCertificato.getValue();
  1030.                     if(TipoOperazione.CHANGE.equals(tipoOp) && archivio==null) {
  1031.                         archivio = soggettoOld.getCredenziali(0).getCertificate();
  1032.                     }
  1033.                     if(tipoCredenzialiSSLTipoArchivio.equals(org.openspcoop2.utils.certificate.ArchiveType.CER)) {
  1034.                         cSelezionato = ArchiveLoader.load(archivio);
  1035.                     }else {
  1036.                         cSelezionato = ArchiveLoader.load(tipoCredenzialiSSLTipoArchivio, archivio, tipoCredenzialiSSLAliasCertificato, tipoCredenzialiSSLFileCertificatoPassword);
  1037.                     }
  1038.                     //soggettoAutenticato = this.soggettiCore.getSoggettoRegistroAutenticatoSsl(cSelezionato.getCertificate(), strictVerifier);
  1039.                     // Fix: usando il metodo sopra e' permesso caricare due soggetti con lo stesso certificato (anche serial number) uno in strict e uno no, e questo e' sbagliato.
  1040.                     List<org.openspcoop2.core.registry.Soggetto> soggettiAutenticati = this.soggettiCore.soggettoWithCredenzialiSslList(cSelezionato.getCertificate(), strictVerifier);
  1041.                     if(soggettiAutenticati!=null && soggettiAutenticati.size()>0) {
  1042.                         soggettoAutenticato = soggettiAutenticati.get(0);
  1043.                         if(!strictVerifier) {
  1044.                             List<org.openspcoop2.core.registry.Soggetto> soggettiAutenticatiCheck = this.soggettiCore.soggettoWithCredenzialiSslList(cSelezionato.getCertificate(), true);
  1045.                             if(soggettiAutenticatiCheck==null || soggettiAutenticatiCheck.isEmpty() ) {
  1046.                                 details=ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_DETAILS;
  1047.                             }
  1048.                         }
  1049.                     }
  1050.                     tipoSsl = "certificato";
  1051.                 }
  1052.                
  1053.                 if(soggettoAutenticato!=null && tipoOp.equals(TipoOperazione.CHANGE)){
  1054.                     if(idInt == soggettoAutenticato.getId()){
  1055.                         soggettoAutenticato = null;
  1056.                     }
  1057.                 }

  1058.                 // Messaggio di errore
  1059.                 if(soggettoAutenticato!=null){
  1060.                     String labelSoggettoAutenticato = this.getLabelNomeSoggetto(new IDSoggetto(soggettoAutenticato.getTipo(), soggettoAutenticato.getNome()));
  1061.                     this.pd.setMessage("Il soggetto "+labelSoggettoAutenticato+" possiede già le credenziali ssl ("+tipoSsl+") indicate."+details);
  1062.                     return false;
  1063.                 }
  1064.                
  1065.                 if(!this.soggettiCore.isSoggettiApplicativiCredenzialiSslPermitSameCredentials()) {
  1066.                     // Verifico applicativi
  1067.                    
  1068.                     details = "";
  1069.                     List<ServizioApplicativo> saList = null;
  1070.                     tipoSsl = null;
  1071.                    
  1072.                     if(tipoCredenzialiSSLSorgente.equals(ConnettoriCostanti.VALUE_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_CONFIGURAZIONE_MANUALE)) {
  1073.                         saList = this.saCore.servizioApplicativoWithCredenzialiSslList(subject,issuer,
  1074.                                 dominioEsternoModI ? ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiModIFirma() : ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiHttps());
  1075.                         tipoSsl = "subject/issuer";
  1076.                     }
  1077.                     else {
  1078.                        
  1079.                         saList = this.saCore.servizioApplicativoWithCredenzialiSslList(cSelezionato.getCertificate(), strictVerifier,
  1080.                                 dominioEsternoModI ? ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiModIFirma() : ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiHttps());
  1081.                         if(!strictVerifier && saList!=null && !saList.isEmpty()) {
  1082.                             List<ServizioApplicativo> saListCheck = this.saCore.servizioApplicativoWithCredenzialiSslList(cSelezionato.getCertificate(), true,
  1083.                                     dominioEsternoModI ? ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiModIFirma() : ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiHttps());
  1084.                             if(saListCheck==null || saListCheck.isEmpty() ) {
  1085.                                 details=ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_DETAILS;
  1086.                             }
  1087.                         }
  1088.                         tipoSsl = "certificato";
  1089.                        
  1090.                     }
  1091.                    
  1092.                     if(saList!=null) {
  1093.                         for (int i = 0; i < saList.size(); i++) {
  1094.                             ServizioApplicativo sa = saList.get(i);
  1095.                
  1096.                             boolean tokenWithHttpsEnabledByConfigSA = false;
  1097.                             if(sa.getInvocazionePorta()!=null && sa.getInvocazionePorta().sizeCredenzialiList()>0) {
  1098.                                 Credenziali c = sa.getInvocazionePorta().getCredenziali(0);
  1099.                                 if(c!=null && c.getTokenPolicy()!=null && StringUtils.isNotEmpty(c.getTokenPolicy())) {
  1100.                                     // se entro in questa servlet sono sicuramente con credenziale ssl, se esiste anche token policy abbiamo la combo
  1101.                                     tokenWithHttpsEnabledByConfigSA = true;
  1102.                                 }
  1103.                             }
  1104.                            
  1105.                             if(!tokenWithHttpsEnabledByConfigSA) {  // se e' abilitato il token non deve essere controllata l'univocita' del certificato
  1106.                            
  1107.                                 // Raccolgo informazioni soggetto
  1108.                                 // Messaggio di errore
  1109.                                 String labelSoggettoApplicativo = this.getLabelNomeSoggetto(new IDSoggetto(sa.getTipoSoggettoProprietario(), sa.getNomeSoggettoProprietario()));
  1110.                                 this.pd.setMessage("L'applicativo "+sa.getNome()+" (soggetto: "+labelSoggettoApplicativo+") possiede già le credenziali ssl ("+tipoSsl+") indicate."+details);
  1111.                                 return false;
  1112.                                
  1113.                             }
  1114.                         }
  1115.                     }
  1116.                 }
  1117.             }
  1118.             else if (tipoauth.equals(ConnettoriCostanti.AUTENTICAZIONE_TIPO_PRINCIPAL)) {
  1119.                 // recupero soggetto con stesse credenziali
  1120.                 Soggetto soggettoAutenticato = this.soggettiCore.getSoggettoRegistroAutenticatoPrincipal(principal);
  1121.                
  1122.                 if(soggettoAutenticato!=null && tipoOp.equals(TipoOperazione.CHANGE)){
  1123.                     if(idInt == soggettoAutenticato.getId()){
  1124.                         soggettoAutenticato = null;
  1125.                     }
  1126.                 }

  1127.                 // Messaggio di errore
  1128.                 if(soggettoAutenticato!=null){
  1129.                     String labelSoggettoAutenticato = this.getLabelNomeSoggetto(new IDSoggetto(soggettoAutenticato.getTipo(), soggettoAutenticato.getNome()));
  1130.                     this.pd.setMessage("Il soggetto "+labelSoggettoAutenticato+" possiede già il principal indicato");
  1131.                     return false;
  1132.                 }
  1133.                
  1134.                 if(!this.soggettiCore.isSoggettiApplicativiCredenzialiPrincipalPermitSameCredentials()) {
  1135.                     // Verifico applicativi
  1136.                    
  1137.                     List<ServizioApplicativo> saList = this.saCore.servizioApplicativoWithCredenzialiPrincipalList(principal);

  1138.                     for (int i = 0; i < saList.size(); ) {
  1139.                         ServizioApplicativo sa = saList.get(i);

  1140.                         // Messaggio di errore
  1141.                         String labelSoggettoApplicativo = this.getLabelNomeSoggetto(new IDSoggetto(sa.getTipoSoggettoProprietario(), sa.getNomeSoggettoProprietario()));
  1142.                         this.pd.setMessage("L'applicativo "+sa.getNome()+" (soggetto: "+labelSoggettoApplicativo+") possiede già il principal indicato");
  1143.                         return false; // ne basta uno
  1144.                     }
  1145.                 }
  1146.             }
  1147.            
  1148.            
  1149.             return true;
  1150.         } catch (Exception e) {
  1151.             this.logError(e.getMessage(), e);
  1152.             throw new DriverControlStationException(e.getMessage(),e);
  1153.         }
  1154.     }

  1155.     public void prepareSoggettiList(List<org.openspcoop2.core.registry.Soggetto> lista, ISearch ricerca) throws Exception {
  1156.         try {
  1157.             boolean modalitaCompleta = this.isModalitaCompleta();
  1158.            
  1159.             if(!modalitaCompleta) {
  1160.                 this.pd.setCustomListViewName(SoggettiCostanti.SOGGETTI_NOME_VISTA_CUSTOM_LISTA);
  1161.             }
  1162.            
  1163.             ServletUtils.addListElementIntoSession(this.request, this.session, SoggettiCostanti.OBJECT_NAME_SOGGETTI);

  1164.             boolean multiTenant = this.core.isMultitenant();
  1165.            
  1166.             Boolean contaListe = ServletUtils.getContaListeFromSession(this.session);
  1167.             int idLista = Liste.SOGGETTI;
  1168.             int limit = ricerca.getPageSize(idLista);
  1169.             int offset = ricerca.getIndexIniziale(idLista);
  1170.             String search = ServletUtils.getSearchFromSession(ricerca, idLista);

  1171.             String filterProtocollo = addFilterProtocol(ricerca, idLista, true);
  1172.             boolean profiloSelezionato = false;
  1173.             String protocolloSel = filterProtocollo;
  1174.             if(protocolloSel==null) {
  1175.                 // significa che e' stato selezionato un protocollo nel menu in alto a destra
  1176.                 List<String> protocolli = this.core.getProtocolli(this.request, this.session);
  1177.                 if(protocolli!=null && protocolli.size()==1) {
  1178.                     protocolloSel = protocolli.get(0);
  1179.                 }
  1180.             }
  1181.             if( (filterProtocollo!=null &&
  1182.                     //!"".equals(filterProtocollo) &&
  1183.                     !CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PROTOCOLLO_QUALSIASI.equals(filterProtocollo))
  1184.                     ||
  1185.                 (filterProtocollo==null && protocolloSel!=null)
  1186.                     ) {
  1187.                 profiloSelezionato = true;
  1188.             }
  1189.            
  1190.             if(this.core.isGestionePddAbilitata(this)==false && multiTenant) {
  1191.                 String filterDominio = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_DOMINIO);
  1192.                 addFilterDominio(filterDominio, false);
  1193.             }
  1194.            
  1195.             String filterTipoSoggetto = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_TIPO_SOGGETTO);
  1196.             this.addFilterTipoSoggetto(filterTipoSoggetto,false);
  1197.            
  1198.             String filterTipoCredenziali = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_TIPO_CREDENZIALI);
  1199.             this.addFilterTipoCredenziali(filterTipoCredenziali,true,false);
  1200.            
  1201.             String filterCredenziale = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_CREDENZIALE);
  1202.             this.addFilterCredenziale(filterTipoCredenziali, filterCredenziale);
  1203.            
  1204.             String filterCredenzialeIssuer = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_CREDENZIALE_ISSUER);
  1205.             this.addFilterCredenzialeIssuer(filterTipoCredenziali, filterCredenzialeIssuer);
  1206.                        
  1207.             String filterRuolo = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_RUOLO);
  1208.             addFilterRuolo(filterRuolo, false);
  1209.            
  1210.             String filterGruppo = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_GRUPPO);
  1211.             addFilterGruppo(filterProtocollo, filterGruppo, true);
  1212.            
  1213.             String filterApiContesto = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_API_CONTESTO);
  1214.             this.addFilterApiContesto(filterApiContesto, true);
  1215.            
  1216.             if(profiloSelezionato &&
  1217.                     (filterApiContesto!=null &&
  1218.                     //!"".equals(filterApiContesto) &&
  1219.                     !CostantiControlStation.DEFAULT_VALUE_PARAMETRO_API_CONTESTO_QUALSIASI.equals(filterApiContesto))
  1220.                     &&
  1221.                     !SoggettiCostanti.SOGGETTO_RUOLO_EROGATORE.equals(filterTipoSoggetto)
  1222.                     &&
  1223.                     !(SoggettiCostanti.SOGGETTO_RUOLO_FRUITORE.equals(filterTipoSoggetto) && TipoPdD.DELEGATA.getTipo().equals(filterApiContesto))) {
  1224.                 String filterApiImplementazione = SearchUtils.getFilter(ricerca, idLista, Filtri.FILTRO_API_IMPLEMENTAZIONE);
  1225.                 this.addFilterApiImplementazione(filterProtocollo, null, filterGruppo, filterApiContesto, filterApiImplementazione, false);
  1226.             }
  1227.             else {
  1228.                 SearchUtils.clearFilter(ricerca, idLista, Filtri.FILTRO_API_IMPLEMENTAZIONE);
  1229.             }
  1230.            
  1231.             // filtri proprieta
  1232.             String protocolloPerFiltroProprieta = protocolloSel;
  1233.             // valorizzato con il protocollo nel menu in alto a destra oppure null, controllo se e' stato selezionato nel filtro di ricerca
  1234.             if(protocolloPerFiltroProprieta == null) {
  1235.                 if(
  1236.                         //"".equals(filterProtocollo) ||
  1237.                         CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PROTOCOLLO_QUALSIASI.equals(filterProtocollo)) {
  1238.                     protocolloPerFiltroProprieta = null;
  1239.                 } else {
  1240.                     protocolloPerFiltroProprieta = filterProtocollo;
  1241.                 }
  1242.             }
  1243.            
  1244.             // **** filtro proprieta ****
  1245.            
  1246.             List<String> nomiProprieta = this.nomiProprietaSoggetti(protocolloPerFiltroProprieta);
  1247.             if(nomiProprieta != null && !nomiProprieta.isEmpty()) {
  1248.                 this.addFilterSubtitle(CostantiControlStation.NAME_SUBTITLE_PROPRIETA, CostantiControlStation.LABEL_SUBTITLE_PROPRIETA, false);
  1249.                
  1250.                 // filtro nome
  1251.                 this.addFilterProprietaNome(ricerca, idLista, nomiProprieta);
  1252.                
  1253.                 // filtro valore
  1254.                 this.addFilterProprietaValore(ricerca, idLista, nomiProprieta);
  1255.                
  1256.                 // imposto apertura sezione
  1257.                 this.impostaAperturaSubtitle(CostantiControlStation.NAME_SUBTITLE_PROPRIETA);
  1258.             }
  1259.            
  1260.             // **** fine filtro proprieta ****
  1261.            
  1262.             this.pd.setIndex(offset);
  1263.             this.pd.setPageSize(limit);
  1264.             this.pd.setNumEntries(ricerca.getNumEntries(idLista));

  1265.             // setto la barra del titolo
  1266.             this.pd.setSearchLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_NOME);
  1267.             if (search.equals("")) {
  1268.                 this.pd.setSearchDescription("");
  1269.                 ServletUtils.setPageDataTitle(this.pd,
  1270.                         new Parameter(SoggettiCostanti.LABEL_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST));
  1271.             }
  1272.             else{
  1273.                 ServletUtils.setPageDataTitle(this.pd,
  1274.                         new Parameter(SoggettiCostanti.LABEL_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST),
  1275.                         new Parameter(Costanti.PAGE_DATA_TITLE_LABEL_RISULTATI_RICERCA, null));
  1276.             }

  1277.             boolean showProtocolli = this.core.countProtocolli(this.request, this.session)>1;

  1278.             setLabelColonne(modalitaCompleta, multiTenant, showProtocolli);

  1279.             // preparo i dati
  1280.             List<List<DataElement>> dati = new ArrayList<>();

  1281.             // controllo eventuali risultati ricerca
  1282.             if (!search.equals("")) {
  1283.                 ServletUtils.enabledPageDataSearch(this.pd, SoggettiCostanti.LABEL_SOGGETTI, search);
  1284.             }

  1285.             // Prendo la lista di pdd dell'utente connesso
  1286.             /**List<String> nomiPdd = new ArrayList<>();
  1287.             List<PdDControlStation> listaPdd = this.core.pddList(superUser, new Search(true));
  1288.             Iterator<PdDControlStation> itP = listaPdd.iterator();
  1289.             while (itP.hasNext()) {
  1290.                 PdDControlStation pds = (PdDControlStation) itP.next();
  1291.                 nomiPdd.add(pds.getNome());
  1292.             }*/

  1293.             if(lista!=null) {
  1294.                 Iterator<org.openspcoop2.core.registry.Soggetto> it = lista.listIterator();
  1295.                 while (it.hasNext()) {
  1296.                     List<DataElement> e = modalitaCompleta
  1297.                             ? this.creaEntry(modalitaCompleta, multiTenant, contaListe, showProtocolli, it)
  1298.                                     : this.creaEntryCustom(multiTenant, showProtocolli, it);
  1299.    
  1300.                     dati.add(e);
  1301.                 }
  1302.             }

  1303.             this.pd.setDati(dati);
  1304.             this.pd.setAddButton(true);

  1305.             // preparo bottoni
  1306.             if(lista!=null && !lista.isEmpty() &&
  1307.                 this.core.isShowPulsantiImportExport()) {

  1308.                 ExporterUtils exporterUtils = new ExporterUtils(this.archiviCore);
  1309.                 if(exporterUtils.existsAtLeastOneExportMode(ArchiveType.SOGGETTO, this.request, this.session)){

  1310.                     List<AreaBottoni> bottoni = new ArrayList<>();

  1311.                     AreaBottoni ab = new AreaBottoni();
  1312.                     List<DataElement> otherbott = new ArrayList<>();
  1313.                     DataElement de = new DataElement();
  1314.                     de.setValue(SoggettiCostanti.LABEL_SOGGETTI_ESPORTA_SELEZIONATI);
  1315.                     de.setOnClick(SoggettiCostanti.LABEL_SOGGETTI_ESPORTA_SELEZIONATI_ONCLICK);
  1316.                     de.setDisabilitaAjaxStatus();
  1317.                     otherbott.add(de);
  1318.                     ab.setBottoni(otherbott);
  1319.                     bottoni.add(ab);

  1320.                     this.pd.setAreaBottoni(bottoni);

  1321.                 }

  1322.             }

  1323.         } catch (Exception e) {
  1324.             this.logError(e.getMessage(), e);
  1325.             throw new DriverControlStationException(e.getMessage(),e);
  1326.         }
  1327.     }
  1328.     private List<DataElement> creaEntry(boolean modalitaCompleta, boolean multiTenant, Boolean contaListe,
  1329.             boolean showProtocolli, Iterator<org.openspcoop2.core.registry.Soggetto> it)
  1330.             throws DriverControlStationException, DriverControlStationNotFound, DriverRegistroServiziNotFound,
  1331.             DriverRegistroServiziException, Exception, DriverConfigurazioneException, DriverConfigurazioneNotFound {
  1332.         org.openspcoop2.core.registry.Soggetto elem = it.next();

  1333.         PdDControlStation pdd = null;
  1334.         String nomePdD = elem.getPortaDominio();
  1335.         if (nomePdD!=null && (!nomePdD.equals("-")) )
  1336.             pdd = this.pddCore.getPdDControlStation(nomePdD);
  1337.         boolean pddEsterna = this.pddCore.isPddEsterna(nomePdD);

  1338.         List<DataElement> e = new ArrayList<>();

  1339.         String protocollo = this.soggettiCore.getProtocolloAssociatoTipoSoggetto(elem.getTipo());
  1340.                            
  1341.         DataElement de = new DataElement();
  1342.         de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_CHANGE,
  1343.                 new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,elem.getId()+""),
  1344.                 new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME,elem.getNome()),
  1345.                 new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO,elem.getTipo()));
  1346.         de.setValue(this.getLabelNomeSoggetto(protocollo, elem.getTipo(), elem.getNome()));
  1347.         de.setIdToRemove(elem.getId().toString());
  1348.         de.setToolTip(de.getValue());
  1349.         de.setSize(this.core.getElenchiMenuIdentificativiLunghezzaMassima());
  1350.         e.add(de);

  1351.         if(showProtocolli) {
  1352.             de = new DataElement();
  1353.             de.setValue(this.getLabelProtocollo(protocollo));
  1354.             e.add(de);
  1355.         }
  1356.        
  1357.         if(this.core.isGestionePddAbilitata(this)) {
  1358.             de = new DataElement();
  1359.             if (pdd != null && (!nomePdD.equals("-"))){
  1360.                 if (!nomePdD.equals("-")){
  1361.                     //if (nomiPdd.contains(nomePdD)) {
  1362.                     if(this.core.isSinglePdD()){
  1363.                         de.setUrl(PddCostanti.SERVLET_NAME_PDD_SINGLEPDD_CHANGE,
  1364.                                 new Parameter(PddCostanti.PARAMETRO_PDD_ID,pdd.getId()+""),
  1365.                                 new Parameter(PddCostanti.PARAMETRO_PDD_NOME,pdd.getNome()));
  1366.                     }else{
  1367.                         de.setUrl(PddCostanti.SERVLET_NAME_PDD_CHANGE,
  1368.                                 new Parameter(PddCostanti.PARAMETRO_PDD_ID,pdd.getId()+""));
  1369.                     }
  1370.                     //}
  1371.                 }
  1372.                 de.setValue(nomePdD);
  1373.             }
  1374.             else{
  1375.                 de.setValue("-");
  1376.             }
  1377.             e.add(de);
  1378.         }
  1379.         else if(multiTenant) {
  1380.             de = new DataElement();
  1381.             if(pddEsterna) {
  1382.                 de.setValue(SoggettiCostanti.SOGGETTO_DOMINIO_ESTERNO_LABEL);
  1383.             }else {
  1384.                 de.setValue(SoggettiCostanti.SOGGETTO_DOMINIO_OPERATIVO_LABEL);
  1385.             }
  1386.             e.add(de);
  1387.         }

  1388.         if(modalitaCompleta) {
  1389.            
  1390.             boolean showConnettore = this.core.isRegistroServiziLocale() &&
  1391.                     (this.pddCore.isPddEsterna(nomePdD) || multiTenant );
  1392.            
  1393.             de = new DataElement();
  1394.             if(showConnettore){
  1395.                 de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_ENDPOINT,
  1396.                         new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,elem.getId()+""),
  1397.                         new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME,elem.getNome()),
  1398.                         new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO,elem.getTipo()));
  1399.                 ServletUtils.setDataElementVisualizzaLabel(de);
  1400.             }
  1401.             else{
  1402.                 de.setType(DataElementType.TEXT);
  1403.                 de.setValue("-");
  1404.             }
  1405.             e.add(de);
  1406.         }

  1407.        
  1408.         // Ruoli
  1409.         de = new DataElement();
  1410.         de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_RUOLI_LIST,
  1411.                 new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,elem.getId()+""));
  1412.         if (contaListe) {
  1413.             // BugFix OP-674
  1414.             //List<String> lista1 = this.soggettiCore.soggettiRuoliList(elem.getId(),new Search(true));
  1415.             ConsoleSearch searchForCount = new ConsoleSearch(true,1);
  1416.             this.soggettiCore.soggettiRuoliList(elem.getId(),searchForCount);
  1417.             //int numRuoli = lista1.size();
  1418.             int numRuoli = searchForCount.getNumEntries(Liste.SOGGETTI_RUOLI);
  1419.             ServletUtils.setDataElementVisualizzaLabel(de,(long)numRuoli);
  1420.         } else
  1421.             ServletUtils.setDataElementVisualizzaLabel(de);
  1422.         e.add(de);
  1423.        
  1424.        
  1425.         //Servizi Appicativi
  1426.         if(modalitaCompleta) {
  1427.             de = new DataElement();
  1428.             if (pddEsterna) {
  1429.                 de.setType(DataElementType.TEXT);
  1430.                 de.setValue("-");
  1431.             }
  1432.             else {
  1433.                 de.setUrl(ServiziApplicativiCostanti.SERVLET_NAME_SERVIZI_APPLICATIVI_LIST,
  1434.                         new Parameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_PROVIDER,elem.getId()+""));
  1435.                 if (contaListe) {
  1436.                     // BugFix OP-674
  1437.                     //List<ServizioApplicativo> lista1 = this.saCore.soggettiServizioApplicativoList(new Search(true), elem.getId());
  1438.                     ConsoleSearch searchForCount = new ConsoleSearch(true,1);
  1439.                     this.setFilterRuoloServizioApplicativo(searchForCount, Liste.SERVIZI_APPLICATIVI_BY_SOGGETTO);
  1440.                     this.saCore.soggettiServizioApplicativoList(searchForCount, elem.getId());
  1441.                     //int numSA = lista1.size();
  1442.                     int numSA = searchForCount.getNumEntries(Liste.SERVIZI_APPLICATIVI_BY_SOGGETTO);
  1443.                     ServletUtils.setDataElementVisualizzaLabel(de,(long)numSA);
  1444.                 } else
  1445.                     ServletUtils.setDataElementVisualizzaLabel(de);
  1446.             }
  1447.             e.add(de);
  1448.         }
  1449.        
  1450.         if(modalitaCompleta) {
  1451.             de = new DataElement();
  1452.             if (pddEsterna) {
  1453.                 // se la pdd e' esterna non e' possibile
  1454.                 // inseririre porte applicative
  1455.                 de.setType(DataElementType.TEXT);
  1456.                 de.setValue("-");
  1457.             } else {
  1458.                 de.setUrl(PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_LIST,
  1459.                         new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO,elem.getId()+""),
  1460.                         new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME_SOGGETTO,elem.getNome()),
  1461.                         new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TIPO_SOGGETTO,elem.getTipo()));
  1462.                 if (contaListe) {
  1463.                     // BugFix OP-674
  1464.                     //List<PortaApplicativa> lista1 = this.porteApplicativeCore.porteAppList(elem.getId().intValue(), new Search(true));
  1465.                     ConsoleSearch searchForCount = new ConsoleSearch(true,1);
  1466.                     this.porteApplicativeCore.porteAppList(elem.getId().intValue(), searchForCount);
  1467.                     //int numPA = lista1.size();
  1468.                     int numPA = searchForCount.getNumEntries(Liste.PORTE_APPLICATIVE_BY_SOGGETTO);
  1469.                     ServletUtils.setDataElementVisualizzaLabel(de,(long)numPA);
  1470.                 } else
  1471.                     ServletUtils.setDataElementVisualizzaLabel(de);

  1472.             }
  1473.             e.add(de);

  1474.             de = new DataElement();
  1475.             if (pddEsterna) {
  1476.                 // se la pdd e' esterna non e' possibile
  1477.                 // inseririre porte delegate
  1478.                 de.setType(DataElementType.TEXT);
  1479.                 de.setValue("-");
  1480.             } else {
  1481.                 de.setUrl(PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_LIST,
  1482.                         new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO,elem.getId()+""),
  1483.                         new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME_SOGGETTO,elem.getNome()),
  1484.                         new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TIPO_SOGGETTO,elem.getTipo()));
  1485.                 if (contaListe) {
  1486.                     // BugFix OP-674
  1487.                     //List<PortaDelegata> lista1 = this.porteDelegateCore.porteDelegateList(elem.getId().intValue(), new Search(true));
  1488.                     ConsoleSearch searchForCount = new ConsoleSearch(true,1);
  1489.                     this.porteDelegateCore.porteDelegateList(elem.getId().intValue(), searchForCount);
  1490.                     //int numPD = lista1.size();
  1491.                     int numPD = searchForCount.getNumEntries(Liste.PORTE_DELEGATE_BY_SOGGETTO);
  1492.                     ServletUtils.setDataElementVisualizzaLabel(de,(long)numPD);
  1493.                 } else
  1494.                     ServletUtils.setDataElementVisualizzaLabel(de);
  1495.             }
  1496.             e.add(de);
  1497.         }
  1498.         return e;
  1499.     }
  1500.     private void setLabelColonne(boolean modalitaCompleta, boolean multiTenant, boolean showProtocolli) {
  1501.        
  1502.         if(!modalitaCompleta) {
  1503.             List<String> labels = new ArrayList<>();
  1504.             labels.add(SoggettiCostanti.LABEL_SOGGETTI);
  1505.            
  1506.             this.pd.setLabels(labels.toArray(new String[1]));
  1507.         } else {
  1508.             // setto le label delle colonne
  1509.             //int totEl = modalitaCompleta ? 4 : 2;
  1510.             int totEl = 4;
  1511.             if( showProtocolli ) {
  1512.                 totEl++;
  1513.             }
  1514.             if(multiTenant || this.pddCore.isGestionePddAbilitata(this)) {
  1515.                 // pdd o dominio
  1516.                 totEl++;
  1517.             }
  1518.             if(modalitaCompleta) {
  1519.                 totEl++; // connettore column
  1520.             }
  1521.             if(modalitaCompleta) {
  1522.                 totEl++; // connettore servizi applicativi
  1523.             }
  1524.             String[] labels = new String[totEl];
  1525.             int i = 0;
  1526.             labels[i++] = SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_NOME;
  1527.             if( showProtocolli ) {
  1528.                 labels[i++] = SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_PROTOCOLLO_COMPACT;
  1529.             }
  1530.             if(this.pddCore.isGestionePddAbilitata(this)) {
  1531.                 labels[i++] = PddCostanti.LABEL_PORTA_DI_DOMINIO;
  1532.             }
  1533.             else if(multiTenant) {
  1534.                 labels[i++] = SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_DOMINIO;
  1535.             }
  1536.             if(modalitaCompleta) {
  1537.                 labels[i++] = ConnettoriCostanti.LABEL_CONNETTORE;
  1538.             }
  1539.             labels[i++] = RuoliCostanti.LABEL_RUOLI;
  1540.             if(modalitaCompleta) {
  1541.                 labels[i++] = ServiziApplicativiCostanti.LABEL_SERVIZI_APPLICATIVI;
  1542.             }
  1543.     //          else {
  1544.     //              labels[i++] = ServiziApplicativiCostanti.LABEL_APPLICATIVI;
  1545.     //          }
  1546.             if(modalitaCompleta) {
  1547.                 labels[i++] = PorteApplicativeCostanti.LABEL_PORTE_APPLICATIVE;
  1548.                 labels[i++] = PorteDelegateCostanti.LABEL_PORTE_DELEGATE;
  1549.             }
  1550.             this.pd.setLabels(labels);
  1551.         }
  1552.     }
  1553.    
  1554.     private List<DataElement> creaEntryCustom(boolean multiTenant, boolean showProtocolli,
  1555.             Iterator<org.openspcoop2.core.registry.Soggetto> it)
  1556.             throws DriverRegistroServiziException,
  1557.             DriverControlStationException, DriverControlStationNotFound, DriverConfigurazioneException {
  1558.         org.openspcoop2.core.registry.Soggetto elem = it.next();

  1559.         List<DataElement> e = new ArrayList<>();
  1560.        
  1561.         // Titolo (nome soggetto)
  1562.         String protocollo = this.soggettiCore.getProtocolloAssociatoTipoSoggetto(elem.getTipo());
  1563.        
  1564.         List<Parameter> listaParametriChange = new ArrayList<>();
  1565.         listaParametriChange.add(new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,elem.getId()+""));
  1566.         listaParametriChange.add(new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME,elem.getNome()));
  1567.         listaParametriChange.add(new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO,elem.getTipo()));
  1568.                
  1569.         DataElement de = new DataElement();
  1570.         de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_CHANGE, listaParametriChange.toArray(new Parameter[listaParametriChange.size()]));
  1571.         de.setValue(this.getLabelNomeSoggetto(protocollo, elem.getTipo(), elem.getNome()));
  1572.         de.setIdToRemove(elem.getId().toString());
  1573.         de.setToolTip(de.getValue());
  1574.         de.setType(DataElementType.TITLE);
  1575.         e.add(de);
  1576.        
  1577.        
  1578.         String nomePdD = elem.getPortaDominio();
  1579.         boolean pddEsterna = this.pddCore.isPddEsterna(nomePdD);

  1580.         // Metadati (profilo + dominio)
  1581.         if(showProtocolli || multiTenant) {
  1582.             boolean addMetadati = true;
  1583.             de = new DataElement();
  1584.            
  1585.             if(multiTenant) {
  1586.                 String dominioLabel = "";
  1587.                 if(pddEsterna) {
  1588.                     dominioLabel = SoggettiCostanti.SOGGETTO_DOMINIO_ESTERNO_LABEL;
  1589.                 }else {
  1590.                     dominioLabel = SoggettiCostanti.SOGGETTO_DOMINIO_OPERATIVO_LABEL;
  1591.                 }
  1592.                
  1593.                
  1594.                 if(showProtocolli) {
  1595.                     String labelProtocollo =this.getLabelProtocollo(protocollo);
  1596.                     de.setValue(MessageFormat.format(SoggettiCostanti.MESSAGE_METADATI_SOGGETTO_CON_PROFILO, labelProtocollo, dominioLabel));
  1597.                 } else {
  1598.                     de.setValue(MessageFormat.format(SoggettiCostanti.MESSAGE_METADATI_SOGGETTO_SENZA_PROFILO, dominioLabel));
  1599.                 }
  1600.             } else {
  1601.                 String labelProtocollo =this.getLabelProtocollo(protocollo);
  1602.                 de.setValue(MessageFormat.format(SoggettiCostanti.MESSAGE_METADATI_SOGGETTO_SOLO_PROFILO, labelProtocollo));
  1603.             }
  1604.            
  1605.             de.setType(DataElementType.SUBTITLE);
  1606.            
  1607.             if(addMetadati)
  1608.                 e.add(de);
  1609.         }

  1610.         // Ruoli
  1611.         List<String> listaRuoli = this.soggettiCore.soggettiRuoliList(elem.getId(),new ConsoleSearch(true));
  1612.         for (int j = 0; j < listaRuoli.size(); j++) {
  1613.             String ruolo = listaRuoli.get(j);
  1614.            
  1615.             de = new DataElement();
  1616.             de.setName(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_RUOLO + "_" + j);
  1617.             de.setType(DataElementType.BUTTON);
  1618.             de.setLabel(ruolo);
  1619.            
  1620. /**                 int indexOf = ruoliDisponibili.indexOf(ruolo);
  1621. //                  if(indexOf == -1)
  1622. //                      indexOf = 0;
  1623. //                  
  1624. //                  indexOf = indexOf % CostantiControlStation.NUMERO_GRUPPI_CSS;*/
  1625.            
  1626.             de.setStyleClass("ruolo-label-info-0"); /**+indexOf);*/
  1627.            
  1628.             de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_RUOLI_LIST,
  1629.                     new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,elem.getId()+""));
  1630.            
  1631.             de.setToolTip(RuoliCostanti.LABEL_RUOLI);
  1632.            
  1633.             e.add(de);
  1634.         }
  1635.        
  1636.         listaParametriChange.add(new Parameter(CostantiControlStation.PARAMETRO_VERIFICA_CERTIFICATI_FROM_LISTA, "true"));
  1637.         listaParametriChange.add(new Parameter(CostantiControlStation.PARAMETRO_RESET_CACHE_FROM_LISTA, "true"));
  1638.        
  1639.         String labelSoggetto = this.getLabelNomeSoggetto(protocollo, elem.getTipo(), elem.getNome());
  1640.        
  1641.         // In Uso Button
  1642.         this.addInUsoButton(e, labelSoggetto, elem.getId()+"", InUsoType.SOGGETTO);
  1643.        
  1644.         if(this.core.isSoggettiVerificaCertificati()) {
  1645.             // Verifica certificati visualizzato solo se il soggetto ha credenziali https
  1646.             boolean ssl = false;
  1647.             for (int i = 0; i < elem.sizeCredenzialiList(); i++) {
  1648.                 CredenzialiSoggetto c = elem.getCredenziali(i);
  1649.                 if(org.openspcoop2.core.registry.constants.CredenzialeTipo.SSL.equals(c.getTipo())) {
  1650.                         //&& c.getCertificate()!=null) { non viene ritornato dalla lista
  1651.                     ssl = true;
  1652.                 }
  1653.             }
  1654.             if(ssl) {
  1655.                 this.addVerificaCertificatiButton(e, SoggettiCostanti.SERVLET_NAME_SOGGETTI_VERIFICA_CERTIFICATI, listaParametriChange);
  1656.             }
  1657.         }
  1658.                
  1659.         // se e' abilitata l'opzione reset cache per elemento, visualizzo il comando nell'elenco dei comandi disponibili nella lista
  1660.         if(this.core.isElenchiVisualizzaComandoResetCacheSingoloElemento()){
  1661.             this.addComandoResetCacheButton(e,this.getLabelNomeSoggetto(protocollo, elem.getTipo(), elem.getNome()), SoggettiCostanti.SERVLET_NAME_SOGGETTI_CHANGE, listaParametriChange);
  1662.         }
  1663.        
  1664.         // Proprieta Button
  1665.         /**if(this.existsProprietaOggetto(elem.getProprietaOggetto(), elem.getDescrizione())) {
  1666.          * la lista non riporta le proprietà. Ma esistono e poi sarà la servlet a gestirlo
  1667.          */
  1668.         this.addProprietaOggettoButton(e, labelSoggetto, elem.getId()+"", InUsoType.SOGGETTO);
  1669.        
  1670.         return e;
  1671.     }

  1672.     public void prepareSoggettiConfigList(List<org.openspcoop2.core.config.Soggetto> lista, ISearch ricerca) throws Exception {
  1673.         try {
  1674.             ServletUtils.addListElementIntoSession(this.request, this.session, SoggettiCostanti.OBJECT_NAME_SOGGETTI);

  1675.             Boolean contaListeObject = ServletUtils.getContaListeFromSession(this.session);
  1676.             boolean contaListe = false;
  1677.             if(contaListeObject!=null) {
  1678.                 contaListe = contaListeObject.booleanValue();
  1679.             }

  1680.             int idLista = Liste.SOGGETTI;
  1681.             int limit = ricerca.getPageSize(idLista);
  1682.             int offset = ricerca.getIndexIniziale(idLista);
  1683.             String search = ServletUtils.getSearchFromSession(ricerca, idLista);

  1684.             String filterProtocollo = addFilterProtocol(ricerca, idLista, true);
  1685.             String protocolloSel = filterProtocollo;
  1686.             if(protocolloSel==null) {
  1687.                 // significa che e' stato selezionato un protocollo nel menu in alto a destra
  1688.                 List<String> protocolli = this.core.getProtocolli(this.request, this.session);
  1689.                 if(protocolli!=null && protocolli.size()==1) {
  1690.                     protocolloSel = protocolli.get(0);
  1691.                 }
  1692.             }
  1693.            
  1694.             // filtri proprieta
  1695.             String protocolloPerFiltroProprieta = protocolloSel;
  1696.             // valorizzato con il protocollo nel menu in alto a destra oppure null, controllo se e' stato selezionato nel filtro di ricerca
  1697.             if(protocolloPerFiltroProprieta == null) {
  1698.                 if(
  1699.                         //"".equals(filterProtocollo) ||
  1700.                         CostantiControlStation.DEFAULT_VALUE_PARAMETRO_PROTOCOLLO_QUALSIASI.equals(filterProtocollo)) {
  1701.                     protocolloPerFiltroProprieta = null;
  1702.                 } else {
  1703.                     protocolloPerFiltroProprieta = filterProtocollo;
  1704.                 }
  1705.             }
  1706.            
  1707.             // **** filtro proprieta ****
  1708.            
  1709.             List<String> nomiProprieta = this.nomiProprietaSoggetti(protocolloPerFiltroProprieta);
  1710.             if(nomiProprieta != null && !nomiProprieta.isEmpty()) {
  1711.                 this.addFilterSubtitle(CostantiControlStation.NAME_SUBTITLE_PROPRIETA, CostantiControlStation.LABEL_SUBTITLE_PROPRIETA, false);
  1712.                
  1713.                 // filtro nome
  1714.                 this.addFilterProprietaNome(ricerca, idLista, nomiProprieta);
  1715.                
  1716.                 // filtro valore
  1717.                 this.addFilterProprietaValore(ricerca, idLista, nomiProprieta);
  1718.                
  1719.                 // imposto apertura sezione
  1720.                 this.impostaAperturaSubtitle(CostantiControlStation.NAME_SUBTITLE_PROPRIETA);
  1721.             }
  1722.            
  1723.             // **** fine filtro proprieta ****
  1724.                        
  1725.                        
  1726.             this.pd.setIndex(offset);
  1727.             this.pd.setPageSize(limit);
  1728.             this.pd.setNumEntries(ricerca.getNumEntries(idLista));

  1729.             // setto la barra del titolo
  1730.             if (search.equals("")) {
  1731.                 this.pd.setSearchDescription("");
  1732.                 ServletUtils.setPageDataTitle(this.pd,
  1733.                         new Parameter(SoggettiCostanti.LABEL_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST));
  1734.             }
  1735.             else{
  1736.                 ServletUtils.setPageDataTitle(this.pd,
  1737.                         new Parameter(SoggettiCostanti.LABEL_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST),
  1738.                         new Parameter(Costanti.PAGE_DATA_TITLE_LABEL_RISULTATI_RICERCA, null));
  1739.             }

  1740.             boolean showProtocolli = this.core.countProtocolli(this.request, this.session)>1;
  1741.            
  1742.             // setto le label delle colonne
  1743.             int totEl = this.isModalitaCompleta() ? 3 : 1;
  1744.             if( showProtocolli ) {
  1745.                 totEl++;
  1746.             }
  1747.             if(this.isModalitaCompleta()) {
  1748.                 totEl++; // connettore servizi applicativi
  1749.             }
  1750.             String[] labels = new String[totEl];
  1751.             int i = 0;
  1752.             labels[i++] = SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_NOME;
  1753.             if( showProtocolli ) {
  1754.                 labels[i++] = SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_PROTOCOLLO_COMPACT;
  1755.             }
  1756.             if(this.isModalitaCompleta()) {
  1757.                 labels[i++] = ServiziApplicativiCostanti.LABEL_SERVIZI_APPLICATIVI;
  1758.             }
  1759. /**         else {
  1760. //              labels[i++] = ServiziApplicativiCostanti.LABEL_APPLICATIVI;
  1761. //          }*/
  1762.             if(this.isModalitaCompleta()) {
  1763.                 labels[i++] = PorteApplicativeCostanti.LABEL_PORTE_APPLICATIVE;
  1764.                 labels[i] = PorteDelegateCostanti.LABEL_PORTE_DELEGATE;
  1765.             }
  1766.            
  1767.             this.pd.setLabels(labels);

  1768.             // preparo i dati
  1769.             List<List<DataElement>> dati = new ArrayList<>();

  1770.             // controllo eventuali risultati ricerca
  1771.             if (!search.equals("")) {
  1772.                 ServletUtils.enabledPageDataSearch(this.pd, SoggettiCostanti.LABEL_SOGGETTI, search);
  1773.             }

  1774.             if(lista!=null) {
  1775.                 Iterator<org.openspcoop2.core.config.Soggetto> it = lista.listIterator();
  1776.                 while (it.hasNext()) {
  1777.                     org.openspcoop2.core.config.Soggetto elem = it.next();
  1778.    
  1779.                     List<DataElement> e = new ArrayList<>();
  1780.                    
  1781.                     //Soggetto
  1782.                     DataElement de = new DataElement();
  1783.                     de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_CHANGE,
  1784.                             new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,elem.getId()+""),
  1785.                             new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME,elem.getNome()),
  1786.                             new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO,elem.getTipo()));
  1787.                     de.setValue(elem.getTipo() + "/" + elem.getNome());
  1788.                     de.setIdToRemove(elem.getId().toString());
  1789.                     de.setSize(this.core.getElenchiMenuIdentificativiLunghezzaMassima());
  1790.                     e.add(de);
  1791.    
  1792.                     if(showProtocolli) {
  1793.                         de = new DataElement();
  1794.                         de.setValue(this.getLabelProtocollo(this.soggettiCore.getProtocolloAssociatoTipoSoggetto(elem.getTipo())));
  1795.                         e.add(de);
  1796.                     }
  1797.                    
  1798.                     //Servizi Appicativi
  1799.                     if(this.isModalitaCompleta()) {
  1800.                         de = new DataElement();
  1801.                         de.setUrl(ServiziApplicativiCostanti.SERVLET_NAME_SERVIZI_APPLICATIVI_LIST,
  1802.                                 new Parameter(ServiziApplicativiCostanti.PARAMETRO_SERVIZI_APPLICATIVI_PROVIDER,elem.getId()+""));
  1803.                         if (contaListe) {
  1804.                             // BugFix OP-674
  1805.                             /**List<ServizioApplicativo> lista1 = this.saCore.soggettiServizioApplicativoList(new Search(true), elem.getId());*/
  1806.                             ConsoleSearch searchForCount = new ConsoleSearch(true,1);
  1807.                             this.setFilterRuoloServizioApplicativo(searchForCount, Liste.SERVIZI_APPLICATIVI_BY_SOGGETTO);
  1808.                             this.saCore.soggettiServizioApplicativoList(searchForCount, elem.getId());
  1809.                             /**int numSA = lista1.size();*/
  1810.                             int numSA = searchForCount.getNumEntries(Liste.SERVIZI_APPLICATIVI_BY_SOGGETTO);
  1811.                             ServletUtils.setDataElementVisualizzaLabel(de,(long)numSA);
  1812.                         } else
  1813.                             ServletUtils.setDataElementVisualizzaLabel(de);
  1814.                         e.add(de);
  1815.                     }
  1816.                    
  1817.                     if(this.isModalitaCompleta()) {
  1818.                         //Porte Applicative
  1819.                         de = new DataElement();
  1820.                         de.setUrl(PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_LIST,
  1821.                                 new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO,elem.getId()+""),
  1822.                                 new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME_SOGGETTO,elem.getNome()),
  1823.                                 new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TIPO_SOGGETTO,elem.getTipo()));
  1824.                         if (contaListe) {
  1825.                             // BugFix OP-674
  1826.                             /** List<PortaApplicativa> lista1 = this.porteApplicativeCore.porteAppList(elem.getId().intValue(), new Search(true));*/
  1827.                             ConsoleSearch searchForCount = new ConsoleSearch(true,1);
  1828.                             this.porteApplicativeCore.porteAppList(elem.getId().intValue(), searchForCount);
  1829.                             /**int numPA = lista1.size();*/
  1830.                             int numPA = searchForCount.getNumEntries(Liste.PORTE_APPLICATIVE_BY_SOGGETTO);
  1831.                             ServletUtils.setDataElementVisualizzaLabel(de,(long)numPA);
  1832.                         } else
  1833.                             ServletUtils.setDataElementVisualizzaLabel(de);
  1834.                         e.add(de);
  1835.        
  1836.                         //Porte Delegate
  1837.                         de = new DataElement();
  1838.                         de.setUrl(PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_LIST,
  1839.                                 new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO,elem.getId()+""),
  1840.                                 new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME_SOGGETTO,elem.getNome()),
  1841.                                 new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TIPO_SOGGETTO,elem.getTipo()));
  1842.                         if (contaListe) {
  1843.                             // BugFix OP-674
  1844.                             /**List<PortaDelegata> lista1 = this.porteDelegateCore.porteDelegateList(elem.getId().intValue(), new Search(true));*/
  1845.                             ConsoleSearch searchForCount = new ConsoleSearch(true,1);
  1846.                             this.porteDelegateCore.porteDelegateList(elem.getId().intValue(), searchForCount);
  1847.                             /**int numPD = lista1.size();*/
  1848.                             int numPD = searchForCount.getNumEntries(Liste.PORTE_DELEGATE_BY_SOGGETTO);
  1849.                             ServletUtils.setDataElementVisualizzaLabel(de,(long)numPD);
  1850.                         } else
  1851.                             ServletUtils.setDataElementVisualizzaLabel(de);
  1852.                         e.add(de);
  1853.                     }
  1854.    
  1855.    
  1856.                     dati.add(e);
  1857.                 }
  1858.             }

  1859.             this.pd.setDati(dati);
  1860.             this.pd.setAddButton(true);

  1861.             // preparo bottoni
  1862.             if(lista!=null && !lista.isEmpty()){
  1863.                 if (this.core.isShowPulsantiImportExport()) {

  1864.                     ExporterUtils exporterUtils = new ExporterUtils(this.archiviCore);
  1865.                     if(exporterUtils.existsAtLeastOneExportMode(ArchiveType.SOGGETTO, this.request, this.session)){

  1866.                         List<AreaBottoni> bottoni = new ArrayList<>();

  1867.                         AreaBottoni ab = new AreaBottoni();
  1868.                         List<DataElement> otherbott = new ArrayList<>();
  1869.                         DataElement de = new DataElement();
  1870.                         de.setValue(SoggettiCostanti.LABEL_SOGGETTI_ESPORTA_SELEZIONATI);
  1871.                         de.setOnClick(SoggettiCostanti.LABEL_SOGGETTI_ESPORTA_SELEZIONATI_ONCLICK);
  1872.                         de.setDisabilitaAjaxStatus();
  1873.                         otherbott.add(de);
  1874.                         ab.setBottoni(otherbott);
  1875.                         bottoni.add(ab);

  1876.                         this.pd.setAreaBottoni(bottoni);

  1877.                     }

  1878.                 }
  1879.             }

  1880.         } catch (Exception e) {
  1881.             this.logError("Exception prepareSoggetti(Config)List: " + e.getMessage(), e);
  1882.             throw new DriverControlStationException(e.getMessage(),e);
  1883.         }

  1884.     }



  1885.     public boolean soggettiEndPointCheckData(TipoOperazione tipoOp,List<ExtendedConnettore> listExtendedConnettore, String tipoSoggetto, String nomeSoggetto) throws Exception {
  1886.         try {
  1887.             String id = this.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_ID);
  1888.             int idInt = 0;
  1889.             if (tipoOp.equals(TipoOperazione.CHANGE)) {
  1890.                 idInt = Integer.parseInt(id);
  1891.             }
  1892.             //String endpointtype = this.getParameter(ConnettoriCostanti.PARAMETRO_CONNETTORE_ENDPOINT_TYPE);
  1893.             String endpointtype = this.readEndPointType();

  1894.             String protocollo = this.soggettiCore.getProtocolloAssociatoTipoSoggetto(tipoSoggetto);
  1895.             if (!this.endPointCheckData(null, protocollo, false, listExtendedConnettore)) {
  1896.                 return false;
  1897.             }

  1898.             // Se il connettore e' disabilitato devo controllare che i
  1899.             // connettore dei suoi servizi non siano disabilitati
  1900.             if (endpointtype.equals(TipiConnettore.DISABILITATO.toString())) {
  1901.                
  1902.                 org.openspcoop2.core.registry.Soggetto soggetto = this.soggettiCore.getSoggettoRegistro(new IDSoggetto(tipoSoggetto, nomeSoggetto));
  1903.                 if(this.pddCore.isPddEsterna(soggetto.getPortaDominio())){
  1904.                
  1905.                     boolean trovatoServ = this.soggettiCore.existsSoggettoServiziWithoutConnettore(idInt);
  1906.                     if (trovatoServ) {
  1907.                         this.pd.setMessage("Il connettore deve essere specificato poichè alcuni servizi del soggetto non hanno un connettore definito");
  1908.                         return false;
  1909.                     }
  1910.                    
  1911.                 }
  1912.                 else{
  1913.                    
  1914.                     boolean escludiSoggettiEsterni = true;
  1915.                     boolean trovatoServ = this.soggettiCore.existFruizioniServiziSoggettoWithoutConnettore(idInt, escludiSoggettiEsterni);
  1916.                     if (trovatoServ) {
  1917.                         this.pd.setMessage("Il connettore deve essere specificato poichè alcune fruizioni dei servizi erogati dal soggetto non hanno un connettore definito");
  1918.                         return false;
  1919.                     }
  1920.                    
  1921.                 }
  1922.                
  1923.             }

  1924.             return true;

  1925.         } catch (Exception e) {
  1926.             this.logError(e.getMessage(), e);
  1927.             throw new DriverControlStationException(e.getMessage(),e);
  1928.         }
  1929.     }
  1930.    
  1931.    
  1932.     public void prepareRuoliList(ISearch ricerca, List<String> lista)
  1933.                     throws Exception {
  1934.         try {
  1935.             String id = this.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID);
  1936.             String accessDaChangeTmp = this.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTO_RUOLI_ACCESSO_DA_CHANGE);
  1937.             boolean accessDaChange = ServletUtils.isCheckBoxEnabled(accessDaChangeTmp);

  1938.             ServletUtils.addListElementIntoSession(this.request, this.session, SoggettiCostanti.OBJECT_NAME_SOGGETTI_RUOLI,
  1939.                     new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID, id),
  1940.                     new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_RUOLI_ACCESSO_DA_CHANGE, accessDaChangeTmp));

  1941.             int idLista = Liste.SOGGETTI_RUOLI;
  1942.             int limit = ricerca.getPageSize(idLista);
  1943.             int offset = ricerca.getIndexIniziale(idLista);
  1944.             String search = ServletUtils.getSearchFromSession(ricerca, idLista);

  1945.             this.pd.setIndex(offset);
  1946.             this.pd.setPageSize(limit);
  1947.             this.pd.setNumEntries(ricerca.getNumEntries(idLista));

  1948.             Soggetto soggettoRegistry = this.soggettiCore.getSoggettoRegistro(Long.parseLong(id));
  1949.             String tmpTitle = this.getLabelNomeSoggetto(new IDSoggetto(soggettoRegistry.getTipo(),soggettoRegistry.getNome()));



  1950.             // setto la barra del titolo
  1951.             if(accessDaChange) {
  1952.                 ServletUtils.setPageDataTitle_ServletFirst(this.pd, SoggettiCostanti.LABEL_SOGGETTI,
  1953.                         SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST);
  1954.                 ServletUtils.appendPageDataTitle(this.pd,
  1955.                         new Parameter(tmpTitle,
  1956.                                 SoggettiCostanti.SERVLET_NAME_SOGGETTI_CHANGE,
  1957.                                 new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,soggettoRegistry.getId()+""),
  1958.                                 new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME,soggettoRegistry.getNome()),
  1959.                                 new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO,soggettoRegistry.getTipo())));
  1960.                 ServletUtils.appendPageDataTitle(this.pd,
  1961.                         new Parameter(RuoliCostanti.LABEL_RUOLI, null));
  1962.             }
  1963.             else {
  1964.                 ServletUtils.setPageDataTitle_ServletChange(this.pd, SoggettiCostanti.LABEL_SOGGETTI,
  1965.                         SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST, "Ruoli di " + tmpTitle);
  1966.             }


  1967.             // controllo eventuali risultati ricerca
  1968.             this.pd.setSearchLabel(CostantiControlStation.LABEL_PARAMETRO_RUOLO);
  1969.             if (!search.equals("")) {
  1970.                 ServletUtils.enabledPageDataSearch(this.pd, RuoliCostanti.LABEL_RUOLI, search);
  1971.             }

  1972.             // setto le label delle colonne
  1973.             String[] labels = {
  1974.                     CostantiControlStation.LABEL_PARAMETRO_RUOLO
  1975.             };
  1976.             this.pd.setLabels(labels);

  1977.             // preparo i dati
  1978.             List<List<DataElement>> dati = new ArrayList<>();

  1979.             if (lista != null) {
  1980.                 Iterator<String> it = lista.iterator();
  1981.                 while (it.hasNext()) {
  1982.                     String ruolo = it.next();

  1983.                     List<DataElement> e = new ArrayList<>();

  1984.                     DataElement de = new DataElement();
  1985.                     de.setValue(ruolo);
  1986.                     de.setIdToRemove(ruolo);
  1987.                    
  1988.                     if(!this.isModalitaCompleta()) {
  1989.                         Ruolo ruoloObj = this.ruoliCore.getRuolo(ruolo);
  1990.                         Parameter pIdRuolo = new Parameter(RuoliCostanti.PARAMETRO_RUOLO_ID, ruoloObj.getId()+"");
  1991.                        
  1992.                         String url = new Parameter("", RuoliCostanti.SERVLET_NAME_RUOLI_CHANGE , pIdRuolo).getValue();
  1993.                         String tooltip = ruolo;
  1994.                        
  1995.                         this.newDataElementVisualizzaInNuovoTab(de, url, tooltip);
  1996.                     }
  1997.                    
  1998.                     e.add(de);

  1999.                     dati.add(e);
  2000.                 }
  2001.             }

  2002.             this.pd.setDati(dati);
  2003.             this.pd.setAddButton(true);

  2004.         } catch (Exception e) {
  2005.             this.logError(e.getMessage(), e);
  2006.             throw new DriverControlStationException(e.getMessage(),e);
  2007.         }
  2008.     }

  2009.    
  2010.     private void addFilterTipoSoggetto(String tipoSoggetto, boolean postBack) throws Exception{
  2011.         try {
  2012.             String [] tmpLabels = SoggettiCostanti.getLabelsSoggettoRuoloTipo();
  2013.             String [] tmpValues = SoggettiCostanti.getValuesSoggettoRuoloTipo();
  2014.            
  2015.             String [] values = new String[tmpValues.length + 1];
  2016.             String [] labels = new String[tmpLabels.length + 1];
  2017.             labels[0] = SoggettiCostanti.LABEL_PARAMETRO_FILTRO_SOGGETTO_TIPO_QUALSIASI;
  2018.             values[0] = SoggettiCostanti.DEFAULT_VALUE_PARAMETRO_FILTRO_SOGGETTO_TIPO_QUALSIASI;
  2019.             for (int i =0; i < tmpLabels.length ; i ++) {
  2020.                 labels[i+1] = tmpLabels[i];
  2021.                 values[i+1] = tmpValues[i];
  2022.             }
  2023.            
  2024.             String selectedValue = tipoSoggetto != null ? tipoSoggetto : SoggettiCostanti.DEFAULT_VALUE_PARAMETRO_FILTRO_SOGGETTO_TIPO_QUALSIASI;
  2025.            
  2026.             String label = SoggettiCostanti.LABEL_PARAMETRO_SOGGETTO_TIPO;

  2027.             this.pd.addFilter(Filtri.FILTRO_TIPO_SOGGETTO, label, selectedValue, values, labels, postBack, this.getSize());
  2028.            
  2029.         } catch (Exception e) {
  2030.             this.logError(e.getMessage(), e);
  2031.             throw new DriverControlStationException(e.getMessage(),e);
  2032.         }
  2033.     }
  2034.    
  2035.     public void prepareSoggettiCredenzialiList(Soggetto soggettoRegistry, String id) throws Exception{
  2036.         try {
  2037.             List<Parameter> parametersServletSoggettoChange = new ArrayList<>();
  2038.             Parameter pIdSoggetto = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID, id);
  2039.             Parameter pNomeSoggetto = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME, soggettoRegistry.getNome());
  2040.             Parameter pTipoSoggetto = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO, soggettoRegistry.getTipo());
  2041.             parametersServletSoggettoChange.add(pIdSoggetto);
  2042.             parametersServletSoggettoChange.add(pNomeSoggetto);
  2043.             parametersServletSoggettoChange.add(pTipoSoggetto);
  2044.            
  2045.             ServletUtils.addListElementIntoSession(this.request, this.session, SoggettiCostanti.OBJECT_NAME_SOGGETTI_CREDENZIALI, parametersServletSoggettoChange.toArray(new Parameter[parametersServletSoggettoChange.size()]));

  2046.             this.pd.setIndex(0);
  2047.             this.pd.setPageSize(soggettoRegistry.sizeCredenzialiList());
  2048.             this.pd.setNumEntries(soggettoRegistry.sizeCredenzialiList());
  2049.            
  2050.             // ricerca disattivata
  2051.             ServletUtils.disabledPageDataSearch(this.pd);
  2052.            
  2053.             // setto la barra del titolo
  2054.             String protocollo = this.soggettiCore.getProtocolloAssociatoTipoSoggetto(soggettoRegistry.getTipo());
  2055.            
  2056.             ServletUtils.setPageDataTitle(this.pd,
  2057.                     new Parameter(SoggettiCostanti.LABEL_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST),
  2058.                     new Parameter(this.getLabelNomeSoggetto(protocollo, soggettoRegistry.getTipo() , soggettoRegistry.getNome()),
  2059.                     SoggettiCostanti.SERVLET_NAME_SOGGETTI_CHANGE, parametersServletSoggettoChange.toArray(new Parameter[parametersServletSoggettoChange.size()])),
  2060.                     new Parameter(ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_CERTIFICATI, null)
  2061.                     );
  2062.            
  2063.             // setto le label delle colonne
  2064.             List<String> labels = new ArrayList<>();
  2065.            
  2066.             labels.add(ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_ALIAS_CERTIFICATO_PRINCIPALE);
  2067.             labels.add(ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_ALIAS_CERTIFICATO_SUBJECT);
  2068.             labels.add(ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_ALIAS_CERTIFICATO_ISSUER);
  2069.             labels.add(ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_VERIFICA_TUTTI_CAMPI);
  2070.             labels.add(ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_ALIAS_CERTIFICATO_NOT_BEFORE);
  2071.             labels.add(ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_ALIAS_CERTIFICATO_NOT_AFTER);
  2072.            
  2073.             this.pd.setLabels(labels.toArray(new String[1]));

  2074.             // preparo i dati
  2075.             List<List<DataElement>> dati = new ArrayList<>();
  2076.            
  2077.             List<CredenzialiSoggetto> lista = soggettoRegistry.getCredenzialiList();

  2078.             Iterator<CredenzialiSoggetto> it = lista.listIterator();
  2079.             int i = 0;
  2080.             while (it.hasNext()) {
  2081.                
  2082.                 List<DataElement> e = new ArrayList<>();
  2083.                 CredenzialiSoggetto credenziali = it.next();
  2084.                 Certificate cSelezionato = ArchiveLoader.load(credenziali.getCertificate());
  2085.                 String tipoCredenzialiSSLAliasCertificatoIssuer = cSelezionato.getCertificate().getIssuer().getNameNormalized();
  2086.                 String tipoCredenzialiSSLAliasCertificatoSubject = cSelezionato.getCertificate().getSubject().getNameNormalized();
  2087.                 boolean verificaTuttiCampi = credenziali.getCertificateStrictVerification();
  2088.                 Date notBefore = cSelezionato.getCertificate().getNotBefore();
  2089.                 String tipoCredenzialiSSLAliasCertificatoNotBefore = this.getSdfCredenziali().format(notBefore);
  2090.                 Date notAfter = cSelezionato.getCertificate().getNotAfter();
  2091.                 String tipoCredenzialiSSLAliasCertificatoNotAfter = this.getSdfCredenziali().format(notAfter);
  2092.                
  2093.                 Parameter pIdCredenziale = new Parameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CREDENZIALI_ID, i+"");
  2094.                 List<Parameter> parametersServletCredenzialeChange = new ArrayList<>();
  2095.                 parametersServletCredenzialeChange.add(pIdCredenziale);
  2096.                 parametersServletCredenzialeChange.addAll(parametersServletSoggettoChange);
  2097.                 parametersServletCredenzialeChange.add(new Parameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_FILE_CERTIFICATO_MULTI_AGGIORNA,Costanti.CHECK_BOX_ENABLED));
  2098.                
  2099.                 //  Principale: si/no
  2100.                 DataElement de = new DataElement();
  2101.                 de.setType(DataElementType.TEXT);
  2102.                 de.setValue(i == 0 ? CostantiControlStation.LABEL_SI : CostantiControlStation.LABEL_NO);
  2103.                 de.allineaTdAlCentro();
  2104.                 de.setWidthPx(60);
  2105.                 e.add(de);
  2106.                
  2107.                 // Subject con link edit
  2108.                 de = new DataElement();
  2109.                 de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_CREDENZIALI_CHANGE,
  2110.                         parametersServletCredenzialeChange.toArray(new Parameter[parametersServletCredenzialeChange.size()]));
  2111.                 de.setSize(ConnettoriCostanti.NUMERO_CARATTERI_SUBJECT_DA_VISUALIZZARE_IN_LISTA_CERTIFICATI);
  2112.                 de.setValue(StringEscapeUtils.escapeHtml(tipoCredenzialiSSLAliasCertificatoSubject));
  2113.                 de.setToolTip(StringEscapeUtils.escapeHtml(tipoCredenzialiSSLAliasCertificatoSubject));
  2114.                 de.setIdToRemove(i+"");
  2115.                 e.add(de);
  2116.                
  2117.                 // Issuer
  2118.                 de = new DataElement();
  2119.                 String issuerValue = StringEscapeUtils.escapeHtml(tipoCredenzialiSSLAliasCertificatoIssuer);
  2120.                 if(issuerValue.length() > ConnettoriCostanti.NUMERO_CARATTERI_SUBJECT_DA_VISUALIZZARE_IN_LISTA_CERTIFICATI) {
  2121.                     issuerValue = issuerValue.substring(0,(ConnettoriCostanti.NUMERO_CARATTERI_SUBJECT_DA_VISUALIZZARE_IN_LISTA_CERTIFICATI-3)) + "...";
  2122.                 }
  2123.                 de.setValue(issuerValue);
  2124.                 de.setToolTip(StringEscapeUtils.escapeHtml(tipoCredenzialiSSLAliasCertificatoIssuer));
  2125.                 e.add(de);
  2126.                
  2127.                 // verifica tutti i campi
  2128.                 de = new DataElement();
  2129.                 de.setType(DataElementType.TEXT);
  2130.                 de.setValue(verificaTuttiCampi ? ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_VERIFICA_TUTTI_CAMPI_ENABLE :
  2131.                     ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_VERIFICA_TUTTI_CAMPI_DISABLE);
  2132.                 de.allineaTdAlCentro();
  2133.                 de.setWidthPx(70);
  2134.                 e.add(de);
  2135.                
  2136.                 // not before
  2137.                 de = new DataElement();
  2138.                 de.setType(DataElementType.TEXT);
  2139.                 if(verificaTuttiCampi) {
  2140.                     de.setValue(tipoCredenzialiSSLAliasCertificatoNotBefore);
  2141.                 }
  2142.                 else {
  2143.                     de.setValue("-");
  2144.                 }
  2145.                 de.allineaTdAlCentro();
  2146.                 de.setWidthPx(140);
  2147.                 if(notBefore.after(new Date())) {
  2148.                     // bold
  2149.                     de.setLabelStyleClass(Costanti.INPUT_TEXT_BOLD_CSS_CLASS);
  2150.                     de.setWidthPx(150);
  2151.                 }
  2152.                 e.add(de);  
  2153.                
  2154.                 // not after
  2155.                 de = new DataElement();
  2156.                 de.setType(DataElementType.TEXT);
  2157.                 if(verificaTuttiCampi) {
  2158.                     de.setValue(tipoCredenzialiSSLAliasCertificatoNotAfter);
  2159.                 }else {
  2160.                     de.setValue("-");
  2161.                 }
  2162.                 de.allineaTdAlCentro();
  2163.                 de.setWidthPx(140);
  2164.                 if(notAfter.before(new Date())) {
  2165.                     // bold e rosso
  2166.                     de.setLabelStyleClass(Costanti.INPUT_TEXT_BOLD_RED_CSS_CLASS);
  2167.                     de.setWidthPx(150);
  2168.                 }
  2169.                 e.add(de);

  2170.                 dati.add(e);
  2171.                 i++;
  2172.             }

  2173.             this.pd.setDati(dati);
  2174.             this.pd.setAddButton(true);
  2175.            
  2176.         } catch (Exception e) {
  2177.             this.logError(e.getMessage(), e);
  2178.             throw new DriverControlStationException(e.getMessage(),e);
  2179.         }
  2180.     }

  2181.     public List<DataElement> addSoggettoHiddenToDati(List<DataElement> dati, String id, String nome, String tipo) throws Exception {
  2182.        
  2183.         DataElement de = new DataElement();
  2184.         de.setLabel(SoggettiCostanti.PARAMETRO_SOGGETTO_ID);
  2185.         de.setValue(id);
  2186.         de.setType(DataElementType.HIDDEN);
  2187.         de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_ID);
  2188.         dati.add(de);
  2189.        
  2190.         if(nome != null) {
  2191.             de = new DataElement();
  2192.             de.setLabel(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME);
  2193.             de.setValue(nome);
  2194.             de.setType(DataElementType.HIDDEN);
  2195.             de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME);
  2196.             dati.add(de);
  2197.         }
  2198.        
  2199.         if(tipo != null) {
  2200.             de = new DataElement();
  2201.             de.setLabel(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO);
  2202.             de.setValue(tipo);
  2203.             de.setType(DataElementType.HIDDEN);
  2204.             de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO);
  2205.             dati.add(de);
  2206.         }
  2207.        
  2208.         return dati;
  2209.     }
  2210.    
  2211.     public boolean soggettiCredenzialiCertificatiCheckData(TipoOperazione tipoOp, String id, Soggetto soggettoOld, int idxCertificato, String protocollo) throws Exception {
  2212.         try {
  2213.             int idInt = 0;
  2214.             if (tipoOp.equals(TipoOperazione.CHANGE)) {
  2215.                 idInt = Integer.parseInt(id);
  2216.             }

  2217.             /**boolean oldPasswordCifrata = false;
  2218.             if(soggettoOld!=null && soggettoOld.sizeCredenzialiList()>0 && soggettoOld.getCredenziali(0).isCertificateStrictVerification()) {
  2219.                 oldPasswordCifrata = true;
  2220.             }
  2221.             boolean encryptEnabled = this.saCore.isSoggettiPasswordEncryptEnabled();
  2222.             if(this.credenzialiCheckData(tipoOp,oldPasswordCifrata, encryptEnabled, this.soggettiCore.getSoggettiPasswordVerifier())==false){
  2223.                 return false;
  2224.             }*/

  2225.             String tipoauth = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_TIPO_AUTENTICAZIONE);
  2226.             if (tipoauth == null) {
  2227.                 tipoauth = ConnettoriCostanti.DEFAULT_AUTENTICAZIONE_TIPO;
  2228.             }
  2229.            
  2230.             String subject = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_SUBJECT);
  2231.             String issuer = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_ISSUER);
  2232.             if("".equals(issuer)) {
  2233.                 issuer = null;
  2234.             }
  2235.            
  2236.             String tipoCredenzialiSSLSorgente = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL);
  2237.             if(tipoCredenzialiSSLSorgente == null) {
  2238.                 tipoCredenzialiSSLSorgente = ConnettoriCostanti.VALUE_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_CONFIGURAZIONE_MANUALE;
  2239.             }
  2240.             String tipoCredenzialiSSLConfigurazioneManualeSelfSigned= this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_MANUALE_SELF_SIGNED);
  2241.             if (tipoCredenzialiSSLConfigurazioneManualeSelfSigned == null) {
  2242.                 tipoCredenzialiSSLConfigurazioneManualeSelfSigned = Costanti.CHECK_BOX_ENABLED;
  2243.             }
  2244.            
  2245.             boolean dominioEsternoModI = false;
  2246.             if(soggettoOld!=null) {
  2247.                 dominioEsternoModI = this.isProfiloModIPA(protocollo) && this.pddCore.isPddEsterna(soggettoOld.getPortaDominio());
  2248.             }
  2249.            
  2250.             String details = "";
  2251.             Soggetto soggettoAutenticato = null;
  2252.             String tipoSsl = null;
  2253.             Certificate cSelezionato = null;
  2254.             boolean strictVerifier = false;
  2255.             List<org.openspcoop2.core.registry.Soggetto> soggettiAutenticati = null;
  2256.             if(tipoCredenzialiSSLSorgente.equals(ConnettoriCostanti.VALUE_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_CONFIGURAZIONE_MANUALE)) {
  2257.        
  2258.                 // recupero soggetto con stesse credenziali
  2259.                 soggettoAutenticato = this.soggettiCore.getSoggettoRegistroAutenticatoSsl(subject, issuer);
  2260.                 tipoSsl = "subject/issuer";
  2261.        
  2262.             } else {
  2263.                
  2264.                 BinaryParameter tipoCredenzialiSSLFileCertificato = this.getBinaryParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_FILE_CERTIFICATO);
  2265.                 String tipoCredenzialiSSLVerificaTuttiICampi = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_VERIFICA_TUTTI_CAMPI);
  2266.                 strictVerifier = ServletUtils.isCheckBoxEnabled(tipoCredenzialiSSLVerificaTuttiICampi);
  2267.                 String tipoCredenzialiSSLTipoArchivioS = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_TIPO_ARCHIVIO);
  2268.                 String tipoCredenzialiSSLFileCertificatoPassword = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_FILE_CERTIFICATO_PASSWORD);
  2269.                 String tipoCredenzialiSSLAliasCertificato = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_ALIAS_CERTIFICATO);
  2270.                 if (tipoCredenzialiSSLAliasCertificato == null) {
  2271.                     tipoCredenzialiSSLAliasCertificato = "";
  2272.                 }
  2273.                 org.openspcoop2.utils.certificate.ArchiveType tipoCredenzialiSSLTipoArchivio= null;
  2274.                 if(tipoCredenzialiSSLTipoArchivioS == null) {
  2275.                     tipoCredenzialiSSLTipoArchivio = org.openspcoop2.utils.certificate.ArchiveType.CER;
  2276.                 } else {
  2277.                     tipoCredenzialiSSLTipoArchivio = org.openspcoop2.utils.certificate.ArchiveType.valueOf(tipoCredenzialiSSLTipoArchivioS);
  2278.                 }
  2279.                 byte [] archivio = tipoCredenzialiSSLFileCertificato.getValue();
  2280.                 if(TipoOperazione.CHANGE.equals(tipoOp) && archivio==null) {
  2281.                     archivio = soggettoOld.getCredenziali(idxCertificato).getCertificate();
  2282.                 }
  2283.                 if(tipoCredenzialiSSLTipoArchivio.equals(org.openspcoop2.utils.certificate.ArchiveType.CER)) {
  2284.                     cSelezionato = ArchiveLoader.load(archivio);
  2285.                 }else {
  2286.                     cSelezionato = ArchiveLoader.load(tipoCredenzialiSSLTipoArchivio, archivio, tipoCredenzialiSSLAliasCertificato, tipoCredenzialiSSLFileCertificatoPassword);
  2287.                 }
  2288.                 /**soggettoAutenticato = this.soggettiCore.getSoggettoRegistroAutenticatoSsl(cSelezionato.getCertificate(), strictVerifier);*/
  2289.                 // Fix: usando il metodo sopra e' permesso caricare due soggetti con lo stesso certificato (anche serial number) uno in strict e uno no, e questo e' sbagliato.
  2290.                 soggettiAutenticati = this.soggettiCore.soggettoWithCredenzialiSslList(cSelezionato.getCertificate(), strictVerifier);
  2291.                 if(soggettiAutenticati!=null && !soggettiAutenticati.isEmpty()) {
  2292.                     soggettoAutenticato = soggettiAutenticati.get(0);
  2293.                     if(!strictVerifier) {
  2294.                         List<org.openspcoop2.core.registry.Soggetto> soggettiAutenticatiCheck = this.soggettiCore.soggettoWithCredenzialiSslList(cSelezionato.getCertificate(), true);
  2295.                         if(soggettiAutenticatiCheck==null || soggettiAutenticatiCheck.isEmpty() ) {
  2296.                             details=ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_DETAILS;
  2297.                         }
  2298.                     }
  2299.                 }
  2300.                 tipoSsl = "certificato";
  2301.             }
  2302.            
  2303.             if(soggettoAutenticato!=null && tipoOp.equals(TipoOperazione.CHANGE) &&
  2304.                 idInt == soggettoAutenticato.getId()){
  2305.                 soggettoAutenticato = null;
  2306.             }

  2307.             // Messaggio di errore
  2308.             if(soggettoAutenticato!=null){
  2309.                 String labelSoggettoAutenticato = this.getLabelNomeSoggetto(new IDSoggetto(soggettoAutenticato.getTipo(), soggettoAutenticato.getNome()));
  2310.                 this.pd.setMessage("Il soggetto "+labelSoggettoAutenticato+" possiede già le credenziali ssl ("+tipoSsl+") indicate."+details);
  2311.                 return false;
  2312.             }
  2313.            
  2314.            
  2315.             if(!this.soggettiCore.isSoggettiApplicativiCredenzialiSslPermitSameCredentials()) {
  2316.                 // Verifico applicativi
  2317.            
  2318.                 details = "";
  2319.                 List<ServizioApplicativo> saList = null;
  2320.                 if(tipoCredenzialiSSLSorgente.equals(ConnettoriCostanti.VALUE_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_CONFIGURAZIONE_MANUALE)) {
  2321.                     saList = this.saCore.servizioApplicativoWithCredenzialiSslList(subject,issuer,
  2322.                             dominioEsternoModI ? ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiModIFirma() : ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiHttps());
  2323.                     tipoSsl = "subject/issuer";
  2324.                 }
  2325.                 else {
  2326.                    
  2327.                     saList = this.saCore.servizioApplicativoWithCredenzialiSslList(cSelezionato.getCertificate(), strictVerifier,
  2328.                             dominioEsternoModI ? ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiModIFirma() : ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiHttps());
  2329.                     if(!strictVerifier && saList!=null && !saList.isEmpty()) {
  2330.                         List<ServizioApplicativo> saListCheck = this.saCore.servizioApplicativoWithCredenzialiSslList(cSelezionato.getCertificate(), true,
  2331.                                 dominioEsternoModI ? ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiModIFirma() : ConfigurazioneFiltroServiziApplicativi.getFiltroApplicativiHttps());
  2332.                         if(saListCheck==null || saListCheck.isEmpty() ) {
  2333.                             details=ConnettoriCostanti.LABEL_PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_DETAILS;
  2334.                         }
  2335.                     }
  2336.                     tipoSsl = "certificato";
  2337.                    
  2338.                 }
  2339.                
  2340.                 if(saList!=null) {
  2341.                     for (int i = 0; i < saList.size(); i++) {
  2342.                         ServizioApplicativo sa = saList.get(i);
  2343.        
  2344.                         boolean tokenWithHttpsEnabledByConfigSA = false;
  2345.                         if(sa.getInvocazionePorta()!=null && sa.getInvocazionePorta().sizeCredenzialiList()>0) {
  2346.                             Credenziali c = sa.getInvocazionePorta().getCredenziali(0);
  2347.                             if(c!=null && c.getTokenPolicy()!=null && StringUtils.isNotEmpty(c.getTokenPolicy())) {
  2348.                                 // se entro in questa servlet sono sicuramente con credenziale ssl, se esiste anche token policy abbiamo la combo
  2349.                                 tokenWithHttpsEnabledByConfigSA = true;
  2350.                             }
  2351.                         }
  2352.                        
  2353.                         if(!tokenWithHttpsEnabledByConfigSA) {  // se e' abilitato il token non deve essere controllata l'univocita' del certificato
  2354.                             // Raccolgo informazioni soggetto
  2355.                             // Messaggio di errore
  2356.                             String labelSoggetto = this.getLabelNomeSoggetto(new IDSoggetto(sa.getTipoSoggettoProprietario(), sa.getNomeSoggettoProprietario()));
  2357.                             this.pd.setMessage("L'applicativo "+sa.getNome()+" (soggetto: "+labelSoggetto+") possiede già le credenziali ssl ("+tipoSsl+") indicate."+details);
  2358.                             return false;  
  2359.                         }
  2360.                        
  2361.                     }
  2362.                 }
  2363.             }
  2364.            
  2365.            
  2366.            
  2367.             // Verifico che non sia già associato al soggetto
  2368.            
  2369.             String actionConfirm = this.getParameter(Costanti.PARAMETRO_ACTION_CONFIRM);
  2370.             boolean promuoviInCorso = false;
  2371.             if(actionConfirm != null && actionConfirm.equals(Costanti.PARAMETRO_ACTION_CONFIRM_VALUE_OK)){
  2372.                 promuoviInCorso = true;
  2373.             }
  2374.            
  2375.             String aggiornatoCertificatoPrecaricatoTmp = this.getParameter(ConnettoriCostanti.PARAMETRO_CREDENZIALI_AUTENTICAZIONE_CONFIGURAZIONE_SSL_FILE_CERTIFICATO_MULTI_AGGIORNA);
  2376.             boolean aggiornatoCertificatoPrecaricato = ServletUtils.isCheckBoxEnabled(aggiornatoCertificatoPrecaricatoTmp);
  2377.            
  2378.             if(!promuoviInCorso && !aggiornatoCertificatoPrecaricato && cSelezionato!=null &&
  2379.                     /**soggettiAutenticati!=null && soggettiAutenticati.size()>0*/
  2380.                     soggettoOld!=null
  2381.                     ) {
  2382.                 // dovrebbe essere 1 grazie al precedente controllo
  2383.                 /**org.openspcoop2.core.registry.Soggetto soggettoCheck = soggettiAutenticati.get(0);*/
  2384.                 org.openspcoop2.core.registry.Soggetto soggettoCheck = soggettoOld;
  2385.                 if(soggettoCheck.sizeCredenzialiList()>0) {
  2386.                     int i = 0;
  2387.                     for (CredenzialiSoggetto c : soggettoCheck.getCredenzialiList()) {
  2388.                         Certificate check = ArchiveLoader.load(c.getCertificate());
  2389.                         if(check.getCertificate().equals(cSelezionato.getCertificate()) && i!=idxCertificato) {
  2390.                             this.pd.setMessage("Il certificato selezionato risulta già associato al soggetto");
  2391.                             return false;
  2392.                         }
  2393.                         i++;
  2394.                     }
  2395.                 }
  2396.             }
  2397.            
  2398.             return true;
  2399.         } catch (Exception e) {
  2400.             this.logError(e.getMessage(), e);
  2401.             throw new DriverControlStationException(e.getMessage(),e);
  2402.         }
  2403.     }
  2404.     public void prepareSoggettiProprietaList(Soggetto soggettoRegistry, String id, ConsoleSearch ricerca,   List<Proprieta> lista) throws DriverControlStationException {
  2405.         try {
  2406.             List<Parameter> parametersServletSoggettoChange = new ArrayList<>();
  2407.             Parameter pIdSoggetto = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID, id);
  2408.             Parameter pNomeSoggetto = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME, soggettoRegistry.getNome());
  2409.             Parameter pTipoSoggetto = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO, soggettoRegistry.getTipo());
  2410.             parametersServletSoggettoChange.add(pIdSoggetto);
  2411.             parametersServletSoggettoChange.add(pNomeSoggetto);
  2412.             parametersServletSoggettoChange.add(pTipoSoggetto);
  2413.            
  2414.             ServletUtils.addListElementIntoSession(this.request, this.session, SoggettiCostanti.OBJECT_NAME_SOGGETTI_PROPRIETA, parametersServletSoggettoChange.toArray(new Parameter[parametersServletSoggettoChange.size()]));

  2415.             // setto la barra del titolo
  2416.             String protocollo = this.soggettiCore.getProtocolloAssociatoTipoSoggetto(soggettoRegistry.getTipo());
  2417.            
  2418.             int idLista = Liste.SOGGETTI_PROP;
  2419.             int limit = ricerca.getPageSize(idLista);
  2420.             int offset = ricerca.getIndexIniziale(idLista);
  2421.             String search = ServletUtils.getSearchFromSession(ricerca, idLista);

  2422.             this.pd.setIndex(offset);
  2423.             this.pd.setPageSize(limit);
  2424.             this.pd.setNumEntries(ricerca.getNumEntries(idLista));
  2425.            
  2426.             // setto la barra del titolo
  2427.             List<Parameter> lstParam = new ArrayList<>();
  2428.             lstParam.add(new Parameter(SoggettiCostanti.LABEL_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST));
  2429.             lstParam.add(new Parameter(this.getLabelNomeSoggetto(protocollo, soggettoRegistry.getTipo() , soggettoRegistry.getNome()),
  2430.                     SoggettiCostanti.SERVLET_NAME_SOGGETTI_CHANGE, parametersServletSoggettoChange.toArray(new Parameter[parametersServletSoggettoChange.size()])));

  2431.             this.pd.setSearchLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROP_NOME);
  2432.             if(search.equals("")){
  2433.                 this.pd.setSearchDescription("");
  2434.                 lstParam.add(new Parameter(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROPRIETA, null));
  2435.             }else{
  2436.                 lstParam.add(new Parameter(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROPRIETA,
  2437.                         SoggettiCostanti.SERVLET_NAME_SOGGETTI_PROPRIETA_LIST, parametersServletSoggettoChange.toArray(new Parameter[parametersServletSoggettoChange.size()])));
  2438.                 lstParam.add(new Parameter(SoggettiCostanti.LABEL_SOGGETTI_RISULTATI_RICERCA, null));
  2439.             }

  2440.             // setto la barra del titolo
  2441.             ServletUtils.setPageDataTitle(this.pd, lstParam.toArray(new Parameter[lstParam.size()]));

  2442.             // controllo eventuali risultati ricerca
  2443.             if (!search.equals("")) {
  2444.                 ServletUtils.enabledPageDataSearch(this.pd, SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROPRIETA, search);
  2445.             }

  2446.             // setto le label delle colonne
  2447.             String valueLabel = SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROP_VALORE;
  2448.             String[] labels = { SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROP_NOME, valueLabel };
  2449.             this.pd.setLabels(labels);

  2450.             // preparo i dati
  2451.             List<List<DataElement>> dati = new ArrayList<>();

  2452.             if (lista != null) {
  2453.                 Iterator<Proprieta> it = lista.iterator();
  2454.                 while (it.hasNext()) {
  2455.                     Proprieta ssp = it.next();

  2456.                     List<DataElement> e = new ArrayList<>();

  2457.                     Parameter pNomeProprieta = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTI_PROP_NOME, ssp.getNome());
  2458.                     List<Parameter> parametersServletProprietaChange = new ArrayList<>();
  2459.                     parametersServletProprietaChange.add(pNomeProprieta);
  2460.                     parametersServletProprietaChange.addAll(parametersServletSoggettoChange);
  2461.                
  2462.                     DataElement de = new DataElement();
  2463.                     de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_PROPRIETA_CHANGE,
  2464.                             parametersServletProprietaChange.toArray(new Parameter[parametersServletProprietaChange.size()]));
  2465.                     de.setValue(ssp.getNome());
  2466.                     de.setIdToRemove(ssp.getNome());
  2467.                     e.add(de);

  2468.                     de = new DataElement();
  2469.                     if(ssp.getValore()!=null) {
  2470.                         if(StringUtils.isNotEmpty(ssp.getValore()) &&
  2471.                                 BYOKManager.isEnabledBYOK() &&
  2472.                                 this.core.getDriverBYOKUtilities().isWrappedWithAnyPolicy(ssp.getValore())) {
  2473.                             de.setValue(CostantiControlStation.VALORE_CIFRATO);
  2474.                         }
  2475.                         else {
  2476.                             de.setValue(ssp.getValore());
  2477.                         }
  2478.                     }
  2479.                     e.add(de);

  2480.                     dati.add(e);
  2481.                 }
  2482.             }

  2483.             this.pd.setDati(dati);
  2484.             this.pd.setAddButton(true);

  2485.         } catch (Exception e) {
  2486.             this.logError(e.getMessage(), e);
  2487.             throw new DriverControlStationException(e.getMessage(),e);
  2488.         }
  2489.        
  2490.     }
  2491.    
  2492.     public  List<DataElement> addProprietaToDati(TipoOperazione tipoOp, int size, String nome, String valore, List<DataElement> dati) {

  2493.         DataElement de = new DataElement();
  2494.         de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROPRIETA);
  2495.         de.setType(DataElementType.TITLE);
  2496.         dati.add(de);
  2497.        
  2498.         de = new DataElement();
  2499.         de.setLabel(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROP_NOME);
  2500.         de.setValue(nome);
  2501.         if(TipoOperazione.ADD.equals(tipoOp)){
  2502.             de.setType(DataElementType.TEXT_EDIT);
  2503.             de.setRequired(true);
  2504.         }
  2505.         else{
  2506.             de.setType(DataElementType.TEXT);
  2507.         }
  2508.         de.setName(SoggettiCostanti.PARAMETRO_SOGGETTI_PROP_NOME);
  2509.         de.setSize(size);
  2510.         dati.add(de);

  2511.         de = new DataElement();
  2512.         de.setLabel(CostantiControlStation.LABEL_PARAMETRO_VALORE);
  2513.         de.setName(SoggettiCostanti.PARAMETRO_SOGGETTI_PROP_VALORE);
  2514.         this.core.getLockUtilities().lockProperty(de, valore);
  2515.         de.setRequired(true);
  2516.         de.setSize(size);
  2517.         dati.add(de);

  2518.         return dati;
  2519.     }
  2520.    
  2521.     public boolean soggettiProprietaCheckData(TipoOperazione tipoOp) throws DriverControlStationException {
  2522.         try {
  2523.             String id = this.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID);
  2524.             int idSogg = Integer.parseInt(id);
  2525.             String nome = this.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTI_PROP_NOME);
  2526.             String valore = this.getLockedParameter(SoggettiCostanti.PARAMETRO_SOGGETTI_PROP_VALORE, false);

  2527.             // Campi obbligatori
  2528.             if (nome.equals("") || valore.equals("")) {
  2529.                 String tmpElenco = "";
  2530.                 if (nome.equals("")) {
  2531.                     tmpElenco = SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROP_NOME;
  2532.                 }
  2533.                 if (valore.equals("")) {
  2534.                     if (tmpElenco.equals("")) {
  2535.                         tmpElenco = SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROP_VALORE;
  2536.                     } else {
  2537.                         tmpElenco = tmpElenco + ", " + SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROP_VALORE;
  2538.                     }
  2539.                 }
  2540.                 this.pd.setMessage(MessageFormat.format(SoggettiCostanti.MESSAGGIO_ERRORE_DATI_INCOMPLETI_E_NECESSARIO_INDICARE_XX, tmpElenco));
  2541.                 return false;
  2542.             }

  2543.            
  2544.             if (nome.indexOf(" ") != -1) {
  2545.                 this.pd.setMessage(CostantiControlStation.MESSAGGIO_ERRORE_NON_INSERIRE_SPAZI_NEI_CAMPI_DI_TESTO);
  2546.                 return false;
  2547.             }
  2548.             if(!this.checkLength255(nome, SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROP_NOME)) {
  2549.                 return false;
  2550.             }
  2551.            
  2552.             if( !this.core.getDriverBYOKUtilities().isEnabledBYOK() || !this.core.getDriverBYOKUtilities().isWrappedWithAnyPolicy(valore) ){
  2553.                 if (valore.indexOf(" ") != -1) {
  2554.                     this.pd.setMessage(CostantiControlStation.MESSAGGIO_ERRORE_NON_INSERIRE_SPAZI_NEI_CAMPI_DI_TESTO);
  2555.                     return false;
  2556.                 }
  2557.                 if(!this.checkLength4000(valore, SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROP_VALORE)) {
  2558.                     return false;
  2559.                 }
  2560.             }

  2561.             // Se tipoOp = add, controllo che la property non sia gia'
  2562.             // stata
  2563.             // registrata per l'applicativo
  2564.             if (tipoOp.equals(TipoOperazione.ADD)) {
  2565.                 boolean giaRegistrato = false;
  2566.                
  2567.                 Soggetto soggettoRegistry = this.soggettiCore.getSoggettoRegistro(idSogg);
  2568.                 String protocollo = this.soggettiCore.getProtocolloAssociatoTipoSoggetto(soggettoRegistry.getTipo());
  2569.                 String nomeporta = this.getLabelNomeSoggetto(protocollo, soggettoRegistry.getTipo() , soggettoRegistry.getNome());

  2570.                 for (int i = 0; i < soggettoRegistry.sizeProprietaList(); i++) {
  2571.                     Proprieta tmpProp = soggettoRegistry.getProprieta(i);
  2572.                     if (nome.equals(tmpProp.getNome())) {
  2573.                         giaRegistrato = true;
  2574.                         break;
  2575.                     }
  2576.                 }

  2577.                 if (giaRegistrato) {
  2578.                     this.pd.setMessage(MessageFormat.format(
  2579.                             SoggettiCostanti.MESSAGGIO_ERRORE_LA_PROPRIETA_XX_E_GIA_STATO_ASSOCIATA_AL_SA_YY, nome,
  2580.                             nomeporta));
  2581.                     return false;
  2582.                 }
  2583.             }

  2584.             return true;
  2585.         } catch (Exception e) {
  2586.             this.logError(e.getMessage(), e);
  2587.             throw new DriverControlStationException(e.getMessage(),e);
  2588.         }
  2589.     }

  2590. }