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

  22. import org.openspcoop2.message.OpenSPCoop2Message;
  23. import org.openspcoop2.pdd.core.autorizzazione.AutorizzazioneException;
  24. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  25. import org.openspcoop2.protocol.sdk.constants.ErroriIntegrazione;
  26. import org.openspcoop2.protocol.sdk.constants.IntegrationFunctionError;

  27. /**
  28.  * Esempio di AutorizzazioneContenutoKO
  29.  *
  30.  * @author Andrea Poli (apoli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  */

  34. public class AutorizzazioneContenutoKO extends AbstractAutorizzazioneContenutoBase {

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

  37.         EsitoAutorizzazionePortaDelegata esito = new EsitoAutorizzazionePortaDelegata();
  38.        
  39.         // Autorizzazzione servizio applicativoo
  40.         try{
  41.             ByteArrayOutputStream bout = new ByteArrayOutputStream();
  42.             msg.writeTo(bout, false);
  43.             bout.flush();
  44.             bout.close();
  45.            
  46.             System.out.println("(TestKO) Messaggio ricevuto: "+bout.toString());
  47.            
  48.             String servizioApplicativo = null;
  49.             if(datiInvocazione.getIdServizioApplicativo()!=null){
  50.                 servizioApplicativo = datiInvocazione.getIdServizioApplicativo().getNome();
  51.             }
  52.            
  53.             esito.setErroreIntegrazione(IntegrationFunctionError.CONTENT_AUTHORIZATION_DENY, ErroriIntegrazione.ERRORE_428_AUTORIZZAZIONE_CONTENUTO_FALLITA.getErrore428_AutorizzazioneContenutoFallita(servizioApplicativo));
  54.             esito.setAutorizzato(false);
  55.             return esito;
  56.            
  57.         }catch(Exception e){
  58.             esito.setEccezioneProcessamento(e);
  59.             OpenSPCoop2Logger.getLoggerOpenSPCoopCore().error("Autorizzazione per contenuto non riuscita",e);
  60.             throw new AutorizzazioneException("Errore di processamento durante l'autorizzazione per contenuto: "+e.getMessage(),e);
  61.         }
  62.    

  63.     }

  64. }