Skip to content

Commit

Permalink
Use UUID directly for generating session IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
ldaley committed Apr 23, 2019
1 parent 9d3a717 commit 7b2f09e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ SessionStore sessionStoreAdapter(@Named(LOCAL_MEMORY_SESSION_CACHE_BINDING_NAME)
}

@Provides
@Singleton
SessionIdGenerator sessionIdGenerator() {
return new DefaultSessionIdGenerator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}

0 comments on commit 7b2f09e

Please sign in to comment.