/** * @return app suffixed by a positive random long */ public static String createFileSystemContextId() { return "app-" + Math.abs(sRandom.nextLong()); }
/** * @return a random long which is guaranteed to be non negative (zero is allowed) */ public static synchronized long getRandomNonNegativeLong() { return Math.abs(sRandom.nextLong()); }
@Override public void run() { SecureRandom random = new SecureRandom(); // Get the real random seed from /dev/random queue.add(random.nextLong()); } };
private String createKey() { SecureRandom random = new SecureRandom(); return Long.toString(random.nextLong()); }
private String generateRandomPassword() { if (random == null) { try { random = SecureRandom.getInstance("SHA1PRNG"); } catch (NoSuchAlgorithmException e) { // Shouldn't happen... throw new RuntimeException("Failed find SHA1PRNG algorithm!"); } } return Long.toString(random.nextLong()); } }
/** * Get a cryptographically secure pseudo random long value. * * @return the random long value */ public static long secureRandomLong() { return getSecureRandom().nextLong(); }
/** * Creates and returns a HS2 cookie token. * @param clientUserName Client User name. * @return An unsigned cookie token generated from input parameters. * The final cookie generated is of the following format : * cu=<username>&rn=<randomNumber>&s=<cookieSignature> */ public static String createCookieToken(String clientUserName) { StringBuilder sb = new StringBuilder(); sb.append(COOKIE_CLIENT_USER_NAME).append(COOKIE_KEY_VALUE_SEPARATOR).append(clientUserName). append(COOKIE_ATTR_SEPARATOR); sb.append(COOKIE_CLIENT_RAND_NUMBER).append(COOKIE_KEY_VALUE_SEPARATOR). append((new SecureRandom()).nextLong()); return sb.toString(); }
private String generateUuid(final String propposedId, final String destinationGroupId, final String seed) { long msb = UUID.nameUUIDFromBytes((propposedId + destinationGroupId).getBytes(StandardCharsets.UTF_8)).getMostSignificantBits(); UUID uuid; if (StringUtils.isBlank(seed)) { long lsb = randomGenerator.nextLong(); // since msb is extracted from type-one UUID, the type-one semantics will be preserved uuid = new UUID(msb, lsb); } else { UUID seedId = UUID.nameUUIDFromBytes((propposedId + destinationGroupId + seed).getBytes(StandardCharsets.UTF_8)); uuid = new UUID(msb, seedId.getLeastSignificantBits()); } LOG.debug("Generating UUID {} from currentId={}, seed={}", uuid, propposedId, seed); return uuid.toString(); }
/** * */ public final static UUID generateId(long currentTime) { return generateId(currentTime, randomGenerator.nextLong(), true); }
/** * Get a cryptographically secure pseudo random long value. * * @return the random long value */ public static long secureRandomLong() { SecureRandom sr = getSecureRandom(); synchronized (sr) { return sr.nextLong(); } }
long secureInitializer = secureRandom.nextLong(); Random rand = new Random( secureInitializer + Runtime.getRuntime().freeMemory() ); synchronized ( rand )
@Override public File createTempDirectory(String prefix) throws IOException { // Identify and create our temp dir, if needed createPOIFilesDirectory(); // Generate a unique new filename // FIXME: Java 7+: use java.nio.Files#createTempDirectory final long n = random.nextLong(); File newDirectory = new File(dir, prefix + Long.toString(n)); createTempDirectory(newDirectory); // Set the delete on exit flag, unless explicitly disabled if (System.getProperty(KEEP_FILES) == null) { newDirectory.deleteOnExit(); } // All done return newDirectory; } }
long lsb = randomGenerator.nextLong(); if (isCopy) { uuid = ComponentIdGenerator.generateId(msb, lsb, true); // will increment msb if necessary
/** * Generate schema class. * * @param schema the schema * @param uniqueSchemas the unique schemas * @return the list * @throws IOException Signals that an I/O exception has occurred. */ public static List<JavaDynamicBean> generateSchemaSources( Schema schema, Map<String, Schema> uniqueSchemas) throws IOException { SpecificCompiler compiler = new SpecificCompiler(schema); compiler.setStringType(StringType.String); compiler.setFieldVisibility(FieldVisibility.PRIVATE); File tmpdir = new File(System.getProperty("java.io.tmpdir")); long value = RANDOM.nextLong(); if (value == Long.MIN_VALUE) { // corner case value = 0; } else { value = Math.abs(value); } File tmpOutputDir = new File(tmpdir, "tmp-gen-" + Long.toString(value)); tmpOutputDir.mkdirs(); compiler.compileToDestination(null, tmpOutputDir); List<JavaDynamicBean> sources = getJavaSources(tmpOutputDir, uniqueSchemas); tmpOutputDir.delete(); return sources; }
@Test public void testLogToFile() throws Exception { final Logger logger = this.ctx.getLogger(FILE_LOGGER_NAME); final long random = this.random.nextLong(); logger.debug("This is test message number {}", random); int count = 0; String line = Strings.EMPTY; try (final BufferedReader in = new BufferedReader(new FileReader(this.logFileName))) { while (in.ready()) { ++count; line = in.readLine(); } } assertThat(count, is(equalTo(1))); assertThat(line, endsWith(Long.toString(random))); }
@Test public void testLogToFile() throws Exception { final Logger logger = this.ctx.getLogger(FILE_LOGGER_NAME); final long random = this.random.nextLong(); logger.debug("This is test message number {}", random); int count = 0; String line = Strings.EMPTY; try (BufferedReader in = new BufferedReader(new FileReader(this.logFileName))) { while (in.ready()) { ++count; line = in.readLine(); } } assertThat(count, is(equalTo(1))); assertThat(line, endsWith(Long.toString(random))); }
public ThriftHttpServlet(TProcessor processor, TProtocolFactory protocolFactory, String authType, UserGroupInformation serviceUGI, UserGroupInformation httpUGI, HiveAuthFactory hiveAuthFactory) { super(processor, protocolFactory); this.authType = authType; this.serviceUGI = serviceUGI; this.httpUGI = httpUGI; this.hiveAuthFactory = hiveAuthFactory; this.isCookieAuthEnabled = hiveConf.getBoolVar( ConfVars.HIVE_SERVER2_THRIFT_HTTP_COOKIE_AUTH_ENABLED); // Initialize the cookie based authentication related variables. if (isCookieAuthEnabled) { // Generate the signer with secret. String secret = Long.toString(RAN.nextLong()); LOG.debug("Using the random number as the secret for cookie generation " + secret); this.signer = new CookieSigner(secret.getBytes()); this.cookieMaxAge = (int) hiveConf.getTimeVar( ConfVars.HIVE_SERVER2_THRIFT_HTTP_COOKIE_MAX_AGE, TimeUnit.SECONDS); this.cookieDomain = hiveConf.getVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_COOKIE_DOMAIN); this.cookiePath = hiveConf.getVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_COOKIE_PATH); // always send secure cookies for SSL mode this.isCookieSecure = hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_USE_SSL); this.isHttpOnlyCookie = hiveConf.getBoolVar( ConfVars.HIVE_SERVER2_THRIFT_HTTP_COOKIE_IS_HTTPONLY); } }
final Account account = context.getAuthenticated(Account.class); final Device device = account.getAuthenticatedDevice().get(); final String connectionId = String.valueOf(new SecureRandom().nextLong()); final Timer.Context timer = durationTimer.time(); final WebsocketAddress address = new WebsocketAddress(account.getNumber(), device.getId());
assertEquals(Arrays.asList(path("/A/B1/C1")), sorted(igfs.listPaths(path("/A/B1")))); String text = "Test long number: " + rnd.nextLong();