iluwatar / java-design-patterns

Design patterns implemented in Java
https://java-design-patterns.com
Other
88.32k stars 26.21k forks source link

Implement Server Session pattern #2848

Closed iluwatar closed 2 months ago

iluwatar commented 3 months ago

The Server Session pattern is a design pattern primarily used in web development to manage user sessions on the server-side. When a user interacts with a web application, a unique session is created and maintained on the server for that user. This session stores information about the user's state and interactions with the application, such as login credentials, user preferences, and shopping cart contents.

In this pattern, the server generates a unique session identifier (session ID) for each user session, which is typically sent to the client's browser as a cookie. The client's browser then sends this session ID back to the server with each subsequent request, allowing the server to retrieve the session data and maintain continuity in the user's experience.

Key aspects of the Server Session pattern include:

This pattern is essential for maintaining a stateful interaction between a stateless HTTP client and server, providing a personalized user experience across web requests.

Acceptance Criteria:

Ehspresso commented 3 months ago

I would like to take this issue on.

Ehspresso commented 3 months ago

Hi, I have implemented the pattern. I am not sure if it is suitable. Here is the explanation of my implementation, let me know if it is acceptable and what can be changed before I continue forward.

A server starts up. The user can create a session by visiting localhost:8080/login. This stores a sessionid and user number in a map. The user can logout by visiting localhost:8080/logout. Multiple users can login and have sessions simultaneously and their user number is automatically incremented. Multiple users can be simulated by visiting localhost:8080/login on multiple browsers, or firefox's container addon. Sessions expire after 1 minute by having a user's sessionid and user number deleted from the map If a user attempts to logout after their session expired then a message is shown saying the session is null.

iluwatar commented 3 months ago

Sounds good @Ehspresso