UniversallyUniqueIdentifierV4GeneratorSecureRandom.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.id;

  21. import java.util.UUID;

  22. import com.fasterxml.uuid.Generators;
  23. import com.fasterxml.uuid.impl.RandomBasedGenerator;
  24. /**
  25.  * Implementazione tramite com.fasterxml.uuid.impl.RandomBasedGenerator
  26.  *
  27.  * @author Poli Andrea (apoli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */

  31. public class UniversallyUniqueIdentifierV4GeneratorSecureRandom extends AbstractUniversallyUniqueIdentifierGenerator{

  32. // Version 4: These are generated from random (or pseudo-random) numbers. If you just need to generate a UUID, this is probably what you want.
  33. //  UUIDv4 from reading RFC4122, it looks like that version does NOT eliminate possibility of collisions.
  34. //  It is just a random number generator. If that is true, than you have a very GOOD chance of two machines in the world eventually creating the same "UUID"v4
  35. //  (quotes because there isn't a mechanism for guaranteeing U.niversal U.niqueness).

  36.     // Generators are fully thread-safe, so a single instance may be shared among multiple threads.
  37.     private RandomBasedGenerator uuidv4 = Generators.randomBasedGenerator(new java.security.SecureRandom());
  38.    
  39.     @Override
  40.     protected UUID generateUUID() {
  41.         return this.uuidv4.generate();
  42.     }

  43. }