BYOKRemoteConfig.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.utils.certificate.byok;

  21. import java.io.Serializable;
  22. import java.util.Enumeration;
  23. import java.util.HashMap;
  24. import java.util.Map;
  25. import java.util.Properties;

  26. import org.openspcoop2.utils.UtilsException;
  27. import org.slf4j.Logger;

  28. /**
  29.  * BYOKRemoteConfig
  30.  *
  31.  * @author Poli Andrea (apoli@link.it)
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  */
  35. public class BYOKRemoteConfig implements Serializable {

  36.     /**
  37.      *
  38.      */
  39.     private static final long serialVersionUID = -3572589461109860459L;
  40.            
  41.     private String httpEndpoint;
  42.     private String httpMethod;
  43.    
  44.     private Map<String,String> httpHeaders;
  45.    
  46.     private String httpPayloadPath;
  47.     private String httpPayloadInLine;
  48.    
  49.     private String httpUsername;
  50.     private String httpPassword;
  51.    
  52.     private Integer httpConnectionTimeout;
  53.     private Integer httpReadTimeout;

  54.     private boolean https = false;
  55.    
  56.     private boolean httpsHostnameVerifier = false;
  57.    
  58.     private boolean httpsServerAuth = false;
  59.     private String httpsServerAuthTrustStorePath;
  60.     private String httpsServerAuthTrustStoreType;
  61.     private String httpsServerAuthTrustStorePassword;
  62.     private String httpsServerAuthTrustStoreCrls;
  63.     private String httpsServerAuthTrustStoreOcspPolicy;
  64.    
  65.     private boolean httpsClientAuth = false;
  66.     private String httpsClientAuthKeyStorePath;
  67.     private String httpsClientAuthKeyStoreType;
  68.     private String httpsClientAuthKeyStorePassword;
  69.     private String httpsClientAuthKeyAlias;
  70.     private String httpsClientAuthKeyPassword;
  71.    
  72.     private boolean httpResponseBase64Encoded;
  73.     private boolean httpResponseHexEncoded;
  74.     private String httpResponseJsonPath;
  75.    
  76.    
  77.     protected BYOKRemoteConfig(String id, Properties p, Logger log) throws UtilsException {
  78.                
  79.         if(p==null || p.isEmpty()) {
  80.             log.error("Properties is null");
  81.             throw new UtilsException("Properties '"+BYOKCostanti.PROPERTY_PREFIX+id+".*' undefined");
  82.         }
  83.        
  84.         this.httpEndpoint = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_ENDPOINT, true);
  85.         this.httpMethod = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_METHOD, true);
  86.        
  87.         initHttpHeader(p);
  88.            
  89.         this.httpPayloadPath = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_PAYLOAD_PATH, false);    
  90.         this.httpPayloadInLine = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_PAYLOAD_INLINE, false);    
  91.            
  92.         this.httpUsername = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_USERNAME, false);
  93.         this.httpPassword = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_PASSWORD, false);  
  94.        
  95.         this.httpConnectionTimeout = BYOKConfig.getIntegerProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_CONNECTION_TIMEOUT, false);
  96.         this.httpReadTimeout = BYOKConfig.getIntegerProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_READ_TIMEOUT, false);

  97.         this.https = BYOKConfig.getBooleanProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS, false, false);    
  98.        
  99.         this.httpsHostnameVerifier = BYOKConfig.getBooleanProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_VERIFICA_HOSTNAME, false, this.https);
  100.        
  101.         this.httpsServerAuth = BYOKConfig.getBooleanProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_AUTENTICAZIONE_SERVER, false, this.https);
  102.         this.httpsServerAuthTrustStorePath = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_AUTENTICAZIONE_SERVER_TRUSTSTORE_PATH, false);
  103.         this.httpsServerAuthTrustStoreType = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_AUTENTICAZIONE_SERVER_TRUSTSTORE_TYPE, this.httpsServerAuth);
  104.         this.httpsServerAuthTrustStorePassword = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_AUTENTICAZIONE_SERVER_TRUSTSTORE_PASSWORD, false);
  105.         this.httpsServerAuthTrustStoreCrls = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_AUTENTICAZIONE_SERVER_CRLS, false);
  106.         this.httpsServerAuthTrustStoreOcspPolicy = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_AUTENTICAZIONE_SERVER_OCSP_POLICY, false);
  107.        
  108.         this.httpsClientAuth = BYOKConfig.getBooleanProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_AUTENTICAZIONE_CLIENT, false, false);
  109.         this.httpsClientAuthKeyStorePath = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_AUTENTICAZIONE_CLIENT_KEYSTORE_PATH, false);
  110.         this.httpsClientAuthKeyStoreType = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_AUTENTICAZIONE_CLIENT_KEYSTORE_TYPE, this.httpsClientAuth);
  111.         this.httpsClientAuthKeyStorePassword = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_AUTENTICAZIONE_CLIENT_KEYSTORE_PASSWORD, false);
  112.         this.httpsClientAuthKeyAlias = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_AUTENTICAZIONE_CLIENT_KEY_ALIAS, false);
  113.         this.httpsClientAuthKeyPassword = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTPS_AUTENTICAZIONE_CLIENT_KEY_PASSWORD, false);
  114.        
  115.         this.httpResponseBase64Encoded = BYOKConfig.getBooleanProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_RESPONSE_BASE64_ENCODED, false, false);
  116.         this.httpResponseHexEncoded = BYOKConfig.getBooleanProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_RESPONSE_HEX_ENCODED, false, false);
  117.         this.httpResponseJsonPath = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_RESPONSE_JSON_PATH, false);
  118.     }

  119.     private void initHttpHeader(Properties p) {
  120.         this.httpHeaders = new HashMap<>();
  121.         Enumeration<?> enKeys = p.keys();
  122.         while (enKeys.hasMoreElements()) {
  123.             Object object = enKeys.nextElement();
  124.             if(object instanceof String) {
  125.                 String key = (String) object;
  126.                 if(key.startsWith(BYOKCostanti.PROPERTY_SUFFIX_HTTP_HEADER) && key.length()>BYOKCostanti.PROPERTY_SUFFIX_HTTP_HEADER.length()) {
  127.                     String name = key.substring(BYOKCostanti.PROPERTY_SUFFIX_HTTP_HEADER.length());
  128.                     String value = p.getProperty(key);
  129.                     this.httpHeaders.put(name, value);
  130.                 }
  131.             }
  132.         }
  133.        
  134.     }
  135.    
  136.    
  137.     public String getHttpEndpoint() {
  138.         return this.httpEndpoint;
  139.     }
  140.     public String getHttpMethod() {
  141.         return this.httpMethod;
  142.     }
  143.    
  144.     public Map<String, String> getHttpHeaders() {
  145.         return this.httpHeaders;
  146.     }

  147.     public String getHttpPayloadInLine() {
  148.         return this.httpPayloadInLine;
  149.     }
  150.     public String getHttpPayloadPath() {
  151.         return this.httpPayloadPath;
  152.     }

  153.     public String getHttpUsername() {
  154.         return this.httpUsername;
  155.     }
  156.     public String getHttpPassword() {
  157.         return this.httpPassword;
  158.     }

  159.     public Integer getHttpConnectionTimeout() {
  160.         return this.httpConnectionTimeout;
  161.     }
  162.     public Integer getHttpReadTimeout() {
  163.         return this.httpReadTimeout;
  164.     }

  165.     public boolean isHttps() {
  166.         return this.https;
  167.     }
  168.     public boolean isHttpsHostnameVerifier() {
  169.         return this.httpsHostnameVerifier;
  170.     }

  171.     public boolean isHttpsServerAuth() {
  172.         return this.httpsServerAuth;
  173.     }
  174.     public String getHttpsServerAuthTrustStorePath() {
  175.         return this.httpsServerAuthTrustStorePath;
  176.     }
  177.     public String getHttpsServerAuthTrustStoreType() {
  178.         return this.httpsServerAuthTrustStoreType;
  179.     }
  180.     public String getHttpsServerAuthTrustStorePassword() {
  181.         return this.httpsServerAuthTrustStorePassword;
  182.     }
  183.     public String getHttpsServerAuthTrustStoreCrls() {
  184.         return this.httpsServerAuthTrustStoreCrls;
  185.     }
  186.     public String getHttpsServerAuthTrustStoreOcspPolicy() {
  187.         return this.httpsServerAuthTrustStoreOcspPolicy;
  188.     }

  189.     public boolean isHttpsClientAuth() {
  190.         return this.httpsClientAuth;
  191.     }
  192.     public String getHttpsClientAuthKeyStorePath() {
  193.         return this.httpsClientAuthKeyStorePath;
  194.     }
  195.     public String getHttpsClientAuthKeyStoreType() {
  196.         return this.httpsClientAuthKeyStoreType;
  197.     }
  198.     public String getHttpsClientAuthKeyStorePassword() {
  199.         return this.httpsClientAuthKeyStorePassword;
  200.     }
  201.     public String getHttpsClientAuthKeyAlias() {
  202.         return this.httpsClientAuthKeyAlias;
  203.     }
  204.     public String getHttpsClientAuthKeyPassword() {
  205.         return this.httpsClientAuthKeyPassword;
  206.     }
  207.    
  208.     public boolean isHttpResponseBase64Encoded() {
  209.         return this.httpResponseBase64Encoded;
  210.     }
  211.     public boolean isHttpResponseHexEncoded() {
  212.         return this.httpResponseHexEncoded;
  213.     }
  214.     public String getHttpResponseJsonPath() {
  215.         return this.httpResponseJsonPath;
  216.     }
  217. }