ModITracciaSerializer.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.protocol.modipa.tracciamento;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import org.openspcoop2.core.constants.CostantiLabel;
  24. import org.openspcoop2.core.tracciamento.Proprieta;
  25. import org.openspcoop2.message.constants.ServiceBinding;
  26. import org.openspcoop2.protocol.basic.tracciamento.TracciaSerializer;
  27. import org.openspcoop2.protocol.modipa.config.ModIProperties;
  28. import org.openspcoop2.protocol.modipa.constants.ModIConsoleCostanti;
  29. import org.openspcoop2.protocol.modipa.constants.ModICostanti;
  30. import org.openspcoop2.protocol.modipa.utils.ModIPropertiesUtils;
  31. import org.openspcoop2.protocol.sdk.Busta;
  32. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  33. import org.openspcoop2.protocol.sdk.ProtocolException;
  34. import org.openspcoop2.protocol.sdk.tracciamento.TracciaExtInfo;
  35. import org.openspcoop2.protocol.sdk.tracciamento.TracciaExtInfoDefinition;

  36. /**
  37.  * ModITracciaSerializer
  38.  *
  39.  * @author Andrea Poli (apoli@link.it)
  40.  * @author $Author$
  41.  * @version $Rev$, $Date$
  42.  */
  43. public class ModITracciaSerializer extends TracciaSerializer {

  44.     private ModIProperties modiProperties = null;
  45.    
  46.     public ModITracciaSerializer(IProtocolFactory<?> factory) throws ProtocolException {
  47.         super(factory);
  48.         this.modiProperties = ModIProperties.getInstance();
  49.     }

  50.     @Override
  51.     public boolean isSupportedExtInfo() {
  52.         return true;
  53.     }
  54.    
  55.     @Override
  56.     public List<TracciaExtInfoDefinition> getExtInfoDefinition(){
  57.         List<TracciaExtInfoDefinition> list = new ArrayList<>();
  58.        
  59.         TracciaExtInfoDefinition interazioneAsincrona = new TracciaExtInfoDefinition();
  60.         interazioneAsincrona.setPrefixId(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_INTERAZIONE_ASINCRONA_PREFIX);
  61.         interazioneAsincrona.setLabel(ModIConsoleCostanti.MODIPA_API_TRACCIA_EXT_INFO_PROFILO_INTERAZIONE_NON_BLOCCANTE_LABEL);
  62.         list.add(interazioneAsincrona);
  63.        
  64.         TracciaExtInfoDefinition sicurezzaMessaggio = new TracciaExtInfoDefinition();
  65.         sicurezzaMessaggio.setPrefixId(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_SICUREZZA_MESSAGGIO_PREFIX);
  66.         sicurezzaMessaggio.setLabel(ModIConsoleCostanti.MODIPA_API_TRACCIA_EXT_INFO_PROFILO_SICUREZZA_MESSAGGIO_LABEL);
  67.         list.add(sicurezzaMessaggio);
  68.        
  69.         TracciaExtInfoDefinition sicurezzaMessaggioSignedHeaders = new TracciaExtInfoDefinition();
  70.         sicurezzaMessaggioSignedHeaders.setPrefixId(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_SICUREZZA_MESSAGGIO_SIGNED_HEADER_PREFIX);
  71.         sicurezzaMessaggioSignedHeaders.setLabel(ModIConsoleCostanti.MODIPA_API_TRACCIA_EXT_INFO_PROFILO_SICUREZZA_MESSAGGIO_SIGNED_HEADERS_LABEL);
  72.         list.add(sicurezzaMessaggioSignedHeaders);
  73.        
  74.         TracciaExtInfoDefinition sicurezzaMessaggioSignedSoapParts = new TracciaExtInfoDefinition();
  75.         sicurezzaMessaggioSignedSoapParts.setPrefixId(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_SICUREZZA_MESSAGGIO_SIGNED_SOAP_PREFIX);
  76.         sicurezzaMessaggioSignedSoapParts.setLabel(ModIConsoleCostanti.MODIPA_API_TRACCIA_EXT_INFO_PROFILO_SICUREZZA_MESSAGGIO_SIGNED_SOAP_LABEL);
  77.         list.add(sicurezzaMessaggioSignedSoapParts);
  78.        
  79.         TracciaExtInfoDefinition sicurezzaMessaggioTokenAudit = new TracciaExtInfoDefinition();
  80.         sicurezzaMessaggioTokenAudit.setPrefixId(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_AUDIT_PREFIX);
  81.         sicurezzaMessaggioTokenAudit.setLabel(ModIConsoleCostanti.MODIPA_API_TRACCIA_EXT_INFO_PROFILO_SICUREZZA_MESSAGGIO_AUDIT_LABEL);
  82.         list.add(sicurezzaMessaggioTokenAudit);
  83.        
  84.         return list;
  85.     }
  86.     @Override
  87.     public List<TracciaExtInfo> extractExtInfo(Busta busta, ServiceBinding tipoApi){
  88.        
  89.         boolean terminologiaBozza = this.modiProperties.isModIVersioneBozza();
  90.        
  91.         List<TracciaExtInfo> list = super.extractExtInfo(busta, tipoApi);
  92.         if(list!=null && !list.isEmpty()) {
  93.             for (TracciaExtInfo tracciaExtInfo : list) {
  94.                 List<Proprieta> proprieta = tracciaExtInfo.getProprieta();
  95.                 if(proprieta!=null && !proprieta.isEmpty()) {
  96.                     for (Proprieta p : proprieta) {
  97.                         //System.out.println("["+p.getNome()+"]=["+p.getValore()+"]");
  98.                         if(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_INTERAZIONE.equals(p.getNome())) {
  99.                             p.setNome(ModIConsoleCostanti.MODIPA_API_PROFILO_INTERAZIONE_LABEL);
  100.                             if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_CRUD.equalsIgnoreCase(p.getValore())) {
  101.                                 p.setValore(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_LABEL_CRUD);
  102.                             }
  103.                             else if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_BLOCCANTE.equalsIgnoreCase(p.getValore())) {
  104.                                 p.setValore(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_LABEL_BLOCCANTE);
  105.                             }
  106.                             else if(ModICostanti.MODIPA_PROFILO_INTERAZIONE_VALUE_NON_BLOCCANTE.equalsIgnoreCase(p.getValore())) {
  107.                                 p.setValore(ModIConsoleCostanti.MODIPA_PROFILO_INTERAZIONE_LABEL_NON_BLOCCANTE);
  108.                             }
  109.                         }
  110.                         else if(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_SICUREZZA_CANALE.equals(p.getNome())) {
  111.                             p.setNome(ModIConsoleCostanti.MODIPA_API_PROFILO_CANALE_LABEL);
  112.                             if(ModICostanti.MODIPA_PROFILO_SICUREZZA_CANALE_VALUE_IDAC01.equalsIgnoreCase(p.getValore())) {
  113.                                 p.setValore(terminologiaBozza ? ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_CANALE_LABEL_IDAC01_OLD : ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_CANALE_LABEL_IDAC01_NEW);
  114.                             }
  115.                             else if(ModICostanti.MODIPA_PROFILO_SICUREZZA_CANALE_VALUE_IDAC02.equalsIgnoreCase(p.getValore())) {
  116.                                 p.setValore(terminologiaBozza ? ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_CANALE_LABEL_IDAC02_OLD : ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_CANALE_LABEL_IDAC02_NEW);
  117.                             }
  118.                         }
  119.                         else if(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_SICUREZZA_MESSAGGIO.equals(p.getNome())) {
  120.                             p.setNome(ModIConsoleCostanti.MODIPA_API_PROFILO_SICUREZZA_MESSAGGIO_LABEL);
  121.                             if(tipoApi!=null && ServiceBinding.REST.equals(tipoApi)) {
  122.                                 if(ModIPropertiesUtils.convertProfiloSicurezzaToSDKValue(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM01,true).equalsIgnoreCase(p.getValore())) {
  123.                                     p.setValore(terminologiaBozza ? ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM01_REST_OLD : ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM01_REST_NEW);
  124.                                 }
  125.                                 else if(ModIPropertiesUtils.convertProfiloSicurezzaToSDKValue(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM02,true).equalsIgnoreCase(p.getValore())) {
  126.                                     p.setValore(terminologiaBozza ? ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM02_REST_OLD : ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM02_REST_NEW);
  127.                                 }
  128.                                 else if(ModIPropertiesUtils.convertProfiloSicurezzaToSDKValue(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0301,true).equalsIgnoreCase(p.getValore())) {
  129.                                     p.setValore(terminologiaBozza ? ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM0301_REST_OLD : ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM0301_REST_NEW);
  130.                                 }
  131.                                 else if(ModIPropertiesUtils.convertProfiloSicurezzaToSDKValue(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0302,true).equalsIgnoreCase(p.getValore())) {
  132.                                     p.setValore(terminologiaBozza ? ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM0302_REST_OLD : ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM0302_REST_NEW);
  133.                                 }
  134.                                 else if(ModIPropertiesUtils.convertProfiloSicurezzaToSDKValue(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0401,true).equalsIgnoreCase(p.getValore())) {
  135.                                     p.setValore(ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM0401_REST);
  136.                                 }
  137.                                 else if(ModIPropertiesUtils.convertProfiloSicurezzaToSDKValue(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0402,true).equalsIgnoreCase(p.getValore())) {
  138.                                     p.setValore(ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM0402_REST);
  139.                                 }
  140.                             }
  141.                             else if(tipoApi!=null && ServiceBinding.SOAP.equals(tipoApi)) {
  142.                                 if(ModIPropertiesUtils.convertProfiloSicurezzaToSDKValue(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM01,false).equalsIgnoreCase(p.getValore())) {
  143.                                     p.setValore(terminologiaBozza ? ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM01_SOAP_OLD : ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM01_SOAP_NEW);
  144.                                 }
  145.                                 else if(ModIPropertiesUtils.convertProfiloSicurezzaToSDKValue(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM02,false).equalsIgnoreCase(p.getValore())) {
  146.                                     p.setValore(terminologiaBozza ? ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM02_SOAP_OLD : ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM02_SOAP_NEW);
  147.                                 }
  148.                                 else if(ModIPropertiesUtils.convertProfiloSicurezzaToSDKValue(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0301,false).equalsIgnoreCase(p.getValore())) {
  149.                                     p.setValore(terminologiaBozza ? ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM0301_SOAP_OLD : ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM0301_SOAP_NEW);
  150.                                 }
  151.                                 else if(ModIPropertiesUtils.convertProfiloSicurezzaToSDKValue(ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_VALUE_IDAM0302,false).equalsIgnoreCase(p.getValore())) {
  152.                                     p.setValore(terminologiaBozza ? ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM0302_SOAP_OLD : ModIConsoleCostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_LABEL_IDAM0302_SOAP_NEW);
  153.                                 }
  154.                             }
  155.                         }
  156.                         else if(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN.equals(p.getNome())) {
  157.                             p.setNome(CostantiLabel.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_SORGENTE_TOKEN_IDAUTH);
  158.                         }
  159.                         else if(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_AUDIT_PATTERN.equals(p.getNome())) {
  160.                             p.setNome(CostantiLabel.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_LABEL);
  161.                         }
  162.                         else if(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_AUDIT_SCHEMA.equals(p.getNome())) {
  163.                             p.setNome(CostantiLabel.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_CORNICE_SICUREZZA_SCHEMA_AUDIT_LABEL);
  164.                         }
  165.                         else if(ModIConsoleCostanti.MODIPA_API_TRACCIA_EXT_INFO_PROFILO_SICUREZZA_MESSAGGIO_SIGNED_HEADERS_LABEL.equals(tracciaExtInfo.getLabel()) &&
  166.                                 p.getNome()!=null && p.getNome().contains(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_SICUREZZA_MESSAGGIO_SIGNED_HEADER_MULTIPLE_VALUE_SUFFIX) &&
  167.                                     !p.getNome().endsWith(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_SICUREZZA_MESSAGGIO_SIGNED_HEADER_MULTIPLE_VALUE_SUFFIX)) {
  168.                             p.setNome(p.getNome().substring(0, p.getNome().indexOf(ModICostanti.MODIPA_BUSTA_EXT_PROFILO_SICUREZZA_MESSAGGIO_SIGNED_HEADER_MULTIPLE_VALUE_SUFFIX)));
  169.                         }
  170.                     }
  171.                 }
  172.             }
  173.         }
  174.         return list;
  175.     }
  176. }