InRequestProtocolHandler.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.pdd.core.handlers.transazioni;

  21. import org.openspcoop2.core.constants.Costanti;
  22. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  23. import org.openspcoop2.pdd.core.controllo_traffico.handler.InRequestProtocolHandlerGestioneControlloTraffico;
  24. import org.openspcoop2.pdd.core.credenziali.Credenziali;
  25. import org.openspcoop2.pdd.core.credenziali.engine.GestoreCredenzialiEngine;
  26. import org.openspcoop2.pdd.core.handlers.HandlerException;
  27. import org.openspcoop2.pdd.core.handlers.InRequestProtocolContext;
  28. import org.openspcoop2.pdd.core.transazioni.Transaction;
  29. import org.openspcoop2.pdd.core.transazioni.TransactionContext;
  30. import org.openspcoop2.pdd.core.transazioni.TransactionDeletedException;
  31. import org.openspcoop2.pdd.core.transazioni.TransactionNotExistsException;

  32. /**    
  33.  * InRequestProtocolHandler
  34.  *
  35.  * @author Poli Andrea (poli@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  */
  39. public class InRequestProtocolHandler extends FirstPositionHandler implements  org.openspcoop2.pdd.core.handlers.InRequestProtocolHandler{

  40.     @Override
  41.     public void invoke(InRequestProtocolContext context) throws HandlerException {
  42.        
  43.         OpenSPCoop2Properties op2Properties = OpenSPCoop2Properties.getInstance();
  44.         if(op2Properties.isTransazioniEnabled()==false) {
  45.             return;
  46.         }
  47.        
  48.         String idTransazione = (String) context.getPddContext().getObject(Costanti.ID_TRANSAZIONE);
  49.        
  50.         //System.out.println("------------- InRequestHandler ("+idTransazione+")("+context.getTipoPorta().getTipo()+") -------------------");
  51.        
  52.         try{
  53.        
  54.             Transaction tr = TransactionContext.getTransaction(idTransazione);
  55.            
  56.             if(context.getConnettore()!=null){
  57.                 Credenziali credenziali = context.getConnettore().getCredenziali();
  58.                 String credenzialiFornite = "";
  59.                 if(credenziali!=null){
  60.                     credenzialiFornite = credenziali.toString(!Credenziali.SHOW_BASIC_PASSWORD,
  61.                             Credenziali.SHOW_ISSUER,
  62.                             !Credenziali.SHOW_DIGEST_CLIENT_CERT,
  63.                             Credenziali.SHOW_SERIAL_NUMBER_CLIENT_CERT,
  64.                             "","","\n"); // riporto anche l'issuer ed il serial number del cert e formatto differentemente
  65.                 }

  66.                 boolean credenzialiModificateTramiteGateway = false;
  67.                 if(tr.getCredenziali()!=null){
  68.                     if(tr.getCredenziali().equals(credenzialiFornite) == false){
  69.                         credenzialiModificateTramiteGateway=true;
  70.                     }
  71.                 }
  72.                 if(credenzialiModificateTramiteGateway==true){  
  73.                     if(context.getPddContext()!=null && context.getPddContext().containsKey(Costanti.IDENTITA_GESTORE_CREDENZIALI)) {
  74.                         String identitaGateway = (String) context.getPddContext().getObject(Costanti.IDENTITA_GESTORE_CREDENZIALI);
  75.                         tr.setCredenziali(GestoreCredenzialiEngine.getDBValuePrefixGatewayCredenziali(identitaGateway,credenzialiFornite));
  76.                         //System.out.println("SET CREDENZIALI VIA GATEWAY ["+credenzialiFornite+"]");
  77.                     }
  78.                 }
  79.             }
  80.            
  81.             if(op2Properties.isControlloTrafficoEnabled()){
  82.                 tr.getTempiElaborazione().startControlloTraffico_rateLimiting();
  83.                 try {
  84.                     InRequestProtocolHandlerGestioneControlloTraffico inRequestProtocolHandler_gestioneControlloTraffico =
  85.                             new InRequestProtocolHandlerGestioneControlloTraffico();
  86.                     inRequestProtocolHandler_gestioneControlloTraffico.process(context, tr);
  87.                 }finally {
  88.                     tr.getTempiElaborazione().endControlloTraffico_rateLimiting();
  89.                 }
  90.             }
  91.            
  92.            
  93.         }catch(TransactionDeletedException e){
  94.             throw new HandlerException(e);
  95.             // Non dovrebbe avvenire in questo handler
  96.         }catch(TransactionNotExistsException e){
  97.             throw new HandlerException(e);
  98.             // Non dovrebbe avvenire in questo handler
  99.         }
  100.        
  101.     }

  102. }