SignalHubUtils.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.protocol.modipa.utils;

  21. import java.time.Instant;
  22. import java.util.Base64;
  23. import java.util.List;
  24. import java.util.stream.Collectors;

  25. import org.openspcoop2.core.id.IDServizio;
  26. import org.openspcoop2.core.registry.ProtocolProperty;
  27. import org.openspcoop2.pdd.config.DigestServiceParams;
  28. import org.openspcoop2.protocol.modipa.constants.ModICostanti;
  29. import org.openspcoop2.protocol.sdk.Context;
  30. import org.openspcoop2.protocol.sdk.ProtocolException;
  31. import org.openspcoop2.protocol.sdk.properties.ProtocolPropertiesUtils;
  32. import org.openspcoop2.utils.digest.DigestType;
  33. import org.openspcoop2.utils.random.RandomUtilities;

  34. /**
  35.  * SignalHubUtils classe con metodi di utilita signal hub
  36.  *
  37.  * @author Tommaso Burlon (tommaso.burlon@link.it)
  38.  * @author $Author$
  39.  * @version $Rev$, $Date$
  40.  */
  41. public class SignalHubUtils {
  42.    
  43.     private SignalHubUtils() {}
  44.    
  45.     /**
  46.      * Funzioone per fare il parsing delle protocolProperties di un erogazione impostata per supportare singnal hub
  47.      * per generare nuove informazioni crittografiche per la creazione del digest
  48.      * @param idServizio
  49.      * @param eServiceProperties
  50.      * @param serial
  51.      * @return
  52.      * @throws ProtocolException
  53.      */
  54.     public static DigestServiceParams generateDigestServiceParams(IDServizio idServizio, List<ProtocolProperty> eServiceProperties, Long serial) throws ProtocolException {
  55.         Long durata = ProtocolPropertiesUtils.getRequiredNumberValuePropertyRegistry(eServiceProperties, ModICostanti.MODIPA_API_IMPL_INFO_SIGNAL_HUB_SEED_LIFETIME_ID, true);
  56.         String algorithm = ProtocolPropertiesUtils.getRequiredStringValuePropertyRegistry(eServiceProperties, ModICostanti.MODIPA_API_IMPL_INFO_SIGNAL_HUB_ALGORITHM_ID);
  57.         Long seedSize = ProtocolPropertiesUtils.getRequiredNumberValuePropertyRegistry(eServiceProperties, ModICostanti.MODIPA_API_IMPL_INFO_SIGNAL_HUB_SEED_SIZE_ID, true);
  58.        
  59.         DigestServiceParams param = new DigestServiceParams();
  60.         param.setIdServizio(idServizio);
  61.         param.setDataRegistrazione(Instant.now());
  62.         param.setDurata(durata.intValue());
  63.         param.setDigestAlgorithm(DigestType.fromAlgorithmName(algorithm));
  64.         param.setSeed(Base64.getEncoder().encode(RandomUtilities.getSecureRandom().generateSeed(seedSize.intValue())));
  65.         param.setSerialNumber(serial);
  66.        
  67.         return param;
  68.     }
  69.    
  70.     public static List<ProtocolProperty> obtainSignalHubProtocolProperty(Context context) {
  71.         return ((List<?>) context.get(ModICostanti.MODIPA_KEY_INFO_SIGNAL_HUB_PROPERTIES))
  72.         .stream()
  73.         .map(e -> (ProtocolProperty)e)
  74.         .collect(Collectors.toList());
  75.     }
  76. }