UniversallyUniqueIdentifier.java

/*
 * GovWay - A customizable API Gateway 
 * https://govway.org
 * 
 * Copyright (c) 2005-2024 Link.it srl (https://link.it). 
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3, as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


package org.openspcoop2.utils.id;

import java.util.UUID;


/**
 * UniversallyUniqueIdentifier
 *
 * @author Poli Andrea (apoli@link.it)
 * @author $Author$
 * @version $Rev$, $Date$
 */
public class UniversallyUniqueIdentifier implements IUniqueIdentifier {
	
//	There are two different ways of generating a UUID.
//
//	If you just need a unique ID, you want a version 1 or version 4.
//
//	    Version 1: This generates a unique ID based on a network card MAC address and a timer. These IDs are easy to predict (given one, I might be able to guess another one) and can be traced back to your network card. It's not recommended to create these.
//
//	    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.
//
//	UUIDv1 is NOT secure. It isn't meant to be. It is meant to be UNIQUE, not un-guessable. UUIDv1 uses the current timestamp, plus a machine identifier, 
//	plus some random-ish stuff to make a number that will never be generated by that algorithm again. 
//	This is appropriate for a transaction ID (even if everyone is doing millions of transactions/s).
//	UUIDv4 from reading RFC4122, it looks like that version does NOT eliminate possibility of collisions. 
//	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 
//	(quotes because there isn't a mechanism for guaranteeing U.niversal U.niqueness). 
//	In that situation, I don't think that algorithm belongs in a RFC describing methods for generating unique values. It would belong in a RFC about generating randomness. 
//	For a set of random numbers:
//
//	Riassunto:
//
//	Version 1 is based on MAC address and current time ("space and time"). Much less likely to have collisions than Version 4.
//
//	Version 4 is based on entirely being generated from random numbers using a cryptographically strong random generator.
//
//	The Oracle JVM does not provide a Version 1 generator, apparently because of security and privacy concerns. 
//	The JVM does not provide access to the MAC address of host machine.

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private UUID uuid;
	
	public UUID getUuid() {
		return this.uuid;
	}

	public void setUuid(UUID uuid) {
		this.uuid = uuid;
	}

	@Override
	public String getAsString() {
		return this.uuid.toString();
	}
		
	@Override
	public String toString(){
		return this.getAsString();
	}
}