Java Code Examples for java.util.UUID#version()

The following examples show how to use java.util.UUID#version() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractStreamingHandler.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Nullable
protected UUID getRecordingId(QueryStringDecoder uri, int start, int end, @Nullable String finl) {
   try {
      String path = uri.path();
      String recording = path.substring(start, end);

      UUID uuid = UUID.fromString(recording);
      if (uuid.version() != 1) {
         logger.debug("failed to retreive recording id because uuid wasn't version 1: {}", uri);
         return null;
      }

      if (finl != null) {
         String fin = path.substring(end);
         if (!finl.equals(fin)) {
            logger.debug("failed to retreive recording id because url was wrong: {}", uri);
            return null;
         }
      }

      return uuid;
   } catch (Exception ex) {
      return null;
   }
}
 
Example 2
Source File: MP4Handler.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Nullable
protected UUID getRecordingId(QueryStringDecoder uri, int start, int end, @Nullable String finl) {
   try {
      String path = uri.path();
      String recording = path.substring(start, end);

      UUID uuid = UUID.fromString(recording);
      if (uuid.version() != 1) {
         DOWNLOAD_UUID_BAD.inc();
         log.debug("failed to retreive recording id because uuid wasn't version 1: {}", uri);
         return null;
      }

      if (finl != null) {
         String fin = path.substring(end);
         if (!finl.equals(fin)) {
            DOWNLOAD_URL_BAD.inc();
            log.debug("failed to retreive recording id because url was wrong: {}", uri);
            return null;
         }
      }

      return uuid;
   } catch (Exception ex) {
      DOWNLOAD_ID_BAD.inc();
      return null;
   }
}
 
Example 3
Source File: UUIDTypeTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public String describeCompare(UUID u1, UUID u2, int c)
{
    String tb1 = (u1 == null) ? "null" : (u1.version() == 1) ? "time-based " : "random ";
    String tb2 = (u2 == null) ? "null" : (u2.version() == 1) ? "time-based " : "random ";
    String comp = (c < 0) ? " < " : ((c == 0) ? " = " : " > ");
    return tb1 + u1 + comp + tb2 + u2;
}
 
Example 4
Source File: UUIDTypeTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void logJdkUUIDCompareToVariance(UUID u1, UUID u2, int expC)
{
    if ((u1 == null) || (u2 == null))
        return;
    if (u1.version() != u2.version())
        return;
    if (u1.version() == 1)
        return;
    if (u1.compareTo(u2) != expC)
        logger.info("*** Note: java.util.UUID.compareTo() would have compared this differently");
}
 
Example 5
Source File: Id.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
public static String shortUUIDstr(UUID uuid) {
    String str = uuid.toString();
    int version = uuid.version();
    if ( version == 1 )
        // Type 1 : include varying part! xxxx-yyyy
        // 19-28 is
        //return str.substring(19, 28);
        // 0-6 is the low end of the clock.
        return uuid.toString().substring(0,6);
    if ( version == 4 )
        // Type 4 - use the first few hex characters.
        return uuid.toString().substring(0,6);
    return uuid.toString().substring(0,8);
}
 
Example 6
Source File: TimeUUIDParam.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
protected UUID parse(String input) throws Exception {
    UUID uuid = UUID.fromString(input);
    if (uuid.version() != 1) {
        throw new IllegalArgumentException(); // must be a time uuid
    }
    return uuid;
}
 
Example 7
Source File: UUIDTypeTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void testCompare(UUID u1, UUID u2, int expC)
{
    int c = sign(uuidType.compare(bytebuffer(u1), bytebuffer(u2)));
    expC = sign(expC);
    assertEquals("Expected " + describeCompare(u1, u2, expC) + ", got " + describeCompare(u1, u2, c), expC, c);

    if (((u1 != null) && (u1.version() == 1)) && ((u2 != null) && (u2.version() == 1)))
        assertEquals(c, sign(TimeUUIDType.instance.compare(bytebuffer(u1), bytebuffer(u2))));

    logJdkUUIDCompareToVariance(u1, u2, c);
}
 
