MessageSecuritySender_impl.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.security.message.engine;


  21. import org.openspcoop2.message.OpenSPCoop2Message;
  22. import org.openspcoop2.message.constants.ServiceBinding;
  23. import org.openspcoop2.protocol.sdk.constants.CodiceErroreCooperazione;
  24. import org.openspcoop2.security.SecurityException;
  25. import org.openspcoop2.security.message.IMessageSecuritySender;
  26. import org.openspcoop2.security.message.MessageSecurityContext;
  27. import org.openspcoop2.security.message.MessageSecurityUtilities;
  28. import org.openspcoop2.security.message.constants.SecurityConstants;

  29. /**
  30.  * Classe per la gestione della Sicurezza (role:Sender)
  31.  *
  32.  * @author Lorenzo Nardi (nardi@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */

  36. public class MessageSecuritySender_impl extends MessageSecuritySender {

  37.     protected MessageSecuritySender_impl(MessageSecurityContext messageSecurityContext) {
  38.         super(messageSecurityContext);
  39.     }

  40.     @Override
  41.     protected boolean process(OpenSPCoop2Message message, org.openspcoop2.utils.Map<Object> ctx) {
  42.         try{    
  43.                
  44.             IMessageSecuritySender senderInterface = this.messageSecurityContext.getMessageSecuritySender();
  45.            
  46.            
  47.             // Fix per SOAPFault (quando ci sono le encryptionParts o le signatureParts, la Security fallisce se c'e' un SOAPFault)
  48.             if(ServiceBinding.SOAP.equals(message.getServiceBinding())){
  49.                 if(message.isFault() || message.castAsSoap().getSOAPBody().hasFault()){
  50.                    
  51.                     if(MessageSecurityUtilities.processSOAPFault(this.messageSecurityContext.getOutgoingProperties()) == false){
  52.                         return true; // non devo applicare la sicurezza.
  53.                     }
  54.                    
  55.                 }  
  56.             }
  57.             else if(ServiceBinding.REST.equals(message.getServiceBinding())){
  58.                 if(message.isFault() || message.castAsRest().isProblemDetailsForHttpApis_RFC7807()){
  59.                    
  60.                     if(MessageSecurityUtilities.processProblemDetails(this.messageSecurityContext.getOutgoingProperties()) == false){
  61.                         return true; // non devo applicare la sicurezza.
  62.                     }
  63.                    
  64.                 }  
  65.             }
  66.            
  67.             String action = (String) this.messageSecurityContext.getOutgoingProperties().get(SecurityConstants.ACTION);
  68.             if(action==null || "".equals(action.trim())){
  69.                 return true; // nessuna action: non devo applicare la sicurezza.
  70.             }
  71.            
  72.             // Utilizzo l'engine di sicurezza
  73.             senderInterface.process(this.messageSecurityContext, message, ctx);
  74.            
  75.         }
  76.         catch(Exception e){
  77.            
  78.             String prefix = "Generatosi errore durante il processamento Message-Security(Sender): ";
  79.            
  80.             this.messageSecurityContext.getLog().error(prefix+e.getMessage(),e);
  81.            
  82.             this.msgErrore =  prefix+e.getMessage();
  83.             this.codiceErrore = CodiceErroreCooperazione.SICUREZZA;
  84.            
  85.             if(e instanceof SecurityException){
  86.                 SecurityException securityException = (SecurityException) e;
  87.                 if(securityException.getMsgErrore()!=null){
  88.                     this.msgErrore = prefix+securityException.getMsgErrore();
  89.                 }
  90.                 if(securityException.getCodiceErrore()!=null){
  91.                     this.codiceErrore = securityException.getCodiceErrore();
  92.                 }
  93.             }
  94.            
  95.             return false;
  96.         }
  97.         return true;
  98.     }

  99. }