EsitoAutenticazione.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.autenticazione;

  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 EsitoAutenticazione implements java.io.Serializable {

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

  37.     /** Indicazione se il client e' autenticato */
  38.     private boolean clientAuthenticated = false;
  39.    
  40.     /** Credenziale */
  41.     private String credential; // id autenticato
  42.     private String fullCredential; // descrizione estesa con nome e valore
  43.     private boolean enrichPrincipal = false; // serve ad indicare che la credenziale e' un principal

  44.     /** Indicazione se il client e' identificato */
  45.     private boolean clientIdentified = false;
  46.    
  47.     /** Dettagli aggiuntivi */
  48.     private String details;
  49.        
  50.     private Exception eccezioneProcessamento;
  51.    
  52.     private boolean esitoPresenteInCache = false;
  53.    
  54.     private boolean noCache = false;
  55.    
  56.     private OpenSPCoop2Message errorMessage;
  57.     private String wwwAuthenticateErrorHeader;
  58.    
  59.    
  60.     public String getWwwAuthenticateErrorHeader() {
  61.         return this.wwwAuthenticateErrorHeader;
  62.     }
  63.     public void setWwwAuthenticateErrorHeader(String wwwAuthenticateErrorHeader) {
  64.         this.wwwAuthenticateErrorHeader = wwwAuthenticateErrorHeader;
  65.     }
  66.    
  67.    
  68.     public OpenSPCoop2Message getErrorMessage() {
  69.         return this.errorMessage;
  70.     }
  71.     public void setErrorMessage(OpenSPCoop2Message errorMessage) {
  72.         this.errorMessage = errorMessage;
  73.     }
  74.    
  75.     public String getCredential() {
  76.         return this.credential;
  77.     }
  78.     public void setCredential(String credential) {
  79.         this.credential = credential;
  80.     }
  81.    
  82.     public String getFullCredential() {
  83.         return this.fullCredential;
  84.     }
  85.     public void setFullCredential(String fullCredential) {
  86.         this.fullCredential = fullCredential;
  87.     }
  88.    
  89.     public boolean isEnrichPrincipal() {
  90.         return this.enrichPrincipal;
  91.     }
  92.     public void setEnrichPrincipal(boolean enrichPrincipal) {
  93.         this.enrichPrincipal = enrichPrincipal;
  94.     }
  95.    
  96.     public boolean isClientAuthenticated() {
  97.         return this.clientAuthenticated;
  98.     }

  99.     public void setClientAuthenticated(boolean clientAuthenticated) {
  100.         this.clientAuthenticated = clientAuthenticated;
  101.     }
  102.    
  103.     public boolean isClientIdentified() {
  104.         return this.clientIdentified;
  105.     }

  106.     public void setClientIdentified(boolean clientIdentified) {
  107.         this.clientIdentified = clientIdentified;
  108.     }

  109.     public String getDetails() {
  110.         return this.details;
  111.     }
  112.     public void setDetails(String details) {
  113.         this.details = details;
  114.     }
  115.    
  116.     public Exception getEccezioneProcessamento() {
  117.         return this.eccezioneProcessamento;
  118.     }
  119.     public void setEccezioneProcessamento(Exception eccezioneProcessamento) {
  120.         this.eccezioneProcessamento = eccezioneProcessamento;
  121.         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);
  122.     }
  123.    
  124.     protected String getHeader(){
  125.         if(this.clientIdentified){
  126.             return "AUTENTICATO";
  127.         }
  128.         else{
  129.             return "NON_AUTENTICATO";
  130.         }
  131.     }
  132.    
  133.     public boolean isEsitoPresenteInCache() {
  134.         return this.esitoPresenteInCache;
  135.     }
  136.     public void setEsitoPresenteInCache(boolean esitoPresenteInCache) {
  137.         this.esitoPresenteInCache = esitoPresenteInCache;
  138.     }
  139.    
  140.     public boolean isNoCache() {
  141.         return this.noCache;
  142.     }

  143.     public void setNoCache(boolean noCache) {
  144.         this.noCache = noCache;
  145.     }
  146.    
  147.    
  148.     @Override
  149.     public String toString(){
  150.         StringBuilder bf = new StringBuilder(this.getHeader());
  151.        
  152.         if(this.details!=null){
  153.             bf.append(" ");
  154.             bf.append("details["+this.details+"]");
  155.         }
  156.        
  157.         if(this.eccezioneProcessamento!=null){
  158.             bf.append(" ");
  159.             ByteArrayOutputStream bout = new ByteArrayOutputStream();
  160.             PrintStream ps = new PrintStream(bout);
  161.             try{
  162.                 this.eccezioneProcessamento.printStackTrace(ps);
  163.             }finally{
  164.                 try{
  165.                     ps.flush();
  166.                     ps.close();
  167.                     bout.flush();
  168.                     bout.close();
  169.                 }catch(Exception eClose){
  170.                     // close
  171.                 }
  172.             }
  173.             bf.append("stackTraceEccezioneProcessamento: \n"+bout.toString());
  174.         }
  175.         return bf.toString();
  176.     }
  177. }