UtentiHelper.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.utenti;

  21. import java.text.MessageFormat;
  22. import java.util.ArrayList;
  23. import java.util.Arrays;
  24. import java.util.Calendar;
  25. import java.util.Collections;
  26. import java.util.Comparator;
  27. import java.util.Date;
  28. import java.util.HashMap;
  29. import java.util.Iterator;
  30. import java.util.List;
  31. import java.util.Map;

  32. import javax.servlet.http.HttpServletRequest;
  33. import javax.servlet.http.HttpSession;

  34. import org.apache.commons.lang.StringUtils;
  35. import org.openspcoop2.core.commons.ISearch;
  36. import org.openspcoop2.core.commons.Liste;
  37. import org.openspcoop2.core.id.IDServizio;
  38. import org.openspcoop2.core.id.IDSoggetto;
  39. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  40. import org.openspcoop2.protocol.engine.utils.NamingUtils;
  41. import org.openspcoop2.protocol.utils.ProtocolUtils;
  42. import org.openspcoop2.utils.crypt.PasswordGenerator;
  43. import org.openspcoop2.utils.crypt.PasswordVerifier;
  44. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  45. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  46. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  47. import org.openspcoop2.web.ctrlstat.servlet.ConsoleHelper;
  48. import org.openspcoop2.web.ctrlstat.servlet.login.LoginCostanti;
  49. import org.openspcoop2.web.lib.mvc.CheckboxStatusType;
  50. import org.openspcoop2.web.lib.mvc.Costanti;
  51. import org.openspcoop2.web.lib.mvc.DataElement;
  52. import org.openspcoop2.web.lib.mvc.DataElementType;
  53. import org.openspcoop2.web.lib.mvc.PageData;
  54. import org.openspcoop2.web.lib.mvc.Parameter;
  55. import org.openspcoop2.web.lib.mvc.ServletUtils;
  56. import org.openspcoop2.web.lib.mvc.TipoOperazione;
  57. import org.openspcoop2.web.lib.users.DriverUsersDBException;
  58. import org.openspcoop2.web.lib.users.dao.InterfaceType;
  59. import org.openspcoop2.web.lib.users.dao.Permessi;
  60. import org.openspcoop2.web.lib.users.dao.PermessiUtente;
  61. import org.openspcoop2.web.lib.users.dao.User;
  62. import org.openspcoop2.web.lib.users.dao.UserPassword;

  63. /**
  64.  * UtentiHelper
  65.  *
  66.  * @author Poli Andrea (apoli@link.it)
  67.  * @author $Author$
  68.  * @version $Rev$, $Date$
  69.  */
  70. public class UtentiHelper extends ConsoleHelper {

  71.     public UtentiHelper(HttpServletRequest request, PageData pd,
  72.             HttpSession session) throws Exception {
  73.         super(request, pd, session);
  74.     }
  75.     public UtentiHelper(ControlStationCore core, HttpServletRequest request, PageData pd,
  76.             HttpSession session) throws Exception {
  77.         super(core, request, pd, session);
  78.     }

  79.     private boolean hasOnlyPermessiUtenti(String isServizi,String isDiagnostica,String isReportistica,String isSistema,String isMessaggi,
  80.             String isUtenti,String isAuditing, String isAccordiCooperazione,boolean singlePdD) {
  81.         return (
  82.                 (
  83.                         (isServizi == null)
  84.                         ||
  85.                         !ServletUtils.isCheckBoxEnabled(isServizi)
  86.                 ) &&
  87.                 (
  88.                         !singlePdD
  89.                         ||
  90.                         (
  91.                                 //singlePdD
  92.                                 //&&
  93.                                 (
  94.                                         (isDiagnostica == null) || !ServletUtils.isCheckBoxEnabled(isDiagnostica)
  95.                                 )
  96.                                 &&
  97.                                 (
  98.                                         (isReportistica == null) || !ServletUtils.isCheckBoxEnabled(isReportistica)
  99.                                 )
  100.                         )
  101.                 ) &&
  102.                 ((isSistema == null) || !ServletUtils.isCheckBoxEnabled(isSistema)) &&
  103.                 ((isMessaggi == null) || !ServletUtils.isCheckBoxEnabled(isMessaggi)) &&
  104.                 ((isUtenti != null) || ServletUtils.isCheckBoxEnabled(isUtenti)) &&
  105.                 ((isAuditing == null) || !ServletUtils.isCheckBoxEnabled(isAuditing)) &&
  106.                 ((isAccordiCooperazione == null) || !ServletUtils.isCheckBoxEnabled(isAccordiCooperazione)));
  107.     }
  108.    
  109.     @SuppressWarnings("unused")
  110.     private String getLabelSezionePddMonitorSoggettiServizi(boolean isDiagnosticaEnabled, boolean isReportisticaEnabled) {
  111.        
  112.         if(isDiagnosticaEnabled && isReportisticaEnabled) {
  113.             return UtentiCostanti.LABEL_CONFIGURAZIONE_PDD_MONITOR_MONITORAGGIO_REPORTISTICA;
  114.         }
  115.         else if(isDiagnosticaEnabled) {
  116.             return UtentiCostanti.LABEL_CONFIGURAZIONE_PDD_MONITOR_MONITORAGGIO;
  117.         }
  118.         else {
  119.             return UtentiCostanti.LABEL_CONFIGURAZIONE_PDD_MONITOR_REPORTISTICA;
  120.         }

  121.     }
  122.    
  123.     public List<DataElement> addUtentiToDati(List<DataElement> dati,TipoOperazione tipoOperazione,boolean singlePdD,
  124.             String nomesu,String pwsu,String confpwsu,InterfaceType interfaceType,
  125.             String isServizi,String isDiagnostica,String isReportistica,String isSistema,String isMessaggi,String isUtenti,String isAuditing, String isAccordiCooperazione,
  126.             String changepwd, String [] modalitaGateway,
  127.             String isSoggettiAll, String isServiziAll, User oldImgUser, String scadenza, Date dataUltimoAggiornamentoPassword , boolean oldScadenza,
  128.             String profiloDefaultConsoleGestione, String soggettoDefaultConsoleGestione,
  129.             String profiloDefaultConsoleMonitoraggio, String soggettoDefaultConsoleMonitoraggio, String homePageMonitoraggio, String intervalloTemporaleReportStatistico) throws Exception{

  130.         Boolean contaListe = ServletUtils.getContaListeFromSession(this.session);
  131.        
  132.         boolean onlyUser = ServletUtils.isCheckBoxEnabled(isUtenti) &&
  133.                 !ServletUtils.isCheckBoxEnabled(isServizi) &&
  134.                 !ServletUtils.isCheckBoxEnabled(isAccordiCooperazione) &&
  135.                 !ServletUtils.isCheckBoxEnabled(isDiagnostica) &&
  136.                 !ServletUtils.isCheckBoxEnabled(isReportistica) &&
  137.                 !ServletUtils.isCheckBoxEnabled(isSistema) &&
  138.                 !ServletUtils.isCheckBoxEnabled(isMessaggi) &&
  139.                 !ServletUtils.isCheckBoxEnabled(isAuditing);
  140.        
  141.         DataElement de = new DataElement();
  142.         de.setLabel(UtentiCostanti.LABEL_INFORMAZIONI_UTENTE);
  143.         de.setType(DataElementType.TITLE);
  144.         dati.add(de);

  145.         de = new DataElement();
  146.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_USERNAME);
  147.         de.setValue(nomesu);
  148.         if(TipoOperazione.ADD.equals(tipoOperazione)){
  149.             de.setType(DataElementType.TEXT_EDIT);
  150.             de.setRequired(true);
  151.         }
  152.         else{
  153.             de.setType(DataElementType.TEXT);
  154.         }
  155.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_USERNAME);
  156.         de.setSize(this.getSize());
  157.         dati.add(de);
  158.        
  159.        
  160.         de = new DataElement();
  161.         de.setLabel(UtentiCostanti.LABEL_PERMESSI_GESTIONE);
  162.         de.setType(DataElementType.TITLE);
  163.         dati.add(de);
  164.        
  165.         de = new DataElement();
  166.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_REGISTRO_SUBSECTION);
  167.         de.setType(DataElementType.SUBTITLE);
  168.         dati.add(de);

  169.         de = new DataElement();
  170.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_SERVIZI);
  171.         de.setType(DataElementType.CHECKBOX);
  172.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_SERVIZI);
  173.         ServletUtils.setCheckBox(de, isServizi);
  174.         de.setPostBack(true);
  175.         dati.add(de);
  176.        
  177.         de = new DataElement();
  178.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_ACCORDI_COOPERAZIONE);
  179.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_ACCORDI_COOPERAZIONE);
  180.         if(this.utentiCore.isAccordiCooperazioneEnabled()) {
  181.             de.setType(DataElementType.CHECKBOX);
  182.             de.setPostBack(true);
  183.         }
  184.         else {
  185.             de.setType(DataElementType.HIDDEN);
  186.         }
  187.         ServletUtils.setCheckBox(de, isAccordiCooperazione);
  188.         de.setValue(de.getSelected());
  189.         dati.add(de);
  190.            
  191.         if(singlePdD) {
  192.             de = new DataElement();
  193.             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_GOVWAY_MONITOR_SUBSECTION);
  194.             de.setType(DataElementType.SUBTITLE);
  195.             dati.add(de);
  196.         }
  197.        
  198.         de = new DataElement();
  199.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_DIAGNOSTICA);
  200.         if (singlePdD) {
  201.             de.setType(DataElementType.CHECKBOX);
  202.             ServletUtils.setCheckBox(de, isDiagnostica);
  203.         } else {
  204.             de.setType(DataElementType.HIDDEN);
  205.             de.setValue("");
  206.         }
  207.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_DIAGNOSTICA);
  208.         de.setPostBack(true);
  209.         dati.add(de);
  210.        
  211.         de = new DataElement();
  212.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_REPORTISTICA);
  213.         if (singlePdD) {
  214.             de.setType(DataElementType.CHECKBOX);
  215.             ServletUtils.setCheckBox(de, isReportistica);
  216.         } else {
  217.             de.setType(DataElementType.HIDDEN);
  218.             de.setValue("");
  219.         }
  220.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_REPORTISTICA);
  221.         de.setPostBack(true);
  222.         dati.add(de);
  223.        
  224.         de = new DataElement();
  225.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_STRUMENTI_SUBSECTION);
  226.         de.setType(DataElementType.SUBTITLE);
  227.         dati.add(de);

  228.         de = new DataElement();
  229.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_MESSAGGI);
  230.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_MESSAGGI);
  231.         if(this.utentiCore.showCodaMessage()) {
  232.             de.setType(DataElementType.CHECKBOX);
  233.             de.setPostBack(true);
  234.         }
  235.         else {
  236.             de.setType(DataElementType.HIDDEN);
  237.         }
  238.         ServletUtils.setCheckBox(de, isMessaggi);
  239.         de.setValue(de.getSelected());
  240.         dati.add(de);
  241.        
  242.         de = new DataElement();
  243.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_AUDITING);
  244.         de.setType(DataElementType.CHECKBOX);
  245.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_AUDITING);
  246.         ServletUtils.setCheckBox(de, isAuditing);
  247.         de.setPostBack(true);
  248.         dati.add(de);
  249.        
  250.         de = new DataElement();
  251.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_CONFIGURAZIONE_SUBSECTION);
  252.         de.setType(DataElementType.SUBTITLE);
  253.         dati.add(de);
  254.        
  255.         de = new DataElement();
  256.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_SISTEMA);
  257.         de.setType(DataElementType.CHECKBOX);
  258.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_SISTEMA);
  259.         ServletUtils.setCheckBox(de, isSistema);
  260.         de.setPostBack(true);
  261.         dati.add(de);

  262.         de = new DataElement();
  263.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_UTENTI);
  264.         de.setType(DataElementType.CHECKBOX);
  265.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_UTENTI);
  266.         ServletUtils.setCheckBox(de, isUtenti);
  267.         de.setPostBack(true);
  268.         dati.add(de);
  269.    
  270.        
  271.        
  272.         if(!onlyUser) {
  273.             de = new DataElement();
  274.             de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_DI_HTML_ESCAPE);
  275.             de.setType(DataElementType.TITLE);
  276.             dati.add(de);
  277.            
  278.             List<String> protocolliRegistratiConsole = this.core.getProtocolli();
  279.             for (int i = 0; i < protocolliRegistratiConsole.size() ; i++) {
  280.                 String protocolloName = protocolliRegistratiConsole.get(i);
  281.                 de = new DataElement();
  282.                 de.setLabel(this.getLabelProtocollo(protocolloName));
  283.                 de.setType(DataElementType.CHECKBOX);
  284.                 de.setName(UtentiCostanti.PARAMETRO_UTENTI_MODALITA_PREFIX + protocolloName);
  285.                 ServletUtils.setCheckBox(de, modalitaGateway[i]);
  286.                 de.setPostBack(true);
  287.                 dati.add(de);
  288.             }
  289.         }

  290.        

  291.         // Abilitazioni

  292.         boolean isDiagnosticaEnabled = ServletUtils.isCheckBoxEnabled(isDiagnostica);
  293.         boolean isReportisticaEnabled = ServletUtils.isCheckBoxEnabled(isReportistica);
  294.        
  295.         if(isDiagnosticaEnabled || isReportisticaEnabled) {
  296.        
  297.             de = new DataElement();
  298.             de.setLabel(UtentiCostanti.LABEL_VISIBILITA_DATI_GOVWAY_MONITOR);
  299.             de.setType(DataElementType.TITLE);
  300.             dati.add(de);  
  301.            

  302.             if(this.utentiCore.isMultitenant()) {
  303.                
  304.                 de = new DataElement();
  305.                 de.setLabel(UtentiCostanti.LABEL_UTENTI_SOGGETTI);
  306.                 de.setType(DataElementType.SUBTITLE);
  307.                 dati.add(de);
  308.                
  309. //              if(TipoOperazione.CHANGE.equals(tipoOperazione)) {
  310. //                  String valueSoggetti = getLabelSezionePddMonitorSoggettiServizi(isDiagnosticaEnabled, isReportisticaEnabled) +
  311. //                          UtentiCostanti.LABEL_SUFFIX_RESTRIZIONE_SOGGETTI;
  312. //                  de = new DataElement();
  313. //                  de.setType(DataElementType.NOTE);
  314. //                  de.setValue(valueSoggetti);
  315. //                  dati.add(de);
  316. //              }
  317.                
  318.                 de = new DataElement();
  319.                 de.setType(DataElementType.CHECKBOX);
  320.                 de.setLabel(UtentiCostanti.LABEL_ABILITAZIONI_PUNTUALI_SOGGETTI_TUTTI);
  321.                 de.setName(UtentiCostanti.PARAMETRO_UTENTI_ABILITAZIONI_SOGGETTI_ALL);
  322.                 de.setSelected(ServletUtils.isCheckBoxEnabled(isSoggettiAll));
  323.                 de.setPostBack(true);
  324.                 dati.add(de);
  325.                
  326.                 if(  TipoOperazione.CHANGE.equals(tipoOperazione) && oldImgUser.isPermitAllSoggetti()==false && !ServletUtils.isCheckBoxEnabled(isSoggettiAll)) {
  327.                    
  328.                     de = new DataElement();
  329.                     de.setType(DataElementType.LINK);
  330.                     de.setUrl(UtentiCostanti.SERVLET_NAME_UTENTI_SOGGETTI_LIST, new Parameter(UtentiCostanti.PARAMETRO_UTENTI_USERNAME, nomesu));
  331.                     String nomeLink = UtentiCostanti.LABEL_UTENTI_SOGGETTI;
  332.                     if(contaListe){
  333.                         ConsoleSearch searchForCount = new ConsoleSearch(true,1);
  334.                         this.utentiCore.utentiSoggettiList(nomesu, searchForCount);
  335.                         int num = searchForCount.getNumEntries(Liste.UTENTI_SOGGETTI);
  336.                         ServletUtils.setDataElementCustomLabel(de, nomeLink, (long) num);
  337.                     }else {
  338.                         de.setValue(nomeLink);
  339.                     }
  340.                     dati.add(de);
  341.            
  342.                 }
  343.             }
  344.             else {
  345.                
  346.                 de = new DataElement();
  347.                 de.setType(DataElementType.HIDDEN);
  348.                 de.setName(UtentiCostanti.PARAMETRO_UTENTI_ABILITAZIONI_SOGGETTI_ALL);
  349.                 de.setValue(isSoggettiAll);
  350.                 dati.add(de);
  351.                
  352.             }
  353.            
  354.                
  355.             de = new DataElement();
  356.             de.setLabel(UtentiCostanti.LABEL_UTENTI_SERVIZI);
  357.             de.setType(DataElementType.SUBTITLE);
  358.             dati.add(de);
  359.            
  360. //          if(TipoOperazione.CHANGE.equals(tipoOperazione)) {
  361. //              String valueServizi = getLabelSezionePddMonitorSoggettiServizi(isDiagnosticaEnabled, isReportisticaEnabled)+
  362. //                      UtentiCostanti.LABEL_SUFFIX_RESTRIZIONE_API;
  363. //              de = new DataElement();
  364. //              de.setType(DataElementType.NOTE);
  365. //              de.setValue(valueServizi);
  366. //              dati.add(de);
  367. //          }
  368.            
  369.             de = new DataElement();
  370.             de.setType(DataElementType.CHECKBOX);
  371.             de.setLabel(UtentiCostanti.LABEL_ABILITAZIONI_PUNTUALI_SERVIZI_TUTTI);
  372.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_ABILITAZIONI_SERVIZI_ALL);
  373.             de.setSelected(ServletUtils.isCheckBoxEnabled(isServiziAll));
  374.             de.setPostBack(true);
  375.             dati.add(de);
  376.            
  377.             if((TipoOperazione.CHANGE.equals(tipoOperazione) && oldImgUser.isPermitAllServizi()==false && !ServletUtils.isCheckBoxEnabled(isServiziAll))) {
  378.                
  379.                 de = new DataElement();
  380.                 de.setType(DataElementType.LINK);
  381.                 de.setUrl(UtentiCostanti.SERVLET_NAME_UTENTI_SERVIZI_LIST, new Parameter(UtentiCostanti.PARAMETRO_UTENTI_USERNAME, nomesu));
  382.                 String nomeLink = UtentiCostanti.LABEL_UTENTI_SERVIZI;
  383.                 if(contaListe){
  384.                     ConsoleSearch searchForCount = new ConsoleSearch(true,1);
  385.                     this.utentiCore.utentiServiziList(nomesu, searchForCount);
  386.                     int num = searchForCount.getNumEntries(Liste.UTENTI_SERVIZI);
  387.                     ServletUtils.setDataElementCustomLabel(de, nomeLink, (long) num);
  388.                 }else {
  389.                     de.setValue(nomeLink);
  390.                 }
  391.                 dati.add(de);
  392.                
  393.             }
  394.            
  395.         }
  396.        
  397.        
  398.         boolean utenteConsoleEnabled =
  399.                 ServletUtils.isCheckBoxEnabled(isServizi) ||
  400.                 ServletUtils.isCheckBoxEnabled(isMessaggi) ||
  401.                 ServletUtils.isCheckBoxEnabled(isAuditing) ||
  402.                 ServletUtils.isCheckBoxEnabled(isSistema) ||
  403.                 ServletUtils.isCheckBoxEnabled(isUtenti) ||            
  404.                 ServletUtils.isCheckBoxEnabled(isAccordiCooperazione);
  405.        
  406.         boolean utenteMonitorEnabled = isDiagnosticaEnabled || isReportisticaEnabled;
  407.        
  408.         if(utenteConsoleEnabled || utenteMonitorEnabled) {
  409.        
  410.             de = new DataElement();
  411.             de.setLabel(UtentiCostanti.LABEL_PROFILO_UTENTE);
  412.             de.setType(DataElementType.TITLE);
  413.             dati.add(de);
  414.            
  415.             // se ho selezionato almento un procollo mostro la selezione del protocollo per il profilo utente
  416.             boolean protocolloSelezionato = false;
  417.            
  418.             for (String modalitaI : modalitaGateway) {
  419.                 if(ServletUtils.isCheckBoxEnabled(modalitaI)) {
  420.                     protocolloSelezionato = true;
  421.                     break;
  422.                 }
  423.             }
  424.    
  425.             if(utenteConsoleEnabled) {
  426.            
  427.                 de = new DataElement();
  428.                 de.setLabel(UtentiCostanti.LABEL_PROFILO_UTENTE_CONSOLE_GESTIONE);
  429.                 de.setType(DataElementType.SUBTITLE);
  430.                 dati.add(de);
  431.                
  432.                 de = new DataElement();
  433.                 de.setLabel(UtentiCostanti.LABEL_MODALITA_INTERFACCIA);
  434.                 de.setName(UtentiCostanti.PARAMETRO_UTENTI_TIPO_GUI);
  435.                 boolean permitInterfaceComplete = false;
  436.                 boolean showSelectTipoInterfaccia = true;
  437.                 if(TipoOperazione.CHANGE.equals(tipoOperazione)) {
  438.                     User user = this.utentiCore.getUser(nomesu);
  439.                     permitInterfaceComplete = user.isPermitInterfaceComplete();
  440.                     showSelectTipoInterfaccia = !interfaceType.equals(InterfaceType.COMPLETA);
  441.                 }
  442.                
  443.                 if(showSelectTipoInterfaccia) {
  444.                     de.setType(DataElementType.SELECT);
  445.                     String[] tipiInterfacce=null;
  446.                     String[] tipiInterfacceLabel=null;
  447.                     if(permitInterfaceComplete) {
  448.                         tipiInterfacce = new String[3];        
  449.                     }
  450.                     else {
  451.                         tipiInterfacce = new String[2];
  452.                     }
  453.                     tipiInterfacce[0]=InterfaceType.STANDARD.toString();
  454.                     tipiInterfacce[1]=InterfaceType.AVANZATA.toString();
  455.                     if(permitInterfaceComplete) {
  456.                         tipiInterfacce[2]=InterfaceType.COMPLETA.toString();
  457.                     }
  458.                     tipiInterfacceLabel = new String[tipiInterfacce.length];
  459.                     for (int i = 0; i < tipiInterfacce.length; i++) {
  460.                         tipiInterfacceLabel[i] = tipiInterfacce[i].toLowerCase();
  461.                     }
  462.                     de.setValues(tipiInterfacce);
  463.                     de.setLabels(tipiInterfacceLabel);
  464.                     de.setSelected(interfaceType.toString());
  465.                     dati.add(de);
  466.                 } else {
  467.                     de.setType(DataElementType.HIDDEN);
  468.                     de.setValue(interfaceType.toString());
  469.                     dati.add(de);
  470.                    
  471.                     de = new DataElement();
  472.                     de.setLabel(UtentiCostanti.LABEL_MODALITA_INTERFACCIA);
  473.                     de.setName(UtentiCostanti.PARAMETRO_UTENTI_TIPO_GUI+ "_text");
  474.                     de.setType(DataElementType.TEXT);
  475.                     de.setValue(interfaceType.toString().toLowerCase());
  476.                     dati.add(de);
  477.                 }
  478.                
  479.                 if(!onlyUser) { // selezione di modalita' e soggetto solo se non ho selezionato solo la gestione utenti.
  480.                     if(protocolloSelezionato) {
  481.                         // select list Profilo Interoperabilità
  482.                         List<String> protocolliRegistratiConsole = this.core.getProtocolli();
  483.                        
  484.                         List<String> profiloValues = new ArrayList<>();
  485.                         List<String> profiloLabels = new ArrayList<>();
  486.                         for (int i = 0; i < protocolliRegistratiConsole.size() ; i++) {
  487.                             String protocolloName = protocolliRegistratiConsole.get(i);
  488.                             if(ServletUtils.isCheckBoxEnabled(modalitaGateway[i])) {
  489.                                 profiloValues.add(protocolloName);
  490.                                 String labelProt = ConsoleHelper._getLabelProtocollo(protocolloName);
  491.                                 profiloLabels.add(labelProt);
  492.                             }
  493.                         }
  494.                        
  495.                         if(profiloValues.size() > 1) { // select
  496.                             de = new DataElement();
  497.                             de.setType(DataElementType.SELECT);    
  498.                             de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  499.                            
  500.                             profiloLabels.add(0, UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL);
  501.                             profiloValues.add(0,UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL);
  502.                             de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA);
  503.                             de.setValues(profiloValues);
  504.                             de.setLabels(profiloLabels);
  505.                            
  506.                             de.setSelected(profiloDefaultConsoleGestione);
  507.                             de.setPostBack(true);
  508.                             dati.add(de);
  509.                            
  510.                         } else { // text
  511.                             de = new DataElement();
  512.                             de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  513.                             de.setType(DataElementType.HIDDEN);        
  514.                             de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA);
  515.                             de.setValue(profiloDefaultConsoleGestione);
  516.                             dati.add(de);
  517.                            
  518.                             de = new DataElement();
  519.                             de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  520.                             de.setType(DataElementType.TEXT);          
  521.                             de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA+ "_txt");
  522.                            
  523.                             String protocolloName = profiloValues.get(0);
  524.                             String labelProt = ConsoleHelper._getLabelProtocollo(protocolloName);
  525.                             de.setValue(labelProt);
  526.             //              de.setValue(profiloDefaultUtente.equals(UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL) ? UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL : profiloDefaultUtente);
  527.                             dati.add(de);
  528.                         }
  529.                        
  530.                         // select list soggetti
  531.                         if((profiloDefaultConsoleGestione!=null && !UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL.equals(profiloDefaultConsoleGestione)) ||
  532.                                 profiloValues.size() == 1) {
  533.                            
  534.                             String profiloDefaultCorrente = (profiloValues.size() == 1) ? profiloValues.get(0) : profiloDefaultConsoleGestione;
  535.                            
  536.                             List<IDSoggetto> idSoggettiOperativi = this.soggettiCore.getIdSoggettiOperativi(profiloDefaultCorrente);
  537.                            
  538.                             // se ho selezionato un profilo e ho almeno due soggetti visualizzo la tendina
  539.                             if(idSoggettiOperativi != null && idSoggettiOperativi.size()>1) {
  540.                                 List<String> listaLabel = new ArrayList<>();
  541.                                 Map<String, IDSoggetto> mapLabelIds = new HashMap<>();
  542.                                 for (IDSoggetto idSoggetto : idSoggettiOperativi) {
  543.                                     String labelSoggetto = ConsoleHelper._getLabelNomeSoggetto(idSoggetto);
  544.                                     if(!listaLabel.contains(labelSoggetto)) {
  545.                                         listaLabel.add(labelSoggetto);
  546.                                         mapLabelIds.put(labelSoggetto, idSoggetto);
  547.                                     }
  548.                                 }
  549.                                
  550.                                 // Per ordinare in maniera case insensistive
  551.                                 Collections.sort(listaLabel, new Comparator<String>() {
  552.                                      @Override
  553.                                     public int compare(String o1, String o2) {
  554.                                            return o1.toLowerCase().compareTo(o2.toLowerCase());
  555.                                         }
  556.                                     });
  557.                                
  558.                                 List<String> listaValues = new ArrayList<>();
  559.                                
  560.                                 for (String label : listaLabel) {
  561.                                     listaValues.add(NamingUtils.getSoggettoFromLabel(profiloDefaultCorrente, label).toString());
  562.                                 }
  563.                                
  564.                                 de = new DataElement();
  565.                                 de.setType(DataElementType.SELECT);
  566.                                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  567.                                 listaLabel.add(0, UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL);
  568.                                 listaValues.add(0,UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL);
  569.                                 de.setValues(listaValues);
  570.                                 de.setLabels(listaLabel);
  571.                                 de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO);
  572.                                 de.setSelected(soggettoDefaultConsoleGestione);
  573.                                 dati.add(de);
  574.                                
  575.                             } else { // se ho un solo soggetto visualizzo il text
  576.                                 de = new DataElement();
  577.                                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  578.                                 de.setType(DataElementType.HIDDEN);
  579.                                 de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO);
  580.                                 de.setValue(soggettoDefaultConsoleGestione);
  581.                                 dati.add(de);
  582.                                
  583.                                 de = new DataElement();
  584.                                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  585.                                 de.setType(DataElementType.TEXT);
  586.                                 de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO+ "_txt");
  587.                                
  588.                                 if(idSoggettiOperativi!=null) {
  589.                                     IDSoggetto idSoggetto = idSoggettiOperativi.get(0);
  590.                                     String labelSoggetto = ConsoleHelper._getLabelNomeSoggetto(idSoggetto);
  591.                                     de.setValue(labelSoggetto);
  592.                                 }
  593.             //                  de.setValue(soggettoDefaultUtente.equals(UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL) ? UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL : soggettoDefaultUtente);
  594.                                 dati.add(de);
  595.                             }
  596.                            
  597.                         } else {
  598.                             de = new DataElement();
  599.                             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  600.                             de.setType(DataElementType.HIDDEN);
  601.                             de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO);
  602.                             de.setValue(soggettoDefaultConsoleGestione);
  603.                             dati.add(de);
  604.                         }
  605.                     } else {
  606.                         de = new DataElement();
  607.                         de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  608.                         de.setType(DataElementType.HIDDEN);        
  609.                         de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA);
  610.                         de.setValue(profiloDefaultConsoleGestione);
  611.                         dati.add(de);
  612.                        
  613.                         de = new DataElement();
  614.                         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  615.                         de.setType(DataElementType.HIDDEN);
  616.                         de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO);
  617.                         de.setValue(soggettoDefaultConsoleGestione);
  618.                         dati.add(de);
  619.                     }
  620.                 }
  621.             }
  622.            
  623.             // profilo e soggetti govwayMonitor
  624.             if(utenteMonitorEnabled) {
  625.                 de = new DataElement();
  626.                 de.setLabel(UtentiCostanti.LABEL_PROFILO_UTENTE_CONSOLE_MONITOR);
  627.                 de.setType(DataElementType.SUBTITLE);
  628.                 dati.add(de);
  629.                
  630.                 if(protocolloSelezionato) {
  631.                     // select list Profilo Interoperabilità
  632.                     List<String> protocolliRegistratiConsole = this.core.getProtocolli();
  633.                    
  634.                     List<String> profiloValues = new ArrayList<>();
  635.                     List<String> profiloLabels = new ArrayList<>();
  636.                     for (int i = 0; i < protocolliRegistratiConsole.size() ; i++) {
  637.                         String protocolloName = protocolliRegistratiConsole.get(i);
  638.                         if(ServletUtils.isCheckBoxEnabled(modalitaGateway[i])) {
  639.                             profiloValues.add(protocolloName);
  640.                             String labelProt = ConsoleHelper._getLabelProtocollo(protocolloName);
  641.                             profiloLabels.add(labelProt);
  642.                         }
  643.                     }
  644.                    
  645.                     if(profiloValues.size() > 1) { // select
  646.                         de = new DataElement();
  647.                         de.setType(DataElementType.SELECT);    
  648.                         de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  649.                        
  650.                         profiloLabels.add(0, UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL);
  651.                         profiloValues.add(0,UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL);
  652.                         de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA_MONITOR);
  653.                         de.setValues(profiloValues);
  654.                         de.setLabels(profiloLabels);
  655.                        
  656.                         de.setSelected(profiloDefaultConsoleMonitoraggio);
  657.                         de.setPostBack(true);
  658.                         dati.add(de);
  659.                        
  660.                     } else { // text
  661.                         de = new DataElement();
  662.                         de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  663.                         de.setType(DataElementType.HIDDEN);        
  664.                         de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA_MONITOR);
  665.                         de.setValue(profiloDefaultConsoleMonitoraggio);
  666.                         dati.add(de);
  667.                        
  668.                         de = new DataElement();
  669.                         de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  670.                         de.setType(DataElementType.TEXT);          
  671.                         de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA_MONITOR+ "_txt");
  672.                        
  673.                         String protocolloName = profiloValues.get(0);
  674.                         String labelProt = ConsoleHelper._getLabelProtocollo(protocolloName);
  675.                         de.setValue(labelProt);
  676.     //                  de.setValue(profiloDefaultUtente.equals(UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL) ? UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL : profiloDefaultUtente);
  677.                         dati.add(de);
  678.                     }
  679.                    
  680.                     // select list soggetti
  681.                     if((profiloDefaultConsoleMonitoraggio!=null && !UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL.equals(profiloDefaultConsoleMonitoraggio)) ||
  682.                             profiloValues.size() == 1) {
  683.                        
  684.                         String profiloDefaultCorrente = (profiloValues.size() == 1) ? profiloValues.get(0) : profiloDefaultConsoleMonitoraggio;
  685.                        
  686.                         List<IDSoggetto> idSoggettiOperativi = this.soggettiCore.getIdSoggettiOperativi(profiloDefaultCorrente);
  687.                        
  688.                         // se ho selezionato un profilo e ho almeno due soggetti visualizzo la tendina
  689.                         if(idSoggettiOperativi != null && idSoggettiOperativi.size()>1) {
  690.                             List<String> listaLabel = new ArrayList<>();
  691.                             Map<String, IDSoggetto> mapLabelIds = new HashMap<>();
  692.                             for (IDSoggetto idSoggetto : idSoggettiOperativi) {
  693.                                 String labelSoggetto = ConsoleHelper._getLabelNomeSoggetto(idSoggetto);
  694.                                 if(!listaLabel.contains(labelSoggetto)) {
  695.                                     listaLabel.add(labelSoggetto);
  696.                                     mapLabelIds.put(labelSoggetto, idSoggetto);
  697.                                 }
  698.                             }
  699.                            
  700.                             // Per ordinare in maniera case insensistive
  701.                             Collections.sort(listaLabel, new Comparator<String>() {
  702.                                  @Override
  703.                                 public int compare(String o1, String o2) {
  704.                                        return o1.toLowerCase().compareTo(o2.toLowerCase());
  705.                                     }
  706.                                 });
  707.                            
  708.                             List<String> listaValues = new ArrayList<>();
  709.                            
  710.                             for (String label : listaLabel) {
  711.                                 listaValues.add(NamingUtils.getSoggettoFromLabel(profiloDefaultCorrente, label).toString());
  712.                             }
  713.                            
  714.                             de = new DataElement();
  715.                             de.setType(DataElementType.SELECT);
  716.                             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  717.                             listaLabel.add(0, UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL);
  718.                             listaValues.add(0,UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL);
  719.                             de.setValues(listaValues);
  720.                             de.setLabels(listaLabel);
  721.                             de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO_MONITOR);
  722.                             de.setSelected(soggettoDefaultConsoleMonitoraggio);
  723.                             dati.add(de);
  724.                            
  725.                         } else { // se ho un solo soggetto visualizzo il text
  726.                             de = new DataElement();
  727.                             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  728.                             de.setType(DataElementType.HIDDEN);
  729.                             de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO_MONITOR);
  730.                             de.setValue(soggettoDefaultConsoleMonitoraggio);
  731.                             dati.add(de);
  732.                            
  733.                             de = new DataElement();
  734.                             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  735.                             de.setType(DataElementType.TEXT);
  736.                             de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO_MONITOR+ "_txt");
  737.                            
  738.                             if(idSoggettiOperativi!=null) {
  739.                                 IDSoggetto idSoggetto = idSoggettiOperativi.get(0);
  740.                                 String labelSoggetto = ConsoleHelper._getLabelNomeSoggetto(idSoggetto);
  741.                                 de.setValue(labelSoggetto);
  742.                             }
  743.     //                      de.setValue(soggettoDefaultUtente.equals(UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL) ? UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL : soggettoDefaultUtente);
  744.                             dati.add(de);
  745.                         }
  746.                        
  747.                     } else {
  748.                         de = new DataElement();
  749.                         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  750.                         de.setType(DataElementType.HIDDEN);
  751.                         de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO_MONITOR);
  752.                         de.setValue(soggettoDefaultConsoleMonitoraggio);
  753.                         dati.add(de);
  754.                     }
  755.                 } else {
  756.                     de = new DataElement();
  757.                     de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  758.                     de.setType(DataElementType.HIDDEN);        
  759.                     de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA_MONITOR);
  760.                     de.setValue(profiloDefaultConsoleMonitoraggio);
  761.                     dati.add(de);
  762.                    
  763.                     de = new DataElement();
  764.                     de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  765.                     de.setType(DataElementType.HIDDEN);
  766.                     de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO_MONITOR);
  767.                     de.setValue(soggettoDefaultConsoleMonitoraggio);
  768.                     dati.add(de);
  769.                 }
  770.                
  771.                 // Home page console di monitoraggio
  772.                 de = new DataElement();
  773.                 de.setType(DataElementType.SELECT);
  774.                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO);
  775.                 String[] homePageLabels = { UtentiCostanti.LABEL_VALUE_PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO_TRANSAZIONI, UtentiCostanti.LABEL_VALUE_PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO_STATISTICHE };
  776.                 de.setValues(UtentiCostanti.getValuesParametroUtentiHomePageMonitoraggio());
  777.                 de.setLabels(homePageLabels);
  778.                 de.setName(UtentiCostanti.PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO);
  779.                 de.setPostBack(true);
  780.                 de.setSelected(homePageMonitoraggio);
  781.                 dati.add(de);
  782.                
  783.                 // select per la selezione dell'intervallo temporale del grafico della home
  784.                 if(homePageMonitoraggio.equals(UtentiCostanti.VALUE_PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO_STATISTICHE)) {
  785.                     de = new DataElement();
  786.                     de.setType(DataElementType.SELECT);
  787.                     de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO);
  788.                     String[] intervalloTemporaleLabels = {
  789.                             UtentiCostanti.LABEL_PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO_NO_GRAFICO,
  790.                             UtentiCostanti.LABEL_PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO_ULTIME_24_ORE,
  791.                             UtentiCostanti.LABEL_PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO_ULTIMI_7_GIORNI,
  792.                             UtentiCostanti.LABEL_PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO_ULTIMI_30_GIORNI,
  793.                             UtentiCostanti.LABEL_PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO_ULTIMO_ANNO };
  794.                     de.setValues(UtentiCostanti.getValuesParametroUtentiIntervalloTemporaleHomePageMonitoraggio());
  795.                     de.setLabels(intervalloTemporaleLabels);
  796.                     de.setName(UtentiCostanti.PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO);
  797.                     de.setSelected(intervalloTemporaleReportStatistico);
  798.                     dati.add(de);
  799.                 } else {
  800.                     de = new DataElement();
  801.                     de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO);
  802.                     de.setType(DataElementType.HIDDEN);        
  803.                     de.setName(UtentiCostanti.PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO);
  804.                     de.setValue(intervalloTemporaleReportStatistico);
  805.                     dati.add(de);
  806.                 }
  807.                
  808.             } else {
  809.                 de = new DataElement();
  810.                 de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  811.                 de.setType(DataElementType.HIDDEN);        
  812.                 de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA_MONITOR);
  813.                 de.setValue(profiloDefaultConsoleMonitoraggio);
  814.                 dati.add(de);
  815.                
  816.                 de = new DataElement();
  817.                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  818.                 de.setType(DataElementType.HIDDEN);
  819.                 de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO_MONITOR);
  820.                 de.setValue(soggettoDefaultConsoleMonitoraggio);
  821.                 dati.add(de);
  822.                
  823.                 de = new DataElement();
  824.                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO);
  825.                 de.setType(DataElementType.HIDDEN);        
  826.                 de.setName(UtentiCostanti.PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO);
  827.                 de.setValue(homePageMonitoraggio);
  828.                 dati.add(de);
  829.                
  830.                 de = new DataElement();
  831.                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO);
  832.                 de.setType(DataElementType.HIDDEN);        
  833.                 de.setName(UtentiCostanti.PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO);
  834.                 de.setValue(intervalloTemporaleReportStatistico);
  835.                 dati.add(de);
  836.             }
  837.         } else {
  838.             de = new DataElement();
  839.             de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  840.             de.setType(DataElementType.HIDDEN);        
  841.             de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA_MONITOR);
  842.             de.setValue(profiloDefaultConsoleMonitoraggio);
  843.             dati.add(de);
  844.            
  845.             de = new DataElement();
  846.             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  847.             de.setType(DataElementType.HIDDEN);
  848.             de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO_MONITOR);
  849.             de.setValue(soggettoDefaultConsoleMonitoraggio);
  850.             dati.add(de);
  851.            
  852.             de = new DataElement();
  853.             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO);
  854.             de.setType(DataElementType.HIDDEN);        
  855.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO);
  856.             de.setValue(homePageMonitoraggio);
  857.             dati.add(de);
  858.            
  859.             de = new DataElement();
  860.             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO);
  861.             de.setType(DataElementType.HIDDEN);        
  862.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO);
  863.             de.setValue(intervalloTemporaleReportStatistico);
  864.             dati.add(de);
  865.         }
  866.        
  867.        
  868.        
  869.         boolean loginApplication = this.core.isLoginApplication();
  870.        
  871.         if(loginApplication) {
  872.             de = new DataElement();
  873.             de.setLabel(UtentiCostanti.LABEL_PASSWORD);
  874.             de.setType(DataElementType.TITLE);
  875.             dati.add(de);
  876.         }
  877.        
  878.         PasswordVerifier passwordVerifier = this.utentiCore.getUtenzePasswordVerifier();
  879.        
  880.         // se e' abilitato il controllo sulla scadenza della password visualizzo la checkbox di abilitazione scadenza sul singolo utente
  881.         if(this.utentiCore.isCheckPasswordExpire(passwordVerifier)) {
  882.             de = new DataElement();
  883.             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_SCADENZA);
  884.             de.setType(DataElementType.CHECKBOX);
  885.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_SCADENZA);
  886.             de.setSelected(scadenza);
  887.             de.setSize(this.getSize());
  888.            
  889.             if(TipoOperazione.ADD.equals(tipoOperazione)) {
  890.                 de.setLabelAffiancata(true);
  891.                 de.setNote(MessageFormat.format(UtentiCostanti.LABEL_NOTA_UTENTI_SCADENZA_ADD, passwordVerifier.getExpireDays()));
  892.             }
  893.            
  894.             if(TipoOperazione.CHANGE.equals(tipoOperazione)) {
  895.                 de.setLabelAffiancata(true);
  896.                 boolean passwordExpire = passwordVerifier.isPasswordExpire(dataUltimoAggiornamentoPassword);
  897.                
  898.                 // se l'utente e' stato configurato con controllo scadenza password visualizzo il messaggio di stato attuale della password
  899.                 if(oldScadenza) {
  900.                     if(passwordExpire) {
  901.                         de.setNote(UtentiCostanti.LABEL_UTENTI_SCADENZA_PW_SCADUTA);
  902.                         de.setValoreBoldRed();
  903.                     } else {
  904.                         long giorni = 0;
  905.                         Calendar c = Calendar.getInstance();
  906.                         c.setTime(dataUltimoAggiornamentoPassword);
  907.                         c.add(Calendar.DATE, passwordVerifier.getExpireDays());
  908.                         Date end = c.getTime();
  909.                         Date now = new Date();
  910.                         long endMs = end.getTime();
  911.                         long nowMs = now.getTime();
  912.                         long diff = endMs - nowMs;
  913.                         giorni = (diff / 1000 / 60 / 60 / 24);
  914.                        
  915.                         de.setNote(MessageFormat.format(UtentiCostanti.LABEL_NOTA_UTENTI_SCADENZA_CHANGE, giorni));
  916.                     }
  917.                 }
  918.             }
  919.            
  920.             dati.add(de);
  921.         }

  922.         if(loginApplication && TipoOperazione.CHANGE.equals(tipoOperazione)){
  923.             de = new DataElement();
  924.             de.setLabel(UtentiCostanti.LABEL_MODIFICA);
  925.             de.setType(DataElementType.CHECKBOX);
  926.             //          de.setOnClick("cambiaPassword(\"suChange\");");
  927.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_CHANGE_PW);
  928.             de.setPostBack(true);
  929.             de.setSelected(changepwd);
  930.             de.setSize(this.getSize());
  931.             dati.add(de);
  932.         }

  933.         if( (TipoOperazione.ADD.equals(tipoOperazione)) || (ServletUtils.isCheckBoxEnabled(changepwd)) ){
  934.             de = new DataElement();
  935.             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_PW);
  936.             if(loginApplication) {
  937.                 de.setValue(pwsu);
  938.                 de.setType(DataElementType.CRYPT);
  939.                 de.getPassword().setVisualizzaPasswordChiaro(true);
  940.                 de.getPassword().setVisualizzaBottoneGeneraPassword(true);
  941.                 if(passwordVerifier != null) {
  942.                     PasswordGenerator passwordGenerator = new PasswordGenerator(passwordVerifier);
  943.                     passwordGenerator.setDefaultLength(this.utentiCore.getUtenzeLunghezzaPasswordGenerate());
  944.                     de.getPassword().setPasswordGenerator(passwordGenerator);
  945.                     // stesso messaggio in add e change perche' l'amministratore puo' impostare anche password ripetute
  946.                     de.setNote(passwordVerifier.help(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE));
  947.                 }
  948.                 de.setRequired(true);
  949.             } else {
  950.                 de.setType(DataElementType.HIDDEN);
  951.                 de.setValue(UtentiCostanti.VALORE_PARAMETRO_PW_MODALITA_NO_LOGIN_APPLICATION);
  952.             }
  953.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_PW);
  954.             de.setSize(this.getSize());
  955.             dati.add(de);
  956.         }
  957.        
  958.        
  959.         return dati;

  960.     }


  961.     public void addChangeUtenteInfoToDati(List<DataElement> dati,
  962.             String nomesu,String changepwd,String pwsu,String confpwsu,InterfaceType interfaceType,
  963.             String isServizi,String isDiagnostica,String isReportistica, String isSistema,String isMessaggi,String isUtenti,String isAuditing, String isAccordiCooperazione,
  964.             boolean scegliSuServizi,
  965.             String [] uws, boolean scegliSuAccordi,String [] uwp, String [] modalitaGateway,
  966.             String profiloDefaultConsoleGestione, String soggettoDefaultConsoleGestione,
  967.             String profiloDefaultConsoleMonitoraggio, String soggettoDefaultConsoleMonitoraggio, String homePageMonitoraggio, String intervalloTemporaleReportStatistico) throws Exception{

  968.         DataElement de = new DataElement();
  969.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_USERNAME);
  970.         de.setValue(nomesu);
  971.         de.setType(DataElementType.HIDDEN);
  972.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_USERNAME);
  973.         dati.add(de);

  974.         if(ServletUtils.isCheckBoxEnabled(changepwd)){

  975.             de = new DataElement();
  976.             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_PW);
  977.             de.setValue(pwsu);
  978.             de.setType(DataElementType.HIDDEN);
  979.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_PW);
  980.             dati.add(de);

  981.             de = new DataElement();
  982.             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_CONFERMA_PW);
  983.             de.setValue(confpwsu);
  984.             de.setType(DataElementType.HIDDEN);
  985.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_CONFERMA_PW);
  986.             dati.add(de);

  987.             de = new DataElement();
  988.             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_CHANGE_PW);
  989.             de.setValue(changepwd);
  990.             de.setType(DataElementType.HIDDEN);
  991.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_CHANGE_PW);
  992.             dati.add(de);
  993.         }

  994.         de = new DataElement();
  995.         de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  996.         de.setType(DataElementType.HIDDEN);        
  997.         de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA);
  998.         de.setValue(profiloDefaultConsoleGestione);
  999.         dati.add(de);
  1000.        
  1001.         de = new DataElement();
  1002.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  1003.         de.setType(DataElementType.HIDDEN);
  1004.         de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO);
  1005.         de.setValue(soggettoDefaultConsoleGestione);
  1006.         dati.add(de);

  1007.         de = new DataElement();
  1008.         de.setLabel(UtentiCostanti.LABEL_MODALITA_INTERFACCIA);
  1009.         de.setValue(interfaceType.toString());
  1010.         de.setType(DataElementType.HIDDEN);
  1011.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_TIPO_GUI);
  1012.         dati.add(de);
  1013.        
  1014.         de = new DataElement();
  1015.         de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  1016.         de.setType(DataElementType.HIDDEN);        
  1017.         de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA_MONITOR);
  1018.         de.setValue(profiloDefaultConsoleMonitoraggio);
  1019.         dati.add(de);
  1020.        
  1021.         de = new DataElement();
  1022.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  1023.         de.setType(DataElementType.HIDDEN);
  1024.         de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO_MONITOR);
  1025.         de.setValue(soggettoDefaultConsoleMonitoraggio);
  1026.         dati.add(de);
  1027.        
  1028.         de = new DataElement();
  1029.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO);
  1030.         de.setType(DataElementType.HIDDEN);        
  1031.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO);
  1032.         de.setValue(homePageMonitoraggio);
  1033.         dati.add(de);
  1034.        
  1035.         de = new DataElement();
  1036.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO);
  1037.         de.setType(DataElementType.HIDDEN);        
  1038.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO);
  1039.         de.setValue(intervalloTemporaleReportStatistico);
  1040.         dati.add(de);

  1041.         de = new DataElement();
  1042.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_SERVIZI);
  1043.         de.setValue(isServizi);
  1044.         de.setType(DataElementType.HIDDEN);
  1045.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_SERVIZI);
  1046.         dati.add(de);

  1047.         de = new DataElement();
  1048.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_SISTEMA);
  1049.         de.setValue(isSistema);
  1050.         de.setType(DataElementType.HIDDEN);
  1051.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_SISTEMA);
  1052.         dati.add(de);

  1053.         de = new DataElement();
  1054.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_MESSAGGI);
  1055.         de.setValue(isMessaggi);
  1056.         de.setType(DataElementType.HIDDEN);
  1057.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_MESSAGGI);
  1058.         dati.add(de);

  1059.         de = new DataElement();
  1060.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_DIAGNOSTICA);
  1061.         de.setValue(isDiagnostica);
  1062.         de.setType(DataElementType.HIDDEN);
  1063.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_DIAGNOSTICA);
  1064.         dati.add(de);
  1065.        
  1066.         de = new DataElement();
  1067.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_REPORTISTICA);
  1068.         de.setValue(isReportistica);
  1069.         de.setType(DataElementType.HIDDEN);
  1070.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_REPORTISTICA);
  1071.         dati.add(de);
  1072.        
  1073.         de = new DataElement();
  1074.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_UTENTI);
  1075.         de.setValue(isUtenti);
  1076.         de.setType(DataElementType.HIDDEN);
  1077.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_UTENTI);
  1078.         dati.add(de);

  1079.         de = new DataElement();
  1080.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_AUDITING);
  1081.         de.setValue(isAuditing);
  1082.         de.setType(DataElementType.HIDDEN);
  1083.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_AUDITING);
  1084.         dati.add(de);

  1085.         de = new DataElement();
  1086.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_IS_ACCORDI_COOPERAZIONE);
  1087.         de.setType(DataElementType.HIDDEN);
  1088.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_IS_ACCORDI_COOPERAZIONE);
  1089.         de.setValue(isAccordiCooperazione);
  1090.         dati.add(de);

  1091.         if(scegliSuServizi){
  1092.             de = new DataElement();
  1093.             de.setNote(UtentiCostanti.LABEL_UTENTE_PERMESSI_SERVIZI_NOTE);
  1094.             de.setLabel(UtentiCostanti.LABEL_UTENTE_PERMESSI);
  1095.             de.setType(DataElementType.SELECT);
  1096.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_SINGLE_SU_SERVIZI);
  1097.             de.setValues(uws);
  1098.             dati.add(de);
  1099.         }

  1100.         if(scegliSuAccordi){
  1101.             de = new DataElement();
  1102.             de.setNote(UtentiCostanti.LABEL_UTENTE_PERMESSI_ACCORDI_COOPERAZIONE_NOTE);
  1103.             de.setLabel(UtentiCostanti.LABEL_UTENTE);
  1104.             de.setType(DataElementType.SELECT);
  1105.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_SINGLE_SU_ACCORDI_COOPERAZIONE);
  1106.             de.setValues(uwp);
  1107.             dati.add(de);
  1108.         }
  1109.        
  1110.         List<String> protocolliRegistratiConsole = this.core.getProtocolli();
  1111.         for (int i = 0; i < protocolliRegistratiConsole.size() ; i++) {
  1112.             String protocolloName = protocolliRegistratiConsole.get(i);
  1113.             de = new DataElement();
  1114.             de.setLabel(this.getLabelProtocollo(protocolloName));
  1115.             de.setType(DataElementType.HIDDEN);
  1116.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_MODALITA_PREFIX + protocolloName);
  1117.             de.setValue(modalitaGateway[i]);
  1118.             dati.add(de);
  1119.         }
  1120.     }


  1121.     public void addChooseUtenteForPermessiSToDati(List<DataElement> dati,String objToRemove,boolean scegliSuServizi,
  1122.             String [] uws, boolean scegliSuAccordi,String [] uwp){

  1123.         DataElement de = new DataElement();
  1124.         de.setLabel(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  1125.         de.setValue(objToRemove);
  1126.         de.setType(DataElementType.HIDDEN);
  1127.         de.setName(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  1128.         dati.add(de);

  1129.         if(scegliSuServizi){
  1130.             de = new DataElement();
  1131.             de.setNote(UtentiCostanti.LABEL_UTENTE_PERMESSI_SERVIZI_NOTE);
  1132.             de.setLabel(UtentiCostanti.LABEL_UTENTE_PERMESSI);
  1133.             de.setType(DataElementType.SELECT);
  1134.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_SINGLE_SU_SERVIZI);
  1135.             de.setValues(uws);
  1136.             dati.add(de);
  1137.         }

  1138.         if(scegliSuAccordi){
  1139.             de = new DataElement();
  1140.             de.setNote(UtentiCostanti.LABEL_UTENTE_PERMESSI_ACCORDI_COOPERAZIONE_NOTE);
  1141.             de.setLabel(UtentiCostanti.LABEL_UTENTE);
  1142.             de.setType(DataElementType.SELECT);
  1143.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_SINGLE_SU_ACCORDI_COOPERAZIONE);
  1144.             de.setValues(uwp);
  1145.             dati.add(de);
  1146.         }



  1147.     }

  1148.     public void addUtenteChangeToDati(List<DataElement> dati,InterfaceType interfaceType,
  1149.             String changepw, String nomeUtente, String profiloSelezionatoUtente, String soggettoSelezionatoUtente) throws Exception{

  1150.         DataElement de = new DataElement();
  1151.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_FIRST);
  1152.         de.setType(DataElementType.HIDDEN);
  1153.         de.setValue("false");
  1154.         dati.add(de);
  1155.        
  1156.         de = new DataElement();
  1157.         de.setLabel(UtentiCostanti.LABEL_INFO_UTENTE);
  1158.         de.setType(DataElementType.TITLE);
  1159.         dati.add(de);
  1160.        
  1161.         de = new DataElement();
  1162.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_USERNAME);
  1163.         de.setName(UtentiCostanti.PARAMETRO_UTENTE_LOGIN);
  1164.         de.setType(DataElementType.TEXT);
  1165.         de.setValue(nomeUtente);
  1166.         dati.add(de);
  1167.        
  1168.         User utente = this.utentiCore.getUser(nomeUtente);
  1169.        
  1170.         if(!utente.hasOnlyPermessiUtenti()) { // questa sezione viene visualizzata solo se si hanno i diritti
  1171.             de = new DataElement();
  1172.             de.setType(DataElementType.SUBTITLE);
  1173.             de.setLabel(UtentiCostanti.LABEL_PROFILO);
  1174.             dati.add(de);
  1175.         }
  1176.        
  1177.         // tipo interfaccia
  1178.         de = new DataElement();
  1179.         de.setLabel(UtentiCostanti.LABEL_MODALITA_INTERFACCIA);
  1180.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_TIPO_GUI);
  1181.         if(utente.hasOnlyPermessiUtenti()) {
  1182.             de.setType(DataElementType.HIDDEN);
  1183.             de.setValue(interfaceType.toString());
  1184.         }
  1185.         else {
  1186.             if(interfaceType.equals(InterfaceType.COMPLETA)) {
  1187.                 de.setLabel(UtentiCostanti.LABEL_MODALITA_INTERFACCIA);
  1188.                 de.setType(DataElementType.TEXT);
  1189.                 de.setName(UtentiCostanti.PARAMETRO_UTENTI_TIPO_GUI+"_text");
  1190.                 de.setValue(interfaceType.toString().toLowerCase());
  1191.                 dati.add(de);
  1192.                
  1193.                 de = new DataElement();
  1194.                 de.setLabel(UtentiCostanti.LABEL_MODALITA_INTERFACCIA);
  1195.                 de.setName(UtentiCostanti.PARAMETRO_UTENTI_TIPO_GUI);
  1196.                 de.setType(DataElementType.HIDDEN);
  1197.                 de.setValue(interfaceType.toString());
  1198.                
  1199.             } else {
  1200.                 de.setType(DataElementType.SELECT);    
  1201.                 User user = ServletUtils.getUserFromSession(this.request, this.session);
  1202.                 String[] tipiInterfacce=null;
  1203.                 String[] tipiInterfacceLabel=null;
  1204.                 if(user.isPermitInterfaceComplete()) {
  1205.                     tipiInterfacce = new String[3];        
  1206.                 }
  1207.                 else {
  1208.                     tipiInterfacce = new String[2];
  1209.                 }
  1210.                 tipiInterfacce[0]=InterfaceType.STANDARD.toString();
  1211.                 tipiInterfacce[1]=InterfaceType.AVANZATA.toString();
  1212.                 if(user.isPermitInterfaceComplete()) {
  1213.                     tipiInterfacce[2]=InterfaceType.COMPLETA.toString();
  1214.                 }
  1215.                 tipiInterfacceLabel = new String[tipiInterfacce.length];
  1216.                 for (int i = 0; i < tipiInterfacce.length; i++) {
  1217.                     tipiInterfacceLabel[i] = tipiInterfacce[i].toLowerCase();
  1218.                 }
  1219.                 de.setValues(tipiInterfacce);
  1220.                 de.setLabels(tipiInterfacceLabel);
  1221.                 de.setSelected(interfaceType.toString());
  1222.             }
  1223.         }
  1224.         dati.add(de);
  1225.        
  1226.         de = new DataElement();
  1227.         de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  1228.         if(utente.hasOnlyPermessiUtenti()) {
  1229.             de.setType(DataElementType.HIDDEN);
  1230.             de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA);
  1231.             de.setValue(profiloSelezionatoUtente);
  1232.             dati.add(de);
  1233.         }
  1234.         else {
  1235.             List<String> protocolliDispondibili = this.core.getProtocolli(this.request, this.session, true);
  1236.            
  1237.             if(protocolliDispondibili != null && protocolliDispondibili.size() > 1) {
  1238.                 de.setType(DataElementType.SELECT);
  1239.                
  1240.                 List<String> labelProtocolli = new ArrayList<>();
  1241.                
  1242.                 for (String protocolloDisponibile : ProtocolUtils.orderProtocolli(protocolliDispondibili)) {
  1243.                     String labelProt = ConsoleHelper._getLabelProtocollo(protocolloDisponibile);
  1244.                     labelProtocolli.add(labelProt);
  1245.                 }
  1246.                
  1247.                 labelProtocolli.add(0, UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL);
  1248.                 protocolliDispondibili.add(0,UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL);
  1249.                 de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA);
  1250.                 de.setValues(protocolliDispondibili);
  1251.                 de.setLabels(labelProtocolli);
  1252.                
  1253.                 de.setSelected(profiloSelezionatoUtente);
  1254.                 de.setPostBack(true);
  1255.                 dati.add(de);
  1256.             } else {
  1257.                 // solo un protocollo visualizzo il testo e basta
  1258.                 de.setType(DataElementType.HIDDEN);
  1259.                 de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA);
  1260.                 de.setValue(profiloSelezionatoUtente);
  1261.                 dati.add(de);
  1262.                
  1263.                 // visualizzo label
  1264.                 de = new DataElement();
  1265.                 de.setType(DataElementType.TEXT);
  1266.                 de.setLabel(org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_HTML_ESCAPE);
  1267.                 de.setName(UtentiCostanti.PARAMETRO_UTENTE_TIPO_MODALITA + "_txt");
  1268.                
  1269.                 if(protocolliDispondibili!=null) {
  1270.                     String labelProt = ConsoleHelper._getLabelProtocollo(protocolliDispondibili.get(0));
  1271.                     de.setValue(labelProt);
  1272.                 }
  1273. //              de.setValue(profiloSelezionatoUtente.equals(UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL) ? UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL : ConsoleHelper._getLabelProtocollo(profiloSelezionatoUtente));
  1274.                 dati.add(de);
  1275.                
  1276.             }
  1277.         }
  1278.        
  1279.         if(utente.hasOnlyPermessiUtenti()) {
  1280.             de = new DataElement();
  1281.             de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  1282.             de.setType(DataElementType.HIDDEN);
  1283.             de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO);
  1284.             de.setValue(soggettoSelezionatoUtente);
  1285.             dati.add(de);
  1286.         } else {
  1287.             List<String> protocolliDispondibili = this.core.getProtocolli(this.request, this.session, true);
  1288.             // selezione del soggetto se disponibile        
  1289.             if((profiloSelezionatoUtente!=null && !UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL.equals(profiloSelezionatoUtente))
  1290.                     || protocolliDispondibili.size() == 1) {
  1291.                    
  1292.                 String profiloDefaultCorrente = (protocolliDispondibili.size() == 1) ? protocolliDispondibili.get(0) : profiloSelezionatoUtente;
  1293.                
  1294.                 List<IDSoggetto> idSoggettiOperativi = this.soggettiCore.getIdSoggettiOperativi(profiloDefaultCorrente);
  1295.            
  1296.                 // se ho selezionato un profilo e ho almeno due soggetti visualizzo la tendina
  1297.                 if(idSoggettiOperativi != null && idSoggettiOperativi.size()>1) {
  1298.                     List<String> listaLabel = new ArrayList<>();
  1299.                     Map<String, IDSoggetto> mapLabelIds = new HashMap<>();
  1300.                     for (IDSoggetto idSoggetto : idSoggettiOperativi) {
  1301.                         String labelSoggetto = ConsoleHelper._getLabelNomeSoggetto(idSoggetto);
  1302.                         if(!listaLabel.contains(labelSoggetto)) {
  1303.                             listaLabel.add(labelSoggetto);
  1304.                             mapLabelIds.put(labelSoggetto, idSoggetto);
  1305.                         }
  1306.                     }
  1307.                    
  1308.                     // Per ordinare in maniera case insensistive
  1309.                     Collections.sort(listaLabel, new Comparator<String>() {
  1310.                          @Override
  1311.                         public int compare(String o1, String o2) {
  1312.                                return o1.toLowerCase().compareTo(o2.toLowerCase());
  1313.                             }
  1314.                         });
  1315.                    
  1316.                     List<String> listaValues = new ArrayList<>();
  1317.                    
  1318.                     for (String label : listaLabel) {
  1319.                         listaValues.add(NamingUtils.getSoggettoFromLabel(profiloDefaultCorrente, label).toString());
  1320.                     }
  1321.                    
  1322.                    
  1323.                     de = new DataElement();
  1324.                     de.setType(DataElementType.SELECT);
  1325.                     de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  1326.                     listaLabel.add(0, UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL);
  1327.                     listaValues.add(0,UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL);
  1328.                     de.setValues(listaValues);
  1329.                     de.setLabels(listaLabel);
  1330.                     de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO);
  1331.                     de.setSelected(soggettoSelezionatoUtente);
  1332.                     dati.add(de);
  1333.                    
  1334.                 } else { // se ho un solo soggetto visualizzo il text
  1335.                     de = new DataElement();
  1336.                     de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  1337.                     de.setType(DataElementType.HIDDEN);
  1338.                     de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO);
  1339.                     de.setValue(soggettoSelezionatoUtente);
  1340.                     dati.add(de);
  1341.                    
  1342.                     de = new DataElement();
  1343.                     de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  1344.                     de.setType(DataElementType.TEXT);
  1345.                     de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO+ "_txt");
  1346.                    
  1347.                     if(idSoggettiOperativi!=null) {
  1348.                         IDSoggetto idSoggetto = idSoggettiOperativi.get(0);
  1349.                         String labelSoggetto = ConsoleHelper._getLabelNomeSoggetto(idSoggetto);
  1350.                         de.setValue(labelSoggetto);
  1351.                     }
  1352. //                  de.setValue(soggettoSelezionatoUtente.equals(UtentiCostanti.VALORE_PARAMETRO_MODALITA_ALL) ? UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL : soggettoSelezionatoUtente);
  1353.                     dati.add(de);
  1354.                 }
  1355.             } else {
  1356.                 de = new DataElement();
  1357.                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_SOGGETTO_OPERATIVO);
  1358.                 de.setType(DataElementType.HIDDEN);
  1359.                 de.setName(UtentiCostanti.PARAMETRO_UTENTE_ID_SOGGETTO);
  1360.                 de.setValue(soggettoSelezionatoUtente);
  1361.                 dati.add(de);
  1362.             }
  1363.         }
  1364.        
  1365.         if(this.core.isLoginApplication()) {
  1366.        
  1367.             de = new DataElement();
  1368.             de.setLabel(UtentiCostanti.LABEL_PASSWORD);
  1369.             de.setType(DataElementType.TITLE);
  1370.             dati.add(de);
  1371.    
  1372.             de = new DataElement();
  1373.             de.setLabel(UtentiCostanti.LABEL_MODIFICA);
  1374.             de.setType(DataElementType.CHECKBOX);
  1375.             //      de.setOnClick("cambiaPassword(\"changePwd\");");
  1376.             de.setName(UtentiCostanti.PARAMETRO_UTENTI_CHANGE_PW);
  1377.             de.setPostBack(true);
  1378.             de.setSelected(changepw);
  1379.             de.setSize(this.getSize());
  1380.             dati.add(de);
  1381.    
  1382.    
  1383.             //se e' stato selezionato il link per il cambio password allora mostro i dati
  1384.             if(ServletUtils.isCheckBoxEnabled(changepw)){
  1385.    
  1386.                 PasswordVerifier passwordVerifier = this.utentiCore.getUtenzePasswordVerifier();
  1387.                
  1388.     //          if(ServletUtils.getUserFromSession(this.session).getPermessi().isUtenti()==false){
  1389.                
  1390.                 de = new DataElement();
  1391.                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTE_VECCHIA_PW);
  1392.                 de.setType(DataElementType.CRYPT);
  1393.                 de.setName(UtentiCostanti.PARAMETRO_UTENTE_VECCHIA_PW);
  1394.                 de.setValue("");
  1395.                 de.setSize(this.getSize());
  1396.                 de.setRequired(true);
  1397.                 dati.add(de);
  1398.                    
  1399.     //          }
  1400.    
  1401.                 de = new DataElement();
  1402.                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTE_NUOVA_PW);
  1403.                 de.setType(DataElementType.CRYPT);
  1404.                 de.setName(UtentiCostanti.PARAMETRO_UTENTE_NUOVA_PW);
  1405.                 de.setSize(this.getSize());
  1406.                 de.setValue("");
  1407.                 de.setRequired(true);
  1408.                 dati.add(de);
  1409.    
  1410.                 de = new DataElement();
  1411.                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTE_CONFERMA_NUOVA_PW);
  1412.                 de.setType(DataElementType.CRYPT);
  1413.                 de.setName(UtentiCostanti.PARAMETRO_UTENTE_CONFERMA_NUOVA_PW);
  1414.                 de.setSize(this.getSize());
  1415.                 de.setValue("");
  1416.                 de.setRequired(true);
  1417.                 if(passwordVerifier!=null){
  1418.                     de.setNote(passwordVerifier.helpUpdate(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE));
  1419.                 }
  1420.                 dati.add(de);
  1421.             }

  1422.         }
  1423.         de = new DataElement();
  1424.         de.setType(DataElementType.HIDDEN);
  1425.         de.setName(UtentiCostanti.PARAMETRO_UTENTE_ESEGUI);
  1426.         de.setValue(UtentiCostanti.PARAMETRO_UTENTE_ESEGUI);
  1427.         dati.add(de);
  1428.     }


  1429.     public boolean utentiCheckData(TipoOperazione tipoOperazione,boolean singlePdD,List<String> oldProtocolliSupportati, boolean oldUserHasOnlyPermessiUtenti) throws Exception {
  1430.         try {
  1431.             String nomesu = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_USERNAME);
  1432.             String pwsu = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_PW);
  1433.             // String confpwsu = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_CONFERMA_PASSWORD);
  1434.             String tipoGui = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_TIPO_GUI);
  1435.             String isServizi = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_IS_SERVIZI);
  1436.             String isDiagnostica = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_IS_DIAGNOSTICA);
  1437.             String isReportistica = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_IS_REPORTISTICA);
  1438.             String isSistema = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_IS_SISTEMA);
  1439.             String isMessaggi = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_IS_MESSAGGI);
  1440.             String isUtenti = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_IS_UTENTI);
  1441.             String isAccordiCooperazione = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_IS_ACCORDI_COOPERAZIONE);
  1442.             String isAuditing = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_IS_AUDITING);
  1443.             String changepwd = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_CHANGE_PW);

  1444.             List<String> protocolliRegistratiConsole = this.utentiCore.getProtocolli();
  1445.            
  1446.             String [] modalitaScelte = new String[protocolliRegistratiConsole.size()];
  1447.             List<String> nuoviProtocolliSupportati = new ArrayList<>();
  1448.             for (int i = 0; i < protocolliRegistratiConsole.size() ; i++) {
  1449.                 String protocolloName = protocolliRegistratiConsole.get(i);
  1450.                 modalitaScelte[i] = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_MODALITA_PREFIX + protocolloName);
  1451.                 if(ServletUtils.isCheckBoxEnabled(modalitaScelte[i])) {
  1452.                     nuoviProtocolliSupportati.add(protocolloName);
  1453.                 }
  1454.             }

  1455.             boolean loginApplication = this.core.isLoginApplication();
  1456.            
  1457.             // Campi obbligatori
  1458.             if (TipoOperazione.ADD.equals(tipoOperazione) || ServletUtils.isCheckBoxEnabled(changepwd) ) {
  1459.                 String tmpElenco = "";
  1460.                 if (nomesu.equals("")) {
  1461.                     tmpElenco = UtentiCostanti.LABEL_PARAMETRO_UTENTI_USERNAME;
  1462.                 }
  1463.                 boolean checkPassword = true;
  1464.                 if(TipoOperazione.CHANGE.equals(tipoOperazione) && !ServletUtils.isCheckBoxEnabled(changepwd)){
  1465.                     //if( confpwsu.equals("") && pwsu.equals("") ){
  1466.                     //  checkPassword = false;
  1467.                     //}
  1468.                     checkPassword=false;
  1469.                 }
  1470.                 if(!loginApplication) {
  1471.                     checkPassword=false;
  1472.                 }
  1473.                 if(checkPassword){
  1474.                     if (pwsu==null || pwsu.equals("")) {
  1475.                         if (tmpElenco.equals("")) {
  1476.                             tmpElenco = UtentiCostanti.LABEL_PARAMETRO_UTENTI_PW;
  1477.                         } else {
  1478.                             tmpElenco = tmpElenco + ", "+UtentiCostanti.LABEL_PARAMETRO_UTENTI_PW;
  1479.                         }
  1480.                     }
  1481. //                  if (confpwsu.equals("")) {
  1482. //                      if (tmpElenco.equals("")) {
  1483. //                          tmpElenco = UtentiCostanti.LABEL_PARAMETRO_UTENTI_CONFERMA_PASSWORD;
  1484. //                      } else {
  1485. //                          tmpElenco = tmpElenco + ", "+UtentiCostanti.LABEL_PARAMETRO_UTENTI_CONFERMA_PASSWORD;
  1486. //                      }
  1487. //                  }
  1488.                 }
  1489.                 if(!tmpElenco.equals("")){
  1490.                     this.pd.setMessage("Dati incompleti. &Egrave; necessario indicare: " + tmpElenco);
  1491.                     return false;
  1492.                 }
  1493.             }

  1494.             // Controllo che non ci siano spazi nei campi di testo
  1495. //          if ((nomesu.indexOf(" ") != -1) || ( ServletUtils.isCheckBoxEnabled(changepwd) && ( (pwsu.indexOf(" ") != -1) || (confpwsu.indexOf(" ") != -1)))) {
  1496.             if ((nomesu.indexOf(" ") != -1) || ( ServletUtils.isCheckBoxEnabled(changepwd) &&  pwsu.indexOf(" ") != -1 )) {
  1497.                 this.pd.setMessage("Non inserire spazi nei campi di testo");
  1498.                 return false;
  1499.             }
  1500.            
  1501.             // length
  1502.             if(this.checkLength255(nomesu, UtentiCostanti.LABEL_PARAMETRO_UTENTI_USERNAME)==false) {
  1503.                 return false;
  1504.             }

  1505.             // Controllo che i campi "checkbox" abbiano uno dei valori
  1506.             // ammessi
  1507.             //          if ((isServizi != null) && !isServizi.equals("") && !isServizi.equals("yes") && !isServizi.equals("no")) {
  1508.             //              this.pd.setMessage("Servizi dev'essere selezionato o deselezionato");
  1509.             //              return false;
  1510.             //          }
  1511.             //          if (singlePdD.equals("true") && (isDiagnostica != null) && !isDiagnostica.equals("") && !isDiagnostica.equals("yes") && !isDiagnostica.equals("no")) {
  1512.             //              this.pd.setMessage("Diagnostica dev'essere selezionato o deselezionato");
  1513.             //              return false;
  1514.             //          }
  1515.             //          if (singlePdD.equals("true") && (isReportistica != null) && !isReportistica.equals("") && !isReportistica.equals("yes") && !isReportistica.equals("no")) {
  1516.             //              this.pd.setMessage("Reportistica dev'essere selezionato o deselezionato");
  1517.             //              return false;
  1518.             //          }
  1519.             //          if ((isSistema != null) && !isSistema.equals("") && !isSistema.equals("yes") && !isSistema.equals("no")) {
  1520.             //              this.pd.setMessage("Sistema dev'essere selezionato o deselezionato");
  1521.             //              return false;
  1522.             //          }
  1523.             //          if ((isMessaggi != null) && !isMessaggi.equals("") && !isMessaggi.equals("yes") && !isMessaggi.equals("no")) {
  1524.             //              this.pd.setMessage("Messaggi dev'essere selezionato o deselezionato");
  1525.             //              return false;
  1526.             //          }
  1527.             //          if ((isUtenti != null) && !isUtenti.equals("") && !isUtenti.equals("yes") && !isUtenti.equals("no")) {
  1528.             //              this.pd.setMessage("Utenti dev'essere selezionato o deselezionato");
  1529.             //              return false;
  1530.             //          }
  1531.             //          if ((isAuditing != null) && !isAuditing.equals("") && !isAuditing.equals("yes") && !isAuditing.equals("no")) {
  1532.             //              this.pd.setMessage("Auditing dev'essere selezionato o deselezionato");
  1533.             //              return false;
  1534.             //          }
  1535.             //          if ((isAccordiCooperazione != null) && !isAccordiCooperazione.equals("") && !isAccordiCooperazione.equals("yes") && !isAccordiCooperazione.equals("no")) {
  1536.             //          this.pd.setMessage("Accordi Cooperazione dev'essere selezionato o deselezionato");
  1537.             //          return false;
  1538.             //      }
  1539.            
  1540.             // in modalita change devo controllare che se ho cambiato le modalita' all'utente ci sia almeno un altro utente che puo' gestire le modalita' che lascio
  1541.             User user = null;
  1542.             if(TipoOperazione.CHANGE.equals(tipoOperazione)) {
  1543.                
  1544.                 // prelevo l'utenza dal db
  1545.                 user = this.utentiCore.getUser(nomesu);
  1546.                
  1547.                 // se l'utente aveva solo il controllo degli utenti, questo controllo non importa tanto non ha modalita' associate
  1548.                 if(!oldUserHasOnlyPermessiUtenti) {
  1549.                    
  1550.                     if(oldProtocolliSupportati==null) {
  1551.                         oldProtocolliSupportati = this.utentiCore.getProtocolli();
  1552.                     }
  1553.                    
  1554.                     Collections.sort(oldProtocolliSupportati);
  1555.                     Collections.sort(nuoviProtocolliSupportati);
  1556.                    
  1557.                     List<String> protocolliEliminati = new ArrayList<>();
  1558.                     for (String vecchioProtocollo : oldProtocolliSupportati) {
  1559.                         boolean protocolloEliminato = !nuoviProtocolliSupportati.contains(vecchioProtocollo);
  1560.                        
  1561.                         if(protocolloEliminato)
  1562.                             protocolliEliminati.add(vecchioProtocollo);
  1563.                     }
  1564.                    
  1565.                     if(protocolliEliminati.size() > 0) {
  1566.                         List<String> nomiUtentiDaRimuovere = new ArrayList<>();
  1567.                         nomiUtentiDaRimuovere.add(nomesu);
  1568.                         List<String> utentiDaNonEliminare = new ArrayList<>();
  1569.                         List<String> protocolliNonValidi = new ArrayList<>();
  1570.                         for (String protocolloDaControllare : protocolliEliminati) {
  1571.                             boolean protocolloNonPiuAssociato = this.controllaEsistenzaUtentePerAssociareIlProtocollo(nomiUtentiDaRimuovere, utentiDaNonEliminare, nomesu, protocolloDaControllare);
  1572.                             if(protocolloNonPiuAssociato)
  1573.                                 protocolliNonValidi.add(this.getLabelProtocollo(protocolloDaControllare));
  1574.                         }
  1575.                        
  1576.                         if(utentiDaNonEliminare.size() > 0) {
  1577.                             if(protocolliNonValidi.size() > 1) {
  1578.                                 StringBuilder sbPnV = new StringBuilder();
  1579.                                 for (String protNonVal : protocolliNonValidi) {
  1580.                                     if(sbPnV.length() >0 )
  1581.                                         sbPnV.append(", ");
  1582.                                     sbPnV.append(protNonVal);
  1583.                                 }
  1584.                                
  1585.                                 this.pd.setMessage("L'utente " +utentiDaNonEliminare.get(0) +
  1586.                                     " non pu&ograve; essere modificato poich&egrave; sono stati rilevati oggetti, appartenenti ai "+
  1587.                                         org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLI_DI_HTML_ESCAPE+" '"+ sbPnV.toString() +"', non assegnati a nessun altro utente");
  1588.                             } else {
  1589.                                 this.pd.setMessage("L'utente " +utentiDaNonEliminare.get(0) +
  1590.                                         " non pu&ograve; essere modificato poich&egrave; sono stati rilevati oggetti, appartenenti al "+
  1591.                                         org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_DI_HTML_ESCAPE+" '"+ protocolliNonValidi.get(0) +"', non assegnati a nessun altro utente");
  1592.                             }
  1593.                             return false;
  1594.                         }
  1595.                        
  1596.                         // Controlli su eventuali soggetti/servizi associati alle modalita' deselezionate
  1597.                         for (String protocolloDaControllare : protocolliEliminati) {
  1598.                             // controllo servizi
  1599.                             if(user.getServizi().size() > 0) {
  1600.                                 for (IDServizio idServizio : user.getServizi()) {
  1601.                                     String protocolloAssociatoTipoSoggetto = this.soggettiCore.getProtocolloAssociatoTipoSoggetto(idServizio.getTipo());
  1602.                                     if(protocolloAssociatoTipoSoggetto.equals(protocolloDaControllare)) {
  1603.                                         this.pd.setMessage("L'utente " + nomesu
  1604.                                                 + " non pu&ograve; essere modificato poich&egrave; sono stati rilevati delle API, appartenenti al "+
  1605.                                         org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_DI_HTML_ESCAPE+" '"
  1606.                                                 + this.getLabelProtocollo(protocolloDaControllare) +"', registrate tra le restrizioni dell'utente");
  1607.                                         return false;
  1608.                                     }
  1609.                                 }
  1610.                             }
  1611.                             // controllo soggetti
  1612.                             if(user.getSoggetti().size() > 0) {
  1613.                                 for (IDSoggetto idSoggetto : user.getSoggetti()) {
  1614.                                     String protocolloAssociatoTipoSoggetto = this.soggettiCore.getProtocolloAssociatoTipoSoggetto(idSoggetto.getTipo());
  1615.                                     if(protocolloAssociatoTipoSoggetto.equals(protocolloDaControllare)) {
  1616.                                         this.pd.setMessage("L'utente " + nomesu
  1617.                                                 + " non pu&ograve; essere modificato poich&egrave; sono stati rilevati dei soggetti, appartenenti al "+
  1618.                                         org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_DI_HTML_ESCAPE+" '"
  1619.                                                 + this.getLabelProtocollo(protocolloDaControllare) +"', registrati tra le restrizioni dell'utente");
  1620.                                         return false;
  1621.                                     }
  1622.                                 }
  1623.                             }
  1624.                         }
  1625.                     }
  1626.                 }
  1627.                
  1628.                 // Controlli su soggetti/servizi associati
  1629.                 //1. l'utente aveva un permesso di tipo 'D' e' stato eliminato, devo controllare che non abbia soggetti/servizi associati
  1630.                 if(
  1631.                         (isDiagnostica == null || !ServletUtils.isCheckBoxEnabled(isDiagnostica))
  1632.                         &&
  1633.                         (isReportistica == null || !ServletUtils.isCheckBoxEnabled(isReportistica))
  1634.                         ){
  1635.                    
  1636.                     boolean oldDiagnostica = user.getPermessi().isDiagnostica();
  1637.                     boolean oldReportistica = user.getPermessi().isReportistica();
  1638.                        
  1639.                     if( (oldDiagnostica || oldReportistica) && user.getServizi().size() > 0) {
  1640.                         this.pd.setMessage("L'utente " + nomesu + " non pu&ograve; essere modificato poich&egrave; sono stati rilevate delle API registrate tra le restrizioni dell'utente");
  1641.                         return false;
  1642.                     }
  1643.                     if( (oldDiagnostica || oldReportistica) && user.getSoggetti().size() > 0) {
  1644.                         this.pd.setMessage("L'utente " + nomesu + " non pu&ograve; essere modificato poich&egrave; sono stati rilevati dei soggetti registrati tra le restrizioni dell'utente");
  1645.                         return false;
  1646.                     }
  1647.                 }
  1648.             }
  1649.            

  1650.             // Controllo che i campi "select" abbiano uno dei valori ammessi
  1651.             // solo per l'utente della govwayConsole
  1652.             boolean utenteConsoleEnabled =
  1653.                     ServletUtils.isCheckBoxEnabled(isServizi) ||
  1654.                     ServletUtils.isCheckBoxEnabled(isMessaggi) ||
  1655.                     ServletUtils.isCheckBoxEnabled(isAuditing) ||
  1656.                     ServletUtils.isCheckBoxEnabled(isSistema) ||
  1657.                     ServletUtils.isCheckBoxEnabled(isUtenti) ||            
  1658.                     ServletUtils.isCheckBoxEnabled(isAccordiCooperazione);
  1659.            
  1660.             if(utenteConsoleEnabled) {
  1661.                 try {
  1662.                     InterfaceType.convert(tipoGui, true);
  1663.                 }catch(Exception e) {
  1664.                     this.pd.setMessage("Tipo dev'essere uno dei seguenti valori: "+InterfaceType.AVANZATA + ", " + InterfaceType.STANDARD + ".");
  1665.                     return false;
  1666.                 }
  1667.                
  1668.                 String homePageMonitoraggio = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO);
  1669.                 String intervalloTemporaleHomePageConsoleMonitoraggio = this.getParameter(UtentiCostanti.PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO);

  1670.                 if(!Arrays.asList(UtentiCostanti.getValuesParametroUtentiHomePageMonitoraggio()).contains(homePageMonitoraggio)) {
  1671.                     this.pd.setMessage(UtentiCostanti.LABEL_PARAMETRO_UTENTI_HOME_PAGE_MONITORAGGIO + " contiene un valore non valido.");
  1672.                     return false;
  1673.                 }
  1674.                 if(!Arrays.asList(UtentiCostanti.getValuesParametroUtentiIntervalloTemporaleHomePageMonitoraggio()).contains(intervalloTemporaleHomePageConsoleMonitoraggio)) {
  1675.                     this.pd.setMessage(UtentiCostanti.LABEL_PARAMETRO_UTENTI_INTERVALLO_TEMPORALE_HOME_PAGE_MONITORAGGIO + " contiene un valore non valido.");
  1676.                     return false;
  1677.                 }
  1678.             }
  1679.            
  1680.             // Controllo che le password corrispondano
  1681.             boolean checkPassword = true;
  1682.             if(TipoOperazione.CHANGE.equals(tipoOperazione) && !ServletUtils.isCheckBoxEnabled(changepwd)){
  1683.                 //if( confpwsu.equals("") && pwsu.equals("") ){
  1684.                 //  checkPassword = false;
  1685.                 //}
  1686.                 checkPassword=false;
  1687.             }
  1688.             if(!loginApplication) {
  1689.                 checkPassword=false;
  1690.             }
  1691. //          if (checkPassword && !pwsu.equals(confpwsu)) {
  1692. //              this.pd.setMessage("Le password non corrispondono");
  1693. //              return false;
  1694. //          }
  1695.            
  1696.             if (checkPassword){
  1697.                 PasswordVerifier passwordVerifier = this.utentiCore.getUtenzePasswordVerifier();
  1698.                 if(passwordVerifier!=null){
  1699.                     StringBuilder motivazioneErrore = new StringBuilder();
  1700.                     if(passwordVerifier.validate(nomesu, pwsu, motivazioneErrore)==false){
  1701.                         this.pd.setMessage(motivazioneErrore.toString());
  1702.                         return false;
  1703.                     }
  1704.                    
  1705.                     // controllo storico password in caso di change
  1706.                     // Attualmente l'amministratore puo' impostare una vecchia password
  1707. //                  if(TipoOperazione.CHANGE.equals(tipoOperazione) && passwordVerifier.isHistory()) {
  1708. //                      List<UserPassword> precedentiPassword = user.getPrecedentiPassword();
  1709. //                      
  1710. ////                        String tmpPass = pwsu;
  1711. ////                        if(this.utentiCore.isUtenzePasswordEncryptEnabled()) {
  1712. ////                            tmpPass = this.utentiCore.getUtenzePasswordManager().crypt(pwsu);
  1713. ////                        }
  1714. //
  1715. //                      // se la lista storico e' vuota controllo la password precedente salvata nel bean
  1716. //                      if(precedentiPassword == null || precedentiPassword.isEmpty()) {
  1717. //                          boolean trovato = this.utentiCore.getUtenzePasswordManager().check(pwsu, user.getPassword());
  1718. //                          if(!trovato && this.utentiCore.getUtenzePasswordManager_backwardCompatibility()!=null) {
  1719. //                              trovato = this.utentiCore.getUtenzePasswordManager_backwardCompatibility().check(pwsu, user.getPassword());
  1720. //                          }
  1721. //                          if (trovato) {
  1722. //                              this.pd.setMessage(UtentiCostanti.MESSAGGIO_ERRORE_PASSWORD_GIA_UTILIZZATA);
  1723. //                              return false;
  1724. //                          }
  1725. //                      }
  1726. //                      
  1727. //                      for (UserPassword userPassword : precedentiPassword) {
  1728. //                          boolean trovato = this.utentiCore.getUtenzePasswordManager().check(pwsu, userPassword.getPassword());
  1729. //                          if(!trovato && this.utentiCore.getUtenzePasswordManager_backwardCompatibility()!=null) {
  1730. //                              trovato = this.utentiCore.getUtenzePasswordManager_backwardCompatibility().check(pwsu, userPassword.getPassword());
  1731. //                          }
  1732. //                          if (trovato) {
  1733. //                              this.pd.setMessage(UtentiCostanti.MESSAGGIO_ERRORE_PASSWORD_GIA_UTILIZZATA);
  1734. //                              return false;
  1735. //                          }
  1736. //                      }
  1737. //                  }
  1738.                 }
  1739.             }

  1740.             // Almeno un permesso dev'essere selezionato
  1741.             if (
  1742.                     (
  1743.                             (isServizi == null) || !ServletUtils.isCheckBoxEnabled(isServizi)
  1744.                     ) &&
  1745.                     (
  1746.                             !singlePdD
  1747.                             ||
  1748.                             (
  1749.                                     //singlePdD
  1750.                                     //&&
  1751.                                     (
  1752.                                             (isDiagnostica == null) || !ServletUtils.isCheckBoxEnabled(isDiagnostica)
  1753.                                     )
  1754.                                     &&
  1755.                                     (
  1756.                                             (isReportistica == null) || !ServletUtils.isCheckBoxEnabled(isReportistica)
  1757.                                     )
  1758.                             )
  1759.                     ) &&
  1760.                     ((isSistema == null) || !ServletUtils.isCheckBoxEnabled(isSistema)) &&
  1761.                     ((isMessaggi == null) || !ServletUtils.isCheckBoxEnabled(isMessaggi)) &&
  1762.                     ((isUtenti == null) || !ServletUtils.isCheckBoxEnabled(isUtenti)) &&
  1763.                     ((isAuditing == null) || !ServletUtils.isCheckBoxEnabled(isAuditing)) &&
  1764.                     ((isAccordiCooperazione == null) || !ServletUtils.isCheckBoxEnabled(isAccordiCooperazione))) {
  1765.                 this.pd.setMessage("Selezionare almeno un Permesso");
  1766.                 return false;
  1767.             }

  1768.             boolean modalitaPresenti = false;
  1769.             // controllo che abbia selezionato almeno una modalita gateway  
  1770.             for (int i = 0; i < modalitaScelte.length; i++) {
  1771.                 modalitaPresenti  = ((modalitaScelte[i] != null) && ServletUtils.isCheckBoxEnabled(modalitaScelte[i]));
  1772.                
  1773.                 if(modalitaPresenti)
  1774.                     break;
  1775.             }
  1776.            
  1777.             // se l'utenza che sto creando e' solo Utenti ignoro la modalita gateway
  1778.             if(hasOnlyPermessiUtenti(isServizi, isDiagnostica, isReportistica, isSistema, isMessaggi, isUtenti, isAuditing, isAccordiCooperazione, singlePdD)==false) {
  1779.                            
  1780.                 if(!modalitaPresenti) {
  1781.                     this.pd.setMessage("Selezionare almeno un "+org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_DI_HTML_ESCAPE);
  1782.                     return false;
  1783.                 }
  1784.             }
  1785.             else {
  1786.                 if(modalitaPresenti) {
  1787.                     this.pd.setMessage("Se all'utente viene assegnato solamente il Permesso 'U' non deve essere selezionata alcun "+org.openspcoop2.core.constants.Costanti.LABEL_PARAMETRO_PROTOCOLLO_DI_HTML_ESCAPE);
  1788.                     return false;
  1789.                 }
  1790.             }
  1791.            
  1792.             // Se è stato selezionato solo la configurazione senza il permesso dei servizi non ha senso.
  1793.             if(!singlePdD){
  1794.                 /*if( ((isServizi == null) || !isServizi.equals("yes")) &&
  1795.                         ((isMessaggi == null) || !isMessaggi.equals("yes")) &&
  1796.                         ((isSistema != null) && isSistema.equals("yes")) ) {
  1797.                     this.pd.setMessage("Il Permesso 'C' è selezionabile solo in combinazione con i permessi 'S' e/o 'M'");
  1798.                     return false;
  1799.                 }*/
  1800.             }

  1801.             // Controllo che non esistano altri utenti con lo stesso nome
  1802.             if (TipoOperazione.ADD.equals(tipoOperazione)) {
  1803.                 boolean trovato = this.utentiCore.existsUser(nomesu);
  1804.                 if (trovato) {
  1805.                     this.pd.setMessage("Esiste gi&agrave; un utente con nome " + nomesu);
  1806.                     return false;
  1807.                 }
  1808.             }

  1809.             // Se sono in modifica e l'utente modificato non ha il
  1810.             // permesso U, controllo che non fosse proprio l'unico
  1811.             // utente ad avere il permesso U
  1812.             if (TipoOperazione.CHANGE.equals(tipoOperazione) &&
  1813.                     (isUtenti == null || !ServletUtils.isCheckBoxEnabled(isUtenti))) {
  1814.                 List<String> usersWithU = this.utentiCore.getUsersWithType(Permessi.UTENTI.toString());
  1815.                 if (usersWithU.size() == 1 &&
  1816.                         usersWithU.get(0).equals(nomesu)) {
  1817.                     this.pd.setMessage("Non è possibile eliminare il permesso 'Utenti', poichè non esistono altri utenti con tale permesso");
  1818.                     return false;
  1819.                 }
  1820.             }



  1821.             return true;

  1822.         } catch (Exception e) {
  1823.             this.log.error("Exception: " + e.getMessage(), e);
  1824.             throw new Exception(e);
  1825.         }
  1826.     }

  1827.     boolean changePwCheckData() throws Exception {

  1828.         try{

  1829.             String oldpw = this.getParameter(UtentiCostanti.PARAMETRO_UTENTE_VECCHIA_PW);
  1830.             String newpw = this.getParameter(UtentiCostanti.PARAMETRO_UTENTE_NUOVA_PW);
  1831.             String confpw = this.getParameter(UtentiCostanti.PARAMETRO_UTENTE_CONFERMA_NUOVA_PW);
  1832.             String changepwd = this.getParameter(UtentiCostanti.PARAMETRO_UTENTE_CHANGE_PW);

  1833.             if (!ServletUtils.isCheckBoxEnabled(changepwd)) {
  1834.                 // non si vuole cambiare le pwd
  1835.                 return true;
  1836.             }

  1837.             // String cpwd = this.procToCall.cryptPw(oldpw);
  1838.             User user = ServletUtils.getUserFromSession(this.request, this.session);

  1839.             if(user.getPermessi().isUtenti()==false){
  1840.                 boolean trovato = this.utentiCore.getUtenzePasswordManager().check(oldpw, user.getPassword());
  1841.                 if(!trovato && this.utentiCore.getUtenzePasswordManagerBackwardCompatibility()!=null) {
  1842.                     trovato = this.utentiCore.getUtenzePasswordManagerBackwardCompatibility().check(oldpw, user.getPassword());
  1843.                 }
  1844.                 if (!trovato) {
  1845.                     this.pd.setMessage("La vecchia password indicata non e' corretta");
  1846.                     return false;
  1847.                 }
  1848.                
  1849.                 // Controllo che non ci siano spazi nei campi di testo
  1850.                 if ((oldpw.indexOf(" ") != -1)) {
  1851.                     this.pd.setMessage("Non inserire spazi nei campi di testo");
  1852.                     return false;
  1853.                 }
  1854.             }

  1855.             // Campi obbligatori
  1856.             if ( (newpw==null || newpw.equals("")) || (confpw==null || confpw.equals("")) ) {
  1857.                 this.pd.setMessage("Dati incompleti. &Egrave; necessario indicare una password");
  1858.                 return false;
  1859.             }

  1860.             // Controllo che non ci siano spazi nei campi di testo
  1861.             if ((newpw.indexOf(" ") != -1) || (confpw.indexOf(" ") != -1)) {
  1862.                 this.pd.setMessage("Non inserire spazi nei campi di testo");
  1863.                 return false;
  1864.             }

  1865.             // Controllo che la vecchia password e la nuova corrispondano
  1866.             if(user.getPermessi().isUtenti()==false){
  1867.                 if (oldpw.equals(newpw)) {
  1868.                     this.pd.setMessage("La nuova password deve essere differente dalla vecchia");
  1869.                     return false;
  1870.                 }
  1871.             }
  1872.            
  1873.             // Controllo che le password corrispondano
  1874.             if (!newpw.equals(confpw)) {
  1875.                 this.pd.setMessage(UtentiCostanti.MESSAGGIO_ERRORE_PASSWORD_NUOVE_DIFFERENTI);
  1876.                 return false;
  1877.             }

  1878.             PasswordVerifier passwordVerifier = this.utentiCore.getUtenzePasswordVerifier();
  1879.             if(passwordVerifier!=null){
  1880.                 StringBuilder motivazioneErrore = new StringBuilder();
  1881.                 if(passwordVerifier.validate(user.getLogin(), newpw, motivazioneErrore)==false){
  1882.                     this.pd.setMessage(motivazioneErrore.toString());
  1883.                     return false;
  1884.                 }
  1885.                
  1886.                 // controllo storico password in caso di change
  1887.                 if(passwordVerifier.isHistory()) {
  1888.                     List<UserPassword> precedentiPassword = user.getPrecedentiPassword();
  1889.                    
  1890. //                  String tmpPass = newpw;
  1891. //                  if(this.utentiCore.isUtenzePasswordEncryptEnabled()) {
  1892. //                      tmpPass = this.utentiCore.getUtenzePasswordManager().crypt(newpw);
  1893. //                  }
  1894.                    
  1895.                     if(precedentiPassword == null || precedentiPassword.isEmpty()) {
  1896.                         boolean trovato = this.utentiCore.getUtenzePasswordManager().check(newpw, user.getPassword());
  1897.                         if(!trovato && this.utentiCore.getUtenzePasswordManagerBackwardCompatibility()!=null) {
  1898.                             trovato = this.utentiCore.getUtenzePasswordManagerBackwardCompatibility().check(newpw, user.getPassword());
  1899.                         }
  1900.                         if (trovato) {
  1901.                             this.pd.setMessage(UtentiCostanti.MESSAGGIO_ERRORE_PASSWORD_GIA_UTILIZZATA);
  1902.                             return false;
  1903.                         }
  1904.                     }
  1905.                    
  1906.                     for (UserPassword userPassword : precedentiPassword) {
  1907.                         boolean trovato = this.utentiCore.getUtenzePasswordManager().check(newpw, userPassword.getPassword());
  1908.                         if(!trovato && this.utentiCore.getUtenzePasswordManagerBackwardCompatibility()!=null) {
  1909.                             trovato = this.utentiCore.getUtenzePasswordManagerBackwardCompatibility().check(newpw, userPassword.getPassword());
  1910.                         }
  1911.                         if (trovato) {
  1912.                             this.pd.setMessage(UtentiCostanti.MESSAGGIO_ERRORE_PASSWORD_GIA_UTILIZZATA);
  1913.                             return false;
  1914.                         }
  1915.                     }
  1916.                 }
  1917.             }
  1918.            
  1919.             return true;

  1920.         } catch (Exception e) {
  1921.             this.log.error("Exception: " + e.getMessage(), e);
  1922.             throw new Exception(e);
  1923.         }
  1924.     }

  1925.     public void prepareUtentiList(ISearch ricerca, List<User> lista, boolean singlePdD) throws Exception {
  1926.         try {
  1927.             ServletUtils.addListElementIntoSession(this.request, this.session, UtentiCostanti.OBJECT_NAME_UTENTI);

  1928.             String userLogin = ServletUtils.getUserLoginFromSession(this.session);

  1929.             int idLista = Liste.SU;
  1930.             int limit = ricerca.getPageSize(idLista);
  1931.             int offset = ricerca.getIndexIniziale(idLista);
  1932.             String search = ServletUtils.getSearchFromSession(ricerca, idLista);

  1933.             this.pd.setIndex(offset);
  1934.             this.pd.setPageSize(limit);
  1935.             this.pd.setNumEntries(ricerca.getNumEntries(idLista));

  1936.             // setto la barra del titolo
  1937.             if (search.equals("")) {
  1938.                 this.pd.setSearchDescription("");
  1939.                 ServletUtils.setPageDataTitle(this.pd,
  1940.                         new Parameter(UtentiCostanti.LABEL_UTENTI, UtentiCostanti.SERVLET_NAME_UTENTI_LIST));
  1941.             }
  1942.             else{
  1943.                 ServletUtils.setPageDataTitle(this.pd,
  1944.                         new Parameter(UtentiCostanti.LABEL_UTENTI, UtentiCostanti.SERVLET_NAME_UTENTI_LIST),
  1945.                         new Parameter(Costanti.PAGE_DATA_TITLE_LABEL_RISULTATI_RICERCA, null));
  1946.             }

  1947.             // controllo eventuali risultati ricerca
  1948.             if (!search.equals("")) {
  1949.                 ServletUtils.enabledPageDataSearch(this.pd, UtentiCostanti.LABEL_UTENTI, search);
  1950.             }

  1951.             // setto le label delle colonne
  1952.             String[] labels = {
  1953.                     "",
  1954.                     UtentiCostanti.LABEL_UTENTE, UtentiCostanti.LABEL_MODALITA_INTERFACCIA,
  1955.                     UtentiCostanti.LABEL_MODALITA_GATEWAY_COMPACT,
  1956.                     UtentiCostanti.LABEL_PERMESSI_GESTIONE, UtentiCostanti.LABEL_CAMBIA_IDENTITA };
  1957.             this.pd.setLabels(labels);

  1958.             // preparo i dati
  1959.             List<List<DataElement>> dati = new ArrayList<>();
  1960.            
  1961.             PasswordVerifier passwordVerifier = this.utentiCore.getUtenzePasswordVerifier();

  1962.             if (lista != null) {
  1963.                 Iterator<User> it = lista.iterator();
  1964.                 while (it.hasNext()) {
  1965.                     User mySU = it.next();

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

  1967.                     // Stato utente
  1968.                     DataElement de = new DataElement();
  1969.                     de.setWidthPx(10);
  1970.                     de.setType(DataElementType.CHECKBOX);
  1971.                     if(mySU.isConfigurazioneValidaAbilitazioni()){
  1972.                         de.setSelected(CheckboxStatusType.ABILITATO);
  1973.                     }
  1974.                     else{
  1975.                         de.setToolTip(mySU.getReasonInvalidConfiguration());
  1976.                         de.setValue(mySU.getReasonInvalidConfiguration());
  1977.                         de.setSelected(CheckboxStatusType.DISABILITATO);
  1978.                     }
  1979.                    
  1980.                     // se e' abilitato il check di scadenza delle password e la password e' scaduta imposto il check rosso
  1981.                     if(this.core.isCheckPasswordExpire(passwordVerifier)) {
  1982.                         if(mySU.isCheckLastUpdatePassword()) {
  1983.                             if(passwordVerifier.isPasswordExpire(mySU.getLastUpdatePassword())) {
  1984.                                 de.setToolTip(UtentiCostanti.LABEL_UTENTI_SCADENZA_PW_SCADUTA);
  1985.                                 de.setValue(UtentiCostanti.LABEL_UTENTI_SCADENZA_PW_SCADUTA);
  1986.                                 de.setSelected(CheckboxStatusType.DISABILITATO);
  1987.                             }
  1988.                         }
  1989.                     }
  1990.                    
  1991.                     de.setUrl(UtentiCostanti.SERVLET_NAME_UTENTI_CHANGE,
  1992.                             new Parameter(UtentiCostanti.PARAMETRO_UTENTI_USERNAME, mySU.getLogin()));
  1993.                     e.add(de);
  1994.                    
  1995.                     // nome utente
  1996.                     de = new DataElement();
  1997.                     de.setUrl(UtentiCostanti.SERVLET_NAME_UTENTI_CHANGE,
  1998.                             new Parameter(UtentiCostanti.PARAMETRO_UTENTI_USERNAME, mySU.getLogin()));
  1999.                     de.setIdToRemove(mySU.getId().toString());
  2000.                     de.setValue(mySU.getLogin());
  2001.                     e.add(de);

  2002.                     // modalita interfaccia
  2003.                     de = new DataElement();
  2004.                     if(mySU.hasOnlyPermessiUtenti()) {
  2005.                         de.setValue("-");
  2006.                     }
  2007.                     else {
  2008.                         de.setValue(mySU.getInterfaceType().toString().toLowerCase());
  2009.                     }
  2010.                     e.add(de);
  2011.                    
  2012.                     // modalita gateway
  2013.                     de = new DataElement();
  2014.                    
  2015.                     List<String> protocolliSupportati = mySU.getProtocolliSupportati();
  2016.                     if(protocolliSupportati == null)
  2017.                         protocolliSupportati = new ArrayList<>();
  2018.                    
  2019.                     if(mySU.hasOnlyPermessiUtenti()) {
  2020.                         de.setValue("-");
  2021.                     }
  2022.                     else {
  2023.                         if(protocolliSupportati.size() > 0) {
  2024.                             Collections.sort(protocolliSupportati);
  2025.                             List<String> protocolliInstallati = this.core.getProtocolli();
  2026.                             Collections.sort(protocolliInstallati);
  2027.                            
  2028.                             String labelProtocolli = null;
  2029.                             if(protocolliSupportati.size() == protocolliInstallati.size()) {
  2030.                                 boolean all = true;
  2031.                                 for (int i = 0; i < protocolliInstallati.size(); i++) {
  2032.                                     String pI = protocolliInstallati.get(i);
  2033.                                     String pS = protocolliSupportati.get(i);
  2034.                                    
  2035.                                     if(!pI.equals(pS)) {
  2036.                                         all=false;
  2037.                                         break;
  2038.                                     }
  2039.                                 }
  2040.                                
  2041.                                 if(all)
  2042.                                     labelProtocolli = UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL;
  2043.                             }
  2044.                            
  2045.                             if(labelProtocolli == null) {
  2046.                                 StringBuilder sb = new StringBuilder();
  2047.                                 for (int i = 0; i < protocolliSupportati.size(); i++) {
  2048.                                     String pS = protocolliSupportati.get(i);
  2049.                                     if(sb.length() > 0)
  2050.                                         sb.append(", ");
  2051.                                    
  2052.                                     sb.append(this.getLabelProtocollo(pS));
  2053.                                 }
  2054.                                 labelProtocolli = sb.toString();
  2055.                             }
  2056.                            
  2057.                             de.setValue(labelProtocolli);
  2058.                         } else {
  2059.                             de.setValue(UtentiCostanti.LABEL_PARAMETRO_MODALITA_ALL);
  2060.                         }
  2061.                     }
  2062.                     e.add(de);

  2063.                     // permessi utente
  2064.                     de = new DataElement();
  2065.                     if(singlePdD){
  2066.                         de.setValue(mySU.getPermessi().toString(","));
  2067.                     }else{
  2068.                         PermessiUtente maschera = new PermessiUtente();
  2069.                         maschera.setAuditing(true);
  2070.                         maschera.setServizi(true);
  2071.                         maschera.setSistema(true);
  2072.                         maschera.setUtenti(true);
  2073.                         maschera.setCodeMessaggi(true);
  2074.                         maschera.setAccordiCooperazione(true);
  2075.                         de.setValue(mySU.getPermessi().toString(",",maschera));
  2076.                     }
  2077.                     e.add(de);

  2078.                     // login as su
  2079.                     de = new DataElement();
  2080.                     if (!userLogin.equals(mySU.getLogin()) && !this.hasOnlyPermessiDiagnosticaReportistica(mySU) &&
  2081.                             mySU.isConfigurazioneValidaAbilitazioni()) {
  2082.                         de.setUrl(LoginCostanti.SERVLET_NAME_LOGIN_AS_SU,
  2083.                                 new Parameter(LoginCostanti.PARAMETRO_LOGIN_LOGIN, mySU.getLogin()));
  2084.                         de.setValue(UtentiCostanti.LABEL_ACCEDI);
  2085.                     } else
  2086.                         de.setValue("");
  2087.                     e.add(de);

  2088.                     dati.add(e);
  2089.                 }
  2090.             }

  2091.             this.pd.setDati(dati);
  2092.             this.pd.setAddButton(true);
  2093.         } catch (Exception e) {
  2094.             this.log.error("Exception: " + e.getMessage(), e);
  2095.             throw new Exception(e);
  2096.         }
  2097.     }
  2098.    
  2099.     public List<String> controlloModalitaUtenteDaEliminare(List<String> nomiUtentiDaRimuovere, List<String> utentiDaNonEliminare, User user) throws DriverRegistroServiziException, DriverUsersDBException {
  2100.         return controlloModalitaUtenteDaEliminare(nomiUtentiDaRimuovere, utentiDaNonEliminare, user, user.getProtocolliSupportati());
  2101.     }
  2102.    
  2103.     public List<String> controlloModalitaUtenteDaEliminare(List<String> nomiUtentiDaRimuovere, List<String> utentiDaNonEliminare, User user, List<String> protocolliSupportati) throws DriverRegistroServiziException, DriverUsersDBException {
  2104.         List<String> protocolliNonPiuAssociati = new ArrayList<>();
  2105.         if(protocolliSupportati != null && protocolliSupportati.size() > 0) {
  2106.             for (String protocollo : protocolliSupportati) {
  2107.                 boolean protocolloNonPiuAssociato = controllaEsistenzaUtentePerAssociareIlProtocollo(nomiUtentiDaRimuovere, utentiDaNonEliminare, user.getLogin(), protocollo);
  2108.                 if(protocolloNonPiuAssociato)
  2109.                 protocolliNonPiuAssociati.add(protocollo);
  2110.             }
  2111.         }
  2112.        
  2113.         return protocolliNonPiuAssociati;
  2114.     }

  2115.     public boolean controllaEsistenzaUtentePerAssociareIlProtocollo(List<String> nomiUtentiDaRimuovere, List<String> utentiDaNonEliminare, String userLogin,
  2116.             String protocollo) throws DriverRegistroServiziException, DriverUsersDBException {
  2117.         boolean protocolloNonPiuAssociato = false;
  2118.         boolean existsAlmostOneOrganization = this.utentiCore.existsAlmostOneOrganization(null, userLogin, protocollo);
  2119.         if(existsAlmostOneOrganization) {
  2120.             List<String> usersByProtocolloSupportatoTmp = this.utentiCore.getUsersByProtocolloSupportato(protocollo,true);
  2121.            
  2122.             List<String> usersByProtocolloSupportato = new ArrayList<>();
  2123.             for (String uDE : usersByProtocolloSupportatoTmp) {
  2124.                 if(nomiUtentiDaRimuovere.contains(uDE) == false) {
  2125.                     usersByProtocolloSupportato.add(uDE);
  2126.                 }
  2127.             }
  2128.            
  2129.             if(usersByProtocolloSupportato.size() < 1) {
  2130.                 protocolloNonPiuAssociato = true;
  2131.                 if(!utentiDaNonEliminare.contains(userLogin))
  2132.                     utentiDaNonEliminare.add(userLogin);
  2133.             }
  2134.         }
  2135.        
  2136.         return protocolloNonPiuAssociato;
  2137.     }
  2138.    
  2139.    
  2140.     /***
  2141.      * Restituisce true se l'utente User puo' gestire tutte le modalita' dell'utente userToCheck
  2142.      *
  2143.      * @param userLoginToCheck
  2144.      * @param userLogin
  2145.      * @return true se l'utente User puo' gestire tutte le modalita' dell'utente userToCheck
  2146.      * @throws DriverUsersDBException
  2147.      */
  2148.     public boolean checkUsersModalitaGatewayCompatibili(String userLoginToCheck, String userLogin) throws DriverUsersDBException {
  2149.         User userToCheck = this.utentiCore.getUser(userLoginToCheck);
  2150.         User user = this.utentiCore.getUser(userLogin);
  2151.         return checkUsersModalitaGatewayCompatibili(userToCheck, user);
  2152.     }
  2153.    
  2154.     /***
  2155.      * Restituisce true se l'utente User puo' gestire tutte le modalita' dell'utente userToCheck
  2156.      *
  2157.      * @param userToCheck
  2158.      * @param user
  2159.      * @return true se l'utente User puo' gestire tutte le modalita' dell'utente userToCheck
  2160.      */
  2161.     public boolean checkUsersModalitaGatewayCompatibili(User userToCheck, User user) {
  2162.         // utente che sto controllando e' un utente che gestisce solo utenti, non ci sono controlli da effettuare
  2163.         if(userToCheck.hasOnlyPermessiUtenti()) return true;
  2164.        
  2165.         // se l'utente destinazione possiede tutti i protocolli allora non ci sono controlli da fare
  2166.         List<String> protocolliRegistratiConsole = this.utentiCore.getProtocolli();
  2167.         if(user.getProtocolliSupportati() == null) return true;
  2168.        
  2169.         boolean userHasAll= true;
  2170.         for (String protocolloConsole : protocolliRegistratiConsole) {
  2171.             if(!user.getProtocolliSupportati().contains(protocolloConsole)) {
  2172.                 userHasAll = false;
  2173.                 break;
  2174.             }
  2175.         }
  2176.        
  2177.         // se l'utente li ha tutti il controllo e' ok
  2178.         if(userHasAll) return true;
  2179.        
  2180.         // l'utente destinazione non gestisce tutti i protocolli, se userTocheck li aveva tutti allora user non puo' gestire tutte le modalita di userTocheck
  2181.         if(userToCheck.getProtocolliSupportati() == null) return false;
  2182.        
  2183.         boolean usertoCheckHasAll= true;
  2184.         for (String protocolloConsole : protocolliRegistratiConsole) {
  2185.             if(!userToCheck.getProtocolliSupportati().contains(protocolloConsole)) {
  2186.                 usertoCheckHasAll = false;
  2187.                 break;
  2188.             }
  2189.         }
  2190.        
  2191.         if(usertoCheckHasAll) return false;
  2192.        
  2193.         // a questo punto nessuno dei due utenti possiede tutte le modalita'
  2194.         // cerco semplicemente la prima modalita' posseduta da userToCheck che non puo' essere gestita da user.
  2195.         for (String protocolloUserToCheck : userToCheck.getProtocolliSupportati()) {
  2196.             if(!user.getProtocolliSupportati().contains(protocolloUserToCheck))
  2197.                 return false;
  2198.         }
  2199.        
  2200.         return true;
  2201.        
  2202.     }

  2203.     public void prepareUtentiSoggettiList(ConsoleSearch ricerca, List<IDSoggetto> lista, User user) throws Exception{
  2204.         try {
  2205.             ServletUtils.addListElementIntoSession(this.request, this.session, UtentiCostanti.OBJECT_NAME_UTENTI_SOGGETTI,
  2206.                     new Parameter(UtentiCostanti.PARAMETRO_UTENTI_USERNAME, user.getLogin()));

  2207.             int idLista = Liste.UTENTI_SOGGETTI;
  2208.             int limit = ricerca.getPageSize(idLista);
  2209.             int offset = ricerca.getIndexIniziale(idLista);
  2210.             String search = ServletUtils.getSearchFromSession(ricerca, idLista);
  2211.            
  2212.             addFilterProtocol(ricerca, idLista, user.getProtocolliSupportati());

  2213.             this.pd.setIndex(offset);
  2214.             this.pd.setPageSize(limit);
  2215.             this.pd.setNumEntries(ricerca.getNumEntries(idLista));
  2216.            
  2217.             boolean showProtocolli = (user.getProtocolliSupportati() != null && user.getProtocolliSupportati().size() >1);
  2218.            
  2219.             List<Parameter> lstParam = new ArrayList<>();
  2220.             lstParam.add(new Parameter(UtentiCostanti.LABEL_UTENTI ,UtentiCostanti.SERVLET_NAME_UTENTI_LIST));
  2221.             lstParam.add(new Parameter(user.getLogin(), UtentiCostanti.SERVLET_NAME_UTENTI_CHANGE, new Parameter(UtentiCostanti.PARAMETRO_UTENTI_USERNAME, user.getLogin())));
  2222.             // setto la barra del titolo
  2223.             if (search.equals("")) {
  2224.                 this.pd.setSearchDescription("");
  2225.                 lstParam.add(new Parameter(UtentiCostanti.LABEL_UTENTI_SOGGETTI, null));
  2226.             }else {
  2227.                 lstParam.add(new Parameter(UtentiCostanti.LABEL_UTENTI_SOGGETTI, UtentiCostanti.SERVLET_NAME_UTENTI_SOGGETTI_LIST,
  2228.                         new Parameter(UtentiCostanti.PARAMETRO_UTENTI_USERNAME, user.getLogin())));
  2229.                 lstParam.add(new Parameter(Costanti.PAGE_DATA_TITLE_LABEL_RISULTATI_RICERCA, null));    
  2230.             }
  2231.            
  2232.             // controllo eventuali risultati ricerca
  2233.             this.pd.setSearchLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_SOGGETTO);
  2234.             if (!search.equals("")) {
  2235.                 ServletUtils.enabledPageDataSearch(this.pd, UtentiCostanti.LABEL_UTENTI_SOGGETTI, search);
  2236.             }
  2237.            
  2238.             ServletUtils.setPageDataTitle(this.pd,lstParam);
  2239.                    
  2240.             // setto le label delle colonne
  2241.             int totEl = 1;
  2242.             if( showProtocolli ) {
  2243.                 totEl++;
  2244.             }
  2245.             String[] labels = new String[totEl];
  2246.             int i = 0;
  2247.             labels[i++] = UtentiCostanti.LABEL_PARAMETRO_UTENTI_SOGGETTO;
  2248.             if( showProtocolli ) {
  2249.                 labels[i++] = UtentiCostanti.LABEL_PARAMETRO_UTENTI_PROTOCOLLO;
  2250.             }
  2251.             this.pd.setLabels(labels);

  2252.             // preparo i dati
  2253.             List<List<DataElement>> dati = new ArrayList<>();
  2254.            
  2255.             if (lista != null) {
  2256.                 Iterator<IDSoggetto> it = lista.iterator();
  2257.                 while (it.hasNext()) {
  2258.                     IDSoggetto soggetto = it.next();

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

  2260.                     String protocollo = this.soggettiCore.getProtocolloAssociatoTipoSoggetto(soggetto.getTipo());
  2261.                     // soggetto
  2262.                     DataElement de = new DataElement();
  2263.                     de.setValue(this.getLabelNomeSoggetto(protocollo, soggetto.getTipo(), soggetto.getNome()));
  2264.                     de.setIdToRemove(soggetto.getTipo() + "/" + soggetto.getNome());
  2265.                     de.setToolTip(this.getLabelNomeSoggetto(protocollo, soggetto.getTipo(), soggetto.getNome()));
  2266.                     e.add(de);
  2267.                    
  2268.                     if(showProtocolli) {
  2269.                         de = new DataElement();
  2270.                         de.setValue(this.getLabelProtocollo(this.soggettiCore.getProtocolloAssociatoTipoSoggetto(soggetto.getTipo())));
  2271.                         e.add(de);
  2272.                     }
  2273.                    
  2274.                     dati.add(e);
  2275.                 }
  2276.             }
  2277.                    
  2278.             this.pd.setDati(dati);
  2279.             this.pd.setAddButton(true);
  2280.         } catch (Exception e) {
  2281.             this.log.error("Exception: " + e.getMessage(), e);
  2282.             throw new Exception(e);
  2283.         }
  2284.     }
  2285.    
  2286.     public void prepareUtentiServiziList(ConsoleSearch ricerca, List<IDServizio> lista, User user) throws Exception{
  2287.         try {
  2288.             ServletUtils.addListElementIntoSession(this.request, this.session, UtentiCostanti.OBJECT_NAME_UTENTI_SERVIZI,
  2289.                     new Parameter(UtentiCostanti.PARAMETRO_UTENTI_USERNAME, user.getLogin()));

  2290.             int idLista = Liste.UTENTI_SERVIZI;
  2291.             int limit = ricerca.getPageSize(idLista);
  2292.             int offset = ricerca.getIndexIniziale(idLista);
  2293.             String search = ServletUtils.getSearchFromSession(ricerca, idLista);
  2294.            
  2295.             addFilterProtocol(ricerca, idLista, user.getProtocolliSupportati());

  2296.             this.pd.setIndex(offset);
  2297.             this.pd.setPageSize(limit);
  2298.             this.pd.setNumEntries(ricerca.getNumEntries(idLista));
  2299.            
  2300.             boolean showProtocolli = (user.getProtocolliSupportati() != null && user.getProtocolliSupportati().size() >1);
  2301.            
  2302.             List<Parameter> lstParam = new ArrayList<>();
  2303.             lstParam.add(new Parameter(UtentiCostanti.LABEL_UTENTI ,UtentiCostanti.SERVLET_NAME_UTENTI_LIST));
  2304.             lstParam.add(new Parameter(user.getLogin(), UtentiCostanti.SERVLET_NAME_UTENTI_CHANGE, new Parameter(UtentiCostanti.PARAMETRO_UTENTI_USERNAME, user.getLogin())));
  2305.             // setto la barra del titolo
  2306.             if (search.equals("")) {
  2307.                 this.pd.setSearchDescription("");
  2308.                 lstParam.add(new Parameter(UtentiCostanti.LABEL_UTENTI_SERVIZI, null));
  2309.             }else {
  2310.                 lstParam.add(new Parameter(UtentiCostanti.LABEL_UTENTI_SERVIZI, UtentiCostanti.SERVLET_NAME_UTENTI_SERVIZI_LIST,
  2311.                         new Parameter(UtentiCostanti.PARAMETRO_UTENTI_USERNAME, user.getLogin())));
  2312.                 lstParam.add(new Parameter(Costanti.PAGE_DATA_TITLE_LABEL_RISULTATI_RICERCA, null));    
  2313.             }
  2314.            
  2315.             // controllo eventuali risultati ricerca
  2316.             this.pd.setSearchLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_SERVIZIO);
  2317.             if (!search.equals("")) {
  2318.                 ServletUtils.enabledPageDataSearch(this.pd, UtentiCostanti.LABEL_UTENTI_SERVIZI, search);
  2319.             }
  2320.            
  2321.             ServletUtils.setPageDataTitle(this.pd,lstParam);
  2322.                    
  2323.             // setto le label delle colonne
  2324.             int totEl = 2;
  2325.             if( showProtocolli ) {
  2326.                 totEl++;
  2327.             }
  2328.             String[] labels = new String[totEl];
  2329.             int i = 0;
  2330.             labels[i++] = UtentiCostanti.LABEL_PARAMETRO_UTENTI_SERVIZIO;
  2331.             labels[i++] = UtentiCostanti.LABEL_PARAMETRO_UTENTI_SOGGETTO_EROGATORE;
  2332.             if( showProtocolli ) {
  2333.                 labels[i++] = UtentiCostanti.LABEL_PARAMETRO_UTENTI_PROTOCOLLO;
  2334.             }
  2335.             this.pd.setLabels(labels);
  2336.             this.pd.setLabels(labels);

  2337.             // preparo i dati
  2338.             List<List<DataElement>> dati = new ArrayList<>();
  2339.            
  2340.             if (lista != null) {
  2341.                 Iterator<IDServizio> it = lista.iterator();
  2342.                 while (it.hasNext()) {
  2343.                     IDServizio servizio = it.next();
  2344.                     List<DataElement> e = new ArrayList<>();

  2345.                     String protocollo = this.soggettiCore.getProtocolloAssociatoTipoSoggetto(servizio.getTipo());
  2346.                     String uriASPS = this.idServizioFactory.getUriFromIDServizio(servizio);

  2347.                     // servizio
  2348.                     DataElement de = new DataElement();
  2349.                     de.setValue(this.getLabelNomeServizio(protocollo, servizio.getTipo(), servizio.getNome(), servizio.getVersione()));
  2350.                     de.setIdToRemove(uriASPS);
  2351.                     e.add(de);
  2352.                    
  2353.                     // soggetto
  2354.                     de = new DataElement();
  2355.                     de.setValue(this.getLabelNomeSoggetto(protocollo, servizio.getSoggettoErogatore().getTipo(), servizio.getSoggettoErogatore().getNome()));
  2356.                     e.add(de);
  2357.                    
  2358.                     if(showProtocolli) {
  2359.                         de = new DataElement();
  2360.                         de.setValue(this.getLabelProtocollo(protocollo));
  2361.                         e.add(de);
  2362.                     }
  2363.                    
  2364.                     dati.add(e);
  2365.                 }
  2366.             }
  2367.                    
  2368.             this.pd.setDati(dati);
  2369.             this.pd.setAddButton(true);
  2370.         } catch (Exception e) {
  2371.             this.log.error("Exception: " + e.getMessage(), e);
  2372.             throw new Exception(e);
  2373.         }
  2374.     }

  2375.     public void addUtentiSoggettiToDati(List<DataElement> dati, TipoOperazione tipoOperazione, String nomesu, String soggetto, String[] soggettiValues, String[] soggettiLabels, List<String> listaTipiProtocollo, String tipoProtocollo) throws Exception {

  2376.         DataElement de = new DataElement();
  2377.         de.setLabel(UtentiCostanti.LABEL_UTENTI_SOGGETTI);
  2378.         de.setType(DataElementType.TITLE);
  2379.         dati.add(de);

  2380.         de = new DataElement();
  2381.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_USERNAME);
  2382.         de.setValue(nomesu);
  2383.         de.setType(DataElementType.HIDDEN);
  2384.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_USERNAME);
  2385.         dati.add(de);
  2386.        
  2387.         de = new DataElement();
  2388.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_PROTOCOLLO);
  2389.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_PROTOCOLLO);
  2390.         if(listaTipiProtocollo != null && listaTipiProtocollo.size() > 1){
  2391.                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_PROTOCOLLO);
  2392.                 de.setValues(listaTipiProtocollo);
  2393.                 de.setLabels(this.getLabelsProtocolli(listaTipiProtocollo));
  2394.                 de.setSelected(tipoProtocollo);
  2395.                 de.setType(DataElementType.SELECT);
  2396.                 de.setPostBack(true);
  2397.         } else {
  2398.             de.setValue(tipoProtocollo);
  2399.             de.setType(DataElementType.HIDDEN);
  2400.         }
  2401.        
  2402.         de.setSize(this.getSize());
  2403.         dati.add(de);
  2404.        
  2405.         de = new DataElement();
  2406.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_SOGGETTO);
  2407.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_SOGGETTO);
  2408.         if(soggettiValues != null && soggettiValues.length > 1){
  2409.             de.setType(DataElementType.SELECT);    
  2410.             de.setValues(soggettiValues);
  2411.             de.setLabels(soggettiLabels);
  2412.             de.setSelected(soggetto);
  2413.             de.setRequired(true);
  2414.         } else {
  2415.             de.setValue(soggetto);
  2416.             de.setType(DataElementType.HIDDEN);
  2417.         }
  2418.         dati.add(de);
  2419.        
  2420.     }
  2421.    
  2422.     public void addUtentiServiziToDati(List<DataElement> dati, TipoOperazione tipoOperazione, String nomesu, String servizio, String[] serviziValues, String[] serviziLabels, List<String> listaTipiProtocollo, String tipoProtocollo) throws Exception {

  2423.         DataElement de = new DataElement();
  2424.         de.setLabel(UtentiCostanti.LABEL_UTENTI_SERVIZI);
  2425.         de.setType(DataElementType.TITLE);
  2426.         dati.add(de);

  2427.         de = new DataElement();
  2428.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_USERNAME);
  2429.         de.setValue(nomesu);
  2430.         de.setType(DataElementType.HIDDEN);
  2431.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_USERNAME);
  2432.         dati.add(de);
  2433.        
  2434.         de = new DataElement();
  2435.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_PROTOCOLLO);
  2436.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_PROTOCOLLO);
  2437.         if(listaTipiProtocollo != null && listaTipiProtocollo.size() > 1){
  2438.                 de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_PROTOCOLLO);
  2439.                 de.setValues(listaTipiProtocollo);
  2440.                 de.setLabels(this.getLabelsProtocolli(listaTipiProtocollo));
  2441.                 de.setSelected(tipoProtocollo);
  2442.                 de.setType(DataElementType.SELECT);
  2443.                 de.setPostBack(true);
  2444.         } else {
  2445.             de.setValue(tipoProtocollo);
  2446.             de.setType(DataElementType.HIDDEN);
  2447.         }
  2448.         de.setSize(this.getSize());
  2449.         dati.add(de);
  2450.        
  2451.         de = new DataElement();
  2452.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTI_SERVIZIO);
  2453.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_SERVIZIO);
  2454.         if(serviziValues != null && serviziValues.length > 1){
  2455.             de.setType(DataElementType.SELECT);    
  2456.             de.setValues(serviziValues);
  2457.             de.setLabels(serviziLabels);
  2458.             de.setSelected(servizio);
  2459.             de.setRequired(true);
  2460.         } else {
  2461.             de.setValue(servizio);
  2462.             de.setType(DataElementType.HIDDEN);
  2463.         }
  2464.         dati.add(de);
  2465.        
  2466.     }

  2467.     public boolean utentiSoggettiCheckData(TipoOperazione tipoOperazione, String nomesu, String soggetto) throws Exception{
  2468.         // controllo selezione soggetto
  2469.         if (StringUtils.isEmpty(soggetto) || soggetto.equals(CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO)) {
  2470.             this.pd.setMessage(UtentiCostanti.MESSAGGIO_ERRORE_NOME_SOGGETTO_OBBLIGATORIO);
  2471.             return false;
  2472.         }
  2473.        
  2474.         return true;
  2475.     }
  2476.    
  2477.     public boolean utentiServiziCheckData(TipoOperazione tipoOperazione, String nomesu, String servizio) throws Exception{
  2478.         // controllo selezione soggetto
  2479.         if (StringUtils.isEmpty(servizio) || servizio.equals(CostantiControlStation.DEFAULT_VALUE_NON_SELEZIONATO)) {
  2480.             this.pd.setMessage(UtentiCostanti.MESSAGGIO_ERRORE_NOME_SERVIZIO_OBBLIGATORIO);
  2481.             return false;
  2482.         }
  2483.        
  2484.         return true;
  2485.     }
  2486.    
  2487.     public void addUtenteChangePasswordScadutaToDati(List<DataElement> dati, TipoOperazione tipoOperazione) throws Exception{

  2488.         DataElement de = new DataElement();
  2489.         de.setName(UtentiCostanti.PARAMETRO_UTENTI_FIRST);
  2490.         de.setType(DataElementType.HIDDEN);
  2491.         de.setValue("false");
  2492.         dati.add(de);
  2493.        
  2494.         de = new DataElement();
  2495.         de.setLabel(UtentiCostanti.LABEL_PASSWORD);
  2496.         de.setType(DataElementType.TITLE);
  2497.         dati.add(de);

  2498.         PasswordVerifier passwordVerifier = this.utentiCore.getUtenzePasswordVerifier();
  2499.        
  2500.         de = new DataElement();
  2501.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTE_VECCHIA_PW);
  2502.         de.setType(DataElementType.CRYPT);
  2503.         de.setName(UtentiCostanti.PARAMETRO_UTENTE_VECCHIA_PW);
  2504.         de.setValue("");
  2505.         de.setSize(this.getSize());
  2506.         de.setRequired(true);
  2507.         dati.add(de);
  2508.            
  2509.         de = new DataElement();
  2510.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTE_NUOVA_PW);
  2511.         de.setType(DataElementType.CRYPT);
  2512.         de.setName(UtentiCostanti.PARAMETRO_UTENTE_NUOVA_PW);
  2513.         de.setSize(this.getSize());
  2514.         de.setValue("");
  2515.         de.setRequired(true);
  2516.         dati.add(de);

  2517.         de = new DataElement();
  2518.         de.setLabel(UtentiCostanti.LABEL_PARAMETRO_UTENTE_CONFERMA_NUOVA_PW);
  2519.         de.setType(DataElementType.CRYPT);
  2520.         de.setName(UtentiCostanti.PARAMETRO_UTENTE_CONFERMA_NUOVA_PW);
  2521.         de.setSize(this.getSize());
  2522.         de.setValue("");
  2523.         de.setRequired(true);
  2524.         if(passwordVerifier!=null){
  2525.             de.setNote(passwordVerifier.helpUpdate(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE));
  2526.         }
  2527.         dati.add(de);

  2528.         de = new DataElement();
  2529.         de.setType(DataElementType.HIDDEN);
  2530.         de.setName(UtentiCostanti.PARAMETRO_UTENTE_ESEGUI);
  2531.         de.setValue(UtentiCostanti.PARAMETRO_UTENTE_ESEGUI);
  2532.         dati.add(de);
  2533.     }
  2534.    
  2535.     boolean changePwScadutaCheckData() throws Exception {

  2536.         try{

  2537.             String oldpw = this.getParameter(UtentiCostanti.PARAMETRO_UTENTE_VECCHIA_PW);
  2538.             String newpw = this.getParameter(UtentiCostanti.PARAMETRO_UTENTE_NUOVA_PW);
  2539.             String confpw = this.getParameter(UtentiCostanti.PARAMETRO_UTENTE_CONFERMA_NUOVA_PW);

  2540.             // String cpwd = this.procToCall.cryptPw(oldpw);
  2541.             String userToUpdate = ServletUtils.getObjectFromSession(this.request, this.session, String.class, LoginCostanti.ATTRIBUTO_MODALITA_CAMBIA_PWD_SCADUTA);
  2542.            
  2543.             User user = this.utentiCore.getUser(userToUpdate);

  2544.             boolean trovato = this.utentiCore.getUtenzePasswordManager().check(oldpw, user.getPassword());
  2545.             if(!trovato && this.utentiCore.getUtenzePasswordManagerBackwardCompatibility()!=null) {
  2546.                 trovato = this.utentiCore.getUtenzePasswordManagerBackwardCompatibility().check(oldpw, user.getPassword());
  2547.             }
  2548.             if (!trovato) {
  2549.                 this.pd.setMessage("La vecchia password indicata non &egrave; corretta");
  2550.                 return false;
  2551.             }
  2552.            
  2553.             // Controllo che non ci siano spazi nei campi di testo
  2554.             if ((oldpw.indexOf(" ") != -1)) {
  2555.                 this.pd.setMessage("Non inserire spazi nei campi di testo");
  2556.                 return false;
  2557.             }

  2558.             // Campi obbligatori
  2559.             if (newpw.equals("") || confpw.equals("")) {
  2560.                 this.pd.setMessage("Dati incompleti. &Egrave; necessario indicare una password");
  2561.                 return false;
  2562.             }

  2563.             // Controllo che non ci siano spazi nei campi di testo
  2564.             if ((newpw.indexOf(" ") != -1) || (confpw.indexOf(" ") != -1)) {
  2565.                 this.pd.setMessage("Non inserire spazi nei campi di testo");
  2566.                 return false;
  2567.             }

  2568.             // Controllo che la vecchia password e la nuova corrispondano
  2569.             if (oldpw.equals(newpw)) {
  2570.                 this.pd.setMessage("La nuova password deve essere differente dalla vecchia");
  2571.                 return false;
  2572.             }
  2573.            
  2574.             // Controllo che le password corrispondano
  2575.             if (!newpw.equals(confpw)) {
  2576.                 this.pd.setMessage(UtentiCostanti.MESSAGGIO_ERRORE_PASSWORD_NUOVE_DIFFERENTI);
  2577.                 return false;
  2578.             }

  2579.             PasswordVerifier passwordVerifier = this.utentiCore.getUtenzePasswordVerifier();
  2580.             if(passwordVerifier!=null){
  2581.                 StringBuilder motivazioneErrore = new StringBuilder();
  2582.                 if(passwordVerifier.validate(user.getLogin(), newpw, motivazioneErrore)==false){
  2583.                     this.pd.setMessage(motivazioneErrore.toString());
  2584.                     return false;
  2585.                 }
  2586.                
  2587.                 // controllo storico password in caso di change
  2588.                 if(passwordVerifier.isHistory()) {
  2589.                     List<UserPassword> precedentiPassword = user.getPrecedentiPassword();
  2590.                    
  2591. //                  String tmpPass = newpw;
  2592. //                  if(this.utentiCore.isUtenzePasswordEncryptEnabled()) {
  2593. //                      tmpPass = this.utentiCore.getUtenzePasswordManager().crypt(newpw);
  2594. //                  }
  2595.                    
  2596.                     if(precedentiPassword == null || precedentiPassword.isEmpty()) {
  2597.                         trovato = this.utentiCore.getUtenzePasswordManager().check(newpw, user.getPassword());
  2598.                         if(!trovato && this.utentiCore.getUtenzePasswordManagerBackwardCompatibility()!=null) {
  2599.                             trovato = this.utentiCore.getUtenzePasswordManagerBackwardCompatibility().check(newpw, user.getPassword());
  2600.                         }
  2601.                         if (trovato) {
  2602.                             this.pd.setMessage(UtentiCostanti.MESSAGGIO_ERRORE_PASSWORD_GIA_UTILIZZATA);
  2603.                             return false;
  2604.                         }
  2605.                     }
  2606.                    
  2607.                     for (UserPassword userPassword : precedentiPassword) {
  2608.                         trovato = this.utentiCore.getUtenzePasswordManager().check(newpw, userPassword.getPassword());
  2609.                         if(!trovato && this.utentiCore.getUtenzePasswordManagerBackwardCompatibility()!=null) {
  2610.                             trovato = this.utentiCore.getUtenzePasswordManagerBackwardCompatibility().check(newpw, userPassword.getPassword());
  2611.                         }
  2612.                         if (trovato) {
  2613.                             this.pd.setMessage(UtentiCostanti.MESSAGGIO_ERRORE_PASSWORD_GIA_UTILIZZATA);
  2614.                             return false;
  2615.                         }
  2616.                     }
  2617.                 }
  2618.             }
  2619.            
  2620.             return true;

  2621.         } catch (Exception e) {
  2622.             this.log.error("Exception: " + e.getMessage(), e);
  2623.             throw new Exception(e);
  2624.         }
  2625.     }
  2626.    
  2627.     public String incapsulaValoreStato(String valoreStato) {
  2628.         if(valoreStato!=null){
  2629.             valoreStato = "{" + valoreStato + "}"; // trasformo in json
  2630.         }
  2631.         return valoreStato;
  2632.     }

  2633.     public String extractValoreStato(String valoreStato) {
  2634.         if(valoreStato!=null){
  2635.             if(valoreStato.startsWith("{")){
  2636.                 valoreStato = valoreStato.substring(1);
  2637.             }
  2638.             if(valoreStato.endsWith("}")){
  2639.                 valoreStato = valoreStato.substring(0, (valoreStato.length()-1) );
  2640.             }
  2641.         }
  2642.         return  valoreStato;
  2643.     }
  2644. }