### JdbcIndexedSessionRepository Configuration Example Source: https://docs.spring.io/spring-session/reference/4.0-SNAPSHOT/api/java/org/springframework/session/jdbc/JdbcIndexedSessionRepository.html An example demonstrating how to instantiate and configure JdbcIndexedSessionRepository using JdbcTemplate and TransactionTemplate. ```APIDOC ## JdbcIndexedSessionRepository Configuration ### Description This section provides an example of how to create and configure an instance of `JdbcIndexedSessionRepository`. ### Usage Instantiate `JdbcTemplate` and `TransactionTemplate`, configure them, and then pass them to the `JdbcIndexedSessionRepository` constructor. ### Code Example ```java JdbcTemplate jdbcTemplate = new JdbcTemplate(); // ... configure jdbcTemplate ... TransactionTemplate transactionTemplate = new TransactionTemplate(); // ... configure transactionTemplate ... JdbcIndexedSessionRepository sessionRepository = new JdbcIndexedSessionRepository(jdbcTemplate, transactionTemplate); ``` ### Notes Refer to the Spring Framework Reference Documentation for details on configuring `JdbcTemplate` and `TransactionTemplate`. ``` -------------------------------- ### Basic Spring Session Configuration Source: https://docs.spring.io/spring-session/docs/3.3.8-SNAPSHOT/api/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.html Example of how to enable Spring HttpSession and configure a basic SessionRepository using a ConcurrentHashMap. This is a common setup for in-memory session storage. ```java @Configuration @EnableSpringHttpSession public class SpringHttpSessionConfig { @Bean public MapSessionRepository sessionRepository() { return new MapSessionRepository(new ConcurrentHashMap<>()); } } ``` -------------------------------- ### Running the Security Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/java-security.html Execute this Gradle command to run the security sample application. ```bash $ ./gradlew :spring-session-sample-javaconfig-security:tomcatRun ``` -------------------------------- ### Example HTTP Request with Session ID Header Source: https://docs.spring.io/spring-session/docs/3.3.8-SNAPSHOT/api/org/springframework/session/web/http/HeaderHttpSessionIdResolver.html Clients should include the session ID in subsequent requests using the same header name configured by the server. This example demonstrates including the 'X-Auth-Token' header in a GET request. ```http GET /messages/ HTTP/1.1 Host: example.com X-Auth-Token: f81d4fae-7dec-11d0-a765-00a0c91e6bf6 ``` -------------------------------- ### Run boot-findbyusername Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/boot-findbyusername.html Execute the sample application to test session management by username. Ensure Redis 2.8+ is running on localhost with the default port. ```bash $ ./gradlew :spring-session-sample-boot-findbyusername:bootRun ``` -------------------------------- ### Run the httpsession-jdbc-boot Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/boot-jdbc.html Execute the Gradle command to build and run the sample application, which demonstrates Spring Session with JDBC and Spring Boot. ```bash $ ./gradlew :spring-session-sample-boot-jdbc:bootRun ``` -------------------------------- ### Example HTTP Response with Session ID Header Source: https://docs.spring.io/spring-session/docs/3.3.8-SNAPSHOT/api/org/springframework/session/web/http/HeaderHttpSessionIdResolver.html When a session is created, the server includes a response header with the specified name and the session ID value. This example shows the 'X-Auth-Token' header. ```http HTTP/1.1 200 OK X-Auth-Token: f81d4fae-7dec-11d0-a765-00a0c91e6bf6 ``` -------------------------------- ### Running the httpsession-xml Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/xml-redis.html Command to run the httpsession-xml sample application using Gradle. Ensure Redis is running locally. ```bash $ ./gradlew :spring-session-sample-xml-redis:tomcatRun ``` -------------------------------- ### Run REST Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/java-rest.html Run the sample application using the provided Gradle command. Ensure Redis is running on localhost. ```bash $ ./gradlew :spring-session-sample-javaconfig-rest:tomcatRun ``` -------------------------------- ### Example of Expiring a Session Cookie in HTTP Response Source: https://docs.spring.io/spring-session/reference/3.4/api/java/org/springframework/session/web/http/CookieHttpSessionIdResolver.html This example shows the HTTP response header for expiring a session cookie. The Expires attribute is set to a past date to instruct the client to remove the cookie. ```http HTTP/1.1 200 OK Set-Cookie: SESSION=f81d4fae-7dec-11d0-a765-00a0c91e6bf6; Expires=Thur, 1 Jan 1970 00:00:00 GMT; Secure; HttpOnly ``` -------------------------------- ### Run Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/boot-webflux-custom-cookie.html Execute the Gradle task to run the webflux-custom-cookie sample application. Ensure Redis is running locally. ```bash $ ./gradlew :spring-session-sample-boot-webflux-custom-cookie:bootRun ``` -------------------------------- ### getResponse() Source: https://docs.spring.io/spring-session/reference/api/java/index-all.html Gets the response to write to. ```APIDOC ## getResponse() ### Description Gets the response to write to. ### Method Not applicable (Java method) ### Endpoint Not applicable (Java method) ### Parameters None ### Request Example Not applicable (Java method) ### Response Not applicable (Java method) ``` -------------------------------- ### Run MongoDB Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/boot-mongo.html Execute this Gradle command to build and run the sample application that demonstrates Spring Session with MongoDB. ```bash $ ./gradlew :samples:mongo:bootRun ``` -------------------------------- ### getRequest() Source: https://docs.spring.io/spring-session/reference/api/java/index-all.html Gets the request to use. ```APIDOC ## getRequest() ### Description Gets the request to use. ### Method Not applicable (Java method) ### Endpoint Not applicable (Java method) ### Parameters None ### Request Example Not applicable (Java method) ### Response Not applicable (Java method) ``` -------------------------------- ### Run WebSocket Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/boot-websocket.html Command to run the 'websocket' sample application, which demonstrates Spring Session integration with WebSockets. ```bash $ ./gradlew :spring-session-sample-boot-websocket:bootRun ``` -------------------------------- ### getTypeId() Source: https://docs.spring.io/spring-session/reference/3.4/api/java/index-all.html Gets the type identifier. ```APIDOC ## getTypeId() ### Description Gets the type identifier. ### Method N/A (Method documentation) ### Endpoint N/A (Method documentation) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Run the HttpSession JDBC Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/java-jdbc.html Invoke this command to run the sample application using Gradle. Ensure you have obtained the source code first. ```bash $ ./gradlew :spring-session-sample-javaconfig-jdbc:tomcatRun ``` -------------------------------- ### getSessionDispatcherTypes Source: https://docs.spring.io/spring-session/reference/3.4/api/java/org/springframework/session/web/context/AbstractHttpSessionApplicationInitializer.html Get the `DispatcherType` for the springSessionRepositoryFilter. ```APIDOC ## Method Details ### getSessionDispatcherTypes `protected EnumSet getSessionDispatcherTypes()` Get the `DispatcherType` for the springSessionRepositoryFilter. Returns: the `DispatcherType` for the filter ``` -------------------------------- ### Running the WebSocket Sample Application Source: https://docs.spring.io/spring-session/reference/2.7/guides/boot-websocket.html Command to run the Spring Session WebSocket sample application using Gradle. ```bash $ ./gradlew :spring-session-sample-boot-websocket:bootRun ``` -------------------------------- ### Example of Setting a Session Cookie in HTTP Response Source: https://docs.spring.io/spring-session/reference/3.4/api/java/org/springframework/session/web/http/CookieHttpSessionIdResolver.html This example shows the HTTP response header for setting a session cookie. The cookie is marked as session cookie, uses the context path for the path, and is marked as HTTPOnly and Secure. ```http HTTP/1.1 200 OK Set-Cookie: SESSION=f81d4fae-7dec-11d0-a765-00a0c91e6bf6; Path=/context-root; Secure; HttpOnly ``` -------------------------------- ### FlushMode.IMMEDIATE Source: https://docs.spring.io/spring-session/reference/3.4/api/java/org/springframework/session/FlushMode.html Writes to session store as soon as possible. For example `SessionRepository.createSession()` will write the session to session store. Another example is that setting an attribute using `Session.setAttribute(String, Object)` will also write to session store immediately. ```APIDOC ### IMMEDIATE public static final FlushMode IMMEDIATE Writes to session store as soon as possible. For example `SessionRepository.createSession()` will write the session to session store. Another example is that setting an attribute using `Session.setAttribute(String, Object)` will also write to session store immediately. ``` -------------------------------- ### Run Spring Boot Redis Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/boot-redis.html Execute this Gradle command to run the sample application demonstrating Spring Session with Redis. ```bash $ ./gradlew :spring-session-sample-boot-redis:bootRun ``` -------------------------------- ### getSessionRepositoryCustomizers() Source: https://docs.spring.io/spring-session/reference/3.4/api/java/index-all.html Gets the session repository customizers. ```APIDOC ## getSessionRepositoryCustomizers() ### Description Gets the session repository customizers. ### Method N/A (Method documentation) ### Endpoint N/A (Method documentation) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Run HttpSession Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/java-redis.html Execute this Gradle command to run the tomcat server for the httpsession sample application. Ensure Redis is running locally on the default port. ```bash $ ./gradlew :spring-session-sample-javaconfig-redis:tomcatRun ``` -------------------------------- ### getSessionIdGenerator() Source: https://docs.spring.io/spring-session/reference/3.4/api/java/index-all.html Gets the session ID generator. ```APIDOC ## getSessionIdGenerator() ### Description Gets the session ID generator. ### Method N/A (Method documentation) ### Endpoint N/A (Method documentation) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Run Hazelcast Spring Session Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/java-hazelcast.html Command to build and run the Hazelcast Spring Session sample application using Gradle. ```bash $ ./gradlew :spring-session-sample-javaconfig-hazelcast:tomcatRun ``` -------------------------------- ### HazelcastIndexedSessionRepository Configuration Example Source: https://docs.spring.io/spring-session/docs/3.3.8-SNAPSHOT/api/org/springframework/session/hazelcast/HazelcastIndexedSessionRepository.html Demonstrates how to create and configure a HazelcastIndexedSessionRepository instance, including setting up Hazelcast and configuring the session map for indexed lookups. ```APIDOC ## HazelcastIndexedSessionRepository Configuration ### Description This section provides examples for configuring and initializing `HazelcastIndexedSessionRepository`. ### Usage To use `HazelcastIndexedSessionRepository`, you need a Hazelcast instance. The repository can be configured to support indexed session lookups, such as by principal name, by adding specific attribute and index configurations to the Hazelcast `IMap`. ### Example 1: Basic Initialization ```java import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository; import com.hazelcast.config.Config; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; // ... Config config = new Config(); // ... configure Hazelcast ... HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config); HazelcastIndexedSessionRepository sessionRepository = new HazelcastIndexedSessionRepository(hazelcastInstance); ``` ### Example 2: Configuring for Indexed Lookups (Principal Name) This example shows how to configure the Hazelcast `IMap` to enable searching sessions by principal name. ```java import org.springframework.session.hazelcast.HazelcastIndexedSessionRepository; import com.hazelcast.config.AttributeConfig; import com.hazelcast.config.Config; import com.hazelcast.config.IndexConfig; import com.hazelcast.config.IndexType; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; // ... AttributeConfig attributeConfig = new AttributeConfig() .setName(HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) .setExtractorClassName("com.example.PrincipalNameExtractor.class"); // Replace with your actual extractor Config config = new Config(); config.getMapConfig(HazelcastIndexedSessionRepository.DEFAULT_SESSION_MAP_NAME) .addAttributeConfig(attributeConfig) .addIndexConfig(new IndexConfig( IndexType.HASH, HazelcastIndexedSessionRepository.PRINCIPAL_NAME_ATTRIBUTE)); Hazelcast.newHazelcastInstance(config); // Then initialize the repository with the configured Hazelcast instance HazelcastIndexedSessionRepository sessionRepository = new HazelcastIndexedSessionRepository(hazelcastInstance); ``` ### Key Fields - **`DEFAULT_SESSION_MAP_NAME`** (String): The default name of the `IMap` used by Spring Session to store sessions. - **`PRINCIPAL_NAME_ATTRIBUTE`** (String): The custom attribute name used for the principal's name when indexing sessions. ``` -------------------------------- ### Session.getCreationTime() Source: https://docs.spring.io/spring-session/reference/3.4/api/java/index-all.html Gets the time when this session was created. ```APIDOC ## Session.getCreationTime() ### Description Retrieves the timestamp indicating when the session was initially created. ### Method N/A (This is a getter method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response - **return value** (long) - The creation time of the session as a timestamp. ``` -------------------------------- ### Run httpsession-jdbc-xml Sample Application Source: https://docs.spring.io/spring-session/reference/2.6/guides/xml-jdbc.html Execute the Gradle command to run the tomcat server for the httpsession-jdbc-xml sample application. Access the application at localhost:8080 after it starts. ```bash $ ./gradlew :spring-session-sample-xml-jdbc:tomcatRun ``` -------------------------------- ### getSessionRedisOperations Source: https://docs.spring.io/spring-session/reference/3.4/api/java/org/springframework/session/data/redis/ReactiveRedisIndexedSessionRepository.html Gets the session Redis operations. ```APIDOC ## getSessionRedisOperations ### Description Gets the session Redis operations. ### Method `org.springframework.data.redis.core.ReactiveRedisOperations getSessionRedisOperations()` ``` -------------------------------- ### Constructor Source: https://docs.spring.io/spring-session/docs/3.3.8-SNAPSHOT/api/org/springframework/session/data/redis/config/annotation/web/http/AbstractRedisHttpSessionConfiguration.html Initializes the AbstractRedisHttpSessionConfiguration. ```APIDOC ## Constructor Summary Constructors Constructor Description `AbstractRedisHttpSessionConfiguration()` ``` -------------------------------- ### getSessionExpiredChannel Source: https://docs.spring.io/spring-session/reference/3.4/api/java/org/springframework/session/data/redis/ReactiveRedisIndexedSessionRepository.html Gets the session expired channel. ```APIDOC ## getSessionExpiredChannel ### Description Gets the session expired channel. ### Method `String getSessionExpiredChannel()` ``` -------------------------------- ### onStartup(ServletContext) Source: https://docs.spring.io/spring-session/docs/3.3.8-SNAPSHOT/api/index-all.html Initializes the HTTP session application context. ```APIDOC ## onStartup(ServletContext) ### Description Callback method invoked when the web application startup is complete, used for initializing the HTTP session application context. ### Method `onStartup` ### Class `org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer` ``` -------------------------------- ### getSessionDeletedChannel Source: https://docs.spring.io/spring-session/reference/3.4/api/java/org/springframework/session/data/redis/ReactiveRedisIndexedSessionRepository.html Gets the session deleted channel. ```APIDOC ## getSessionDeletedChannel ### Description Gets the session deleted channel. ### Method `String getSessionDeletedChannel()` ``` -------------------------------- ### AbstractRedisWebSessionConfiguration getRedisConnectionFactory Method Source: https://docs.spring.io/spring-session/docs/3.3.8-SNAPSHOT/api/org/springframework/session/data/redis/config/annotation/web/server/AbstractRedisWebSessionConfiguration.html Gets the ReactiveRedisConnectionFactory. ```java public org.springframework.data.redis.connection.ReactiveRedisConnectionFactory getRedisConnectionFactory() ``` -------------------------------- ### Constructor Details Source: https://docs.spring.io/spring-session/docs/3.3.8-SNAPSHOT/api/org/springframework/session/web/context/AbstractHttpSessionApplicationInitializer.html Details about the constructors for AbstractHttpSessionApplicationInitializer. ```APIDOC ## protected AbstractHttpSessionApplicationInitializer() ### Description Creates a new instance that assumes the Spring Session configuration is loaded by some other means than this class. For example, a user might create a `ContextLoaderListener` using a subclass of `AbstractContextLoaderInitializer`. ### See Also * `ContextLoaderListener` ## protected AbstractHttpSessionApplicationInitializer(Class... configurationClasses) ### Description Creates a new instance that will instantiate the `ContextLoaderListener` with the specified classes. ### Parameters * `configurationClasses` (Class...) - `@Configuration` classes that will be used to configure the context ``` -------------------------------- ### getSessionRepositoryCustomizers Source: https://docs.spring.io/spring-session/docs/3.3.8-SNAPSHOT/api/org/springframework/session/data/redis/config/annotation/web/http/AbstractRedisHttpSessionConfiguration.html Gets a list of customizers for the SessionRepository. ```APIDOC ## Method Summary Instance Methods Modifier and Type Method Description `protected List>` `getSessionRepositoryCustomizers()` ``` -------------------------------- ### RedisIndexedSessionRepository.getSessionExpiredChannel() Source: https://docs.spring.io/spring-session/reference/4.0-SNAPSHOT/api/java/index-all.html Gets the name of the channel that SessionExpiredEvents are published to. ```APIDOC ## RedisIndexedSessionRepository.getSessionExpiredChannel() ### Description Gets the name of the channel that `SessionExpiredEvent`s are published to. ### Method N/A (Class Method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response - **channelName** (String) - The name of the session expired channel. ``` -------------------------------- ### Basic Session Usage Source: https://docs.spring.io/spring-session/reference/2.6/api.html Demonstrates the typical lifecycle of a Session, including creation, attribute setting, saving, and retrieval. ```java public class RepositoryDemo { private SessionRepository repository; public void demo() { S toSave = this.repository.createSession(); User rwinch = new User("rwinch"); toSave.setAttribute(ATTR_USER, rwinch); this.repository.save(toSave); S session = this.repository.findById(toSave.getId()); User user = session.getAttribute(ATTR_USER); assertThat(user).isEqualTo(rwinch); } // ... setter methods ... } ``` -------------------------------- ### AbstractHttpSessionApplicationInitializer(Class... configurationClasses) Source: https://docs.spring.io/spring-session/reference/3.4/api/java/org/springframework/session/web/context/AbstractHttpSessionApplicationInitializer.html Creates a new instance that will instantiate the `ContextLoaderListener` with the specified classes. ```APIDOC ## Constructor Details ### AbstractHttpSessionApplicationInitializer `protected AbstractHttpSessionApplicationInitializer(Class... configurationClasses)` Creates a new instance that will instantiate the `ContextLoaderListener` with the specified classes. Parameters: * `configurationClasses` - `@Configuration` classes that will be used to configure the context ``` -------------------------------- ### RedisIndexedSessionRepository.getSessionDeletedChannel() Source: https://docs.spring.io/spring-session/reference/4.0-SNAPSHOT/api/java/index-all.html Gets the name of the channel that SessionDeletedEvents are published to. ```APIDOC ## RedisIndexedSessionRepository.getSessionDeletedChannel() ### Description Gets the name of the channel that `SessionDeletedEvent`s are published to. ### Method N/A (Class Method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response - **channelName** (String) - The name of the session deleted channel. ``` -------------------------------- ### RedisIndexedSessionRepository.getSessionCreatedChannelPrefix() Source: https://docs.spring.io/spring-session/reference/4.0-SNAPSHOT/api/java/index-all.html Gets the prefix for the channel that SessionCreatedEvents are published to. ```APIDOC ## RedisIndexedSessionRepository.getSessionCreatedChannelPrefix() ### Description Gets the prefix for the channel that `SessionCreatedEvent`s are published to. ### Method N/A (Class Method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response - **channelPrefix** (String) - The prefix for the session created channel. ``` -------------------------------- ### Create Session and Verify in Redis Source: https://docs.spring.io/spring-session/reference/2.7/guides/java-rest.html Create a session by authenticating and then use redis-cli to view the session data stored in Redis. This demonstrates Spring Session's persistence mechanism. ```bash $ curl -v http://localhost:8080/ -u user:password Copied! ``` ```text HTTP/1.1 200 OK ... X-Auth-Token: 7e8383a4-082c-4ffe-a4bc-c40fd3363c5e {"username":"user"} ``` -------------------------------- ### Session.getAttributeNames() Source: https://docs.spring.io/spring-session/reference/3.4/api/java/index-all.html Gets the attribute names that have a value associated with it. ```APIDOC ## Session.getAttributeNames() ### Description Retrieves a collection of all attribute names currently stored within the session. ### Method N/A (This is a getter method) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response - **return value** (Collection) - A collection of attribute names. ``` -------------------------------- ### AbstractHttpSessionApplicationInitializer Constructors Source: https://docs.spring.io/spring-session/docs/3.3.8-SNAPSHOT/api/org/springframework/session/web/context/AbstractHttpSessionApplicationInitializer.html Provides details on how to instantiate AbstractHttpSessionApplicationInitializer, either assuming configuration is handled elsewhere or by specifying configuration classes for ContextLoaderListener. ```APIDOC ## Constructors ### `AbstractHttpSessionApplicationInitializer()` Creates a new instance that assumes the Spring Session configuration is loaded by some other means than this class. ### `AbstractHttpSessionApplicationInitializer(Class... configurationClasses)` Creates a new instance that will instantiate the `ContextLoaderListener` with the specified classes. ``` -------------------------------- ### getFlushMode Source: https://docs.spring.io/spring-session/reference/3.4/api/java/org/springframework/session/data/redis/config/annotation/web/http/AbstractRedisHttpSessionConfiguration.html Gets the flush mode for Redis operations. ```APIDOC ## Method: getFlushMode ### Signature protected FlushMode getFlushMode() ### Description Gets the flush mode for Redis operations. ``` -------------------------------- ### Example WebSocket Configuration with Spring Session Source: https://docs.spring.io/spring-session/docs/3.3.8-SNAPSHOT/api/org/springframework/session/web/socket/config/annotation/AbstractSessionWebSocketMessageBrokerConfigurer.html Demonstrates how to extend AbstractSessionWebSocketMessageBrokerConfigurer to enable STOMP endpoints and configure the message broker with SockJS support. ```java @Configuration @EnableScheduling @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractSessionWebSocketMessageBrokerConfigurer { @Override protected void configureStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/messages") .withSockJS(); } @Override public void configureMessageBroker(MessageBrokerRegistry registry) { registry.enableSimpleBroker("/queue/", "/topic/"); registry.setApplicationDestinationPrefixes("/app"); } } ``` -------------------------------- ### getSessionDeletedChannel Source: https://docs.spring.io/spring-session/reference/3.4/api/java/org/springframework/session/data/redis/RedisIndexedSessionRepository.html Gets the name of the channel that SessionDeletedEvents are published to. ```APIDOC ## getSessionDeletedChannel ### Description Gets the name of the channel that `SessionDeletedEvent`s are published to. ### Method `String getSessionDeletedChannel()` ```