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

  21. import java.io.ByteArrayOutputStream;
  22. import java.io.PrintStream;

  23. import org.openspcoop2.message.OpenSPCoop2Message;


  24. /**
  25.  * Esito di un processo di autorizzazione.
  26.  *
  27.  * @author Andrea Poli (apoli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public abstract class EsitoAutorizzazione implements java.io.Serializable {

  32.    
  33.     /**
  34.      *
  35.      */
  36.     private static final long serialVersionUID = 1L;

  37.     /** Indicazione se il e' autorizzato */
  38.     private boolean autorizzato;
  39.    
  40.     /** Dettagli aggiuntivi */
  41.     private String details;
  42.        
  43.     private Exception eccezioneProcessamento;
  44.    
  45.     private boolean esitoPresenteInCache = false;
  46.    
  47.     private boolean noCache = false;
  48.    
  49.     private OpenSPCoop2Message errorMessage;
  50.     private String wwwAuthenticateErrorHeader;
  51.    
  52.    
  53.     public String getWwwAuthenticateErrorHeader() {
  54.         return this.wwwAuthenticateErrorHeader;
  55.     }
  56.     public void setWwwAuthenticateErrorHeader(String wwwAuthenticateErrorHeader) {
  57.         this.wwwAuthenticateErrorHeader = wwwAuthenticateErrorHeader;
  58.     }
  59.    
  60.    
  61.     public OpenSPCoop2Message getErrorMessage() {
  62.         return this.errorMessage;
  63.     }
  64.     public void setErrorMessage(OpenSPCoop2Message errorMessage) {
  65.         this.errorMessage = errorMessage;
  66.     }
  67.        
  68.     /**
  69.      * Ritorna l'indicazione se e' autorizzato
  70.      *
  71.      * @return indicazione se e' autorizzato
  72.      */
  73.     public boolean isAutorizzato() {
  74.         return this.autorizzato;
  75.     }
  76.    
  77.     /**
  78.      * Imposta l'indicazione se il servizio e' autorizzato
  79.      *
  80.      * @param servizioAutorizzato indicazione se il servizio e' autorizzato
  81.      */
  82.     public void setAutorizzato(boolean servizioAutorizzato) {
  83.         this.autorizzato = servizioAutorizzato;
  84.     }

  85.     public String getDetails() {
  86.         return this.details;
  87.     }
  88.     public void setDetails(String details) {
  89.         this.details = details;
  90.     }
  91.    
  92.     public Exception getEccezioneProcessamento() {
  93.         return this.eccezioneProcessamento;
  94.     }
  95.     public void setEccezioneProcessamento(Exception eccezioneProcessamento) {
  96.         this.eccezioneProcessamento = eccezioneProcessamento;
  97.         this.noCache = true; // per default quando si imposta una eccezione di processamento il risultato non sarĂ  salvato. Se si vuole cacharlo richiamare il metodo setNoCache(false);
  98.     }
  99.    
  100.     public String getHeader(){
  101.         if(this.autorizzato){
  102.             return "AUTORIZZATO";
  103.         }
  104.         else{
  105.             return "NON_AUTORIZZATO";
  106.         }
  107.     }
  108.    
  109.     public boolean isEsitoPresenteInCache() {
  110.         return this.esitoPresenteInCache;
  111.     }
  112.     public void setEsitoPresenteInCache(boolean esitoPresenteInCache) {
  113.         this.esitoPresenteInCache = esitoPresenteInCache;
  114.     }
  115.    
  116.     public boolean isNoCache() {
  117.         return this.noCache;
  118.     }

  119.     public void setNoCache(boolean noCache) {
  120.         this.noCache = noCache;
  121.     }
  122.    
  123.     @Override
  124.     public String toString(){
  125.         StringBuilder bf = new StringBuilder(this.getHeader());
  126.        
  127.         if(this.details!=null){
  128.             bf.append(" ");
  129.             bf.append("details["+this.details+"]");
  130.         }
  131.        
  132.         if(this.eccezioneProcessamento!=null){
  133.             bf.append(" ");
  134.             ByteArrayOutputStream bout = new ByteArrayOutputStream();
  135.             PrintStream ps = new PrintStream(bout);
  136.             try{
  137.                 this.eccezioneProcessamento.printStackTrace(ps);
  138.             }finally{
  139.                 try{
  140.                     ps.flush();
  141.                     ps.close();
  142.                     bout.flush();
  143.                     bout.close();
  144.                 }catch(Exception eClose){
  145.                     // close
  146.                 }
  147.             }
  148.             bf.append("stackTraceEccezioneProcessamento: \n"+bout.toString());
  149.         }
  150.         return bf.toString();
  151.     }
  152. }