AbstractAutorizzazioneRoles.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 ruoli
  31.  *
  32.  * @author Andrea Poli (apoli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */

  36. abstract class AbstractAutorizzazioneRoles extends AbstractAutorizzazioneBase {

  37.     private boolean checkRuoloRegistro;
  38.     private boolean checkRuoloEsterno;
  39.     private String nomeAutorizzazione;
  40.    
  41.     protected AbstractAutorizzazioneRoles(boolean checkRuoloRegistro, boolean checkRuoloEsterno, String nomeAutorizzazione){
  42.         this.checkRuoloRegistro = checkRuoloRegistro;
  43.         this.checkRuoloEsterno = checkRuoloEsterno;
  44.         this.nomeAutorizzazione = nomeAutorizzazione;
  45.     }
  46.    

  47.     @Override
  48.     public EsitoAutorizzazionePortaDelegata process(DatiInvocazionePortaDelegata datiInvocazione) throws AutorizzazioneException{

  49.         EsitoAutorizzazionePortaDelegata esito = new EsitoAutorizzazionePortaDelegata();
  50.        
  51.         String servizioApplicativo = null;
  52.         if(datiInvocazione.getIdServizioApplicativo()!=null){
  53.             servizioApplicativo = datiInvocazione.getIdServizioApplicativo().getNome();
  54.         }
  55.        
  56.         try{
  57.             StringBuilder detailsBuffer = new StringBuilder();
  58.             if( ConfigurazionePdDManager.getInstance(datiInvocazione.getState()).
  59.                     autorizzazioneTrasportoRoles(datiInvocazione.getPd(), datiInvocazione.getServizioApplicativo(),
  60.                             datiInvocazione.getInfoConnettoreIngresso(),
  61.                             this.getPddContext(), datiInvocazione.getRequestInfo(),
  62.                             this.checkRuoloRegistro, this.checkRuoloEsterno,
  63.                             detailsBuffer)==false){
  64.                 if(servizioApplicativo!=null){
  65.                     esito.setErroreIntegrazione(IntegrationFunctionError.AUTHORIZATION_MISSING_ROLE, ErroriIntegrazione.ERRORE_404_AUTORIZZAZIONE_FALLITA_SA.
  66.                             getErrore404_AutorizzazioneFallitaServizioApplicativo(servizioApplicativo));
  67.                 }
  68.                 else{
  69.                     esito.setErroreIntegrazione(IntegrationFunctionError.AUTHORIZATION_MISSING_ROLE, ErroriIntegrazione.ERRORE_404_AUTORIZZAZIONE_FALLITA_SA.
  70.                             getErrore404_AutorizzazioneFallitaServizioApplicativoAnonimo());
  71.                 }
  72.                 esito.setAutorizzato(false);
  73.                 if(detailsBuffer.length()>0) {
  74.                     esito.setDetails(detailsBuffer.toString());
  75.                 }
  76.                 return esito;
  77.             }
  78.         }catch(DriverConfigurazioneNotFound e){
  79.             if(servizioApplicativo!=null){
  80.                 esito.setErroreIntegrazione(IntegrationFunctionError.AUTHORIZATION_MISSING_ROLE, ErroriIntegrazione.ERRORE_404_AUTORIZZAZIONE_FALLITA_SA.
  81.                         getErrore404_AutorizzazioneFallitaServizioApplicativo(servizioApplicativo,e.getMessage()));
  82.             }
  83.             else{
  84.                 esito.setErroreIntegrazione(IntegrationFunctionError.AUTHORIZATION_MISSING_ROLE, ErroriIntegrazione.ERRORE_404_AUTORIZZAZIONE_FALLITA_SA.
  85.                         getErrore404_AutorizzazioneFallitaServizioApplicativoAnonimo(e.getMessage()));
  86.             }
  87.             esito.setAutorizzato(false);
  88.             esito.setEccezioneProcessamento(e);
  89.             return esito;
  90.         }catch(DriverConfigurazioneException e){
  91.             OpenSPCoop2Logger.getLoggerOpenSPCoopCore().error("Autorizzazione "+this.nomeAutorizzazione+" non riuscita",e);
  92.             esito.setErroreIntegrazione(IntegrationFunctionError.INTERNAL_REQUEST_ERROR, ErroriIntegrazione.ERRORE_5XX_GENERICO_PROCESSAMENTO_MESSAGGIO.
  93.                     get5XX_ErroreProcessamento(CodiceErroreIntegrazione.CODICE_536_CONFIGURAZIONE_NON_DISPONIBILE));
  94.             esito.setAutorizzato(false);
  95.             esito.setEccezioneProcessamento(e);
  96.             return esito;
  97.         }
  98.    
  99.         esito.setAutorizzato(true);
  100.         return esito;
  101.     }

  102. }