NegoziazioneTokenDynamicParameters.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.token;

  21. import java.io.ByteArrayOutputStream;
  22. import java.util.List;
  23. import java.util.Map;

  24. import org.apache.commons.lang.StringUtils;
  25. import org.openspcoop2.core.config.ServizioApplicativo;
  26. import org.openspcoop2.core.constants.CostantiDB;
  27. import org.openspcoop2.core.constants.CostantiLabel;
  28. import org.openspcoop2.core.id.IDFruizione;
  29. import org.openspcoop2.core.id.IDServizio;
  30. import org.openspcoop2.core.id.IDServizioApplicativo;
  31. import org.openspcoop2.core.id.IDSoggetto;
  32. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  33. import org.openspcoop2.core.registry.ProtocolProperty;
  34. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  35. import org.openspcoop2.pdd.config.ConfigurazionePdDManager;
  36. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  37. import org.openspcoop2.pdd.core.CostantiPdD;
  38. import org.openspcoop2.pdd.core.PdDContext;
  39. import org.openspcoop2.pdd.core.byok.BYOKUnwrapPolicyUtilities;
  40. import org.openspcoop2.pdd.core.dynamic.DynamicException;
  41. import org.openspcoop2.pdd.core.dynamic.DynamicUtils;
  42. import org.openspcoop2.pdd.core.dynamic.Template;
  43. import org.openspcoop2.protocol.registry.RegistroServiziManager;
  44. import org.openspcoop2.protocol.sdk.Busta;
  45. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  46. import org.openspcoop2.protocol.sdk.ProtocolException;
  47. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesUtils;
  48. import org.openspcoop2.protocol.sdk.state.IState;
  49. import org.openspcoop2.protocol.sdk.state.RequestInfo;
  50. import org.openspcoop2.protocol.utils.ModIKeystoreUtils;
  51. import org.openspcoop2.security.SecurityException;
  52. import org.openspcoop2.security.keystore.JWKSetStore;
  53. import org.openspcoop2.security.keystore.KeyPairStore;
  54. import org.openspcoop2.security.keystore.MerlinKeystore;
  55. import org.openspcoop2.security.keystore.cache.GestoreKeystoreCache;
  56. import org.openspcoop2.utils.certificate.byok.BYOKProvider;
  57. import org.openspcoop2.utils.certificate.byok.BYOKRequestParams;
  58. import org.openspcoop2.utils.transport.http.HttpRequestMethod;

  59. /**
  60.  * AttributeAuthorityDynamicParameter
  61.  *
  62.  * @author Andrea Poli (apoli@link.it)
  63.  * @author $Author$
  64.  * @version $Rev$, $Date$
  65.  */
  66. public class NegoziazioneTokenDynamicParameters extends AbstractDynamicParameters {

  67.     @SuppressWarnings("unused")
  68.     private PolicyNegoziazioneToken policyNegoziazioneToken;
  69.    
  70.     private String endpoint;
  71.     private String basicUsername;
  72.     private String basicPassword;
  73.     private String bearerToken;
  74.    
  75.     private String usernamePasswordGrantUsername;
  76.     private String usernamePasswordGrantPassword;
  77.    
  78.     private String signedJwtIssuer;
  79.     private String signedJwtClientId;
  80.     private String signedJwtSubject;
  81.     private String signedJwtAudience;
  82.     private String signedJwtJti;
  83.     private String signedJwtPurposeId;
  84.     private String signedJwtSessionInfo;
  85.     private String signedJwtClaims;
  86.     private String signedJwtAuditDigest;
  87.     private String signedJwtAuditDigestAlgo;
  88.    
  89.     private String signedJwtCustomId;
  90.     private String signedJwtX509Url;
  91.    
  92.     private String scope;
  93.     private String audience;
  94.     private String formClientId;
  95.     private String formResource;
  96.     private String parameters;
  97.    
  98.     private HttpRequestMethod httpMethod;
  99.     private String httpContentType;
  100.     private String httpHeaders;
  101.     private String httpPayloadTemplateType;
  102.     private String httpPayload;
  103.    
  104.     private IDServizioApplicativo idApplicativoRichiedente;
  105.     private ServizioApplicativo applicativoRichiedente;
  106.     private String kidApplicativoModI; // nella chiave della cache non viene aggiunto il kid ma l'applicativo richiedente, poichè il kid potrebbe essere condiviso tra più applicativi
  107.     private ModIKeystoreUtils keystoreApplicativoModI;
  108.    
  109.     private IDFruizione idFruizione;
  110.     private String kidFruizioneModI; // nella chiave della cache non viene aggiunto il kid ma l'identificativo della fruizione, poichè il kid potrebbe essere condiviso tra più fruizioni
  111.     private ModIKeystoreUtils keystoreFruizioneModI;
  112.    
  113.    
  114.     // static config
  115.    
  116.     private static boolean signedJwtIssuerCacheKey;
  117.     private static boolean signedJwtClientIdCacheKey;
  118.     private static boolean signedJwtSubjectCacheKey;
  119.     private static boolean signedJwtAudienceCacheKey;
  120.     private static boolean signedJwtJtiCacheKey;
  121.     private static boolean signedJwtPurposeIdCacheKey;
  122.     private static boolean signedJwtSessionInfoCacheKey;
  123.     private static boolean signedJwtClaimsCacheKey;
  124.     private static boolean signedJwtAuditDigestCacheKey;
  125.    
  126.     private static boolean signedJwtCustomIdCacheKey;
  127.     private static boolean signedJwtX509UrlCacheKey;
  128.    
  129.     private static boolean scopeCacheKey;
  130.     private static boolean audienceCacheKey;
  131.     private static boolean formClientIdCacheKey;
  132.     private static boolean formResourceCacheKey;
  133.     private static boolean parametersCacheKey;
  134.    
  135.     private static boolean httpMethodCacheKey;
  136.     private static boolean httpContentTypeCacheKey;
  137.     private static boolean httpHeadersCacheKey;
  138.     private static boolean httpPayloadTemplateTypeCacheKey;
  139.     private static boolean httpPayloadCacheKey;
  140.    
  141.     private static boolean applicativoRichiedenteCacheKey;
  142.    
  143.     private static boolean fruizioneCacheKey;
  144.    
  145.     private static Boolean initCacheKey = null;
  146.     private static synchronized void initCacheKey() {
  147.         if(initCacheKey==null) {
  148.             OpenSPCoop2Properties op2Properties = OpenSPCoop2Properties.getInstance();
  149.            
  150.             signedJwtIssuerCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_ISSUER);
  151.             signedJwtClientIdCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_CLIENT_ID);
  152.             signedJwtSubjectCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_SUBJECT);
  153.             signedJwtAudienceCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_AUDIENCE);
  154.             signedJwtJtiCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_IDENTIFIER);
  155.             signedJwtPurposeIdCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_PURPOSE_ID);
  156.             signedJwtSessionInfoCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_SESSION_INFO);
  157.             signedJwtClaimsCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_CLAIMS);
  158.             signedJwtAuditDigestCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_AUDIT_DIGEST);
  159.            
  160.             signedJwtCustomIdCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_HEADER_KID);
  161.             signedJwtX509UrlCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_HEADER_X509_URL);
  162.            
  163.             scopeCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_FORM_REQUEST_SCOPE);
  164.             audienceCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_FORM_REQUEST_AUDIENCE);
  165.             formClientIdCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_FORM_REQUEST_CLIENT_ID);
  166.             formResourceCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_FORM_REQUEST_RESOURCE);
  167.             parametersCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_FORM_REQUEST_PARAMETERS);
  168.            
  169.             httpMethodCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_HTTP_METHOD);
  170.             httpContentTypeCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_HTTP_CONTENT_TYPE);
  171.             httpHeadersCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_HTTP_HEADERS);
  172.             httpPayloadTemplateTypeCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_HTTP_PAYLOAD_TEMPLATE_TYPE);
  173.             httpPayloadCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_HTTP_PAYLOAD);

  174.             applicativoRichiedenteCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_FORM_APPLICATIVE_REQUESTER);
  175.            
  176.             fruizioneCacheKey = op2Properties.isGestioneRetrieveTokenCacheKey(CostantiPdD.HEADER_INTEGRAZIONE_TOKEN_FORM_OUTBOUND_INTERFACE);
  177.                        
  178.             initCacheKey = true;
  179.         }
  180.     }
  181.     private static void checkInitCacheKey() {
  182.         if(initCacheKey==null) {
  183.             initCacheKey();
  184.         }
  185.     }
  186.    
  187.     private static final String ERRORE_RICHIEDE_IDENTIFICAZIONE_DATI_FRUIZIONE = "richiede l'identificazione dei dati di una fruizione";
  188.     private static final String ERRORE_NON_UTILIZZABILE_APPLICATIVO_IDENTIFICATO = "non è utilizzabile con l'applicativo identificato";
  189.     private static final String ERRORE_CONFIGURAZIONE_APPLICATIVO_NON_COMPLETA = "nella configurazione dell'applicativo non è stato definito un";
  190.     private static final String ERRORE_SEZIONE = "nella sezione";
  191.     private static final String ERRORE_NON_UTILIZZABILE_FRUIZIONE = "non è utilizzabile con la fruizione";
  192.     private static final String ERRORE_CONFIGURAZIONE_MODI_NON_COMPLETA = "nella configurazione 'ModI' non è stato definito un";
  193.     private static final String ERRORE_RICHIEDE_AUTENTICAZIONE_IDENTIFICAZIONE_APPLICATIVO = "richiede l'autenticazione e l'identificazione di un applicativo fruitore";

  194.     public NegoziazioneTokenDynamicParameters(Map<String, Object> dynamicMap,
  195.             PdDContext pddContext, RequestInfo requestInfo, Busta busta, IState state, IProtocolFactory<?> protocolFactory,
  196.             PolicyNegoziazioneToken policyNegoziazioneToken) throws TokenException, DynamicException, ProtocolException {
  197.         super(dynamicMap, pddContext, requestInfo);
  198.                        
  199.         this.policyNegoziazioneToken = policyNegoziazioneToken;
  200.        
  201.         this.endpoint = policyNegoziazioneToken.getEndpoint();
  202.         if(this.endpoint!=null && !"".equals(this.endpoint)) {
  203.             this.endpoint = DynamicUtils.convertDynamicPropertyValue("endpoint.gwt", this.endpoint, dynamicMap, pddContext);    
  204.         }
  205.        
  206.         boolean basic = policyNegoziazioneToken.isBasicAuthentication();
  207.         if(basic) {
  208.             this.basicUsername = policyNegoziazioneToken.getBasicAuthenticationUsername();
  209.             if(this.basicUsername!=null && !"".equals(this.basicUsername)) {
  210.                 this.basicUsername = DynamicUtils.convertDynamicPropertyValue("username.gwt", this.basicUsername, dynamicMap, pddContext);  
  211.             }
  212.            
  213.             this.basicPassword = policyNegoziazioneToken.getBasicAuthenticationPassword();
  214.             if(this.basicPassword!=null && !"".equals(this.basicPassword)) {
  215.                 this.basicPassword = DynamicUtils.convertDynamicPropertyValue("password.gwt", this.basicPassword, dynamicMap, pddContext);  
  216.             }
  217.         }
  218.        
  219.         boolean bearer = policyNegoziazioneToken.isBearerAuthentication();
  220.         if(bearer) {
  221.             this.bearerToken = policyNegoziazioneToken.getBeareAuthenticationToken();
  222.             if(this.bearerToken!=null && !"".equals(this.bearerToken)) {
  223.                 this.bearerToken = DynamicUtils.convertDynamicPropertyValue("bearerToken.gwt", this.bearerToken, dynamicMap, pddContext);  
  224.             }
  225.         }
  226.        
  227.         if(policyNegoziazioneToken.isUsernamePasswordGrant()) {
  228.             this.usernamePasswordGrantUsername = policyNegoziazioneToken.getUsernamePasswordGrantUsername();
  229.             if(this.usernamePasswordGrantUsername!=null && !"".equals(this.usernamePasswordGrantUsername)) {
  230.                 this.usernamePasswordGrantUsername = DynamicUtils.convertDynamicPropertyValue("usernamePasswordGrant_username.gwt", this.usernamePasswordGrantUsername, dynamicMap, pddContext);    
  231.             }
  232.            
  233.             this.usernamePasswordGrantPassword = policyNegoziazioneToken.getUsernamePasswordGrantPassword();
  234.             if(this.usernamePasswordGrantPassword!=null && !"".equals(this.usernamePasswordGrantPassword)) {
  235.                 this.usernamePasswordGrantPassword = DynamicUtils.convertDynamicPropertyValue("usernamePasswordGrant_password.gwt", this.usernamePasswordGrantPassword, dynamicMap, pddContext);    
  236.             }
  237.         }
  238.        
  239.         String clientIdApplicativoModI = null;
  240.         String idApp = null;
  241.        
  242.         String clientIdFruizioneModI = null;
  243.         String idFruizioneLabel = null;
  244.         List<ProtocolProperty> listProtocolPropertiesFruizione = null;
  245.        
  246.         if(policyNegoziazioneToken.isRfc7523x509Grant() || policyNegoziazioneToken.isRfc7523ClientSecretGrant()) {
  247.            
  248.             if(policyNegoziazioneToken.isRfc7523x509Grant()) {
  249.                 if(policyNegoziazioneToken.isJwtSignKeystoreApplicativoModI()) {
  250.                     String prefixError = "Il tipo di keystore indicato nella token policy '"+policyNegoziazioneToken.getName()+"' ";
  251.                     if(busta.getServizioApplicativoFruitore()==null) {
  252.                         throw new TokenException(prefixError+ERRORE_RICHIEDE_AUTENTICAZIONE_IDENTIFICAZIONE_APPLICATIVO);
  253.                     }
  254.                     if(busta.getTipoMittente()==null || busta.getMittente()==null) {
  255.                         throw new TokenException(prefixError+ERRORE_RICHIEDE_AUTENTICAZIONE_IDENTIFICAZIONE_APPLICATIVO+": dominio non identificato");
  256.                     }
  257.                    
  258.                     ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance(state);
  259.                    
  260.                     TokenException te = null;
  261.                     this.idApplicativoRichiedente = new IDServizioApplicativo();
  262.                     this.idApplicativoRichiedente.setNome(busta.getServizioApplicativoFruitore());
  263.                     this.idApplicativoRichiedente.setIdSoggettoProprietario(new IDSoggetto(busta.getTipoMittente(), busta.getMittente()));
  264.                     try {
  265.                         this.applicativoRichiedente = configurazionePdDManager.getServizioApplicativo(this.idApplicativoRichiedente, this.getRequestInfo());
  266.                     }catch(Exception t) {
  267.                         te = new TokenException(prefixError+ERRORE_RICHIEDE_AUTENTICAZIONE_IDENTIFICAZIONE_APPLICATIVO+": "+t.getMessage(),t);
  268.                     }
  269.                    
  270.                     TokenException teToken = null;
  271.                     if(this.applicativoRichiedente==null) {
  272.                         // provo a vedere se l'applicativo fruitore è stato identificato tramite autenticazione token
  273.                         IDServizioApplicativo idServizioApplicativoToken = null;
  274.                         if(pddContext!=null && pddContext.containsKey(org.openspcoop2.core.constants.Costanti.ID_APPLICATIVO_TOKEN)) {
  275.                             idServizioApplicativoToken = (IDServizioApplicativo) pddContext.getObject(org.openspcoop2.core.constants.Costanti.ID_APPLICATIVO_TOKEN);
  276.                         }
  277.                         if(idServizioApplicativoToken!=null) {
  278.                             try {
  279.                                 this.idApplicativoRichiedente = idServizioApplicativoToken;
  280.                                 this.applicativoRichiedente = configurazionePdDManager.getServizioApplicativo(this.idApplicativoRichiedente, this.getRequestInfo());
  281.                             }catch(Exception t) {
  282.                                 teToken = new TokenException(prefixError+ERRORE_RICHIEDE_AUTENTICAZIONE_IDENTIFICAZIONE_APPLICATIVO+": "+t.getMessage(),t);
  283.                             }
  284.                         }
  285.                     }
  286.                    
  287.                     if(this.applicativoRichiedente==null) {
  288.                         if(te!=null) {
  289.                             throw te;
  290.                         }
  291.                         else if(teToken!=null) {
  292.                             throw teToken;
  293.                         }
  294.                         else {
  295.                             throw new TokenException(prefixError+ERRORE_RICHIEDE_AUTENTICAZIONE_IDENTIFICAZIONE_APPLICATIVO);
  296.                         }
  297.                     }
  298.                    
  299.                     if(!org.openspcoop2.protocol.engine.constants.Costanti.MODIPA_PROTOCOL_NAME.equals(protocolFactory.getProtocol())) {
  300.                         throw new TokenException(prefixError+"è utilizzabile solamente con il profilo di interoperabilità 'ModI'");
  301.                     }
  302.                    
  303.                     idApp = this.idApplicativoRichiedente.getNome() + " (Soggetto: "+this.idApplicativoRichiedente.getIdSoggettoProprietario().getNome()+")";
  304.                    
  305.                     try {
  306.                         this.keystoreApplicativoModI = new ModIKeystoreUtils(this.applicativoRichiedente, "Token Policy Negoziazione - Signed JWT");
  307.                     }catch(Exception t) {
  308.                         throw new TokenException(prefixError+"non è utilizzabile: "+t.getMessage(),t);
  309.                     }
  310.                 }
  311.                 else if(policyNegoziazioneToken.isJwtSignKeystoreFruizioneModI()) {
  312.                     String prefixError = "Il tipo di keystore indicato nella token policy '"+policyNegoziazioneToken.getName()+"' ";
  313.                    
  314.                     if(busta.getTipoMittente()==null || busta.getMittente()==null) {
  315.                         throw new TokenException(prefixError+"non è utilizzabile: soggetto fruitore non identificato");
  316.                     }
  317.                     if(busta.getTipoDestinatario()==null || busta.getDestinatario()==null) {
  318.                         throw new TokenException(prefixError+"non è utilizzabile: soggetto erogatore non identificato");
  319.                     }
  320.                     if(busta.getTipoServizio()==null || busta.getServizio()==null || busta.getVersioneServizio()==null) {
  321.                         throw new TokenException(prefixError+"non è utilizzabile: dati servizio non identificati");
  322.                     }
  323.                    
  324.                     RegistroServiziManager registroServiziManager = RegistroServiziManager.getInstance(state);
  325.                    
  326.                     IDSoggetto idFruitore = new IDSoggetto(busta.getTipoMittente(), busta.getMittente());
  327.                     IDServizio idServizio = null;
  328.                     try {
  329.                         idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(busta.getTipoServizio(), busta.getServizio(),
  330.                                 busta.getTipoDestinatario(), busta.getDestinatario(),
  331.                                 busta.getVersioneServizio());
  332.                     }catch(Exception e) {
  333.                         throw new TokenException(e.getMessage(),e);
  334.                     }
  335.                     this.idFruizione = new IDFruizione();
  336.                     this.idFruizione.setIdFruitore(idFruitore);
  337.                     this.idFruizione.setIdServizio(idServizio);
  338.                    
  339.                     if(!org.openspcoop2.protocol.engine.constants.Costanti.MODIPA_PROTOCOL_NAME.equals(protocolFactory.getProtocol())) {
  340.                         throw new TokenException(prefixError+"è utilizzabile solamente con il profilo di interoperabilità 'ModI'");
  341.                     }
  342.                    
  343.                     AccordoServizioParteSpecifica asps = null;
  344.                     try {
  345.                         asps = registroServiziManager.getAccordoServizioParteSpecifica(this.idFruizione.getIdServizio(), null, false, this.getRequestInfo());
  346.                     }catch(Exception t) {
  347.                         throw new TokenException(prefixError+"richiede l'identificazione di servizio: "+t.getMessage(),t);
  348.                     }
  349.                                        
  350.                     idFruizioneLabel = this.idFruizione.getIdFruitore().getNome() + " -> "+this.idFruizione.getIdServizio().getNome()+" (Soggetto: "+this.idFruizione.getIdServizio().getSoggettoErogatore().getNome()+")";
  351.                    
  352.                     try {
  353.                         this.keystoreFruizioneModI = new ModIKeystoreUtils(true, this.idFruizione.getIdFruitore(), asps, "Token Policy Negoziazione - Signed JWT",
  354.                                 NegoziazioneTokenDynamicParametersModIUtils.getSicurezzaMessaggioCertificatiKeyStoreTipo(),
  355.                                 NegoziazioneTokenDynamicParametersModIUtils.getSicurezzaMessaggioCertificatiKeyStorePath(),
  356.                                 NegoziazioneTokenDynamicParametersModIUtils.getSicurezzaMessaggioCertificatiKeyStorePassword(),
  357.                                 NegoziazioneTokenDynamicParametersModIUtils.getSicurezzaMessaggioCertificatiKeyAlias(),
  358.                                 NegoziazioneTokenDynamicParametersModIUtils.getSicurezzaMessaggioCertificatiKeyPassword());
  359.                     }catch(Exception t) {
  360.                         throw new TokenException(prefixError+"non è utilizzabile: "+t.getMessage(),t);
  361.                     }
  362.                    
  363.                     listProtocolPropertiesFruizione = ProtocolPropertiesUtils.getProtocolProperties(true, this.idFruizione.getIdFruitore(), asps);
  364.                 }
  365.             }
  366.            
  367.             if(policyNegoziazioneToken.isJwtSignIncludeKeyIdApplicativoModI()) {
  368.                 String prefixError = "La modalità di generazione del Key Id (kid), indicata nella token policy '"+policyNegoziazioneToken.getName()+"', ";
  369.                 if(this.applicativoRichiedente==null) {
  370.                     throw new TokenException(prefixError+ERRORE_RICHIEDE_AUTENTICAZIONE_IDENTIFICAZIONE_APPLICATIVO);
  371.                 }
  372.                 String kidApplicativoModIConfig = ProtocolPropertiesUtils.getOptionalStringValuePropertyConfig(this.applicativoRichiedente.getProtocolPropertyList(), CostantiDB.MODIPA_SICUREZZA_TOKEN_KID_ID);
  373.                 if(kidApplicativoModIConfig==null || StringUtils.isEmpty(kidApplicativoModIConfig)) {
  374.                     throw new TokenException(prefixError+ERRORE_NON_UTILIZZABILE_APPLICATIVO_IDENTIFICATO+" '"+idApp+
  375.                             "': "+ERRORE_CONFIGURAZIONE_APPLICATIVO_NON_COMPLETA+" '"+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_KID+
  376.                             "' "+ERRORE_SEZIONE+" '"+CostantiLabel.MODIPA_SICUREZZA_TOKEN_SUBTITLE_LABEL+"'");
  377.                 }
  378.                 this.kidApplicativoModI = kidApplicativoModIConfig;
  379.                 if(this.kidApplicativoModI!=null && !"".equals(this.kidApplicativoModI) && !Costanti.POLICY_RETRIEVE_TOKEN_JWT_CLAIM_UNDEFINED.equals(this.kidApplicativoModI)) {
  380.                     this.kidApplicativoModI = DynamicUtils.convertDynamicPropertyValue("kid.gwt", this.kidApplicativoModI, dynamicMap, pddContext);
  381.                 }
  382.             }
  383.             else if(policyNegoziazioneToken.isJwtSignIncludeKeyIdFruizioneModI()) {
  384.                 String prefixError = "La modalità di generazione del Key Id (kid), indicata nella token policy '"+policyNegoziazioneToken.getName()+"', ";
  385.                 if(this.idFruizione==null) {
  386.                     throw new TokenException(prefixError+ERRORE_RICHIEDE_IDENTIFICAZIONE_DATI_FRUIZIONE);
  387.                 }
  388.                 String kidFruizioneModIConfig = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(listProtocolPropertiesFruizione, CostantiDB.MODIPA_PROFILO_SICUREZZA_OAUTH_KID);
  389.                 if(kidFruizioneModIConfig==null || StringUtils.isEmpty(kidFruizioneModIConfig)) {
  390.                     throw new TokenException(prefixError+ERRORE_NON_UTILIZZABILE_FRUIZIONE+" '"+idFruizioneLabel+
  391.                             "': "+ERRORE_CONFIGURAZIONE_MODI_NON_COMPLETA+" '"+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_KID+"'");
  392.                 }
  393.                 this.kidFruizioneModI = kidFruizioneModIConfig;
  394.                 if(this.kidFruizioneModI!=null && !"".equals(this.kidFruizioneModI) && !Costanti.POLICY_RETRIEVE_TOKEN_JWT_CLAIM_UNDEFINED.equals(this.kidFruizioneModI)) {
  395.                     this.kidFruizioneModI = DynamicUtils.convertDynamicPropertyValue("kid.gwt", this.kidFruizioneModI, dynamicMap, pddContext);
  396.                 }
  397.             }
  398.            
  399.             if(policyNegoziazioneToken.isJwtIssuerApplicativoModI()) {
  400.                 String prefixError = "La modalità di generazione dell'Issuer, indicata nella token policy '"+policyNegoziazioneToken.getName()+"', ";
  401.                 if(this.applicativoRichiedente==null) {
  402.                     throw new TokenException(prefixError+ERRORE_RICHIEDE_AUTENTICAZIONE_IDENTIFICAZIONE_APPLICATIVO);
  403.                 }
  404.                 clientIdApplicativoModI = ProtocolPropertiesUtils.getOptionalStringValuePropertyConfig(this.applicativoRichiedente.getProtocolPropertyList(), CostantiDB.MODIPA_SICUREZZA_TOKEN_CLIENT_ID);
  405.                 if(clientIdApplicativoModI==null || StringUtils.isEmpty(clientIdApplicativoModI)) {
  406.                     throw new TokenException(prefixError+ERRORE_NON_UTILIZZABILE_APPLICATIVO_IDENTIFICATO+" '"+idApp+
  407.                             "': "+ERRORE_CONFIGURAZIONE_APPLICATIVO_NON_COMPLETA+" '"+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_CLIENT_ID+
  408.                             "' "+ERRORE_SEZIONE+" '"+CostantiLabel.MODIPA_SICUREZZA_TOKEN_SUBTITLE_LABEL+"'");
  409.                 }
  410.                 this.signedJwtIssuer = clientIdApplicativoModI;
  411.             }
  412.             else if(policyNegoziazioneToken.isJwtIssuerFruizioneModI()) {
  413.                 String prefixError = "La modalità di generazione dell'Issuer, indicata nella token policy '"+policyNegoziazioneToken.getName()+"', ";
  414.                 if(this.idFruizione==null) {
  415.                     throw new TokenException(prefixError+ERRORE_RICHIEDE_IDENTIFICAZIONE_DATI_FRUIZIONE);
  416.                 }
  417.                 clientIdFruizioneModI = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(listProtocolPropertiesFruizione, CostantiDB.MODIPA_PROFILO_SICUREZZA_OAUTH_IDENTIFICATIVO);
  418.                 if(clientIdFruizioneModI==null || StringUtils.isEmpty(clientIdFruizioneModI)) {
  419.                     throw new TokenException(prefixError+ERRORE_NON_UTILIZZABILE_FRUIZIONE+" '"+idFruizioneLabel+
  420.                             "': "+ERRORE_CONFIGURAZIONE_MODI_NON_COMPLETA+" '"+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_CLIENT_ID+
  421.                             " "+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_CLIENT_ID_SEARCH+"'");
  422.                 }
  423.                 this.signedJwtIssuer = clientIdFruizioneModI;
  424.             }
  425.             else {
  426.                 this.signedJwtIssuer = policyNegoziazioneToken.getJwtIssuer();
  427.             }
  428.             if(this.signedJwtIssuer!=null && !"".equals(this.signedJwtIssuer) && !Costanti.POLICY_RETRIEVE_TOKEN_JWT_CLAIM_UNDEFINED.equals(this.signedJwtIssuer)) {
  429.                 this.signedJwtIssuer = DynamicUtils.convertDynamicPropertyValue("issuer.gwt", this.signedJwtIssuer, dynamicMap, pddContext);    
  430.             }
  431.            
  432.            
  433.             if(policyNegoziazioneToken.isJwtClientIdApplicativoModI()) {
  434.                 if(clientIdApplicativoModI==null) {
  435.                     String prefixError = "La modalità di generazione del Client ID, indicata nella token policy '"+policyNegoziazioneToken.getName()+"', ";
  436.                     if(this.applicativoRichiedente==null) {
  437.                         throw new TokenException(prefixError+ERRORE_RICHIEDE_AUTENTICAZIONE_IDENTIFICAZIONE_APPLICATIVO);
  438.                     }
  439.                     String clientId = ProtocolPropertiesUtils.getOptionalStringValuePropertyConfig(this.applicativoRichiedente.getProtocolPropertyList(), CostantiDB.MODIPA_SICUREZZA_TOKEN_CLIENT_ID);
  440.                     if(clientId==null || StringUtils.isEmpty(clientId)) {
  441.                         throw new TokenException(prefixError+ERRORE_NON_UTILIZZABILE_APPLICATIVO_IDENTIFICATO+" '"+idApp+
  442.                                 "': "+ERRORE_CONFIGURAZIONE_APPLICATIVO_NON_COMPLETA+" '"+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_CLIENT_ID+
  443.                                 "' "+ERRORE_SEZIONE+" '"+CostantiLabel.MODIPA_SICUREZZA_TOKEN_SUBTITLE_LABEL+"'");
  444.                     }
  445.                     clientIdApplicativoModI = clientId;
  446.                 }
  447.                 this.signedJwtClientId = clientIdApplicativoModI;
  448.             }
  449.             else if(policyNegoziazioneToken.isJwtClientIdFruizioneModI()) {
  450.                 if(clientIdFruizioneModI==null) {
  451.                     String prefixError = "La modalità di generazione del Client ID, indicata nella token policy '"+policyNegoziazioneToken.getName()+"', ";
  452.                     if(this.idFruizione==null) {
  453.                         throw new TokenException(prefixError+ERRORE_RICHIEDE_IDENTIFICAZIONE_DATI_FRUIZIONE);
  454.                     }
  455.                     String clientId = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(listProtocolPropertiesFruizione, CostantiDB.MODIPA_PROFILO_SICUREZZA_OAUTH_IDENTIFICATIVO);
  456.                     if(clientId==null || StringUtils.isEmpty(clientId)) {
  457.                         throw new TokenException(prefixError+ERRORE_NON_UTILIZZABILE_FRUIZIONE+" '"+idFruizioneLabel+
  458.                                 "': "+ERRORE_CONFIGURAZIONE_MODI_NON_COMPLETA+" '"+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_CLIENT_ID+
  459.                                 " "+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_CLIENT_ID_SEARCH+"'");
  460.                     }
  461.                     clientIdFruizioneModI = clientId;
  462.                 }
  463.                 this.signedJwtClientId = clientIdFruizioneModI;
  464.             }
  465.             else {
  466.                 this.signedJwtClientId = policyNegoziazioneToken.getJwtClientId();
  467.             }
  468.             if(this.signedJwtClientId!=null && !"".equals(this.signedJwtClientId) && !Costanti.POLICY_RETRIEVE_TOKEN_JWT_CLAIM_UNDEFINED.equals(this.signedJwtClientId)) {
  469.                 this.signedJwtClientId = DynamicUtils.convertDynamicPropertyValue("clientId.gwt", this.signedJwtClientId, dynamicMap, pddContext);  
  470.             }
  471.            
  472.            
  473.             if(policyNegoziazioneToken.isJwtSubjectApplicativoModI()) {
  474.                 if(clientIdApplicativoModI==null) {
  475.                     String prefixError = "La modalità di generazione del Subject, indicata nella token policy '"+policyNegoziazioneToken.getName()+"', ";
  476.                     if(this.applicativoRichiedente==null) {
  477.                         throw new TokenException(prefixError+ERRORE_RICHIEDE_AUTENTICAZIONE_IDENTIFICAZIONE_APPLICATIVO);
  478.                     }
  479.                     String clientId = ProtocolPropertiesUtils.getOptionalStringValuePropertyConfig(this.applicativoRichiedente.getProtocolPropertyList(), CostantiDB.MODIPA_SICUREZZA_TOKEN_CLIENT_ID);
  480.                     if(clientId==null || StringUtils.isEmpty(clientId)) {
  481.                         throw new TokenException(prefixError+ERRORE_NON_UTILIZZABILE_APPLICATIVO_IDENTIFICATO+" '"+idApp+
  482.                                 "': "+ERRORE_CONFIGURAZIONE_APPLICATIVO_NON_COMPLETA+" '"+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_CLIENT_ID+
  483.                                 "' "+ERRORE_SEZIONE+" '"+CostantiLabel.MODIPA_SICUREZZA_TOKEN_SUBTITLE_LABEL+"'");
  484.                     }
  485.                     clientIdApplicativoModI = clientId;
  486.                 }
  487.                 this.signedJwtSubject = clientIdApplicativoModI;
  488.             }
  489.             else if(policyNegoziazioneToken.isJwtSubjectFruizioneModI()) {
  490.                 if(clientIdFruizioneModI==null) {
  491.                     String prefixError = "La modalità di generazione del Subject, indicata nella token policy '"+policyNegoziazioneToken.getName()+"', ";
  492.                     if(this.idFruizione==null) {
  493.                         throw new TokenException(prefixError+ERRORE_RICHIEDE_IDENTIFICAZIONE_DATI_FRUIZIONE);
  494.                     }
  495.                     String clientId = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(listProtocolPropertiesFruizione, CostantiDB.MODIPA_PROFILO_SICUREZZA_OAUTH_IDENTIFICATIVO);
  496.                     if(clientId==null || StringUtils.isEmpty(clientId)) {
  497.                         throw new TokenException(prefixError+ERRORE_NON_UTILIZZABILE_FRUIZIONE+" '"+idFruizioneLabel+
  498.                                 "': "+ERRORE_CONFIGURAZIONE_MODI_NON_COMPLETA+" '"+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_CLIENT_ID+
  499.                                 " "+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_CLIENT_ID_SEARCH+"'");
  500.                     }
  501.                     clientIdFruizioneModI = clientId;
  502.                 }
  503.                 this.signedJwtSubject = clientIdFruizioneModI;
  504.             }
  505.             else {
  506.                 this.signedJwtSubject = policyNegoziazioneToken.getJwtSubject();
  507.             }
  508.             if(this.signedJwtSubject!=null && !"".equals(this.signedJwtSubject) && !Costanti.POLICY_RETRIEVE_TOKEN_JWT_CLAIM_UNDEFINED.equals(this.signedJwtSubject)) {
  509.                 this.signedJwtSubject = DynamicUtils.convertDynamicPropertyValue("subject.gwt", this.signedJwtSubject, dynamicMap, pddContext);
  510.             }
  511.            
  512.             this.signedJwtAudience = policyNegoziazioneToken.getJwtAudience();
  513.             if(this.signedJwtAudience!=null && !"".equals(this.signedJwtAudience) && !Costanti.POLICY_RETRIEVE_TOKEN_JWT_CLAIM_UNDEFINED.equals(this.signedJwtAudience)) {
  514.                 this.signedJwtAudience = DynamicUtils.convertDynamicPropertyValue("jwtAudience.gwt", this.signedJwtAudience, dynamicMap, pddContext);  
  515.             }
  516.            
  517.             this.signedJwtJti = policyNegoziazioneToken.getJwtIdentifier();
  518.             if(this.signedJwtJti!=null && !"".equals(this.signedJwtJti) && !Costanti.POLICY_RETRIEVE_TOKEN_JWT_CLAIM_UNDEFINED.equals(this.signedJwtJti)) {
  519.                 this.signedJwtJti = DynamicUtils.convertDynamicPropertyValue("jti.gwt", this.signedJwtJti, dynamicMap, pddContext);
  520.             }
  521.            
  522.             if(policyNegoziazioneToken.isPDND()) {
  523.                
  524.                 this.signedJwtPurposeId = policyNegoziazioneToken.getJwtPurposeId();
  525.                 if(this.signedJwtPurposeId!=null && !"".equals(this.signedJwtPurposeId) && !Costanti.POLICY_RETRIEVE_TOKEN_JWT_CLAIM_UNDEFINED.equals(this.signedJwtPurposeId)) {
  526.                     this.signedJwtPurposeId = DynamicUtils.convertDynamicPropertyValue("jwtPurposeId.gwt", this.signedJwtPurposeId, dynamicMap, pddContext);    
  527.                 }
  528.                
  529.                 this.signedJwtSessionInfo = policyNegoziazioneToken.getJwtSessionInfo();
  530.                 if(this.signedJwtSessionInfo!=null && !"".equals(this.signedJwtSessionInfo)) {
  531.                     this.signedJwtSessionInfo = DynamicUtils.convertDynamicPropertyValue("sessionInfo.gwt", this.signedJwtSessionInfo, dynamicMap, pddContext);
  532.                 }
  533.                
  534.             }
  535.            
  536.             this.signedJwtClaims = policyNegoziazioneToken.getJwtClaims();
  537.             if(this.signedJwtClaims!=null && !"".equals(this.signedJwtClaims)) {
  538.                 this.signedJwtClaims = DynamicUtils.convertDynamicPropertyValue("claims.gwt", this.signedJwtClaims, dynamicMap, pddContext);    
  539.             }
  540.            
  541.             if(this.getPddContext()!=null && this.getPddContext().containsKey(Costanti.MODIPA_CONTEXT_AUDIT_DIGEST)) {
  542.                 this.signedJwtAuditDigest = (String) this.getPddContext().get(Costanti.MODIPA_CONTEXT_AUDIT_DIGEST);
  543.             }
  544.             if(this.getPddContext()!=null && this.getPddContext().containsKey(Costanti.MODIPA_CONTEXT_AUDIT_DIGEST_ALGO)) {
  545.                 this.signedJwtAuditDigestAlgo = (String) this.getPddContext().get(Costanti.MODIPA_CONTEXT_AUDIT_DIGEST_ALGO);
  546.             }
  547.            
  548.             this.signedJwtCustomId = policyNegoziazioneToken.getJwtSignIncludeKeyIdCustom();
  549.             if(this.signedJwtCustomId!=null && !"".equals(this.signedJwtCustomId)) {
  550.                 this.signedJwtCustomId = DynamicUtils.convertDynamicPropertyValue("kid.customId.gwt", this.signedJwtCustomId, dynamicMap, pddContext);  
  551.             }
  552.            
  553.             this.signedJwtX509Url = policyNegoziazioneToken.getJwtSignIncludeX509URL();
  554.             if(this.signedJwtX509Url!=null && !"".equals(this.signedJwtX509Url)) {
  555.                 this.signedJwtX509Url = DynamicUtils.convertDynamicPropertyValue("url-x5u.gwt", this.signedJwtX509Url, dynamicMap, pddContext);
  556.             }
  557.         }
  558.        
  559.         this.scope = policyNegoziazioneToken.getScopeString();
  560.         if(this.scope!=null && !"".equals(this.scope)) {
  561.             this.scope = DynamicUtils.convertDynamicPropertyValue("scopes.gwt", this.scope, dynamicMap, pddContext);    
  562.         }
  563.        
  564.         this.audience = policyNegoziazioneToken.getAudience();
  565.         if(this.audience!=null && !"".equals(this.audience)) {
  566.             this.audience = DynamicUtils.convertDynamicPropertyValue("aud.gwt", this.audience, dynamicMap, pddContext);
  567.         }
  568.        
  569.         if(policyNegoziazioneToken.isPDND()) {
  570.            
  571.             if(policyNegoziazioneToken.isFormClientIdApplicativoModI()) {
  572.                 if(clientIdApplicativoModI==null) {
  573.                     String prefixError = "La modalità di generazione del Client ID nei dati della richiesta, indicata nella token policy '"+policyNegoziazioneToken.getName()+"', ";
  574.                     if(this.applicativoRichiedente==null) {
  575.                         throw new TokenException(prefixError+ERRORE_RICHIEDE_AUTENTICAZIONE_IDENTIFICAZIONE_APPLICATIVO);
  576.                     }
  577.                     String clientId = ProtocolPropertiesUtils.getOptionalStringValuePropertyConfig(this.applicativoRichiedente.getProtocolPropertyList(), CostantiDB.MODIPA_SICUREZZA_TOKEN_CLIENT_ID);
  578.                     if(clientId==null || StringUtils.isEmpty(clientId)) {
  579.                         throw new TokenException(prefixError+ERRORE_NON_UTILIZZABILE_APPLICATIVO_IDENTIFICATO+" '"+idApp+
  580.                                 "': "+ERRORE_CONFIGURAZIONE_APPLICATIVO_NON_COMPLETA+" '"+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_CLIENT_ID+
  581.                                 "' "+ERRORE_SEZIONE+" '"+CostantiLabel.MODIPA_SICUREZZA_TOKEN_SUBTITLE_LABEL+"'");
  582.                     }
  583.                     clientIdApplicativoModI = clientId;
  584.                 }
  585.                 this.formClientId = clientIdApplicativoModI;
  586.             }
  587.             else if(policyNegoziazioneToken.isFormClientIdFruizioneModI()) {
  588.                 if(clientIdFruizioneModI==null) {
  589.                     String prefixError = "La modalità di generazione del Client ID nei dati della richiesta, indicata nella token policy '"+policyNegoziazioneToken.getName()+"', ";
  590.                     if(this.idFruizione==null) {
  591.                         throw new TokenException(prefixError+ERRORE_RICHIEDE_IDENTIFICAZIONE_DATI_FRUIZIONE);
  592.                     }
  593.                     String clientId = ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(listProtocolPropertiesFruizione, CostantiDB.MODIPA_PROFILO_SICUREZZA_OAUTH_IDENTIFICATIVO);
  594.                     if(clientId==null || StringUtils.isEmpty(clientId)) {
  595.                         throw new TokenException(prefixError+ERRORE_NON_UTILIZZABILE_FRUIZIONE+" '"+idFruizioneLabel+
  596.                                 "': "+ERRORE_CONFIGURAZIONE_MODI_NON_COMPLETA+" '"+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_CLIENT_ID+
  597.                                 " "+CostantiLabel.LABEL_CREDENZIALI_AUTENTICAZIONE_TOKEN_CLIENT_ID_SEARCH+"'");
  598.                     }
  599.                     clientIdFruizioneModI = clientId;
  600.                 }
  601.                 this.formClientId = clientIdFruizioneModI;
  602.             }
  603.             else {
  604.                 this.formClientId = policyNegoziazioneToken.getFormClientId();
  605.                 if(this.formClientId==null || "".equals(this.formClientId)) {
  606.                     this.formClientId = policyNegoziazioneToken.getJwtClientId();
  607.                 }
  608.             }
  609.             if(this.formClientId!=null && !"".equals(this.formClientId) && !Costanti.POLICY_RETRIEVE_TOKEN_JWT_CLAIM_UNDEFINED.equals(this.formClientId)) {
  610.                 this.formClientId = DynamicUtils.convertDynamicPropertyValue("formClientId.gwt", this.formClientId, dynamicMap, pddContext);    
  611.             }
  612.            
  613.             this.formResource = policyNegoziazioneToken.getFormResource();
  614.             if(this.formResource!=null && !"".equals(this.formResource) && !Costanti.POLICY_RETRIEVE_TOKEN_JWT_CLAIM_UNDEFINED.equals(this.formResource)) {
  615.                 this.formResource = DynamicUtils.convertDynamicPropertyValue("formResource.gwt", this.formResource, dynamicMap, pddContext);    
  616.             }
  617.         }
  618.        
  619.         this.parameters = policyNegoziazioneToken.getFormParameters();
  620.         if(this.parameters!=null && !"".equals(this.parameters)) {
  621.             this.parameters = DynamicUtils.convertDynamicPropertyValue("parameters.gwt", this.parameters, dynamicMap, pddContext);  
  622.         }
  623.        
  624.         String sHttpMethod = policyNegoziazioneToken.getHttpMethod();
  625.         if(sHttpMethod!=null && !"".equals(sHttpMethod)) {
  626.             // per adesso viene preso da una select list
  627.             /** this.httpMethod = DynamicUtils.convertDynamicPropertyValue("httpMethod.gwt", sHttpMethod, dynamicMap, pddContext); */
  628.             this.httpMethod = HttpRequestMethod.valueOf(sHttpMethod);
  629.         }
  630.        
  631.         this.httpContentType = policyNegoziazioneToken.getHttpContentType();
  632.         if(this.httpContentType!=null && !"".equals(this.httpContentType)) {
  633.             this.httpContentType = DynamicUtils.convertDynamicPropertyValue("httpContentType.gwt", this.httpContentType, dynamicMap, pddContext);  
  634.         }
  635.        
  636.         this.httpHeaders = policyNegoziazioneToken.getHttpHeaders();
  637.         if(this.httpHeaders!=null && !"".equals(this.httpHeaders)) {
  638.             this.httpHeaders = DynamicUtils.convertDynamicPropertyValue("httpHeaders.gwt", this.httpHeaders, dynamicMap, pddContext);  
  639.         }
  640.        
  641.         this.httpPayloadTemplateType = policyNegoziazioneToken.getDynamicPayloadType();
  642.         if(this.httpPayloadTemplateType!=null && !"".equals(this.httpPayloadTemplateType)) {
  643.             // Non è un valore dinamico, ma serve come info da far apparire nella chiave per tipizzare il payload
  644.             /** this.httpPayloadTemplateType = DynamicUtils.convertDynamicPropertyValue("httpPayloadTemplateType.gwt", this.httpPayloadTemplateType, dynamicMap, pddContext);*/
  645.             String httpPayloadDynamic = policyNegoziazioneToken.getDynamicPayload();
  646.             if(httpPayloadDynamic!=null && !"".equals(httpPayloadDynamic)) {
  647.                 if(policyNegoziazioneToken.isDynamicPayloadTemplate()) {
  648.                     this.httpPayload = DynamicUtils.convertDynamicPropertyValue("httpPayload.gwt", httpPayloadDynamic, dynamicMap, pddContext);
  649.                 }
  650.                 else if(policyNegoziazioneToken.isDynamicPayloadFreemarkerTemplate()) {
  651.                     ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance(state);
  652.                        
  653.                     ByteArrayOutputStream bout = new ByteArrayOutputStream();
  654.                     try {
  655.                         Template template = configurazionePdDManager.getTemplatePolicyNegoziazioneRequest(policyNegoziazioneToken.getName(), httpPayloadDynamic.getBytes(), requestInfo);
  656.                         DynamicUtils.convertFreeMarkerTemplate(template, dynamicMap, bout);
  657.                         bout.flush();
  658.                         bout.close();
  659.                     }catch(Exception e) {
  660.                         throw new TokenException(e.getMessage(),e);
  661.                     }
  662.                     this.httpPayload = bout.toString();
  663.                 }
  664.                 else if(policyNegoziazioneToken.isDynamicPayloadVelocityTemplate()) {
  665.                     ConfigurazionePdDManager configurazionePdDManager = ConfigurazionePdDManager.getInstance(state);
  666.                        
  667.                     ByteArrayOutputStream bout = new ByteArrayOutputStream();
  668.                     try {
  669.                         Template template = configurazionePdDManager.getTemplatePolicyNegoziazioneRequest(policyNegoziazioneToken.getName(), httpPayloadDynamic.getBytes(), requestInfo);
  670.                         DynamicUtils.convertVelocityTemplate(template, dynamicMap, bout);
  671.                         bout.flush();
  672.                         bout.close();
  673.                     }catch(Exception e) {
  674.                         throw new TokenException(e.getMessage(),e);
  675.                     }
  676.                     this.httpPayload = bout.toString();
  677.                 }
  678.             }
  679.         }
  680.     }
  681.    
  682.     @Override
  683.     protected String toStringRepresentation() {
  684.         return null; // viene ridefinito il metodo toString
  685.     }
  686.     @Override
  687.     public String toString() {
  688.         return toString("\n", false);
  689.     }
  690.     public String toString(String separator, boolean cacheKey) {
  691.         StringBuilder sb = new StringBuilder();
  692.         String superS = super.toString();
  693.         if(StringUtils.isNotEmpty(superS)) {
  694.             sb.append(superS);
  695.         }
  696.        
  697.         if(cacheKey) {
  698.             checkInitCacheKey();
  699.         }
  700.        
  701.         if(StringUtils.isNotEmpty(this.endpoint)) {
  702.             if(sb.length()>0) {
  703.                 sb.append(separator);
  704.             }
  705.             sb.append("endpoint:").append(this.endpoint);
  706.         }
  707.         if(StringUtils.isNotEmpty(this.basicUsername)) {
  708.             if(sb.length()>0) {
  709.                 sb.append(separator);
  710.             }
  711.             sb.append("user:").append(this.basicUsername);
  712.         }
  713.         if(StringUtils.isNotEmpty(this.basicPassword) && (!cacheKey)) {
  714.             if(sb.length()>0) {
  715.                 sb.append(separator);
  716.             }
  717.             sb.append("password:").append(this.basicPassword);
  718.         }
  719.         if(StringUtils.isNotEmpty(this.bearerToken)) {
  720.             if(sb.length()>0) {
  721.                 sb.append(separator);
  722.             }
  723.             sb.append("token:").append(this.bearerToken);
  724.         }
  725.        
  726.         if(StringUtils.isNotEmpty(this.usernamePasswordGrantUsername)) {
  727.             if(sb.length()>0) {
  728.                 sb.append(separator);
  729.             }
  730.             sb.append("usernamePasswordGrant_username:").append(this.usernamePasswordGrantUsername);
  731.         }
  732.         if(StringUtils.isNotEmpty(this.usernamePasswordGrantPassword) && (!cacheKey)) {
  733.             if(sb.length()>0) {
  734.                 sb.append(separator);
  735.             }
  736.             sb.append("usernamePasswordGrant_password:").append(this.usernamePasswordGrantPassword);
  737.         }
  738.        
  739.         if(StringUtils.isNotEmpty(this.signedJwtIssuer) && (!cacheKey || signedJwtIssuerCacheKey)) {
  740.             if(sb.length()>0) {
  741.                 sb.append(separator);
  742.             }
  743.             sb.append("iss:").append(this.signedJwtIssuer);
  744.         }
  745.         if(StringUtils.isNotEmpty(this.signedJwtClientId) && (!cacheKey || signedJwtClientIdCacheKey)) {
  746.             if(sb.length()>0) {
  747.                 sb.append(separator);
  748.             }
  749.             sb.append("clientId:").append(this.signedJwtClientId);
  750.         }
  751.         if(StringUtils.isNotEmpty(this.signedJwtSubject) && (!cacheKey || signedJwtSubjectCacheKey)) {
  752.             if(sb.length()>0) {
  753.                 sb.append(separator);
  754.             }
  755.             sb.append("sub:").append(this.signedJwtSubject);
  756.         }
  757.         if(StringUtils.isNotEmpty(this.signedJwtAudience) && (!cacheKey || signedJwtAudienceCacheKey)) {
  758.             if(sb.length()>0) {
  759.                 sb.append(separator);
  760.             }
  761.             sb.append("aud:").append(this.signedJwtAudience);
  762.         }
  763.         if(StringUtils.isNotEmpty(this.signedJwtJti) && (!cacheKey || signedJwtJtiCacheKey)) {
  764.             if(sb.length()>0) {
  765.                 sb.append(separator);
  766.             }
  767.             sb.append("jti:").append(this.signedJwtJti);
  768.         }
  769.         if(StringUtils.isNotEmpty(this.signedJwtPurposeId) && (!cacheKey || signedJwtPurposeIdCacheKey)) {
  770.             if(sb.length()>0) {
  771.                 sb.append(separator);
  772.             }
  773.             sb.append("purposeId:").append(this.signedJwtPurposeId);
  774.         }
  775.         if(StringUtils.isNotEmpty(this.signedJwtSessionInfo) && (!cacheKey || signedJwtSessionInfoCacheKey)) {
  776.             if(sb.length()>0) {
  777.                 sb.append(separator);
  778.             }
  779.             sb.append("sInfo:").append(this.signedJwtSessionInfo);
  780.         }
  781.         if(StringUtils.isNotEmpty(this.signedJwtClaims) && (!cacheKey || signedJwtClaimsCacheKey)) {
  782.             if(sb.length()>0) {
  783.                 sb.append(separator);
  784.             }
  785.             sb.append("claims:").append(this.signedJwtClaims);
  786.         }
  787.         if(StringUtils.isNotEmpty(this.signedJwtAuditDigest) && (!cacheKey || signedJwtAuditDigestCacheKey)) {
  788.             if(sb.length()>0) {
  789.                 sb.append(separator);
  790.             }
  791.             sb.append("auditDigest:").append(this.signedJwtAuditDigest);
  792.         }
  793.         if(StringUtils.isNotEmpty(this.signedJwtAuditDigestAlgo) && (!cacheKey || signedJwtAuditDigestCacheKey)) {
  794.             if(sb.length()>0) {
  795.                 sb.append(separator);
  796.             }
  797.             sb.append("auditDigestAlgo:").append(this.signedJwtAuditDigestAlgo);
  798.         }
  799.        
  800.         if(StringUtils.isNotEmpty(this.signedJwtCustomId) && (!cacheKey || signedJwtCustomIdCacheKey)) {
  801.             if(sb.length()>0) {
  802.                 sb.append(separator);
  803.             }
  804.             sb.append("kid:").append(this.signedJwtCustomId);
  805.         }
  806.         if(StringUtils.isNotEmpty(this.signedJwtX509Url) && (!cacheKey || signedJwtX509UrlCacheKey)) {
  807.             if(sb.length()>0) {
  808.                 sb.append(separator);
  809.             }
  810.             sb.append("x5u:").append(this.signedJwtX509Url);
  811.         }
  812.        
  813.         if(StringUtils.isNotEmpty(this.scope) && (!cacheKey || scopeCacheKey)) {
  814.             if(sb.length()>0) {
  815.                 sb.append(separator);
  816.             }
  817.             sb.append("scope:").append(this.scope);
  818.         }
  819.         if(StringUtils.isNotEmpty(this.audience) && (!cacheKey || audienceCacheKey)) {
  820.             if(sb.length()>0) {
  821.                 sb.append(separator);
  822.             }
  823.             sb.append("formAudience:").append(this.audience);
  824.         }
  825.         if(StringUtils.isNotEmpty(this.formClientId) && (!cacheKey || formClientIdCacheKey)) {
  826.             if(sb.length()>0) {
  827.                 sb.append(separator);
  828.             }
  829.             sb.append("formClientId:").append(this.formClientId);
  830.         }
  831.         if(StringUtils.isNotEmpty(this.formResource) && (!cacheKey || formResourceCacheKey)) {
  832.             if(sb.length()>0) {
  833.                 sb.append(separator);
  834.             }
  835.             sb.append("formResource:").append(this.formResource);
  836.         }
  837.         if(StringUtils.isNotEmpty(this.parameters) && (!cacheKey || parametersCacheKey)) {
  838.             if(sb.length()>0) {
  839.                 sb.append(separator);
  840.             }
  841.             sb.append("parameters:").append(this.parameters);
  842.         }
  843.        
  844.         if(this.httpMethod!=null && (!cacheKey || httpMethodCacheKey)) {
  845.             if(sb.length()>0) {
  846.                 sb.append(separator);
  847.             }
  848.             sb.append("httpMethod:").append(this.httpMethod.name());
  849.         }
  850.         if(StringUtils.isNotEmpty(this.httpContentType) && (!cacheKey || httpContentTypeCacheKey)) {
  851.             if(sb.length()>0) {
  852.                 sb.append(separator);
  853.             }
  854.             sb.append("httpContentType:").append(this.httpContentType);
  855.         }
  856.         if(StringUtils.isNotEmpty(this.httpHeaders) && (!cacheKey || httpHeadersCacheKey)) {
  857.             if(sb.length()>0) {
  858.                 sb.append(separator);
  859.             }
  860.             sb.append("httpHeaders:").append(this.httpHeaders);
  861.         }
  862.         if(StringUtils.isNotEmpty(this.httpPayloadTemplateType) && (!cacheKey || httpPayloadTemplateTypeCacheKey)) {
  863.             if(sb.length()>0) {
  864.                 sb.append(separator);
  865.             }
  866.             sb.append("httpPayloadTemplateType:").append(this.httpPayloadTemplateType);
  867.         }
  868.         if(StringUtils.isNotEmpty(this.httpPayload) && (!cacheKey || httpPayloadCacheKey)) {
  869.             if(sb.length()>0) {
  870.                 sb.append(separator);
  871.             }
  872.             sb.append("httpPayload:").append(this.httpPayload);
  873.         }
  874.        
  875.         if(this.idApplicativoRichiedente!=null && (!cacheKey || applicativoRichiedenteCacheKey)) {
  876.             if(sb.length()>0) {
  877.                 sb.append(separator);
  878.             }
  879.             sb.append("applicativeRequester:").append(this.idApplicativoRichiedente.toFormatString());
  880.         }
  881.        
  882.         if(this.idFruizione!=null && (!cacheKey || fruizioneCacheKey)) {
  883.             if(sb.length()>0) {
  884.                 sb.append(separator);
  885.             }
  886.             sb.append("outbound:").append(this.idFruizione.toFormatString());
  887.         }
  888.        
  889.         return sb.toString();
  890.     }
  891.    
  892.     public String getEndpoint() {
  893.         return this.endpoint;
  894.     }

  895.     public String getBasicUsername() {
  896.         return this.basicUsername;
  897.     }
  898.     public String getBasicPassword() {
  899.         return this.basicPassword;
  900.     }
  901.    
  902.     public String getBearerToken() {
  903.         return this.bearerToken;
  904.     }
  905.    
  906.     public String getUsernamePasswordGrantUsername() {
  907.         return this.usernamePasswordGrantUsername;
  908.     }
  909.     public String getUsernamePasswordGrantPassword() {
  910.         return this.usernamePasswordGrantPassword;
  911.     }
  912.    
  913.     public String getSignedJwtIssuer() {
  914.         return this.signedJwtIssuer;
  915.     }

  916.     public String getSignedJwtClientId() {
  917.         return this.signedJwtClientId;
  918.     }

  919.     public String getSignedJwtSubject() {
  920.         return this.signedJwtSubject;
  921.     }

  922.     public String getSignedJwtAudience() {
  923.         return this.signedJwtAudience;
  924.     }

  925.     public String getSignedJwtJti() {
  926.         return this.signedJwtJti;
  927.     }

  928.     public String getSignedJwtPurposeId() {
  929.         return this.signedJwtPurposeId;
  930.     }

  931.     public String getSignedJwtSessionInfo() {
  932.         return this.signedJwtSessionInfo;
  933.     }

  934.     public String getSignedJwtClaims() {
  935.         return this.signedJwtClaims;
  936.     }
  937.    
  938.     public String getSignedJwtAuditDigest() {
  939.         return this.signedJwtAuditDigest;
  940.     }
  941.    
  942.     public String getSignedJwtAuditDigestAlgo() {
  943.         return this.signedJwtAuditDigestAlgo;
  944.     }
  945.    
  946.     public String getSignedJwtCustomId() {
  947.         return this.signedJwtCustomId;
  948.     }
  949.    
  950.     public String getSignedJwtX509Url() {
  951.         return this.signedJwtX509Url;
  952.     }
  953.    
  954.     public String getScope() {
  955.         return this.scope;
  956.     }
  957.    
  958.     public String getAudience() {
  959.         return this.audience;
  960.     }

  961.     public String getFormClientId() {
  962.         return this.formClientId;
  963.     }
  964.    
  965.     public String getFormResource() {
  966.         return this.formResource;
  967.     }

  968.     public String getParameters() {
  969.         return this.parameters;
  970.     }
  971.    
  972.     public HttpRequestMethod getHttpMethod() {
  973.         return this.httpMethod;
  974.     }
  975.     public String getHttpContentType() {
  976.         return this.httpContentType;
  977.     }
  978.     public String getHttpHeaders() {
  979.         return this.httpHeaders;
  980.     }
  981.     public String getHttpPayloadTemplateType() {
  982.         return this.httpPayloadTemplateType;
  983.     }
  984.     public String getHttpPayload() {
  985.         return this.httpPayload;
  986.     }
  987.    
  988.     public IDServizioApplicativo getIdApplicativoRichiedente() {
  989.         return this.idApplicativoRichiedente;
  990.     }
  991.     public ServizioApplicativo getApplicativoRichiedente() {
  992.         return this.applicativoRichiedente;
  993.     }
  994.     public String getKidApplicativoModI() {
  995.         return this.kidApplicativoModI;
  996.     }
  997.     public String getTipoKeystoreApplicativoModI() {
  998.         return this.keystoreApplicativoModI.getSecurityMessageKeystoreType();
  999.     }
  1000.     public boolean isByokPolicyDefinedApplicativoModI() {
  1001.         return BYOKProvider.isPolicyDefined(this.keystoreApplicativoModI.getSecurityMessageKeystoreByokPolicy());
  1002.     }
  1003.     public KeyPairStore getKeyPairStoreApplicativoModI(Map<String,Object> dynamicMap) throws TokenException, SecurityException{
  1004.        
  1005.         String keystoreFile = this.keystoreApplicativoModI.getSecurityMessageKeystorePath();
  1006.         if(keystoreFile==null) {
  1007.             throw new TokenException("JWT Signature private key file undefined");
  1008.         }
  1009.         String keystoreFilePublicKey = this.keystoreApplicativoModI.getSecurityMessageKeystorePathPublicKey();
  1010.         if(keystoreFilePublicKey==null) {
  1011.             throw new TokenException("JWT Signature public key file undefined");
  1012.         }
  1013.         String keyPairAlgorithm = this.keystoreApplicativoModI.getSecurityMessageKeystoreKeyAlgorithm();
  1014.         if(keyPairAlgorithm==null) {
  1015.             throw new TokenException("JWT Signature key pair algorithm undefined");
  1016.         }
  1017.        
  1018.         String keyPassword = this.keystoreApplicativoModI.getSecurityMessageKeyPassword();
  1019.        
  1020.         String keystoreByokPolicy = this.keystoreApplicativoModI.getSecurityMessageKeystoreByokPolicy();
  1021.         BYOKRequestParams byokParams = getBYOKRequestParams(keystoreByokPolicy, dynamicMap);
  1022.        
  1023.         return GestoreKeystoreCache.getKeyPairStore(this.getRequestInfo(), keystoreFile, keystoreFilePublicKey, keyPassword, keyPairAlgorithm, byokParams);
  1024.     }
  1025.     public JWKSetStore getJWKSetStoreApplicativoModI(Map<String,Object> dynamicMap) throws TokenException, SecurityException{
  1026.        
  1027.         String keystoreFile = this.keystoreApplicativoModI.getSecurityMessageKeystorePath();
  1028.         if(keystoreFile==null) {
  1029.             throw new TokenException("JWT Signature keystore file undefined");
  1030.         }
  1031.        
  1032.         String keystoreByokPolicy = this.keystoreApplicativoModI.getSecurityMessageKeystoreByokPolicy();
  1033.         BYOKRequestParams byokParams = getBYOKRequestParams(keystoreByokPolicy, dynamicMap);
  1034.        
  1035.         return GestoreKeystoreCache.getJwkSetStore(this.getRequestInfo(), keystoreFile, byokParams);
  1036.     }
  1037.     public org.openspcoop2.utils.certificate.KeyStore getKeystoreApplicativoModI(Map<String,Object> dynamicMap) throws TokenException, SecurityException{
  1038.         if(this.keystoreApplicativoModI.getSecurityMessageKeystorePath()!=null || this.keystoreApplicativoModI.isSecurityMessageKeystoreHSM()) {
  1039.            
  1040.             String keystoreByokPolicy = this.keystoreApplicativoModI.getSecurityMessageKeystoreByokPolicy();
  1041.             BYOKRequestParams byokParams = null;
  1042.             if(this.keystoreApplicativoModI.getSecurityMessageKeystorePath()!=null) {
  1043.                 byokParams = getBYOKRequestParams(keystoreByokPolicy, dynamicMap);
  1044.             }
  1045.            
  1046.             MerlinKeystore merlinKs = GestoreKeystoreCache.getMerlinKeystore(this.getRequestInfo(), this.keystoreApplicativoModI.getSecurityMessageKeystorePath(), this.keystoreApplicativoModI.getSecurityMessageKeystoreType(),
  1047.                     this.keystoreApplicativoModI.getSecurityMessageKeystorePassword(), byokParams);
  1048.             if(merlinKs==null) {
  1049.                 throw new TokenException("Accesso al keystore '"+this.keystoreApplicativoModI.getSecurityMessageKeystorePath()+"' non riuscito");
  1050.             }
  1051.             return merlinKs.getKeyStore();
  1052.         }
  1053.         else {
  1054.             MerlinKeystore merlinKs = GestoreKeystoreCache.getMerlinKeystore(this.getRequestInfo(), this.keystoreApplicativoModI.getSecurityMessageKeystoreArchive(), this.keystoreApplicativoModI.getSecurityMessageKeystoreType(),
  1055.                     this.keystoreApplicativoModI.getSecurityMessageKeystorePassword());
  1056.             if(merlinKs==null) {
  1057.                 throw new TokenException("Accesso al keystore non riuscito");
  1058.             }
  1059.             return merlinKs.getKeyStore();
  1060.         }
  1061.     }
  1062.     public String getKeyAliasApplicativoModI() {
  1063.         return this.keystoreApplicativoModI.getSecurityMessageKeyAlias();
  1064.     }
  1065.     public String getKeyPasswordApplicativoModI() {
  1066.         return this.keystoreApplicativoModI.getSecurityMessageKeyPassword();
  1067.     }
  1068.    
  1069.     public IDFruizione getIdFruizione() {
  1070.         return this.idFruizione;
  1071.     }
  1072.     public String getKidFruizioneModI() {
  1073.         return this.kidFruizioneModI;
  1074.     }
  1075.     public String getTipoKeystoreFruizioneModI() {
  1076.         return this.keystoreFruizioneModI.getSecurityMessageKeystoreType();
  1077.     }
  1078.     public boolean isByokPolicyDefinedFruizioneModI() {
  1079.         return BYOKProvider.isPolicyDefined(this.keystoreFruizioneModI.getSecurityMessageKeystoreByokPolicy());
  1080.     }
  1081.     public KeyPairStore getKeyPairStoreFruizioneModI(Map<String,Object> dynamicMap) throws TokenException, SecurityException{
  1082.        
  1083.         String keystoreFile = this.keystoreFruizioneModI.getSecurityMessageKeystorePath();
  1084.         if(keystoreFile==null) {
  1085.             throw new TokenException("JWT Signature private key file undefined");
  1086.         }
  1087.         String keystoreFilePublicKey = this.keystoreFruizioneModI.getSecurityMessageKeystorePathPublicKey();
  1088.         if(keystoreFilePublicKey==null) {
  1089.             throw new TokenException("JWT Signature public key file undefined");
  1090.         }
  1091.         String keyPairAlgorithm = this.keystoreFruizioneModI.getSecurityMessageKeystoreKeyAlgorithm();
  1092.         if(keyPairAlgorithm==null) {
  1093.             throw new TokenException("JWT Signature key pair algorithm undefined");
  1094.         }
  1095.        
  1096.         String keyPassword = this.keystoreFruizioneModI.getSecurityMessageKeyPassword();
  1097.        
  1098.         String keystoreByokPolicy = this.keystoreFruizioneModI.getSecurityMessageKeystoreByokPolicy();
  1099.         BYOKRequestParams byokParams = getBYOKRequestParams(keystoreByokPolicy, dynamicMap);
  1100.        
  1101.         return GestoreKeystoreCache.getKeyPairStore(this.getRequestInfo(), keystoreFile, keystoreFilePublicKey, keyPassword, keyPairAlgorithm, byokParams);
  1102.     }
  1103.     public JWKSetStore getJWKSetStoreFruizioneModI(Map<String,Object> dynamicMap) throws TokenException, SecurityException{
  1104.        
  1105.         String keystoreFile = this.keystoreFruizioneModI.getSecurityMessageKeystorePath();
  1106.         if(keystoreFile==null) {
  1107.             throw new TokenException("JWT Signature keystore file undefined");
  1108.         }
  1109.        
  1110.         String keystoreByokPolicy = this.keystoreFruizioneModI.getSecurityMessageKeystoreByokPolicy();
  1111.         BYOKRequestParams byokParams = getBYOKRequestParams(keystoreByokPolicy, dynamicMap);
  1112.        
  1113.         return GestoreKeystoreCache.getJwkSetStore(this.getRequestInfo(), keystoreFile, byokParams);
  1114.     }
  1115.     public org.openspcoop2.utils.certificate.KeyStore getKeystoreFruizioneModI(Map<String,Object> dynamicMap) throws TokenException, SecurityException{
  1116.         if(this.keystoreFruizioneModI.getSecurityMessageKeystorePath()!=null || this.keystoreFruizioneModI.isSecurityMessageKeystoreHSM()) {
  1117.            
  1118.             String keystoreByokPolicy = this.keystoreFruizioneModI.getSecurityMessageKeystoreByokPolicy();
  1119.             BYOKRequestParams byokParams = null;
  1120.             if(this.keystoreFruizioneModI.getSecurityMessageKeystorePath()!=null) {
  1121.                 byokParams = getBYOKRequestParams(keystoreByokPolicy, dynamicMap);
  1122.             }
  1123.            
  1124.             MerlinKeystore merlinKs = GestoreKeystoreCache.getMerlinKeystore(this.getRequestInfo(), this.keystoreFruizioneModI.getSecurityMessageKeystorePath(), this.keystoreFruizioneModI.getSecurityMessageKeystoreType(),
  1125.                     this.keystoreFruizioneModI.getSecurityMessageKeystorePassword(), byokParams);
  1126.             if(merlinKs==null) {
  1127.                 throw new TokenException("Accesso al keystore '"+this.keystoreFruizioneModI.getSecurityMessageKeystorePath()+"' non riuscito");
  1128.             }
  1129.             return merlinKs.getKeyStore();
  1130.         }
  1131.         else {
  1132.             MerlinKeystore merlinKs = GestoreKeystoreCache.getMerlinKeystore(this.getRequestInfo(), this.keystoreFruizioneModI.getSecurityMessageKeystoreArchive(), this.keystoreFruizioneModI.getSecurityMessageKeystoreType(),
  1133.                     this.keystoreFruizioneModI.getSecurityMessageKeystorePassword());
  1134.             if(merlinKs==null) {
  1135.                 throw new TokenException("Accesso al keystore non riuscito");
  1136.             }
  1137.             return merlinKs.getKeyStore();
  1138.         }
  1139.     }
  1140.     public String getKeyAliasFruizioneModI() {
  1141.         return this.keystoreFruizioneModI.getSecurityMessageKeyAlias();
  1142.     }
  1143.     public String getKeyPasswordFruizioneModI() {
  1144.         return this.keystoreFruizioneModI.getSecurityMessageKeyPassword();
  1145.     }
  1146.    
  1147.    
  1148.     private BYOKRequestParams getBYOKRequestParams(String keystoreByokPolicy, Map<String,Object> dynamicMap) throws SecurityException {
  1149.         return BYOKUnwrapPolicyUtilities.getBYOKRequestParams(keystoreByokPolicy, dynamicMap);
  1150.     }
  1151. }