ModIKeystoreConfig.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.protocol.modipa.utils;

  21. import java.util.List;

  22. import org.openspcoop2.core.config.ServizioApplicativo;
  23. import org.openspcoop2.core.id.IDSoggetto;
  24. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  25. import org.openspcoop2.core.registry.ProtocolProperty;
  26. import org.openspcoop2.protocol.modipa.config.ModIProperties;
  27. import org.openspcoop2.protocol.modipa.constants.ModICostanti;
  28. import org.openspcoop2.protocol.sdk.ProtocolException;
  29. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesUtils;
  30. import org.openspcoop2.protocol.utils.ModIKeystoreUtils;
  31. import org.openspcoop2.utils.UtilsException;
  32. import org.openspcoop2.utils.certificate.KeystoreParams;

  33. /**
  34.  * ModIKeystoreConfig
  35.  *
  36.  * @author Poli Andrea (apoli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  */
  40. public class ModIKeystoreConfig extends ModIKeystoreUtils {

  41.     public static boolean isKeystoreDefinitoInFruizione(IDSoggetto soggettoFruitore, AccordoServizioParteSpecifica asps) throws ProtocolException {
  42.         String mode = getKeystoreDefinitoIn(soggettoFruitore, asps);
  43.         return mode!=null && ModICostanti.MODIPA_KEYSTORE_FRUIZIONE.equals(mode);
  44.     }
  45.     public static boolean isKeystoreDefinitoInTokenPolicy(IDSoggetto soggettoFruitore, AccordoServizioParteSpecifica asps) throws ProtocolException {
  46.         String mode = getKeystoreDefinitoIn(soggettoFruitore, asps);
  47.         return mode!=null && ModICostanti.MODIPA_KEYSTORE_FRUIZIONE_TOKEN_POLICY.equals(mode);
  48.     }
  49.     private static String getKeystoreDefinitoIn(IDSoggetto soggettoFruitore, AccordoServizioParteSpecifica asps) throws ProtocolException {
  50.         boolean fruizione = true;
  51.         List<ProtocolProperty> listProtocolProperties = ModIPropertiesUtils.getProtocolProperties(fruizione, soggettoFruitore, asps);
  52.         return ProtocolPropertiesUtils.getOptionalStringValuePropertyRegistry(listProtocolProperties,
  53.                 ModICostanti.MODIPA_PROFILO_SICUREZZA_MESSAGGIO_FRUIZIONE_KEYSTORE_MODE);
  54.     }
  55.    
  56.     public ModIKeystoreConfig(ServizioApplicativo sa, String securityMessageProfile) throws ProtocolException, UtilsException {
  57.         super(sa, securityMessageProfile);
  58.     }
  59.    
  60.     public ModIKeystoreConfig(boolean fruizione, IDSoggetto soggettoFruitore, AccordoServizioParteSpecifica asps, String securityMessageProfile) throws ProtocolException, UtilsException {
  61.         super(fruizione, soggettoFruitore, asps, securityMessageProfile,
  62.                 getSicurezzaMessaggioCertificatiKeyStoreTipo(),
  63.                 getSicurezzaMessaggioCertificatiKeyStorePath(),
  64.                 getSicurezzaMessaggioCertificatiKeyStorePassword(),
  65.                 getSicurezzaMessaggioCertificatiKeyAlias(),
  66.                 getSicurezzaMessaggioCertificatiKeyPassword());
  67.     }
  68.    
  69.     public ModIKeystoreConfig(KeystoreParams kp) throws ProtocolException, UtilsException {
  70.         super(kp);
  71.     }
  72.    
  73.     private static ModIProperties modIProperties = null;
  74.     private static synchronized void initModiProperties() throws ProtocolException {
  75.         if(modIProperties==null) {
  76.             modIProperties = ModIProperties.getInstance();
  77.         }
  78.     }
  79.     private static ModIProperties getModiProperties() throws ProtocolException {
  80.         if(modIProperties==null) {
  81.             initModiProperties();
  82.         }
  83.         return modIProperties;
  84.     }
  85.     private static String getSicurezzaMessaggioCertificatiKeyStoreTipo() throws ProtocolException {
  86.         try {
  87.             return getModiProperties().getSicurezzaMessaggioCertificatiKeyStoreTipo();
  88.         }catch(Exception e) {
  89.             throw new ProtocolException(e.getMessage(),e);
  90.         }
  91.     }
  92.     private static String getSicurezzaMessaggioCertificatiKeyStorePath() throws ProtocolException {
  93.         try {
  94.             if(getSicurezzaMessaggioCertificatiKeyStoreTipo()!=null) {
  95.                 return getModiProperties().getSicurezzaMessaggioCertificatiKeyStorePath();
  96.             }
  97.             return null;
  98.         }catch(Exception e) {
  99.             throw new ProtocolException(e.getMessage(),e);
  100.         }
  101.     }
  102.     private static String getSicurezzaMessaggioCertificatiKeyStorePassword() throws ProtocolException {
  103.         try {
  104.             if(getSicurezzaMessaggioCertificatiKeyStoreTipo()!=null) {
  105.                 return getModiProperties().getSicurezzaMessaggioCertificatiKeyStorePassword();
  106.             }
  107.             return null;
  108.         }catch(Exception e) {
  109.             throw new ProtocolException(e.getMessage(),e);
  110.         }
  111.     }
  112.     private static String getSicurezzaMessaggioCertificatiKeyAlias() throws ProtocolException {
  113.         try {
  114.             if(getSicurezzaMessaggioCertificatiKeyStoreTipo()!=null) {
  115.                 return getModiProperties().getSicurezzaMessaggioCertificatiKeyAlias();
  116.             }
  117.             return null;
  118.         }catch(Exception e) {
  119.             throw new ProtocolException(e.getMessage(),e);
  120.         }
  121.     }
  122.     private static String getSicurezzaMessaggioCertificatiKeyPassword() throws ProtocolException {
  123.         try {
  124.             if(getSicurezzaMessaggioCertificatiKeyStoreTipo()!=null) {
  125.                 return getModiProperties().getSicurezzaMessaggioCertificatiKeyPassword();
  126.             }
  127.             return null;
  128.         }catch(Exception e) {
  129.             throw new ProtocolException(e.getMessage(),e);
  130.         }
  131.     }
  132. }