AutorizzazioneAuthenticated.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.autorizzazione.pd;

  21. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  22. import org.openspcoop2.core.config.driver.DriverConfigurazioneNotFound;
  23. import org.openspcoop2.pdd.config.ConfigurazionePdDManager;
  24. import org.openspcoop2.pdd.core.autorizzazione.AutorizzazioneException;
  25. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  26. import org.openspcoop2.protocol.sdk.constants.CodiceErroreIntegrazione;
  27. import org.openspcoop2.protocol.sdk.constants.ErroriIntegrazione;
  28. import org.openspcoop2.protocol.sdk.constants.IntegrationFunctionError;

  29. /**
  30.  * Classe che implementa una autorizzazione basata sui servizi applicativi autenticati.
  31.  *
  32.  * @author Andrea Poli (apoli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */

  36. public class AutorizzazioneAuthenticated extends AbstractAutorizzazioneBase {

  37.     @Override
  38.     public EsitoAutorizzazionePortaDelegata process(DatiInvocazionePortaDelegata datiInvocazione) throws AutorizzazioneException{

  39.         EsitoAutorizzazionePortaDelegata esito = new EsitoAutorizzazionePortaDelegata();
  40.        
  41.         if(datiInvocazione.getIdServizioApplicativo()==null){
  42.             throw new AutorizzazioneException("Identità servizio applicativo non disponibile; tale informazione è richiesta dall'autorizzazione");
  43.         }  
  44.         String servizioApplicativo = datiInvocazione.getIdServizioApplicativo().getNome();
  45.        
  46.         // Autorizzazzione servizio applicativo
  47.         try{
  48.             if( ConfigurazionePdDManager.getInstance(datiInvocazione.getState()).
  49.                     autorizzazione(datiInvocazione.getPd(),servizioApplicativo) == false ){
  50.                 esito.setErroreIntegrazione(IntegrationFunctionError.AUTHORIZATION_DENY, ErroriIntegrazione.ERRORE_404_AUTORIZZAZIONE_FALLITA_SA.
  51.                         getErrore404_AutorizzazioneFallitaServizioApplicativo(servizioApplicativo));
  52.                 esito.setAutorizzato(false);
  53.                 return esito;
  54.             }
  55.         }catch(DriverConfigurazioneNotFound e){
  56.             esito.setErroreIntegrazione(IntegrationFunctionError.NOT_FOUND, ErroriIntegrazione.ERRORE_401_PORTA_INESISTENTE.getErrore401_PortaInesistente(e.getMessage(), servizioApplicativo));
  57.             esito.setAutorizzato(false);
  58.             return esito;
  59.         }catch(DriverConfigurazioneException e){
  60.             OpenSPCoop2Logger.getLoggerOpenSPCoopCore().error("AutorizzazioneOpenSPCoop non riuscita",e);
  61.             esito.setErroreIntegrazione(IntegrationFunctionError.INTERNAL_REQUEST_ERROR, ErroriIntegrazione.ERRORE_5XX_GENERICO_PROCESSAMENTO_MESSAGGIO.
  62.                     get5XX_ErroreProcessamento(CodiceErroreIntegrazione.CODICE_536_CONFIGURAZIONE_NON_DISPONIBILE));
  63.             esito.setAutorizzato(false);
  64.             esito.setEccezioneProcessamento(e);
  65.             return esito;
  66.         }
  67.    
  68.         esito.setAutorizzato(true);
  69.         return esito;
  70.     }
  71.    
  72. }