BasicConfiguration.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.basic.config;

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

  23. import org.openspcoop2.core.constants.TipoPdD;
  24. import org.openspcoop2.core.id.IDServizio;
  25. import org.openspcoop2.message.config.ServiceBindingConfiguration;
  26. import org.openspcoop2.message.constants.ServiceBinding;
  27. import org.openspcoop2.protocol.basic.BasicComponentFactory;
  28. import org.openspcoop2.protocol.manifest.Binding;
  29. import org.openspcoop2.protocol.manifest.CollaborationProfile;
  30. import org.openspcoop2.protocol.manifest.Functionality;
  31. import org.openspcoop2.protocol.manifest.InterfaceConfiguration;
  32. import org.openspcoop2.protocol.manifest.Openspcoop2;
  33. import org.openspcoop2.protocol.manifest.OrganizationType;
  34. import org.openspcoop2.protocol.manifest.Registry;
  35. import org.openspcoop2.protocol.manifest.ServiceType;
  36. import org.openspcoop2.protocol.manifest.SoapHeaderBypassMustUnderstandHeader;
  37. import org.openspcoop2.protocol.manifest.Version;
  38. import org.openspcoop2.protocol.manifest.constants.InterfaceType;
  39. import org.openspcoop2.protocol.sdk.BypassMustUnderstandCheck;
  40. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  41. import org.openspcoop2.protocol.sdk.ProtocolException;
  42. import org.openspcoop2.protocol.sdk.constants.FunzionalitaProtocollo;
  43. import org.openspcoop2.protocol.sdk.constants.InitialIdConversationType;
  44. import org.openspcoop2.protocol.sdk.constants.ProfiloDiCollaborazione;
  45. import org.openspcoop2.protocol.sdk.registry.IRegistryReader;
  46. import org.openspcoop2.protocol.sdk.registry.RegistryNotFound;
  47. import org.openspcoop2.utils.certificate.remote.RemoteStoreConfig;
  48. import org.openspcoop2.utils.transport.TransportRequestContext;

  49. /**
  50.  * Classe che implementa, l'interfaccia {@link org.openspcoop2.protocol.sdk.config.IProtocolConfiguration}
  51.  *
  52.  * @author Poli Andrea (apoli@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  */
  56. public class BasicConfiguration extends BasicComponentFactory implements org.openspcoop2.protocol.sdk.config.IProtocolConfiguration {

  57.     private Registry registroManifest;
  58.     private Binding bindingManifest;
  59.     private Openspcoop2 manifest;

  60.     public BasicConfiguration(IProtocolFactory<?> factory) throws ProtocolException {
  61.         super(factory);
  62.         this.manifest = this.protocolFactory.getManifest();
  63.         this.registroManifest = this.manifest.getRegistry();
  64.         this.bindingManifest = this.manifest.getBinding();
  65.     }
  66.    

  67.    
  68.    
  69.     @Override
  70.     public ServiceBindingConfiguration getDefaultServiceBindingConfiguration(TransportRequestContext transportRequest) throws ProtocolException{
  71.         return ServiceBindingConfigurationReader.getDefaultServiceBindingConfiguration(this.manifest, transportRequest);
  72.     }
  73.    
  74.     @Override
  75.     public ServiceBinding getIntegrationServiceBinding(IDServizio idServizio, IRegistryReader registryReader) throws ProtocolException, RegistryNotFound{
  76.         return ServiceBindingConfigurationReader.getServiceBinding(idServizio, registryReader);
  77.     }
  78.    
  79.     @Override
  80.     public ServiceBinding getProtocolServiceBinding(ServiceBinding integrationServiceBinding, TransportRequestContext transportRequest) throws ProtocolException{
  81.         return integrationServiceBinding; // stesso service binding tra integration e protocol per default
  82.     }
  83.    
  84.     @Override
  85.     public ServiceBindingConfiguration getServiceBindingConfiguration(TransportRequestContext transportRequest, ServiceBinding serviceBinding,
  86.             IDServizio idServizio, IRegistryReader registryReader) throws ProtocolException, RegistryNotFound{
  87.         return ServiceBindingConfigurationReader.getServiceBindingConfiguration(this.manifest, transportRequest, serviceBinding, idServizio, registryReader);
  88.     }
  89.    
  90.     @Override
  91.     public List<InterfaceType> getInterfacceSupportate(ServiceBinding serviceBinding){
  92.         List<InterfaceType> list = new ArrayList<InterfaceType>();
  93.         switch (serviceBinding) {
  94.         case SOAP:
  95.             if(this.bindingManifest.getSoap()!=null &&
  96.                 this.bindingManifest.getSoap().getInterfaces()!=null &&
  97.                 this.bindingManifest.getSoap().getInterfaces().sizeSpecificationList()>0){
  98.                 for (InterfaceConfiguration interfaceConfiguration : this.bindingManifest.getSoap().getInterfaces().getSpecificationList()) {
  99.                     list.add(interfaceConfiguration.getType());
  100.                 }
  101.             }
  102.             break;
  103.         case REST:
  104.             if(this.bindingManifest.getRest()!=null &&
  105.                 this.bindingManifest.getRest().getInterfaces()!=null &&
  106.                 this.bindingManifest.getRest().getInterfaces().sizeSpecificationList()>0){
  107.                 for (InterfaceConfiguration interfaceConfiguration : this.bindingManifest.getRest().getInterfaces().getSpecificationList()) {
  108.                     list.add(interfaceConfiguration.getType());
  109.                 }
  110.             }
  111.             break;
  112.         }
  113.         return list;
  114.     }
  115.    
  116.     @Override
  117.     public boolean isSupportoSchemaEsternoInterfaccia(ServiceBinding serviceBinding, InterfaceType interfaceType) {
  118.         switch (serviceBinding) {
  119.         case SOAP:
  120.             if(this.bindingManifest.getSoap()!=null &&
  121.                 this.bindingManifest.getSoap().getInterfaces()!=null &&
  122.                 this.bindingManifest.getSoap().getInterfaces().sizeSpecificationList()>0){
  123.                 for (InterfaceConfiguration interfaceConfiguration : this.bindingManifest.getSoap().getInterfaces().getSpecificationList()) {
  124.                     if(interfaceType.equals(interfaceConfiguration.getType())) {
  125.                         return interfaceConfiguration.isSchema();
  126.                     }
  127.                 }
  128.             }
  129.             break;
  130.         case REST:
  131.             if(this.bindingManifest.getRest()!=null &&
  132.                 this.bindingManifest.getRest().getInterfaces()!=null &&
  133.                 this.bindingManifest.getRest().getInterfaces().sizeSpecificationList()>0){
  134.                 for (InterfaceConfiguration interfaceConfiguration : this.bindingManifest.getRest().getInterfaces().getSpecificationList()) {
  135.                     if(interfaceType.equals(interfaceConfiguration.getType())) {
  136.                         return interfaceConfiguration.isSchema();
  137.                     }
  138.                 }
  139.             }
  140.             break;
  141.         }
  142.         return false;
  143.     }
  144.    
  145.     @Override
  146.     public boolean isSupportoSpecificaConversazioni(ServiceBinding serviceBinding, InterfaceType interfaceType) {
  147.         switch (serviceBinding) {
  148.         case SOAP:
  149.             if(this.bindingManifest.getSoap()!=null &&
  150.                 this.bindingManifest.getSoap().getInterfaces()!=null &&
  151.                 this.bindingManifest.getSoap().getInterfaces().sizeSpecificationList()>0){
  152.                 for (InterfaceConfiguration interfaceConfiguration : this.bindingManifest.getSoap().getInterfaces().getSpecificationList()) {
  153.                     if(interfaceType.equals(interfaceConfiguration.getType())) {
  154.                         return interfaceConfiguration.isConversations();
  155.                     }
  156.                 }
  157.             }
  158.             break;
  159.         case REST:
  160.             if(this.bindingManifest.getRest()!=null &&
  161.                 this.bindingManifest.getRest().getInterfaces()!=null &&
  162.                 this.bindingManifest.getRest().getInterfaces().sizeSpecificationList()>0){
  163.                 for (InterfaceConfiguration interfaceConfiguration : this.bindingManifest.getRest().getInterfaces().getSpecificationList()) {
  164.                     if(interfaceType.equals(interfaceConfiguration.getType())) {
  165.                         return interfaceConfiguration.isConversations();
  166.                     }
  167.                 }
  168.             }
  169.             break;
  170.         }
  171.         return false;
  172.     }
  173.    
  174.     @Override
  175.     public boolean isSupportoPortiAccessoAccordiParteSpecifica(ServiceBinding serviceBinding, InterfaceType interfaceType) {
  176.         switch (serviceBinding) {
  177.         case SOAP:
  178.             if(this.bindingManifest.getSoap()!=null &&
  179.                 this.bindingManifest.getSoap().getInterfaces()!=null &&
  180.                 this.bindingManifest.getSoap().getInterfaces().sizeSpecificationList()>0){
  181.                 for (InterfaceConfiguration interfaceConfiguration : this.bindingManifest.getSoap().getInterfaces().getSpecificationList()) {
  182.                     if(interfaceType.equals(interfaceConfiguration.getType())) {
  183.                         return interfaceConfiguration.isImplementation();
  184.                     }
  185.                 }
  186.             }
  187.             break;
  188.         case REST:
  189.             if(this.bindingManifest.getRest()!=null &&
  190.                 this.bindingManifest.getRest().getInterfaces()!=null &&
  191.                 this.bindingManifest.getRest().getInterfaces().sizeSpecificationList()>0){
  192.                 for (InterfaceConfiguration interfaceConfiguration : this.bindingManifest.getRest().getInterfaces().getSpecificationList()) {
  193.                     if(interfaceType.equals(interfaceConfiguration.getType())) {
  194.                         return interfaceConfiguration.isImplementation();
  195.                     }
  196.                 }
  197.             }
  198.             break;
  199.         }
  200.         return false;
  201.     }
  202.    
  203.     @Override
  204.     public boolean isSupportoAutenticazioneSoggetti() {
  205.         return this.registroManifest.getOrganization().getAuthentication();
  206.     }
  207.    
  208.     @Override
  209.     public boolean isSupportatoAutenticazioneApplicativiHttpsConToken() {
  210.         return this.registroManifest.getOrganization().getHttpsWithTokenAuthentication();
  211.     }
  212.    
  213.     @Override
  214.     public boolean isSupportoAutenticazioneApplicativiErogazioni() {
  215.         return this.registroManifest.getOrganization().getInboundApplicativeAuthentication();
  216.     }
  217.    
  218.     @Override
  219.     public boolean isSupportatoAutorizzazioneRichiedenteSenzaAutenticazioneErogazioni() {
  220.         return this.registroManifest.getOrganization().getInboundOrganizationAuthorizationWithoutAuthentication();
  221.     }
  222.    
  223.     @Override
  224.     public boolean isSupportoAutenticazioneApplicativiEsterniErogazioni() {
  225.         return this.registroManifest.getOrganization().getInboundExternalApplicationAuthentication();
  226.     }
  227.    
  228.     @Override
  229.     public boolean isSupportoCodiceIPA() {
  230.         return this.registroManifest.getOrganization().isCodeIPA();
  231.     }
  232.    
  233.     @Override
  234.     public boolean isSupportoIdentificativoPortaSoggetto() {
  235.         return this.registroManifest.getOrganization().isCodeDomain();
  236.     }

  237.     @Override
  238.     public boolean isSupportoIndirizzoRisposta(){
  239.         return this.registroManifest.getOrganization().isReplyToAddress();
  240.     }
  241.    
  242.     @Override
  243.     public boolean isSupportoSoggettoUtilizzoTrattino() {
  244.         return this.registroManifest.getOrganization().isDash();
  245.     }
  246.    
  247.     @Override
  248.     public boolean isSupportoSoggettoReferenteAccordiParteComune() {
  249.         return this.registroManifest.getService().isApiReferent();
  250.     }
  251.    
  252.     @Override
  253.     public boolean isSupportoVersionamentoAccordiParteSpecifica() {
  254.         return this.registroManifest.getService().isVersion();
  255.     }
  256.    
  257.     @Override
  258.     public boolean isSupportoSbustamentoProtocollo() {
  259.         return this.registroManifest.getService().isProtocolEnvelopeManagement();
  260.     }
  261.    
  262.     @Override
  263.     public boolean isSupportoSceltaFault() {
  264.         return this.registroManifest.getService().isFaultChoice();
  265.     }
  266.    
  267.     @Override
  268.     public boolean isAbilitatoRiusoIdCorrelazioneApplicativa() {
  269.         return this.registroManifest.getService().isCorrelationReuseProtocolId();
  270.     }
  271.    
  272.     @Override
  273.     public boolean isAbilitataGenerazioneTracce() {
  274.         return this.registroManifest.getService().isTrace();
  275.     }
  276.    
  277.     @Override
  278.     public boolean isAbilitatoSalvataggioHeaderProtocolloTracce() {
  279.         return true;
  280.     }
  281.    
  282.     @Override
  283.     public List<String> getTipiSoggetti() throws ProtocolException {
  284.         List<String> tipi = new ArrayList<>();
  285.         List<OrganizationType> l = this.registroManifest.getOrganization().getTypes().getTypeList();
  286.         for (int i = 0; i < l.size(); i++) {
  287.             tipi.add(l.get(i).getName());
  288.         }
  289.         return tipi;
  290.     }
  291.    
  292.     @Override
  293.     public String getTipoSoggettoDefault() throws ProtocolException {
  294.         return this.registroManifest.getOrganization().getTypes().getType(0).getName();
  295.     }

  296.     private org.openspcoop2.protocol.manifest.constants.ServiceBinding convert(ServiceBinding serviceBinding){
  297.         switch (serviceBinding) {
  298.             case SOAP:
  299.                 return org.openspcoop2.protocol.manifest.constants.ServiceBinding.SOAP;
  300.             case REST:
  301.                 return org.openspcoop2.protocol.manifest.constants.ServiceBinding.REST;
  302.         }
  303.         return null;
  304.     }
  305.    
  306.     @Override
  307.     public List<String> getTipiServizi(ServiceBinding serviceBinding) throws ProtocolException {
  308.        
  309.         org.openspcoop2.protocol.manifest.constants.ServiceBinding sb = null;
  310.         if(serviceBinding!=null) {
  311.             sb = this.convert(serviceBinding);
  312.         }
  313.        
  314.         List<String> tipi = new ArrayList<>();
  315.         List<ServiceType> l = this.registroManifest.getService().getTypes().getTypeList();
  316.         for (int i = 0; i < l.size(); i++) {
  317.             org.openspcoop2.protocol.manifest.constants.ServiceBinding serviceBindingTmp = l.get(i).getBinding();
  318.             if(serviceBindingTmp==null || (sb!=null && serviceBindingTmp.equals(sb))){
  319.                 tipi.add(l.get(i).getName());  
  320.             }
  321.         }
  322.         return tipi;
  323.     }

  324.     @Override
  325.     public String getTipoServizioDefault(ServiceBinding serviceBinding) throws ProtocolException {
  326.         List<String> l = this.getTipiServizi(serviceBinding);
  327.         if(l!=null && l.size()>0){
  328.             return l.get(0);
  329.         }
  330.         return null;
  331.     }
  332.    
  333.     @Override
  334.     public List<String> getVersioni() throws ProtocolException{
  335.         List<String> tipi = new ArrayList<>();
  336.         List<Version> l = this.registroManifest.getVersions().getVersionList();
  337.         for (int i = 0; i < l.size(); i++) {
  338.             tipi.add(l.get(i).getName());
  339.         }
  340.         return tipi;
  341.     }

  342.     @Override
  343.     public String getVersioneDefault() throws ProtocolException {
  344.         return this.registroManifest.getVersions().getVersion(0).getName();
  345.     }
  346.    
  347.     @Override
  348.     public boolean isSupportato(ServiceBinding serviceBinding, ProfiloDiCollaborazione profiloCollaborazione)
  349.             throws ProtocolException {
  350.         if(profiloCollaborazione==null || serviceBinding==null){
  351.             throw new ProtocolException("Params not defined");
  352.         }
  353.         CollaborationProfile profilo = null;
  354.         if(ServiceBinding.REST.equals(serviceBinding)) {
  355.             if(this.bindingManifest.getRest()!=null) {
  356.                 profilo = new CollaborationProfile();
  357.                 if(this.bindingManifest.getRest().getProfile()!=null) {
  358.                     if(this.bindingManifest.getRest().getProfile().isOneway()) {
  359.                         profilo.setInputOutput(false);
  360.                         profilo.setOneway(true);
  361.                     }
  362.                     else {
  363.                         profilo.setInputOutput(true);
  364.                         profilo.setOneway(false);
  365.                     }
  366.                 }
  367.                 else {
  368.                     profilo.setInputOutput(true);
  369.                     profilo.setOneway(false);
  370.                 }
  371.                 profilo.setAsyncInputOutput(false);
  372.                 profilo.setPolledInputOutput(false);
  373.             }
  374.         }
  375.         else {
  376.             if(this.bindingManifest.getSoap()!=null) {
  377.                 profilo = this.bindingManifest.getSoap().getProfile();
  378.             }
  379.         }
  380.         switch (profiloCollaborazione) {
  381.         case ONEWAY:
  382.             return (profilo!=null ? profilo.isOneway() : true);
  383.         case SINCRONO:      
  384.             return (profilo!=null ? profilo.isInputOutput() : true);
  385.         case ASINCRONO_SIMMETRICO:      
  386.             return (profilo!=null ? profilo.isAsyncInputOutput() : false);
  387.         case ASINCRONO_ASIMMETRICO:    
  388.             return (profilo!=null ? profilo.isPolledInputOutput() : false);
  389.         case UNKNOWN:
  390.             throw new ProtocolException("Param ["+ProfiloDiCollaborazione.UNKNOWN.name()+"] not valid for this method");
  391.         default:
  392.             throw new ProtocolException("Param ["+profiloCollaborazione.getEngineValue()+"] not supported");
  393.         }
  394.     }

  395.     @Override
  396.     public boolean isSupportato(ServiceBinding serviceBinding, FunzionalitaProtocollo funzionalitaProtocollo)
  397.             throws ProtocolException {
  398.         if(funzionalitaProtocollo==null || serviceBinding==null){
  399.             throw new ProtocolException("Params not defined");
  400.         }
  401.         Functionality funzionalita = null;
  402.         if(ServiceBinding.REST.equals(serviceBinding)) {
  403.             if(this.bindingManifest.getRest()!=null) {
  404.                 funzionalita = this.bindingManifest.getRest().getFunctionality();
  405.             }
  406.         }
  407.         else {
  408.             if(this.bindingManifest.getSoap()!=null) {
  409.                 funzionalita = this.bindingManifest.getSoap().getFunctionality();
  410.             }
  411.         }
  412.         switch (funzionalitaProtocollo) {
  413.         case FILTRO_DUPLICATI:
  414.             return (funzionalita!=null ? funzionalita.isDuplicateFilter() : false);
  415.         case CONFERMA_RICEZIONE:        
  416.             return (funzionalita!=null ? funzionalita.isAcknowledgement() : false);
  417.         case COLLABORAZIONE:        
  418.             return (funzionalita!=null ? funzionalita.isConversationIdentifier() : false);
  419.         case RIFERIMENTO_ID_RICHIESTA:      
  420.             return (funzionalita!=null ? funzionalita.isReferenceToRequestIdentifier() : false);
  421.         case CONSEGNA_IN_ORDINE:        
  422.             return (funzionalita!=null ? funzionalita.isDeliveryOrder() : false);
  423.         case SCADENZA:      
  424.             return (funzionalita!=null ? funzionalita.isExpiration() : false);
  425.         case MANIFEST_ATTACHMENTS:      
  426.             return (funzionalita!=null ? funzionalita.getManifestAttachments() : false);
  427.         default:
  428.             throw new ProtocolException("Param ["+funzionalitaProtocollo.getEngineValue()+"] not supported");
  429.         }
  430.     }
  431.    
  432.     @Override
  433.     public boolean isIntegrationInfoRequired(TipoPdD tipoPdD, ServiceBinding serviceBinding, FunzionalitaProtocollo funzionalitaProtocollo) throws ProtocolException{
  434.         return false;
  435.     }
  436.    
  437.     @Override
  438.     public InitialIdConversationType isGenerateInitialIdConversation(TipoPdD tipoPdD, FunzionalitaProtocollo funzionalitaProtocollo) throws ProtocolException{
  439.         return InitialIdConversationType.ID_TRANSAZIONE;
  440.     }
  441.    
  442.     @Override
  443.     public boolean isDataPresenteInIdentificativoMessaggio() {
  444.         return false;
  445.     }
  446.    
  447.     @Override
  448.     public List<BypassMustUnderstandCheck> getBypassMustUnderstandCheck(){
  449.         List<BypassMustUnderstandCheck> list = new ArrayList<BypassMustUnderstandCheck>();
  450.         if( this.manifest.getBinding().getSoap()!=null &&
  451.                 this.manifest.getBinding().getSoap().getSoapHeaderBypassMustUnderstand()!=null &&
  452.                         this.manifest.getBinding().getSoap().getSoapHeaderBypassMustUnderstand().sizeHeaderList()>0){
  453.             for (SoapHeaderBypassMustUnderstandHeader header : this.manifest.getBinding().getSoap().getSoapHeaderBypassMustUnderstand().getHeaderList()) {
  454.                 BypassMustUnderstandCheck bypassMustUnderstandCheck = new BypassMustUnderstandCheck();
  455.                 bypassMustUnderstandCheck.setElementName(header.getLocalName());
  456.                 bypassMustUnderstandCheck.setNamespace(header.getNamespace());
  457.                 list.add(bypassMustUnderstandCheck);
  458.             }
  459.         }
  460.         return list;
  461.     }
  462.    
  463.     @Override
  464.     public List<RemoteStoreConfig> getRemoteStoreConfig() throws ProtocolException{
  465.         return new ArrayList<>();
  466.     }
  467. }