Example 8
Source File: LuckPermsVaultPermission.java    From LuckPerms with MIT License 5 votes vote down vote up
public PermissionHolder lookupUser(UUID uuid) {
    Objects.requireNonNull(uuid, "uuid");

    // loaded already?
    User user = this.plugin.getUserManager().getIfLoaded(uuid);
    if (user != null) {
        return user;
    }

    // if the uuid is version 2, assume it is an NPC
    // see: https://github.com/lucko/LuckPerms/issues/1470
    // and https://github.com/lucko/LuckPerms/issues/1470#issuecomment-475403162
    if (uuid.version() == 2) {
        String npcGroupName = this.plugin.getConfiguration().get(ConfigKeys.VAULT_NPC_GROUP);
        Group npcGroup = this.plugin.getGroupManager().getIfLoaded(npcGroupName);
        if (npcGroup == null) {
            npcGroup = this.plugin.getGroupManager().getIfLoaded(GroupManager.DEFAULT_GROUP_NAME);
            if (npcGroup == null) {
                throw new IllegalStateException("unable to get default group");
            }
        }
        return npcGroup;
    }

    // are we on the main thread?
    if (!this.plugin.getBootstrap().isServerStarting() && this.plugin.getBootstrap().getServer().isPrimaryThread() && !this.plugin.getConfiguration().get(ConfigKeys.VAULT_UNSAFE_LOOKUPS)) {
        throw new RuntimeException(
                "The operation to load user data for '" + uuid + "' was cancelled by LuckPerms. This is NOT a bug. \n" +
                "The lookup request was made on the main server thread. It is not safe to execute a request to \n" +
                "load data for offline players from the database in this context. \n" +
                "If you are a plugin author, please consider making your request asynchronously. \n" +
                "Alternatively, server admins can disable this catch by setting 'vault-unsafe-lookups' to true \n" +
                "in the LP config, but should consider the consequences (lag) before doing so."
        );
    }

    // load an instance from the DB
    return this.plugin.getStorage().loadUser(uuid, null).join();
}
 
Example 9
Source File: UUIDConverter.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
public static String fromTimeUUID(UUID src) {
  if (src.version() != 1) {
    throw new IllegalArgumentException("Not a time UUID!");
  }
  String str = src.toString();
  return str.substring(15, 18) + str.substring(9, 13) + str.substring(0, 8) + str.substring(19, 23)
      + str.substring(24);
}
 
Example 10
Source File: UUIDConverter.java    From Groza with Apache License 2.0 5 votes vote down vote up
public static String fromTimeUUID(UUID src) {
    if (src.version() != 1) {
        throw new IllegalArgumentException("Only Time-Based UUID (Version 1) is supported!");
    }
    String str = src.toString();
    // 58e0a7d7-eebc-11d8-9669-0800200c9a66 => 1d8eebc58e0a7d796690800200c9a66. Note that [11d8] -> [1d8]
    return str.substring(15, 18) + str.substring(9, 13) + str.substring(0, 8) + str.substring(19, 23) + str.substring(24);
}
 
Example 11
Source File: IrisUUID.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static boolean isTime(UUID uuid) {
   return uuid.variant() == 2 && uuid.version() == 1;
}
 
Example 12
Source File: LuckPermsVaultPermission.java    From LuckPerms with MIT License 4 votes vote down vote up
QueryOptions getQueryOptions(@Nullable UUID uuid, @Nullable String world) {
    MutableContextSet context;

    Player player = Optional.ofNullable(uuid).flatMap(u -> this.plugin.getBootstrap().getPlayer(u)).orElse(null);
    if (player != null) {
        context = this.plugin.getContextManager().getContext(player).mutableCopy();
    } else {
        context = this.plugin.getContextManager().getStaticContext().mutableCopy();
    }

    String playerWorld = player == null ? null : player.getWorld().getName();

    // if world is null, we want to do a lookup in the players current context
    // if world is not null, we want to do a lookup in that specific world
    if (world != null && !world.isEmpty() && !world.equalsIgnoreCase(playerWorld)) {
        // remove already accumulated worlds
        context.removeAll(DefaultContextKeys.WORLD_KEY);
        // add the vault world
        context.add(DefaultContextKeys.WORLD_KEY, world.toLowerCase());
    }

    // if we're using a special vault server
    if (useVaultServer()) {
        // remove the normal server context from the set
        context.remove(DefaultContextKeys.SERVER_KEY, getServer());

        // add the vault specific server
        if (!getVaultServer().equals("global")) {
            context.add(DefaultContextKeys.SERVER_KEY, getVaultServer());
        }
    }

    boolean op = false;
    if (player != null) {
        op = player.isOp();
    } else if (uuid != null && uuid.version() == 2) { // npc
        op = this.plugin.getConfiguration().get(ConfigKeys.VAULT_NPC_OP_STATUS);
    }

    QueryOptions.Builder builder = QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder();
    builder.context(context);
    builder.flag(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT, isIncludeGlobal());
    if (op) {
        builder.option(BukkitContextManager.OP_OPTION, true);
    }
    return builder.build();
}
 
