GestoreCredenzialiConfigurazione.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.credenziali.engine;

  21. import java.io.File;
  22. import java.util.HashMap;
  23. import java.util.Map;
  24. import java.util.Properties;

  25. import org.apache.commons.lang.StringUtils;
  26. import org.openspcoop2.core.id.IDSoggetto;
  27. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  28. import org.openspcoop2.pdd.core.credenziali.GestoreCredenzialiException;
  29. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  30. import org.openspcoop2.utils.SemaphoreLock;
  31. import org.openspcoop2.utils.certificate.KeystoreType;

  32. /**    
  33.  * GestoreCredenzialiConfigurazione
  34.  *
  35.  * @author Poli Andrea (poli@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  */
  39. public class GestoreCredenzialiConfigurazione {

  40.     private static Map<String, GestoreCredenzialiConfigurazione> configurazione = new HashMap<>();
  41.     private static org.openspcoop2.utils.Semaphore semaphore = new org.openspcoop2.utils.Semaphore("GestoreCredenzialiConfigurazione");
  42.    
  43.     private static void initConfigurazione(boolean fruizione, IDSoggetto idSoggetto) throws GestoreCredenzialiException {
  44.         String key = getKey(fruizione, idSoggetto);
  45.         if(!configurazione.containsKey(key)) {
  46.             SemaphoreLock lock = null;
  47.             try {
  48.                 lock = semaphore.acquire("initConfig");
  49.             }catch(Exception e) {
  50.                 throw new GestoreCredenzialiException(e.getMessage(),e);
  51.             }
  52.             try {
  53.                 GestoreCredenzialiConfigurazione instance = new GestoreCredenzialiConfigurazione(fruizione, idSoggetto);
  54.                 configurazione.put(key, instance);
  55.             }finally {
  56.                 semaphore.release(lock, "initConfig");
  57.             }
  58.         }
  59.     }
  60.     public static GestoreCredenzialiConfigurazione getConfigurazione(boolean fruizione, IDSoggetto idSoggetto) throws GestoreCredenzialiException {
  61.         OpenSPCoop2Properties op2Properties = OpenSPCoop2Properties.getInstance();
  62.         boolean abilitatoGlobalmente = false;
  63.         if(fruizione) {
  64.             abilitatoGlobalmente = op2Properties.isGestoreCredenzialiPortaDelegataEnabled();
  65.         }
  66.         else {
  67.             abilitatoGlobalmente = op2Properties.isGestoreCredenzialiPortaApplicativaEnabled();
  68.         }
  69.         if(!abilitatoGlobalmente) {
  70.             return null;
  71.         }
  72.        
  73.         String key = getKey(fruizione, idSoggetto);
  74.         if(!configurazione.containsKey(key)) {
  75.             initConfigurazione(fruizione, idSoggetto);
  76.         }  
  77.         return configurazione.get(key);
  78.     }
  79.     private static String getKey(boolean fruizione, IDSoggetto idSoggetto) {
  80.         return (fruizione ? "fruizione_" : "erogazione_" ) + (idSoggetto!=null ? idSoggetto.toString() : "-undefined-");
  81.     }
  82.    
  83.    
  84.     private boolean enabled;
  85.     private String nome;
  86.    
  87.     private String realm;
  88.     private String authType;
  89.    
  90.     private TipoAutenticazioneGestoreCredenziali tipoAutenticazioneCanale = null;
  91.     private String autenticazioneCanaleBasicUsername=null;
  92.     private String autenticazioneCanaleBasicPassword=null;
  93.     private String autenticazioneCanaleSslSubject=null;
  94.     private String autenticazioneCanalePrincipal=null;
  95.    
  96.     private ModalitaAutenticazioneGestoreCredenziali modalitaAutenticazioneCanale = null;
  97.     private String modalitaAutenticazioneCanaleAtLeastOneErrorDescription = null;
  98.    
  99.     private String headerBasicUsername;
  100.     private String headerBasicPassword;
  101.    
  102.     private String headerSslSubject;
  103.     private String headerSslIssuer;
  104.    
  105.     private String headerSslCertificate;
  106.     private boolean headerSslCertificateUrlDecode;
  107.     private boolean headerSslCertificateBase64Decode;
  108.     private boolean headerSslCertificateHexDecode;
  109.     private boolean headerSslCertificateUrlDecodeOrBase64Decode;
  110.     private boolean headerSslCertificateUrlDecodeOrBase64DecodeOrHexDecode;
  111.     private boolean headerSslCertificateEnrichBeginEnd;
  112.     private boolean headerSslCertificateReplaceCharacters;
  113.     private String headerSslCertificateReplaceCharactersSource;
  114.     private String headerSslCertificateReplaceCharactersDest;
  115.     private String headerSslCertificateTrustStorePath;
  116.     private String headerSslCertificateTrustStorePassword;
  117.     private String headerSslCertificateTrustStoreType;
  118.     private boolean headerSslCertificateTrustStoreCheckValid = true;
  119.     private String headerSslCertificateCrlX509;
  120.     private String headerSslCertificateOcspPolicy;
  121.     private String headerSslCertificateNoneOption;
  122.     private boolean headerSslCertificateIgnoreEmpty = true;

  123.     private String headerPrincipal;
  124.    
  125.     private String getProprietaPrefix(String prefix) {
  126.         return "Proprietà '"+prefix;
  127.     }
  128.     private String getMessaggioModalitaNonConfigurataCompletamente() {
  129.         return "modalita non configurata completamente; la modalità '"+this.modalitaAutenticazioneCanale+"' ";
  130.     }

  131.     public GestoreCredenzialiConfigurazione(boolean fruizione, IDSoggetto idSoggetto) throws GestoreCredenzialiException {
  132.        
  133.         OpenSPCoop2Properties op2Properties = OpenSPCoop2Properties.getInstance();
  134.         Properties p = null;
  135.         String prefix = null;
  136.         if(fruizione) {
  137.             p = op2Properties.getGestoreCredenzialiPortaDelegataProperties();
  138.             prefix = OpenSPCoop2Properties.prefixGestoreCredenzialiPortaDelegataProperties;
  139.         }
  140.         else {
  141.             p = op2Properties.getGestoreCredenzialiPortaApplicativaProperties();
  142.             prefix = OpenSPCoop2Properties.prefixGestoreCredenzialiPortaApplicativaProperties;
  143.         }
  144.        
  145.         String protocollo = null;
  146.         try {
  147.             if(idSoggetto!=null) {
  148.                 protocollo = ProtocolFactoryManager.getInstance().getProtocolByOrganizationType(idSoggetto.getTipo());
  149.             }
  150.         }catch(Exception e) {
  151.             throw new GestoreCredenzialiException(e.getMessage(),e);
  152.         }
  153.        
  154.        
  155.        
  156.         String enabledS = getProperty(p, "enabled", protocollo, idSoggetto);
  157.         if(enabledS!=null){
  158.             enabledS = enabledS.trim();
  159.             this.enabled = Boolean.parseBoolean(enabledS);
  160.         }
  161.         else {
  162.             this.enabled = false;
  163.         }
  164.         if(!this.enabled) {
  165.             return;
  166.         }
  167.        
  168.         this.nome = getProperty(p, "nome", protocollo, idSoggetto);
  169.         if(this.nome==null) {
  170.             throw new GestoreCredenzialiException(getProprietaPrefix(prefix)+"nome non impostata");
  171.         }  
  172.        
  173.         this.realm = getProperty(p, "wwwAuthenticate.realm", protocollo, idSoggetto);
  174.         this.authType = getProperty(p, "wwwAuthenticate.authType", protocollo, idSoggetto);
  175.         if( (this.realm!=null && this.authType==null) || (this.realm==null && this.authType!=null) ) {
  176.             throw new GestoreCredenzialiException("L'abilitazione del wwwAuthenticate sul gestore delle credenziali richiede che sia definito sia un nome da associare al realm (trovato "+prefix+"wwwAuthenticate.realm="+this.realm+") che il tipo di autenticazione (trovato "+prefix+"wwwAuthenticate.authType="+this.authType+")");
  177.         }
  178.        
  179.         String authCanaleS = getProperty(p, "autenticazioneCanale", protocollo, idSoggetto);
  180.         if(authCanaleS==null) {
  181.             throw new GestoreCredenzialiException(getProprietaPrefix(prefix)+"autenticazioneCanale non impostata");
  182.         }  
  183.         this.tipoAutenticazioneCanale = TipoAutenticazioneGestoreCredenziali.toEnumConstant(authCanaleS);
  184.         if(this.tipoAutenticazioneCanale==null) {
  185.             throw new GestoreCredenzialiException(getProprietaPrefix(prefix)+"autenticazioneCanale impostata non correttamente, valore indicato ("+authCanaleS+") non gestito");
  186.         }
  187.        
  188.         switch (this.tipoAutenticazioneCanale) {
  189.         case NONE:
  190.             break;
  191.         case BASIC:
  192.             this.autenticazioneCanaleBasicUsername = getProperty(p, "autenticazioneCanale.basic.username", protocollo, idSoggetto);
  193.             if(this.autenticazioneCanaleBasicUsername==null) {
  194.                 throw new GestoreCredenzialiException(getProprietaPrefix(prefix)+"autenticazioneCanale.basic.username non impostata");
  195.             }  
  196.            
  197.             this.autenticazioneCanaleBasicPassword = getProperty(p, "autenticazioneCanale.basic.password", protocollo, idSoggetto);
  198.             if(this.autenticazioneCanaleBasicPassword==null) {
  199.                 throw new GestoreCredenzialiException(getProprietaPrefix(prefix)+"autenticazioneCanale.basic.password non impostata");
  200.             }  
  201.             break;
  202.         case SSL:
  203.             this.autenticazioneCanaleSslSubject = getProperty(p, "autenticazioneCanale.ssl.subject", protocollo, idSoggetto);
  204.             if(this.autenticazioneCanaleSslSubject==null) {
  205.                 throw new GestoreCredenzialiException(getProprietaPrefix(prefix)+"autenticazioneCanale.ssl.subject non impostata");
  206.             }
  207.             break;
  208.         case PRINCIPAL:
  209.             this.autenticazioneCanalePrincipal = getProperty(p, "autenticazioneCanale.principal", protocollo, idSoggetto);
  210.             if(this.autenticazioneCanalePrincipal==null) {
  211.                 throw new GestoreCredenzialiException(getProprietaPrefix(prefix)+"autenticazioneCanale.principal non impostata");
  212.             }
  213.             break;
  214.         }
  215.        
  216.        
  217.         this.headerBasicUsername = getProperty(p, "header.basic.username", protocollo, idSoggetto);
  218.         this.headerBasicPassword = getProperty(p, "header.basic.password", protocollo, idSoggetto);
  219.        
  220.         this.headerSslSubject = getProperty(p, "header.ssl.subject", protocollo, idSoggetto);
  221.         this.headerSslIssuer = getProperty(p, "header.ssl.issuer", protocollo, idSoggetto);
  222.        
  223.         this.headerSslCertificate = getProperty(p, "header.ssl.certificate", protocollo, idSoggetto);
  224.         if(this.headerSslCertificate!=null) {
  225.        
  226.             String pValue = getProperty(p, "header.ssl.certificate.url_decode", protocollo, idSoggetto);
  227.             if(pValue!=null){
  228.                 pValue = pValue.trim();
  229.                 this.headerSslCertificateUrlDecode = Boolean.parseBoolean(pValue);
  230.             }else{
  231.                 this.headerSslCertificateUrlDecode = true;// default a true
  232.             }
  233.            
  234.             pValue = getProperty(p, "header.ssl.certificate.base64_decode", protocollo, idSoggetto);
  235.             if(pValue!=null){
  236.                 pValue = pValue.trim();
  237.                 this.headerSslCertificateBase64Decode = Boolean.parseBoolean(pValue);
  238.             }else{
  239.                 this.headerSslCertificateBase64Decode = true;// default a true
  240.             }
  241.            
  242.             pValue = getProperty(p, "header.ssl.certificate.hex_decode", protocollo, idSoggetto);
  243.             if(pValue!=null){
  244.                 pValue = pValue.trim();
  245.                 this.headerSslCertificateHexDecode = Boolean.parseBoolean(pValue);
  246.             }else{
  247.                 this.headerSslCertificateHexDecode = false;// default a false
  248.             }
  249.            
  250.             pValue = getProperty(p, "header.ssl.certificate.url_decode_or_base64_decode", protocollo, idSoggetto);
  251.             if(pValue!=null){
  252.                 pValue = pValue.trim();
  253.                 this.headerSslCertificateUrlDecodeOrBase64Decode = Boolean.parseBoolean(pValue);
  254.             }else{
  255.                 this.headerSslCertificateUrlDecodeOrBase64Decode = false;// default a false (e' abilitata la proprieta' successiva)
  256.             }
  257.            
  258.             pValue = getProperty(p, "header.ssl.certificate.url_decode_or_base64_decode_or_hex_decode", protocollo, idSoggetto);
  259.             if(pValue!=null){
  260.                 pValue = pValue.trim();
  261.                 this.headerSslCertificateUrlDecodeOrBase64DecodeOrHexDecode = Boolean.parseBoolean(pValue);
  262.             }else{
  263.                 this.headerSslCertificateUrlDecodeOrBase64DecodeOrHexDecode = true;// default a true
  264.             }
  265.            
  266.             pValue = getProperty(p, "header.ssl.certificate.enrich_BEGIN_END", protocollo, idSoggetto);
  267.             if(pValue!=null){
  268.                 pValue = pValue.trim();
  269.                 this.headerSslCertificateEnrichBeginEnd = Boolean.parseBoolean(pValue);
  270.             }else{
  271.                 this.headerSslCertificateEnrichBeginEnd = false;// default a false
  272.             }
  273.            
  274.             pValue = getProperty(p, "header.ssl.certificate.replaceCharacters", protocollo, idSoggetto);
  275.             if(pValue!=null){
  276.                 pValue = pValue.trim();
  277.                 this.headerSslCertificateReplaceCharacters = Boolean.parseBoolean(pValue);
  278.             }else{
  279.                 this.headerSslCertificateReplaceCharacters = false;// default a false
  280.             }
  281.            
  282.             if(this.headerSslCertificateReplaceCharacters) {
  283.                 this.headerSslCertificateReplaceCharactersSource = getProperty(p, "header.ssl.certificate.replaceCharacters.source", protocollo, idSoggetto);
  284.                 if(this.headerSslCertificateReplaceCharactersSource!=null){
  285.                     if(StringUtils.isNotEmpty(this.headerSslCertificateReplaceCharactersSource)) {
  286.                         if("\\t".equals(this.headerSslCertificateReplaceCharactersSource)) {
  287.                             this.headerSslCertificateReplaceCharactersSource = "\t";
  288.                         }
  289.                         else if("\\r".equals(this.headerSslCertificateReplaceCharactersSource)) {
  290.                             this.headerSslCertificateReplaceCharactersSource = "\r";
  291.                         }
  292.                         else if("\\n".equals(this.headerSslCertificateReplaceCharactersSource)) {
  293.                             this.headerSslCertificateReplaceCharactersSource = "\n";
  294.                         }
  295.                         else if("\\r\\n".equals(this.headerSslCertificateReplaceCharactersSource)) {
  296.                             this.headerSslCertificateReplaceCharactersSource = "\r\n";
  297.                         }
  298.                         else if("\\s".equals(this.headerSslCertificateReplaceCharactersSource)) {
  299.                             this.headerSslCertificateReplaceCharactersSource = " "; // viene codificato in spazio
  300.                         }
  301.                     }
  302.                     else {
  303.                         this.headerSslCertificateReplaceCharactersSource = null;
  304.                     }
  305.                 }
  306.                
  307.                 this.headerSslCertificateReplaceCharactersDest = getProperty(p, "header.ssl.certificate.replaceCharacters.dest", protocollo, idSoggetto);
  308.                 if(this.headerSslCertificateReplaceCharactersDest!=null){
  309.                     if(StringUtils.isNotEmpty(this.headerSslCertificateReplaceCharactersDest)) {
  310.                         if("\\t".equals(this.headerSslCertificateReplaceCharactersDest)) {
  311.                             this.headerSslCertificateReplaceCharactersDest = "\t";
  312.                         }
  313.                         if("\\r".equals(this.headerSslCertificateReplaceCharactersDest)) {
  314.                             this.headerSslCertificateReplaceCharactersDest = "\r";
  315.                         }
  316.                         else if("\\n".equals(this.headerSslCertificateReplaceCharactersDest)) {
  317.                             this.headerSslCertificateReplaceCharactersDest = "\n";
  318.                         }
  319.                         else if("\\r\\n".equals(this.headerSslCertificateReplaceCharactersDest)) {
  320.                             this.headerSslCertificateReplaceCharactersDest = "\r\n";
  321.                         }
  322.                         else if("\\s".equals(this.headerSslCertificateReplaceCharactersDest)) {
  323.                             this.headerSslCertificateReplaceCharactersDest = " "; // viene codificato in spazio
  324.                         }
  325.                     }
  326.                     else {
  327.                         this.headerSslCertificateReplaceCharactersDest = null;
  328.                     }
  329.                 }
  330.             }
  331.            
  332.             String t = getProperty(p, "header.ssl.certificate.truststore.path", protocollo, idSoggetto);
  333.             if(t!=null && StringUtils.isNotEmpty(t)) {
  334.                 File fTrustStore = new File(t);
  335.                 if(!fTrustStore.exists()) {
  336.                     throw new GestoreCredenzialiException("Il truststore dei certificati ssl indicato ["+fTrustStore.getAbsolutePath()+"] non esiste");
  337.                 }
  338.                 if(!fTrustStore.canRead()) {
  339.                     throw new GestoreCredenzialiException("Il truststore dei certificati ssl indicato ["+fTrustStore.getAbsolutePath()+"] non è accessibile in lettura");
  340.                 }
  341.                 String password = getProperty(p, "header.ssl.certificate.truststore.password", protocollo, idSoggetto);
  342.                 if(password==null) {
  343.                     throw new GestoreCredenzialiException("Non è stata indicata una password per il truststore dei certificati ssl indicato ["+fTrustStore.getAbsolutePath()+"]");
  344.                 }
  345.                 this.headerSslCertificateTrustStorePath = fTrustStore.getAbsolutePath();
  346.                 this.headerSslCertificateTrustStorePassword = password;
  347.                 String type = getProperty(p, "header.ssl.certificate.truststore.type", protocollo, idSoggetto);
  348.                 if(type==null) {
  349.                     this.headerSslCertificateTrustStoreType = KeystoreType.JKS.getNome();
  350.                 }
  351.                 else {
  352.                     this.headerSslCertificateTrustStoreType = type;
  353.                 }
  354.             }
  355.            
  356.             if(this.headerSslCertificateTrustStorePath!=null) {
  357.                
  358.                 String v = getProperty(p, "header.ssl.certificate.truststore.validityCheck", protocollo, idSoggetto);
  359.                 if(v!=null && StringUtils.isNotEmpty(v)) {
  360.                     try {
  361.                         this.headerSslCertificateTrustStoreCheckValid = Boolean.valueOf(v);
  362.                     }catch(Exception e) {
  363.                         throw new GestoreCredenzialiException("Errore durante la lettura della proprietà 'header.ssl.certificate.truststore.validityCheck' (valore: "+v+"): "+e.getMessage(),e);
  364.                     }
  365.                 }
  366.                
  367.                 String crls = getProperty(p, "header.ssl.certificate.truststore.crls", protocollo, idSoggetto);
  368.                 if(crls!=null && StringUtils.isNotEmpty(crls)) {
  369.                     this.headerSslCertificateCrlX509 = crls;
  370.                 }
  371.                
  372.                 String ocspPolicy = getProperty(p, "header.ssl.certificate.truststore.ocspPolicy", protocollo, idSoggetto);
  373.                 if(ocspPolicy!=null && StringUtils.isNotEmpty(ocspPolicy)) {
  374.                     this.headerSslCertificateOcspPolicy = ocspPolicy;
  375.                 }
  376.             }
  377.            
  378.             pValue = getProperty(p, "header.ssl.certificate.none", protocollo, idSoggetto);
  379.             if(pValue!=null){
  380.                 pValue = pValue.trim();
  381.                 this.headerSslCertificateNoneOption = pValue;
  382.             }
  383.            
  384.             String v = getProperty(p, "header.ssl.certificate.ignoreEmpty", protocollo, idSoggetto);
  385.             if(v!=null && StringUtils.isNotEmpty(v)) {
  386.                 try {
  387.                     this.headerSslCertificateIgnoreEmpty = Boolean.valueOf(v);
  388.                 }catch(Exception e) {
  389.                     throw new GestoreCredenzialiException("Errore durante la lettura della proprietà 'header.ssl.certificate.ignoreEmpty' (valore: "+v+"): "+e.getMessage(),e);
  390.                 }
  391.             }
  392.         }
  393.        
  394.         this.headerPrincipal = getProperty(p, "header.principal", protocollo, idSoggetto);
  395.    
  396.        
  397.         if(this.headerBasicUsername==null && this.headerSslSubject==null && this.headerSslCertificate==null && this.headerPrincipal==null) {
  398.             throw new GestoreCredenzialiException("L'abilitazione del gestore delle credenziali ("+prefix+"*) richiede almeno la definizione di un header su cui vengono fornite le credenziali");
  399.         }
  400.         if(this.headerBasicUsername!=null &&
  401.             this.headerBasicPassword==null) {
  402.             throw new GestoreCredenzialiException("L'abilitazione del gestore delle credenziali ("+prefix+"*) richiede la definizione di un header su cui viene indicata la password, se viene definito un header per l'username");
  403.         }
  404.        
  405.        
  406.         String modalitaCanaleS = getProperty(p, "modalita", protocollo, idSoggetto);
  407.         if(modalitaCanaleS==null) {
  408.             throw new GestoreCredenzialiException(getProprietaPrefix(prefix)+"modalita non impostata");
  409.         }  
  410.         this.modalitaAutenticazioneCanale = ModalitaAutenticazioneGestoreCredenziali.toEnumConstant(modalitaCanaleS);
  411.         if(this.modalitaAutenticazioneCanale==null) {
  412.             throw new GestoreCredenzialiException(getProprietaPrefix(prefix)+"modalita impostata non correttamente, valore indicato ("+modalitaCanaleS+") non gestito");
  413.         }
  414.         switch (this.modalitaAutenticazioneCanale) {
  415.         case NONE:
  416.             break;
  417.         case AT_LEAST_ONE:
  418.             this.modalitaAutenticazioneCanaleAtLeastOneErrorDescription = getProperty(p, "modalita.atLeastOne.error_description.notFound", protocollo, idSoggetto);
  419.             // Il controllo è gia stato fatto sopra che sia definito almeno una modalità per passare la credenziale
  420.             break;
  421.         case BASIC:
  422.             if(this.headerBasicUsername==null || this.headerBasicPassword==null) {
  423.                 throw new GestoreCredenzialiException(getProprietaPrefix(prefix)+getMessaggioModalitaNonConfigurataCompletamente()+"richiede la definizione degli header http dove far veicolare le credenziali basic");
  424.             }
  425.             break;
  426.         case SSL:
  427.             if(this.headerSslSubject==null && this.headerSslCertificate==null) {
  428.                 throw new GestoreCredenzialiException(getProprietaPrefix(prefix)+getMessaggioModalitaNonConfigurataCompletamente()+"richiede la definizione di almeno un header http dove far veicolare le credenziali ssl");
  429.             }
  430.             break;
  431.         case PRINCIPAL:
  432.             if(this.headerPrincipal==null) {
  433.                 throw new GestoreCredenzialiException(getProprietaPrefix(prefix)+getMessaggioModalitaNonConfigurataCompletamente()+"richiede la definizione dell'header http dove far veicolare le credenziali principal");
  434.             }
  435.             break;
  436.         default:
  437.             break;
  438.         }
  439.     }
  440.    
  441.     private String getProperty(Properties p, String key, String protocollo, IDSoggetto idSoggetto) {
  442.        
  443.         String key1 = null;
  444.         String key2 = null;
  445.         String key3 = null;
  446.         String key4 = null;
  447.         String key5 = null;
  448.         String keyOriginale = key;
  449.        
  450.         if(protocollo!=null && idSoggetto!=null) {
  451.             key1 = protocollo+"-"+idSoggetto.getTipo()+"-"+idSoggetto.getNome()+"."+key;
  452.             key3 = protocollo+"-"+idSoggetto.getNome()+"."+key;
  453.         }
  454.         if(idSoggetto!=null) {
  455.             key2 = idSoggetto.getTipo()+"-"+idSoggetto.getNome()+"."+key;
  456.             key4 = idSoggetto.getNome()+"."+key;
  457.         }
  458.         if(protocollo!=null) {
  459.             key5 = protocollo+"."+key;
  460.         }
  461.        
  462.         String value = null;
  463.        
  464.         if(key1!=null) {
  465.             value = p.getProperty(key1);
  466.             if(value!=null) {
  467.                 if(!StringUtils.isEmpty(value.trim())) {
  468.                     return value.trim();
  469.                 }
  470.                 else {
  471.                     return null; // e' stata definita vuota per disattivare una opzione generale
  472.                 }
  473.             }
  474.         }
  475.        
  476.         if(key2!=null) {
  477.             value = p.getProperty(key2);
  478.             if(value!=null) {
  479.                 if(!StringUtils.isEmpty(value.trim())) {
  480.                     return value.trim();
  481.                 }
  482.                 else {
  483.                     return null; // e' stata definita vuota per disattivare una opzione generale
  484.                 }
  485.             }
  486.         }
  487.        
  488.         if(key3!=null) {
  489.             value = p.getProperty(key3);
  490.             if(value!=null) {
  491.                 if(!StringUtils.isEmpty(value.trim())) {
  492.                     return value.trim();
  493.                 }
  494.                 else {
  495.                     return null; // e' stata definita vuota per disattivare una opzione generale
  496.                 }
  497.             }
  498.         }
  499.        
  500.         if(key4!=null) {
  501.             value = p.getProperty(key4);
  502.             if(value!=null) {
  503.                 if(!StringUtils.isEmpty(value.trim())) {
  504.                     return value.trim();
  505.                 }
  506.                 else {
  507.                     return null; // e' stata definita vuota per disattivare una opzione generale
  508.                 }
  509.             }
  510.         }
  511.        
  512.         if(key5!=null) {
  513.             value = p.getProperty(key5);
  514.             if(value!=null) {
  515.                 if(!StringUtils.isEmpty(value.trim())) {
  516.                     return value.trim();
  517.                 }
  518.                 else {
  519.                     return null; // e' stata definita vuota per disattivare una opzione generale
  520.                 }
  521.             }
  522.         }
  523.        
  524.         value = p.getProperty(keyOriginale);
  525.         if(value!=null && !StringUtils.isEmpty(value.trim())) {
  526.             return value.trim();
  527.         }
  528.        
  529.         return null;

  530.     }
  531.    
  532.     public boolean isEnabled() {
  533.         return this.enabled;
  534.     }
  535.     public String getNome() {
  536.         return this.nome;
  537.     }
  538.    
  539.     public String getRealm() {
  540.         return this.realm;
  541.     }
  542.     public String getAuthType() {
  543.         return this.authType;
  544.     }
  545.    
  546.     public TipoAutenticazioneGestoreCredenziali getTipoAutenticazioneCanale() {
  547.         return this.tipoAutenticazioneCanale;
  548.     }
  549.     public String getAutenticazioneCanaleBasicUsername() {
  550.         return this.autenticazioneCanaleBasicUsername;
  551.     }
  552.     public String getAutenticazioneCanaleBasicPassword() {
  553.         return this.autenticazioneCanaleBasicPassword;
  554.     }
  555.     public String getAutenticazioneCanaleSslSubject() {
  556.         return this.autenticazioneCanaleSslSubject;
  557.     }
  558.     public String getAutenticazioneCanalePrincipal() {
  559.         return this.autenticazioneCanalePrincipal;
  560.     }
  561.    
  562.     public ModalitaAutenticazioneGestoreCredenziali getModalitaAutenticazioneCanale() {
  563.         return this.modalitaAutenticazioneCanale;
  564.     }
  565.     public String getModalitaAutenticazioneCanaleAtLeastOneErrorDescription() {
  566.         return this.modalitaAutenticazioneCanaleAtLeastOneErrorDescription;
  567.     }
  568.    
  569.     public String getHeaderBasicUsername() {
  570.         return this.headerBasicUsername;
  571.     }
  572.     public String getHeaderBasicPassword() {
  573.         return this.headerBasicPassword;
  574.     }
  575.    
  576.     public String getHeaderSslSubject() {
  577.         return this.headerSslSubject;
  578.     }
  579.     public String getHeaderSslIssuer() {
  580.         return this.headerSslIssuer;
  581.     }
  582.    
  583.     public String getHeaderSslCertificate() {
  584.         return this.headerSslCertificate;
  585.     }
  586.     public boolean isHeaderSslCertificateUrlDecode() {
  587.         return this.headerSslCertificateUrlDecode;
  588.     }
  589.     public boolean isHeaderSslCertificateBase64Decode() {
  590.         return this.headerSslCertificateBase64Decode;
  591.     }
  592.     public boolean isHeaderSslCertificateHexDecode() {
  593.         return this.headerSslCertificateHexDecode;
  594.     }
  595.     public boolean isHeaderSslCertificateUrlDecodeOrBase64Decode() {
  596.         return this.headerSslCertificateUrlDecodeOrBase64Decode;
  597.     }
  598.     public boolean isHeaderSslCertificateUrlDecodeOrBase64DecodeOrHexDecode() {
  599.         return this.headerSslCertificateUrlDecodeOrBase64DecodeOrHexDecode;
  600.     }
  601.     public boolean isHeaderSslCertificateEnrichBeginEnd() {
  602.         return this.headerSslCertificateEnrichBeginEnd;
  603.     }
  604.     public boolean isHeaderSslCertificateReplaceCharacters() {
  605.         return this.headerSslCertificateReplaceCharacters;
  606.     }
  607.     public String getHeaderSslCertificateReplaceCharactersSource() {
  608.         return this.headerSslCertificateReplaceCharactersSource;
  609.     }
  610.     public String getHeaderSslCertificateReplaceCharactersDest() {
  611.         return this.headerSslCertificateReplaceCharactersDest;
  612.     }
  613.     public String getHeaderSslCertificateTrustStorePath() {
  614.         return this.headerSslCertificateTrustStorePath;
  615.     }
  616.     public String getHeaderSslCertificateTrustStoreType() {
  617.         return this.headerSslCertificateTrustStoreType;
  618.     }
  619.     public String getHeaderSslCertificateTrustStorePassword() {
  620.         return this.headerSslCertificateTrustStorePassword;
  621.     }
  622.     public boolean isHeaderSslCertificateTrustStoreCheckValid() {
  623.         return this.headerSslCertificateTrustStoreCheckValid;
  624.     }
  625.     public String getHeaderSslCertificateCrlX509() {
  626.         return this.headerSslCertificateCrlX509;
  627.     }
  628.     public String getHeaderSslCertificateOcspPolicy() {
  629.         return this.headerSslCertificateOcspPolicy;
  630.     }
  631.     public String getHeaderSslCertificateNoneOption() {
  632.         return this.headerSslCertificateNoneOption;
  633.     }
  634.     public boolean isHeaderSslCertificateIgnoreEmpty() {
  635.         return this.headerSslCertificateIgnoreEmpty;
  636.     }
  637.    
  638.     public String getHeaderPrincipal() {
  639.         return this.headerPrincipal;
  640.     }
  641. }