Skip to content
Permalink
Browse files

Use UUID directly for generating session IDs

  • Loading branch information...
ldaley committed Apr 23, 2019
1 parent 259717a commit f2b63eb82dd71194319fd3945f5edf29b8f3a42d
@@ -194,6 +194,7 @@ SessionStore sessionStoreAdapter(@Named(LOCAL_MEMORY_SESSION_CACHE_BINDING_NAME)
}

@Provides
@Singleton
SessionIdGenerator sessionIdGenerator() {
return new DefaultSessionIdGenerator();
}
@@ -16,18 +16,17 @@

package ratpack.session.internal;

import com.google.inject.Singleton;
import io.netty.util.AsciiString;
import ratpack.session.SessionIdGenerator;

import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

@Singleton
public class DefaultSessionIdGenerator implements SessionIdGenerator {

public AsciiString generateSessionId() {
ThreadLocalRandom random = ThreadLocalRandom.current();
UUID uuid = new UUID(random.nextLong(), random.nextLong());
return AsciiString.of(uuid.toString());
return AsciiString.cached(UUID.randomUUID().toString());

This comment has been minimized.

Copy link
@erdi

erdi Apr 23, 2019

Member

You are aware that UUID.randomUUID() is potentially blocking, right? At least according to this and this.

This comment has been minimized.

Copy link
@ldaley

ldaley Apr 23, 2019

Author Member

It's not on Java 8+ for most environments. JDK 8 removed synchronized and now /dev/urandom (non blocking is used).

This comment has been minimized.

Copy link
@erdi

erdi Apr 23, 2019

Member

Oh, right. Thanks for the explanation.

}

}

0 comments on commit f2b63eb

Please sign in to comment.
You can’t perform that action at this time.