MessageSecurityContext_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.MessageRole;
  23. import org.openspcoop2.protocol.sdk.Busta;
  24. import org.openspcoop2.security.message.MessageSecurityContext;
  25. import org.openspcoop2.security.message.MessageSecurityContextParameters;

  26. /**
  27.  * MessageSecurityContext_impl
  28.  *
  29.  * @author Andrea Poli (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class MessageSecurityContext_impl extends MessageSecurityContext{
  34.    
  35.     public MessageSecurityContext_impl(MessageSecurityContextParameters messageSecurityContextParameters) {
  36.         super(messageSecurityContextParameters);
  37.     }

  38.     private MessageSecurityReceiver receiver;
  39.     private MessageSecuritySender sender;
  40.    
  41.     /** MessageSecurity Process */
  42.     @Override
  43.     public boolean processIncoming(OpenSPCoop2Message message, Busta busta, org.openspcoop2.utils.Map<Object> ctx){
  44.        
  45.         this.receiver = new MessageSecurityReceiver_impl(this);
  46.        
  47.         boolean result = this.receiver.process(message, busta, ctx);
  48.         if(!result){
  49.            
  50.             if(ctx!=null) {
  51.                 if(MessageRole.REQUEST.equals(message.getMessageRole())) {
  52.                     ctx.put(org.openspcoop2.core.constants.Costanti.ERRORE_SICUREZZA_MESSAGGIO_RICHIESTA, "true");
  53.                 }
  54.                 else {
  55.                     ctx.put(org.openspcoop2.core.constants.Costanti.ERRORE_SICUREZZA_MESSAGGIO_RISPOSTA, "true");
  56.                 }
  57.             }
  58.                
  59.             this.codiceErrore = this.receiver.getCodiceErrore();
  60.             this.msgErrore = this.receiver.getMsgErrore();
  61.             this.listaSubCodiceErrore = this.receiver.getListaSubCodiceErrore();
  62.         }
  63.         return result;
  64.     }
  65.    
  66.     @Override
  67.     public boolean processOutgoing(OpenSPCoop2Message message, org.openspcoop2.utils.Map<Object> ctx){
  68.        
  69.         this.sender = new MessageSecuritySender_impl(this);
  70.        
  71.         boolean result = this.sender.process(message, ctx);
  72.         if(!result){
  73.            
  74.             if(ctx!=null) {
  75.                 if(MessageRole.REQUEST.equals(message.getMessageRole())) {
  76.                     ctx.put(org.openspcoop2.core.constants.Costanti.ERRORE_SICUREZZA_MESSAGGIO_RICHIESTA, "true");
  77.                 }
  78.                 else {
  79.                     ctx.put(org.openspcoop2.core.constants.Costanti.ERRORE_SICUREZZA_MESSAGGIO_RISPOSTA, "true");
  80.                 }
  81.             }
  82.            
  83.             this.codiceErrore = this.sender.getCodiceErrore();
  84.             this.msgErrore = this.sender.getMsgErrore();
  85.         }
  86.         return result;
  87.     }
  88.    
  89.     @Override
  90.     public String getSubject(){
  91.         if(this.receiver!=null)
  92.             return this.receiver.getSubject();
  93.         else
  94.             return null;
  95.     }

  96. }