AbstractAutorizzazioneAuthenticatedRoles.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 org.openspcoop2.pdd.core.autorizzazione.AutorizzazioneException;

  22. /**
  23.  * Classe che implementa una autorizzazione basata sui ruoli
  24.  *
  25.  * @author Andrea Poli (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */

  29. abstract class AbstractAutorizzazioneAuthenticatedRoles extends AbstractAutorizzazioneBase {

  30.     private boolean checkRuoloRegistro;
  31.     private boolean checkRuoloEsterno;
  32.     @SuppressWarnings("unused")
  33.     private String nomeAutorizzazione;
  34.    
  35.     protected AbstractAutorizzazioneAuthenticatedRoles(boolean checkRuoloRegistro, boolean checkRuoloEsterno, String nomeAutorizzazione){
  36.         this.checkRuoloRegistro = checkRuoloRegistro;
  37.         this.checkRuoloEsterno = checkRuoloEsterno;
  38.         this.nomeAutorizzazione = nomeAutorizzazione;
  39.     }
  40.    

  41.     @Override
  42.     public EsitoAutorizzazionePortaApplicativa process(DatiInvocazionePortaApplicativa datiInvocazione) throws AutorizzazioneException{

  43.         EsitoAutorizzazionePortaApplicativa esitoAuth = null;
  44.         if(datiInvocazione.getIdSoggettoFruitore()!=null){
  45.             // Se il mittente non è stato identificato non è possibile effettuare il controllo 'authenticated'
  46.             AutorizzazioneAuthenticated auth = new AutorizzazioneAuthenticated();
  47.             auth.init(this.getPddContext(), this.getProtocolFactory(), this.getArgs());
  48.             esitoAuth = auth.process(datiInvocazione);
  49.             if(esitoAuth.isAutorizzato()){
  50.                 return esitoAuth;
  51.             }
  52.         }
  53.        
  54.         IAutorizzazionePortaApplicativa authRuoli = null;
  55.         if(this.checkRuoloRegistro && this.checkRuoloEsterno){
  56.             authRuoli = new AutorizzazioneRoles();
  57.         }
  58.         else if(this.checkRuoloRegistro){
  59.             authRuoli = new AutorizzazioneInternalRoles();
  60.         }
  61.         else {
  62.             authRuoli = new AutorizzazioneExternalRoles();
  63.         }
  64.         authRuoli.init(this.getPddContext(), this.getProtocolFactory(), this.getArgs());
  65.         EsitoAutorizzazionePortaApplicativa esitoAuthRoles = authRuoli.process(datiInvocazione);
  66.         if(esitoAuthRoles.isAutorizzato()){
  67.             return esitoAuthRoles;
  68.         }
  69.        
  70.         // Se non è autorizzato in nessuno dei due modi ritorno l'errore del tipo authenticated
  71.         if(esitoAuth!=null){
  72.             return esitoAuth;
  73.         }
  74.         else{
  75.             return esitoAuthRoles;
  76.         }
  77.     }

  78. }