Example 13
Source File: AbstractConnectionListener.java    From LuckPerms with MIT License 4 votes vote down vote up
public User loadUser(UUID uniqueId, String username) {
    final long startTime = System.currentTimeMillis();

    // register with the housekeeper to avoid accidental unloads
    this.plugin.getUserManager().getHouseKeeper().registerUsage(uniqueId);

    // save uuid data.
    PlayerSaveResult saveResult = this.plugin.getStorage().savePlayerData(uniqueId, username).join();

    // fire UserFirstLogin event
    if (saveResult.includes(PlayerSaveResult.Outcome.CLEAN_INSERT)) {
        this.plugin.getEventDispatcher().dispatchUserFirstLogin(uniqueId, username);
    }

    // most likely because ip forwarding is not setup correctly
    // print a warning to the console
    if (saveResult.includes(PlayerSaveResult.Outcome.OTHER_UNIQUE_IDS_PRESENT_FOR_USERNAME)) {
        Set<UUID> otherUuids = saveResult.getOtherUniqueIds();

        this.plugin.getLogger().warn("LuckPerms already has data for player '" + username + "' - but this data is stored under a different UUID.");
        this.plugin.getLogger().warn("'" + username + "' has previously used the unique ids " + otherUuids + " but is now connecting with '" + uniqueId + "'");

        if (uniqueId.version() == 4) {
            if (this.plugin.getBootstrap().getType() == Platform.Type.BUNGEECORD) {
                this.plugin.getLogger().warn("The UUID the player is connecting with now is Mojang-assigned (type 4). This implies that BungeeCord's IP-Forwarding has not been setup correctly on one (or more) of the backend servers.");
            } if (this.plugin.getBootstrap().getType() == Platform.Type.VELOCITY) {
                this.plugin.getLogger().warn("The UUID the player is connecting with now is Mojang-assigned (type 4). This implies that Velocity's IP-Forwarding has not been setup correctly on one (or more) of the backend servers.");
            } else {
                this.plugin.getLogger().warn("The UUID the player is connecting with now is Mojang-assigned (type 4). This implies that one of the other servers in your network is not authenticating correctly.");
                this.plugin.getLogger().warn("If you're using BungeeCord/Velocity, please ensure that IP-Forwarding is setup correctly on all of your backend servers!");
            }
        } else {
            this.plugin.getLogger().warn("The UUID the player is connecting with now is NOT Mojang-assigned (type " + uniqueId.version() + "). This implies that THIS server is not authenticating correctly, but one (or more) of the other servers/proxies in the network are.");
            this.plugin.getLogger().warn("If you're using BungeeCord/Velocity, please ensure that IP-Forwarding is setup correctly on all of your backend servers!");
        }

        this.plugin.getLogger().warn("See here for more info: https://github.com/lucko/LuckPerms/wiki/Network-Installation#pre-setup");
    }

    User user = this.plugin.getStorage().loadUser(uniqueId, username).join();
    if (user == null) {
        throw new NullPointerException("User is null");
    }

    final long time = System.currentTimeMillis() - startTime;
    if (time >= 1000) {
        this.plugin.getLogger().warn("Processing login for " + username + " took " + time + "ms.");
    }

    return user;
}
 
Example 14
Source File: UUIDUtils.java    From usergrid with Apache License 2.0 4 votes vote down vote up
public static boolean isTimeBased( UUID uuid ) {
    if ( uuid == null ) {
        return false;
    }
    return uuid.version() == 1;
}
 
Example 15
Source File: UuidUtils.java    From gridgo with MIT License 4 votes vote down vote up
public static boolean isTimeBaseUUID(@NonNull UUID uuid) {
    return uuid.version() == 1;
}
 
Example 16
Source File: UuidUtil.java    From uuid-creator with MIT License 4 votes vote down vote up
private static boolean isVersion(UUID uuid, UuidVersion version) {
	if (uuid == null) {
		throw new InvalidUuidException("Null UUID has no version");
	}
	return isRfc4122(uuid) && (uuid.version() == version.getValue());
}
 
Example 17
Source File: UUIDUtils.java    From usergrid with Apache License 2.0 4 votes vote down vote up
public static boolean isTimeBased( UUID uuid ) {
    if ( uuid == null ) {
        return false;
    }
    return uuid.version() == 1;
}
 
Example 18
Source File: UUIDGen.java    From stratio-cassandra with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a milliseconds-since-epoch value for a type-1 UUID.
 *
 * @param uuid a type-1 (time-based) UUID
 * @return the number of milliseconds since the unix epoch
 * @throws IllegalArgumentException if the UUID is not version 1
 */
public static long getAdjustedTimestamp(UUID uuid)
{
    if (uuid.version() != 1)
        throw new IllegalArgumentException("incompatible with uuid version: "+uuid.version());
    return (uuid.timestamp() / 10000) + START_EPOCH;
}
 
Example 19
Source File: UUIDGen.java    From sfs with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a milliseconds-since-epoch value for a type-1 UUID.
 *
 * @param uuid a type-1 (time-based) UUID
 * @return the number of milliseconds since the unix epoch
 * @throws IllegalArgumentException if the UUID is not version 1
 */
public static long getAdjustedTimestamp(UUID uuid) {
    if (uuid.version() != 1)
        throw new IllegalArgumentException("incompatible with uuid version: " + uuid.version());
    return (uuid.timestamp() / 10000) + START_EPOCH;
}
 
Example 20
Source File: UUIDGen.java    From hawkular-metrics with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a milliseconds-since-epoch value for a type-1 UUID.
 *
 * @param uuid a type-1 (time-based) UUID
 * @return the number of milliseconds since the unix epoch
 * @throws IllegalArgumentException if the UUID is not version 1
 */
public static long getAdjustedTimestamp(UUID uuid) {
    if (uuid.version() != 1)
        throw new IllegalArgumentException("incompatible with uuid version: " + uuid.version());
    return (uuid.timestamp() / 10000) + START_EPOCH;
}