DecryptReceiverProvider.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.security.message.jose;

  21. import java.util.Map;
  22. import java.util.Properties;

  23. import org.apache.commons.lang.StringUtils;
  24. import org.openspcoop2.core.mvc.properties.provider.InputValidationUtils;
  25. import org.openspcoop2.core.mvc.properties.provider.ProviderException;
  26. import org.openspcoop2.core.mvc.properties.provider.ProviderValidationException;
  27. import org.openspcoop2.core.mvc.properties.utils.MultiPropertiesUtilities;
  28. import org.openspcoop2.security.message.constants.SecurityConstants;

  29. /**    
  30.  * DecryptReceiverProvider
  31.  *
  32.  * @author Poli Andrea (poli@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  */
  36. public class DecryptReceiverProvider extends KeyStoreWithSecretKeySecurityProvider {

  37.     public DecryptReceiverProvider() {
  38.         super();
  39.     }

  40.    
  41.     @Override
  42.     public void validate(Map<String, Properties> mapProperties) throws ProviderException, ProviderValidationException {
  43.         super.validate(mapProperties);
  44.        
  45.         Properties defaultP = MultiPropertiesUtilities.getDefaultProperties(mapProperties);
  46.        
  47.         Properties p = mapProperties.get("decryptionPropRefId");
  48.         if(p!=null && p.size()>0 &&
  49.             !p.containsKey(SecurityConstants.JOSE_KEYSTORE) && !p.containsKey(SecurityConstants.JOSE_KEYSTORE_JWKSET)) {
  50.             // altrimenti รจ stato fatto inject del keystore
  51.             String file = p.getProperty(SecurityConstants.JOSE_KEYSTORE_FILE);
  52.             if(file!=null && StringUtils.isNotEmpty(file)) {
  53.                 InputValidationUtils.validateTextAreaInput(file, "Decryption - KeyStore - File");
  54.             }
  55.         }
  56.        
  57.         String file = defaultP.getProperty(SecurityConstants.JOSE_TRUSTSTORE_SSL_FILE);
  58.         if(file!=null && StringUtils.isNotEmpty(file)) {
  59.             InputValidationUtils.validateTextAreaInput(file, "Configurazione HTTPS (jku/x5u) - TrustStore - File");
  60.         }
  61.        
  62.         file = defaultP.getProperty(SecurityConstants.JOSE_TRUSTSTORE_SSL_CRL);
  63.         if(file!=null && StringUtils.isNotEmpty(file)) {
  64.             InputValidationUtils.validateTextAreaInput(file, "Configurazione HTTPS (jku/x5u) - TrustStore - CRL File(s)");
  65.         }
  66.        
  67.         file = defaultP.getProperty("joseUseHeaders.keystore.file");
  68.         if(file!=null && StringUtils.isNotEmpty(file)) {
  69.             String fieldName = "Certificati X.509 (x5c/x5u) - KeyStore - File";
  70.             if (MultiPropertiesUtilities.isEnabled(defaultP, "joseUseHeaders.jwk") ||
  71.                     MultiPropertiesUtilities.isEnabled(defaultP, "joseUseHeaders.jku")) {
  72.                 fieldName = "Certificati JWK (jwk/jku) - KeyStore - File";
  73.             }
  74.             InputValidationUtils.validateTextAreaInput(file, fieldName);
  75.         }
  76.        
  77.         file = defaultP.getProperty("joseUseHeaders.keystore.file");
  78.         if(file!=null && StringUtils.isNotEmpty(file)) {
  79.             InputValidationUtils.validateTextAreaInput(file, "Certificati JWK (jwk/jku) - KeyStore - File");
  80.         }
  81.        
  82.         file = defaultP.getProperty("joseUseHeaders.truststore.file");
  83.         if(file!=null && StringUtils.isNotEmpty(file)) {
  84.             InputValidationUtils.validateTextAreaInput(file, "Validazione Certificati X.509 (x5c/x5u) - TrustStore - File");
  85.         }
  86.        
  87.         file = defaultP.getProperty("joseUseHeaders.truststore.crl");
  88.         if(file!=null && StringUtils.isNotEmpty(file)) {
  89.             InputValidationUtils.validateTextAreaInput(file, "Validazione Certificati X.509 (x5c/x5u) - TrustStore - CRL File(s)");
  90.         }
  91.        
  92.        
  93.     }
  94.    
  95. }