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.     private boolean httpResponseJsonPathBase64Encoded;
  76.     private boolean httpResponseJsonPathHexEncoded;
  77.    
  78.     protected BYOKRemoteConfig(String id, Properties p, Logger log, String byokPropertyPrefix) throws UtilsException {
  79.                
  80.         if(p==null || p.isEmpty()) {
  81.             log.error("Properties is null");
  82.             throw new UtilsException("Properties '"+byokPropertyPrefix+id+".*' undefined");
  83.         }
  84.        
  85.         this.httpEndpoint = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_ENDPOINT, true, byokPropertyPrefix);
  86.         this.httpMethod = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_METHOD, true, byokPropertyPrefix);
  87.        
  88.         initHttpHeader(p);
  89.            
  90.         this.httpPayloadPath = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_PAYLOAD_PATH, false, byokPropertyPrefix);    
  91.         this.httpPayloadInLine = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_PAYLOAD_INLINE, false, byokPropertyPrefix);    
  92.            
  93.         this.httpUsername = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_USERNAME, false, byokPropertyPrefix);
  94.         this.httpPassword = BYOKConfig.getProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_PASSWORD, false, byokPropertyPrefix);  
  95.        
  96.         this.httpConnectionTimeout = BYOKConfig.getIntegerProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_CONNECTION_TIMEOUT, false, byokPropertyPrefix);
  97.         this.httpReadTimeout = BYOKConfig.getIntegerProperty(id, p, BYOKCostanti.PROPERTY_SUFFIX_HTTP_READ_TIMEOUT, false, byokPropertyPrefix);

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

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

  150.     public String getHttpPayloadInLine() {
  151.         return this.httpPayloadInLine;
  152.     }
  153.     public String getHttpPayloadPath() {
  154.         return this.httpPayloadPath;
  155.     }

  156.     public String getHttpUsername() {
  157.         return this.httpUsername;
  158.     }
  159.     public String getHttpPassword() {
  160.         return this.httpPassword;
  161.     }

  162.     public Integer getHttpConnectionTimeout() {
  163.         return this.httpConnectionTimeout;
  164.     }
  165.     public Integer getHttpReadTimeout() {
  166.         return this.httpReadTimeout;
  167.     }

  168.     public boolean isHttps() {
  169.         return this.https;
  170.     }
  171.     public boolean isHttpsHostnameVerifier() {
  172.         return this.httpsHostnameVerifier;
  173.     }

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

  192.     public boolean isHttpsClientAuth() {
  193.         return this.httpsClientAuth;
  194.     }
  195.     public String getHttpsClientAuthKeyStorePath() {
  196.         return this.httpsClientAuthKeyStorePath;
  197.     }
  198.     public String getHttpsClientAuthKeyStoreType() {
  199.         return this.httpsClientAuthKeyStoreType;
  200.     }
  201.     public String getHttpsClientAuthKeyStorePassword() {
  202.         return this.httpsClientAuthKeyStorePassword;
  203.     }
  204.     public String getHttpsClientAuthKeyAlias() {
  205.         return this.httpsClientAuthKeyAlias;
  206.     }
  207.     public String getHttpsClientAuthKeyPassword() {
  208.         return this.httpsClientAuthKeyPassword;
  209.     }
  210.    
  211.     public boolean isHttpResponseBase64Encoded() {
  212.         return this.httpResponseBase64Encoded;
  213.     }
  214.     public boolean isHttpResponseHexEncoded() {
  215.         return this.httpResponseHexEncoded;
  216.     }
  217.     public String getHttpResponseJsonPath() {
  218.         return this.httpResponseJsonPath;
  219.     }
  220.     public boolean isHttpResponseJsonPathBase64Encoded() {
  221.         return this.httpResponseJsonPathBase64Encoded;
  222.     }
  223.     public boolean isHttpResponseJsonPathHexEncoded() {
  224.         return this.httpResponseJsonPathHexEncoded;
  225.     }
  226. }