AutorizzazioneContenutoBuiltIn.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 java.util.List;

  22. import org.openspcoop2.core.config.Proprieta;
  23. import org.openspcoop2.message.OpenSPCoop2Message;
  24. import org.openspcoop2.pdd.core.CostantiPdD;
  25. import org.openspcoop2.pdd.core.autorizzazione.AutorizzazioneException;
  26. import org.openspcoop2.pdd.core.autorizzazione.GestoreAutorizzazioneContenutiBuiltIn;
  27. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  28. import org.openspcoop2.protocol.sdk.constants.ErroriIntegrazione;
  29. import org.openspcoop2.protocol.sdk.constants.IntegrationFunctionError;

  30. /**
  31.  * Esempio di AutorizzazioneContenutoBuiltIn
  32.  *
  33.  * @author Andrea Poli (apoli@link.it)
  34.  * @author $Author$
  35.  * @version $Rev$, $Date$
  36.  */

  37. public class AutorizzazioneContenutoBuiltIn extends AbstractAutorizzazioneContenutoBase {

  38.     @Override
  39.     public EsitoAutorizzazionePortaDelegata process(DatiInvocazionePortaDelegata datiInvocazione,OpenSPCoop2Message msg) throws AutorizzazioneException {

  40.         EsitoAutorizzazionePortaDelegata esito = new EsitoAutorizzazionePortaDelegata();
  41.        
  42.         // Autorizzazzione servizio applicativo
  43.         try{
  44.             if(datiInvocazione.getPd()==null) {
  45.                 throw new Exception("Porta Delegata non presente");
  46.             }
  47.             List<Proprieta> regole = datiInvocazione.getPd().getProprietaAutorizzazioneContenutoList();
  48.            
  49.             GestoreAutorizzazioneContenutiBuiltIn gestore = new GestoreAutorizzazioneContenutiBuiltIn();
  50.             gestore.process(msg, datiInvocazione, this.getPddContext(), regole);
  51.            
  52.             if(!gestore.isAutorizzato()) {
  53.                
  54.                 String servizioApplicativo = null;
  55.                 if(datiInvocazione.getIdServizioApplicativo()!=null){
  56.                     servizioApplicativo = datiInvocazione.getIdServizioApplicativo().getNome();
  57.                 }
  58.                 if(servizioApplicativo==null) {
  59.                     servizioApplicativo = CostantiPdD.SERVIZIO_APPLICATIVO_ANONIMO;
  60.                 }
  61.                
  62.                 esito.setErroreIntegrazione(IntegrationFunctionError.CONTENT_AUTHORIZATION_DENY, ErroriIntegrazione.ERRORE_428_AUTORIZZAZIONE_CONTENUTO_FALLITA.getErrore428_AutorizzazioneContenutoFallita(servizioApplicativo));
  63.                 esito.setAutorizzato(false);
  64.                 esito.setDetails(gestore.getErrorMessage());
  65.             }
  66.             else {
  67.                 esito.setAutorizzato(true);
  68.             }

  69.             return esito;
  70.            
  71.         }catch(Exception e){
  72.             esito.setEccezioneProcessamento(e);
  73.             OpenSPCoop2Logger.getLoggerOpenSPCoopCore().error("Autorizzazione per contenuto non riuscita",e);
  74.             throw new AutorizzazioneException("Errore inatteso durante la gestione dell'autorizzazione per contenuti: "+e.getMessage(),e);
  75.         }
  76.    

  77.     }

  78. }