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.pa;

  21. import java.util.List;

  22. import org.openspcoop2.core.config.Proprieta;
  23. import org.openspcoop2.core.id.IDServizioApplicativo;
  24. import org.openspcoop2.core.id.IDSoggetto;
  25. import org.openspcoop2.message.OpenSPCoop2Message;
  26. import org.openspcoop2.pdd.core.autorizzazione.AutorizzazioneException;
  27. import org.openspcoop2.pdd.core.autorizzazione.GestoreAutorizzazioneContenutiBuiltIn;
  28. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  29. import org.openspcoop2.protocol.sdk.constants.CodiceErroreCooperazione;
  30. import org.openspcoop2.protocol.sdk.constants.ErroriCooperazione;
  31. import org.openspcoop2.protocol.sdk.constants.IntegrationFunctionError;

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

  39. public class AutorizzazioneContenutoBuiltIn extends AbstractAutorizzazioneContenutoBase {

  40.     @Override
  41.     public EsitoAutorizzazionePortaApplicativa process(DatiInvocazionePortaApplicativa datiInvocazione, OpenSPCoop2Message msg) throws AutorizzazioneException {
  42.        
  43.         EsitoAutorizzazionePortaApplicativa esito = new EsitoAutorizzazionePortaApplicativa();
  44.        
  45.         // Autorizzazzione servizio applicativo
  46.         try{
  47.            
  48.             if(datiInvocazione.getPa()==null) {
  49.                 throw new Exception("Porta Applicativa non presente");
  50.             }
  51.             List<Proprieta> regole = datiInvocazione.getPa().getProprietaAutorizzazioneContenutoList();
  52.            
  53.             GestoreAutorizzazioneContenutiBuiltIn gestore = new GestoreAutorizzazioneContenutiBuiltIn();
  54.             gestore.process(msg, datiInvocazione, this.getPddContext(), regole);
  55.            
  56.             if(!gestore.isAutorizzato()) {
  57.                
  58.                 IDServizioApplicativo idSA = datiInvocazione.getIdentitaServizioApplicativoFruitore();
  59.                 IDSoggetto soggettoFruitore = datiInvocazione.getIdSoggettoFruitore();
  60.                 //IDServizio servizio = datiInvocazione.getIdServizio();
  61.                
  62.                 String mittente = null;
  63.                 if(idSA!=null && idSA.getNome()!=null) {
  64.                     IDSoggetto soggettoProprietario = null;
  65.                     if(idSA.getIdSoggettoProprietario()!=null) {
  66.                         soggettoProprietario = idSA.getIdSoggettoProprietario();
  67.                     }
  68.                     else if(soggettoFruitore!=null) {
  69.                         soggettoProprietario = soggettoFruitore;
  70.                     }
  71.                     if(soggettoProprietario!=null) {
  72.                         mittente = "L'applicativo "+idSA.getNome()+" ("+soggettoProprietario.getTipo()+"/"+soggettoProprietario.getNome()+")";
  73.                     }
  74.                     else {
  75.                         mittente = "L'applicativo "+idSA.getNome();
  76.                     }
  77.                 }
  78.                 else if(soggettoFruitore!=null) {
  79.                     mittente = "Il soggetto "+soggettoFruitore.getTipo()+"/"+soggettoFruitore.getNome();
  80.                 }
  81.                 else {
  82.                     mittente = "Il chiamante";
  83.                 }
  84.                
  85.                 String errore = mittente+" non รจ autorizzato ad invocare l'API";
  86.                
  87.                 esito.setErroreCooperazione(IntegrationFunctionError.CONTENT_AUTHORIZATION_DENY, ErroriCooperazione.AUTORIZZAZIONE_FALLITA.getErroreAutorizzazione(errore, CodiceErroreCooperazione.SICUREZZA_AUTORIZZAZIONE_FALLITA));
  88.                 esito.setAutorizzato(false);
  89.                 esito.setDetails(gestore.getErrorMessage());
  90.             }
  91.             else {
  92.                 esito.setAutorizzato(true);
  93.             }
  94.            
  95.             return esito;
  96.            
  97.         }catch(Exception e){
  98.             esito.setEccezioneProcessamento(e);
  99.             OpenSPCoop2Logger.getLoggerOpenSPCoopCore().error("Autorizzazione per contenuto non riuscita",e);
  100.             throw new AutorizzazioneException("Errore inatteso durante la gestione dell'autorizzazione per contenuti: "+e.getMessage(),e);
  101.         }
  102.     }

  103.    
  104.    
  105. }