LoaderProperties.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.config.loader.cli;

  21. import java.io.InputStream;
  22. import java.util.Properties;

  23. import org.openspcoop2.core.commons.CoreException;

  24. /**
  25. * LoaderProperties
  26. *
  27. * @author Poli Andrea (apoli@link.it)
  28. * @author $Author$
  29. * @version $Rev$, $Date$
  30. */
  31. public class LoaderProperties {
  32.    
  33.     private static LoaderProperties staticInstance = null;
  34.     private static synchronized void init() throws CoreException{
  35.         if(LoaderProperties.staticInstance == null){
  36.             LoaderProperties.staticInstance = new LoaderProperties();
  37.         }
  38.     }
  39.     public static LoaderProperties getInstance() throws CoreException{
  40.         if(LoaderProperties.staticInstance == null){
  41.             // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  42.             synchronized (LoaderProperties.class) {
  43.                 LoaderProperties.init();
  44.             }
  45.         }
  46.         return LoaderProperties.staticInstance;
  47.     }
  48.    
  49.     private static String getPropertyPrefix(String name) {
  50.         return "Property '"+name+"'";
  51.     }
  52.    
  53.    
  54.    
  55.     private static final String PROPERTIES_FILE = "/config_loader.cli.properties";
  56.    
  57.     private String protocolloDefault = null;
  58.    
  59.     private boolean policyEnable = false;
  60.     private boolean pluginEnable = false;
  61.     private int pluginSeconds = 60;
  62.     private boolean pluginCheckReferences = false;
  63.     private boolean configurazioneGeneraleEnable = false;
  64.    
  65.     private String nomePddOperativa = null;
  66.     private String tipoPddArchivio = null;
  67.    
  68.     private boolean isAbilitatoControlloUnicitaImplementazioneAccordoPerSoggetto;
  69.     private boolean isAbilitatoControlloUnicitaImplementazionePortTypePerSoggetto;
  70.    
  71.     private boolean isSoggettiApplicativiCredenzialiBasicPermitSameCredentials;
  72.     private boolean isSoggettiApplicativiCredenzialiSslPermitSameCredentials;
  73.     private boolean isSoggettiApplicativiCredenzialiPrincipalPermitSameCredentials;

  74.     private String utente = null;
  75.        
  76.     private String utenzePassword = null;

  77.     private String applicativiPassword = null;
  78.     private int applicativiApiKeyPasswordGeneratedLength = -1;
  79.     private boolean applicativiBasicPasswordEnableConstraints = false;
  80.    
  81.     private String soggettiPassword = null;
  82.     private int soggettiApiKeyPasswordGeneratedLength = -1;
  83.     private boolean soggettiBasicPasswordEnableConstraints = false;
  84.    
  85.     private boolean securityLoadBouncyCastleProvider = false;
  86.    
  87.     private String envMapConfig = null;
  88.     private boolean envMapConfigRequired = false;
  89.    
  90.     private String hsmConfig = null;
  91.     private boolean hsmRequired = false;
  92.     private boolean hsmKeyPasswordConfigurable = false;
  93.    
  94.     private String byokConfigurazione = null;
  95.     private boolean byokRequired = false;
  96.     private String byokEnvSecretsConfig = null;
  97.     private boolean byokEnvSecretsConfigRequired = false;
  98.    
  99.     private LoaderProperties() throws CoreException {

  100.         Properties props = new Properties();
  101.         try {
  102.             InputStream is = LoaderProperties.class.getResourceAsStream(LoaderProperties.PROPERTIES_FILE);
  103.             props.load(is);
  104.         } catch(Exception e) {
  105.             throw new CoreException("Errore durante l'init delle properties", e);
  106.         }
  107.        
  108.         // PROPERTIES
  109.                
  110.         this.protocolloDefault = this.getProperty(props, "protocolloDefault", true);
  111.        
  112.         this.policyEnable = this.getBooleanProperty(props, "policy.enable", true);
  113.         this.pluginEnable = this.getBooleanProperty(props, "plugin.enable", true);
  114.         this.pluginCheckReferences = this.getBooleanProperty(props, "plugin.checkReferences", true);
  115.         this.pluginSeconds = this.getIntProperty(props, "plugin.seconds", true);
  116.         this.configurazioneGeneraleEnable = this.getBooleanProperty(props, "configurazioneGenerale.enable", true);
  117.        
  118.         this.nomePddOperativa = this.getProperty(props, "nomePddOperativa", false);
  119.         this.tipoPddArchivio = this.getProperty(props, "tipoPddArchivio", true);
  120.        
  121.         this.utente = this.getProperty(props, "utente", true);
  122.        
  123.         this.isAbilitatoControlloUnicitaImplementazioneAccordoPerSoggetto = this.getBooleanProperty(props, "accordi.implementazioneUnicaPerSoggetto", true);
  124.         this.isAbilitatoControlloUnicitaImplementazionePortTypePerSoggetto = this.getBooleanProperty(props, "accordi.portType.implementazioneUnicaPerSoggetto", true);
  125.        
  126.         this.isSoggettiApplicativiCredenzialiBasicPermitSameCredentials = this.getBooleanProperty(props, "soggettiApplicativi.credenzialiBasic.permitSameCredentials", true);
  127.         this.isSoggettiApplicativiCredenzialiSslPermitSameCredentials = this.getBooleanProperty(props, "soggettiApplicativi.credenzialiSsl.permitSameCredentials", true);
  128.         this.isSoggettiApplicativiCredenzialiPrincipalPermitSameCredentials = this.getBooleanProperty(props, "soggettiApplicativi.credenzialiPrincipal.permitSameCredentials", true);
  129.        
  130.         this.utenzePassword = this.getProperty(props, "utenze.password", true);

  131.         this.applicativiPassword = this.getProperty(props, "applicativi.password", true);
  132.         this.applicativiApiKeyPasswordGeneratedLength = this.getIntProperty(props, "applicativi.api_key.passwordGenerated.length", true);
  133.         this.applicativiBasicPasswordEnableConstraints = this.getBooleanProperty(props, "applicativi.basic.password.enableConstraints", true);
  134.        
  135.         this.soggettiPassword = this.getProperty(props, "soggetti.password", true);
  136.         this.soggettiApiKeyPasswordGeneratedLength = this.getIntProperty(props, "soggetti.api_key.passwordGenerated.length", true);
  137.         this.soggettiBasicPasswordEnableConstraints = this.getBooleanProperty(props, "soggetti.basic.password.enableConstraints", true);

  138.         this.securityLoadBouncyCastleProvider = this.getBooleanProperty(props, "security.addBouncyCastleProvider", false);
  139.        
  140.         this.envMapConfig = this.getProperty(props, "env.map.config", false);
  141.         this.envMapConfigRequired = this.getBooleanProperty(props, "env.map.required", false);
  142.        
  143.         this.hsmConfig = this.getProperty(props, "hsm.config", false);
  144.         this.hsmRequired = this.getBooleanProperty(props, "hsm.required", false);
  145.         this.hsmKeyPasswordConfigurable = this.getBooleanProperty(props, "hsm.keyPassword", false);
  146.        
  147.         this.byokConfigurazione = this.getProperty(props, "byok.config", false);
  148.         this.byokRequired = this.getBooleanProperty(props, "byok.required", false);
  149.         this.byokEnvSecretsConfig = this.getProperty(props, "byok.env.secrets.config", false);
  150.         this.byokEnvSecretsConfigRequired = this.getBooleanProperty(props, "byok.env.secrets.required", false);
  151.        
  152.     }
  153.    
  154.     private String getProperty(Properties props,String name,boolean required) throws CoreException{
  155.         String tmp = props.getProperty(name);
  156.         if(tmp==null){
  157.             if(required){
  158.                 throw new CoreException(getPropertyPrefix(name)+" not found");
  159.             }
  160.             else{
  161.                 return null;
  162.             }
  163.         }
  164.         else{
  165.             return tmp.trim();
  166.         }
  167.     }
  168.     private boolean getBooleanProperty(Properties props,String name,boolean required) throws CoreException{
  169.         String tmp = this.getProperty(props, name, required);
  170.         if(tmp!=null){
  171.             try{
  172.                 return Boolean.parseBoolean(tmp);
  173.             }catch(Exception e){
  174.                 throw new CoreException(getPropertyPrefix(name)+" wrong int format: "+e.getMessage());
  175.             }
  176.         }
  177.         else{
  178.             return false;
  179.         }
  180.     }
  181.     private int getIntProperty(Properties props,String name,boolean required) throws CoreException{
  182.         String tmp = this.getProperty(props, name, required);
  183.         if(tmp!=null){
  184.             try{
  185.                 return Integer.valueOf(tmp);
  186.             }catch(Exception e){
  187.                 throw new CoreException(getPropertyPrefix(name)+" wrong int format: "+e.getMessage());
  188.             }
  189.         }
  190.         else{
  191.             return -1;
  192.         }
  193.     }
  194.    
  195.    
  196.     public String getProtocolloDefault() {
  197.         return this.protocolloDefault;
  198.     }
  199.    
  200.     public boolean isPolicyEnable() {
  201.         return this.policyEnable;
  202.     }
  203.     public boolean isPluginEnable() {
  204.         return this.pluginEnable;
  205.     }
  206.     public boolean isPluginCheckReferences() {
  207.         return this.pluginCheckReferences;
  208.     }
  209.     public int getPluginSeconds() {
  210.         return this.pluginSeconds;
  211.     }
  212.     public boolean isConfigurazioneGeneraleEnable() {
  213.         return this.configurazioneGeneraleEnable;
  214.     }
  215.    
  216.     public String getNomePddOperativa() {
  217.         return this.nomePddOperativa;
  218.     }
  219.     public String getTipoPddArchivio() {
  220.         return this.tipoPddArchivio;
  221.     }
  222.    
  223.     public boolean isAbilitatoControlloUnicitaImplementazioneAccordoPerSoggetto() {
  224.         return this.isAbilitatoControlloUnicitaImplementazioneAccordoPerSoggetto;
  225.     }
  226.     public boolean isAbilitatoControlloUnicitaImplementazionePortTypePerSoggetto() {
  227.         return this.isAbilitatoControlloUnicitaImplementazionePortTypePerSoggetto;
  228.     }
  229.    
  230.     public boolean isSoggettiApplicativiCredenzialiBasicPermitSameCredentials() {
  231.         return this.isSoggettiApplicativiCredenzialiBasicPermitSameCredentials;
  232.     }
  233.     public boolean isSoggettiApplicativiCredenzialiSslPermitSameCredentials() {
  234.         return this.isSoggettiApplicativiCredenzialiSslPermitSameCredentials;
  235.     }
  236.     public boolean isSoggettiApplicativiCredenzialiPrincipalPermitSameCredentials() {
  237.         return this.isSoggettiApplicativiCredenzialiPrincipalPermitSameCredentials;
  238.     }
  239.    
  240.     public String getUtente() {
  241.         return this.utente;
  242.     }
  243.    
  244.     public String getUtenzePassword() {
  245.         return this.utenzePassword;
  246.     }
  247.     public String getApplicativiPassword() {
  248.         return this.applicativiPassword;
  249.     }
  250.     public int getApplicativiApiKeyPasswordGeneratedLength() {
  251.         return this.applicativiApiKeyPasswordGeneratedLength;
  252.     }
  253.     public boolean isApplicativiBasicPasswordEnableConstraints() {
  254.         return this.applicativiBasicPasswordEnableConstraints;
  255.     }
  256.     public String getSoggettiPassword() {
  257.         return this.soggettiPassword;
  258.     }
  259.     public int getSoggettiApiKeyPasswordGeneratedLength() {
  260.         return this.soggettiApiKeyPasswordGeneratedLength;
  261.     }
  262.     public boolean isSoggettiBasicPasswordEnableConstraints() {
  263.         return this.soggettiBasicPasswordEnableConstraints;
  264.     }

  265.     public boolean isSecurityLoadBouncyCastleProvider() {
  266.         return this.securityLoadBouncyCastleProvider;
  267.     }
  268.    
  269.     public String getEnvMapConfig() {
  270.         return this.envMapConfig;
  271.     }
  272.     public boolean isEnvMapConfigRequired(){
  273.         return this.envMapConfigRequired;
  274.     }
  275.    
  276.     public String getHSMConfigurazione() {
  277.         return this.hsmConfig;
  278.     }
  279.     public boolean isHSMRequired() {
  280.         return this.hsmRequired;
  281.     }
  282.     public boolean isHSMKeyPasswordConfigurable() {
  283.         return this.hsmKeyPasswordConfigurable;
  284.     }
  285.    
  286.     public String getBYOKConfigurazione() {
  287.         return this.byokConfigurazione;
  288.     }
  289.     public boolean isBYOKRequired() {
  290.         return this.byokRequired;
  291.     }
  292.     public String getBYOKEnvSecretsConfig() {
  293.         return this.byokEnvSecretsConfig;
  294.     }
  295.     public boolean isBYOKEnvSecretsConfigRequired() {
  296.         return this.byokEnvSecretsConfigRequired;
  297.     }
  298. }