RemoteStoreConfig.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.remote;

  21. import java.util.ArrayList;

  22. import org.openspcoop2.utils.UtilsException;
  23. import org.openspcoop2.utils.certificate.KeyUtils;
  24. import org.openspcoop2.utils.transport.http.ExternalResourceConfig;

  25. /**
  26.  * RemoteStoreConfig
  27.  *
  28.  * @author Poli Andrea (apoli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. public class RemoteStoreConfig extends ExternalResourceConfig {

  33.     private String storeName;
  34.     private String storeLabel;
  35.    
  36.     private String tokenPolicy;
  37.    
  38.     private String baseUrl;
  39.    
  40.     private boolean multitenant;
  41.     private String baseUrlMultitenantDefaultString;
  42.     private String baseUrlMultitenantPlaceholder;
  43.     private String baseUrlMultitenantTenantString;
  44.    
  45.     private RemoteKeyIdMode idMode;
  46.     private String parameterName; // in caso di query o parameter
  47.     private String keyAlgorithm = KeyUtils.ALGO_RSA;
  48.    
  49.     public RemoteStoreConfig(String storeName) {
  50.         super();
  51.         this.storeName = storeName;
  52.         this.storeLabel = storeName; // inizialmente uguale
  53.     }
  54.    
  55.     public RemoteStoreConfig newInstanceMultitenant(String tenant) throws UtilsException {
  56.                
  57.         if(!this.multitenant) {
  58.             throw new UtilsException("Multi-tenant disabled");
  59.         }
  60.        
  61.         RemoteStoreConfig cloned = new RemoteStoreConfig(this.storeName+"");
  62.         cloned.storeLabel = this.storeLabel!=null ? (this.storeLabel+"") : this.storeName;
  63.        
  64.         cloned.tokenPolicy = this.tokenPolicy!=null ? (this.tokenPolicy+"") : null;
  65.        
  66.         cloned.baseUrl = this.baseUrl!=null ? (this.baseUrl+"") : null;
  67.         if(cloned.baseUrl!=null && this.baseUrlMultitenantDefaultString!=null && this.baseUrlMultitenantPlaceholder!=null && this.baseUrlMultitenantTenantString!=null) {
  68.            
  69.             String newString = this.baseUrlMultitenantTenantString.replace(this.baseUrlMultitenantPlaceholder, tenant);
  70.             cloned.baseUrl = cloned.baseUrl.replace(this.baseUrlMultitenantDefaultString, newString);
  71.            
  72.         }
  73.         else {
  74.             cloned.baseUrl = RemoteStoreConfigMultiTenantUtils.getMultitenant(this.multiTenantBaseUrl, tenant, cloned.baseUrl);
  75.         }
  76.        
  77.         cloned.idMode = this.idMode;
  78.         cloned.parameterName = this.parameterName!=null ? (this.parameterName+"") : null;
  79.         cloned.keyAlgorithm = this.keyAlgorithm!=null ? (this.keyAlgorithm+"") : KeyUtils.ALGO_RSA;
  80.        
  81.         // riporto dati ExternalResourceConfig
  82.         this.newInstanceMultitenant(cloned, tenant);
  83.        
  84.         return cloned;
  85.     }
  86.    
  87.     private void newInstanceMultitenant(RemoteStoreConfig cloned, String tenant) {
  88.        
  89.         cloned.readTimeout = this.readTimeout;
  90.         cloned.connectTimeout = this.connectTimeout;
  91.        
  92.         if(this.returnCode!=null) {
  93.             cloned.returnCode = new ArrayList<>();
  94.             for (Integer intValue : this.returnCode) {
  95.                 if(intValue!=null) {
  96.                     cloned.returnCode.add(intValue);
  97.                 }
  98.             }
  99.         }
  100.        
  101.         cloned.basicUsername = this.basicUsername!=null ? (this.basicUsername+"") : null;
  102.         cloned.basicPassword = this.basicPassword!=null ? (this.basicPassword+"") : null;
  103.        
  104.         cloned.hostnameVerifier = this.hostnameVerifier;
  105.        
  106.         cloned.trustAllCerts = this.trustAllCerts;
  107.        
  108.         cloned.trustStore = this.trustStore;
  109.        
  110.         cloned.crlStore = this.crlStore;
  111.        
  112.         cloned.keyStore = this.keyStore;
  113.         cloned.keyAlias = this.keyAlias!=null ? (this.keyAlias+"") : null;
  114.         cloned.keyPassword = this.keyPassword!=null ? (this.keyPassword+"") : null;
  115.        
  116.         cloned.forwardProxyUrl = this.forwardProxyUrl!=null ? (this.forwardProxyUrl+"") : null;
  117.         cloned.forwardProxyHeader = this.forwardProxyHeader!=null ? (this.forwardProxyHeader+"") : null;
  118.         cloned.forwardProxyQueryParameter = this.forwardProxyQueryParameter!=null ? (this.forwardProxyQueryParameter+"") : null;
  119.         cloned.forwardProxyBase64 = this.forwardProxyBase64;
  120.        
  121.         cloned.headers = RemoteStoreConfigMultiTenantUtils.newMapInstance(this.headers);
  122.         cloned.queryParameters = RemoteStoreConfigMultiTenantUtils.newMapInstance(this.queryParameters);
  123.        
  124.         /**cloned.multiTenantBasicUsername = RemoteStoreConfigMultiTenantUtils.newMapInstance(this.multiTenantBasicUsername);
  125.         cloned.multiTenantBasicPassword = RemoteStoreConfigMultiTenantUtils.newMapInstance(this.multiTenantBasicPassword);
  126.        
  127.         cloned.multiTenantHeaders = RemoteStoreConfigMultiTenantUtils.newMultiMapInstance(this.multiTenantHeaders);
  128.         cloned.multiTenantQueryParameters = RemoteStoreConfigMultiTenantUtils.newMultiMapInstance(this.multiTenantQueryParameters);*/
  129.        
  130.         // Devo sovrascrivere
  131.         cloned.basicUsername = RemoteStoreConfigMultiTenantUtils.getMultitenant(this.multiTenantBasicUsername, tenant, cloned.basicUsername);
  132.         cloned.basicPassword = RemoteStoreConfigMultiTenantUtils.getMultitenant(this.multiTenantBasicPassword, tenant, cloned.basicPassword);
  133.         cloned.headers = RemoteStoreConfigMultiTenantUtils.getMultitenant(this.multiTenantHeaders, tenant, cloned.headers);
  134.         cloned.queryParameters = RemoteStoreConfigMultiTenantUtils.getMultitenant(this.multiTenantQueryParameters, tenant, cloned.queryParameters);
  135.        
  136.         // imposto comunque l'indicazione che si tratta di un multitenant
  137.         cloned.multitenant=true;
  138.     }
  139.    
  140.     public String getStoreName() {
  141.         return this.storeName;
  142.     }
  143.    
  144.     public String getStoreLabel() {
  145.         return this.storeLabel;
  146.     }

  147.     public void setStoreLabel(String storeLabel) {
  148.         this.storeLabel = storeLabel;
  149.     }
  150.    
  151.     public String getTokenPolicy() {
  152.         return this.tokenPolicy;
  153.     }

  154.     public void setTokenPolicy(String tokenPolicy) {
  155.         this.tokenPolicy = tokenPolicy;
  156.     }
  157.    
  158.     public String getKeyAlgorithm() {
  159.         return this.keyAlgorithm;
  160.     }

  161.     public void setKeyAlgorithm(String keyAlgorithm) {
  162.         this.keyAlgorithm = keyAlgorithm;
  163.     }

  164.     public String getBaseUrl() {
  165.         return this.baseUrl;
  166.     }

  167.     public void setBaseUrl(String baseUrl) {
  168.         this.baseUrl = baseUrl;
  169.     }

  170.     public RemoteKeyIdMode getIdMode() {
  171.         return this.idMode;
  172.     }

  173.     public void setIdMode(RemoteKeyIdMode idMode) {
  174.         this.idMode = idMode;
  175.     }

  176.     public String getParameterName() {
  177.         return this.parameterName;
  178.     }

  179.     public void setParameterName(String parameterName) {
  180.         this.parameterName = parameterName;
  181.     }
  182.    
  183.     public boolean isMultitenant() {
  184.         return this.multitenant;
  185.     }

  186.     public void setMultitenant(boolean multitenant) {
  187.         this.multitenant = multitenant;
  188.     }
  189.    
  190.     public String getBaseUrlMultitenantDefaultString() {
  191.         return this.baseUrlMultitenantDefaultString;
  192.     }

  193.     public void setBaseUrlMultitenantDefaultString(String baseUrlMultitenantDefaultString) {
  194.         this.baseUrlMultitenantDefaultString = baseUrlMultitenantDefaultString;
  195.     }

  196.     public String getBaseUrlMultitenantPlaceholder() {
  197.         return this.baseUrlMultitenantPlaceholder;
  198.     }

  199.     public void setBaseUrlMultitenantPlaceholder(String baseUrlMultitenantPlaceholder) {
  200.         this.baseUrlMultitenantPlaceholder = baseUrlMultitenantPlaceholder;
  201.     }

  202.     public String getBaseUrlMultitenantTenantString() {
  203.         return this.baseUrlMultitenantTenantString;
  204.     }

  205.     public void setBaseUrlMultitenantTenantString(String baseUrlMultitenantTenantString) {
  206.         this.baseUrlMultitenantTenantString = baseUrlMultitenantTenantString;
  207.     }
  208. }