AutorizzazioneContenutoBusteKO.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.io.ByteArrayOutputStream;

  22. import org.openspcoop2.core.id.IDServizio;
  23. import org.openspcoop2.core.id.IDSoggetto;
  24. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  25. import org.openspcoop2.message.OpenSPCoop2Message;
  26. import org.openspcoop2.pdd.core.autorizzazione.AutorizzazioneException;
  27. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  28. import org.openspcoop2.protocol.sdk.constants.CodiceErroreCooperazione;
  29. import org.openspcoop2.protocol.sdk.constants.ErroriCooperazione;
  30. import org.openspcoop2.protocol.sdk.constants.IntegrationFunctionError;

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

  38. public class AutorizzazioneContenutoBusteKO extends AbstractAutorizzazioneContenutoBase {

  39.     @Override
  40.     public EsitoAutorizzazionePortaApplicativa process(DatiInvocazionePortaApplicativa datiInvocazione, OpenSPCoop2Message msg) throws AutorizzazioneException {
  41.        
  42.         EsitoAutorizzazionePortaApplicativa esito = new EsitoAutorizzazionePortaApplicativa();
  43.        
  44.         // Autorizzazzione servizio applicativo
  45.         try{
  46.            
  47.             ByteArrayOutputStream bout = new ByteArrayOutputStream();
  48.             msg.writeTo(bout, false);
  49.             bout.flush();
  50.             bout.close();
  51.            
  52.             System.out.println("(TestKO) Messaggio ricevuto (Ruolo busta: "+datiInvocazione.getRuoloBusta().toString()+"): "+bout.toString());
  53.            
  54.             IDSoggetto soggettoFruitore = datiInvocazione.getIdSoggettoFruitore();
  55.             IDServizio servizio = datiInvocazione.getIdServizio();
  56.            
  57.             String errore = "Il soggetto "+soggettoFruitore.getTipo()+"/"+soggettoFruitore.getNome() +" non e' autorizzato ad invocare il servizio "+
  58.                     IDServizioFactory.getInstance().getUriFromIDServizio(servizio)+" con il contenuto applicativo fornito";
  59.            
  60.             esito.setErroreCooperazione(IntegrationFunctionError.CONTENT_AUTHORIZATION_DENY, ErroriCooperazione.AUTORIZZAZIONE_FALLITA.getErroreAutorizzazione(errore, CodiceErroreCooperazione.SICUREZZA_AUTORIZZAZIONE_FALLITA));
  61.             esito.setAutorizzato(false);
  62.             return esito;
  63.            
  64.         }catch(Exception e){
  65.             esito.setEccezioneProcessamento(e);
  66.             OpenSPCoop2Logger.getLoggerOpenSPCoopCore().error("Autorizzazione per contenuto non riuscita",e);
  67.             throw new AutorizzazioneException("Errore di processamento durante l'autorizzazione per contenuto buste: "+e.getMessage(),e);
  68.         }
  69.     }

  70.    
  71.    
  72. }