code: public static String generateSecurityToken(int length, boolean urlSafe) {
  		final byte[] bytes = new byte[length];
  		SecureRandom rand;
  		try {
  			rand = SecureRandom.getInstance("SHA1PRNG");
  		} catch (NoSuchAlgorithmException ex) {
  			logger.error(null, ex);
  			rand = new SecureRandom();
  		}
  		rand.nextBytes(bytes);
  		return urlSafe ? base64encURL(bytes) : base64enc(bytes);
  	}
docs: Generates an authentication token - a random string encoded in Base64.
  @param length the length of the generated token
  @param urlSafe switches to a URL safe encoding
  @return a random string