Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.MapSession;
import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository;
import org.springframework.session.hazelcast.HazelcastSessionSerializer;
import org.springframework.session.hazelcast.PrincipalNameExtractor;
import org.springframework.session.hazelcast.config.annotation.web.http.EnableHazelcastHttpSession;
import com.hazelcast.spring.session.HazelcastIndexedSessionRepository;
import com.hazelcast.spring.session.HazelcastSessionSerializer;
import com.hazelcast.spring.session.PrincipalNameExtractor;
import com.hazelcast.spring.session.config.annotation.web.http.EnableHazelcastHttpSession;

// tag::config[]
@EnableHazelcastHttpSession // <1>
Expand Down
35 changes: 22 additions & 13 deletions docs/modules/spring/pages/spring-session-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ It assumes that you have already applied Spring Security to your application.

NOTE: You can find the completed guide in the <<hazelcast-spring-security-sample, Hazelcast Spring Security sample application>>.

== Updating Dependencies
== Update dependencies

Before you use Spring Session, you must update your dependencies.

If you use Maven, you must add the following dependencies:

.pom.xml
Expand All @@ -28,15 +29,24 @@ If you use Maven, you must add the following dependencies:
<version>6.2.7</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-hazelcast</artifactId>
<version>3.2.5</version>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-spring-session</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
----

=== Note on migration from Spring Session Hazelcast 3.x

From version 4.0, the Hazelcast integration with Spring Session is owned by the Hazelcast team.

To migrate your application from using Spring Session Hazelcast 3.x to new Hazelcast Spring Session 4.x:

. Change GroupId to `com.hazelcast` and artifactId to `hazelcast-spring-session`.
. Update your code and change the packages. All Hazelcast-specific classes were moved from `org.springframework.session.hazelcast` to `com.hazelcast.spring.session`.

[[security-spring-configuration]]
== Spring Configuration
== Spring configuration

After adding the required dependencies, we can create our Spring configuration.
The Spring configuration is responsible for creating a servlet filter that replaces the `HttpSession` implementation with an implementation backed by Spring Session.
Expand All @@ -56,13 +66,12 @@ is not set, Hazelcast will serialize sessions using native Java serialization.
<4> We create a `HazelcastInstance` that connects Spring Session to Hazelcast.
By default, the application starts and connects to an embedded instance of Hazelcast.


NOTE: If `HazelcastSessionSerializer` is preferred, it needs to be configured for all Hazelcast cluster members before they start.
In a Hazelcast cluster, all members should use the same serialization method for sessions. Also, if Hazelcast Client/Server topology
is used, then both members and clients must use the same serialization method. The serializer can be registered via `ClientConfig`
with the same `SerializerConfiguration` of members.

== Servlet Container Initialization
== Servlet container initialization
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of https://en.wikipedia.org/wiki/Title_case? I think we use it in all other pages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@Rob-Hazelcast Rob-Hazelcast Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use sentence case for titles, per the Google style guide, but we haven't gone through and updated all the existing docs to match


The instructions detailed in the link:https://docs.spring.io/spring-session/reference/guides/java-security.html#security-spring-configuration[Spring docs] created a Spring bean named `springSessionRepositoryFilter` that implements `Filter`.
The `springSessionRepositoryFilter` bean is responsible for replacing the `HttpSession` with a custom implementation that is backed by Spring Session.
Expand Down Expand Up @@ -102,11 +111,11 @@ By extending `AbstractHttpSessionApplicationInitializer`, we ensure that the Spr
// end::config[]

[[hazelcast-spring-security-sample]]
== Hazelcast Spring Security Sample Application
== Hazelcast Spring Security sample application

This section describes how to work with the Hazelcast Spring Security sample application.

=== Running the Sample Application
=== Running the sample application

You can run the sample by obtaining the link:https://docs.hazelcast.com/hazelcast/latest/spring/spring-session-3.5.2.zip[source code] and invoking the following command:

Expand All @@ -120,7 +129,7 @@ However, if you want to connect to a standalone instance instead, you can config

You should now be able to access the application at http://localhost:8080/

=== Exploring the Security Sample Application
=== Exploring the Security Sample application

You can now try using the application.
To do so, enter the following to log in:
Expand All @@ -132,7 +141,7 @@ Now click the *Login* button.
You should now see a message indicating that your are logged in with the user entered previously.
The user's information is stored in Hazelcast rather than Tomcat's `HttpSession` implementation.

=== How Does It Work?
=== How does it work?

Instead of using Tomcat's `HttpSession`, we persist the values in Hazelcast.
Spring Session replaces the `HttpSession` with an implementation that is backed by a `Map` in Hazelcast.
Expand All @@ -141,12 +150,12 @@ When Spring Security's `SecurityContextPersistenceFilter` saves the `SecurityCon
When a new `HttpSession` is created, Spring Session creates a cookie named `SESSION` in your browser. That cookie contains the ID of your session.
You can view the cookies (with https://developers.google.com/web/tools/chrome-devtools/manage-data/cookies[Chrome] or https://developer.mozilla.org/en-US/docs/Tools/Storage_Inspector[Firefox]).

=== Interacting with the Data Store
=== Interacting with the data store

You can remove the session by using the xref:clients:java.adoc[Java client],
xref:clients:hazelcast-clients.adoc[one of the other clients], or xref:{page-latest-supported-mc}@management-center:getting-started:overview.adoc[Management Center].

==== Using the Console
==== Using the console

For example, to remove the session by using the Management Center console after connecting to your Hazelcast node, run the following commands:

Expand Down
Loading