Additional spring-session-data-geode setup.

This commit is contained in:
John Blum
2017-06-06 00:23:25 -07:00
parent 35e1ba929b
commit 767074d7b8
25 changed files with 881 additions and 872 deletions

28
build.gradle Normal file
View File

@@ -0,0 +1,28 @@
buildscript {
dependencies {
classpath 'io.spring.gradle:spring-build-conventions:0.0.1.RELEASE'
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
}
repositories {
maven { url 'https://repo.spring.io/libs-snapshot' }
maven { url 'https://repo.spring.io/plugins-snapshot' }
}
}
apply plugin: 'io.spring.convention.root'
group = 'org.springframework.session'
description = 'Spring Session'
ext.releaseBuild = version.endsWith('RELEASE')
ext.snapshotBuild = version.endsWith('SNAPSHOT')
ext.milestoneBuild = !(releaseBuild || snapshotBuild)
ext.BOM_GRADLE = "$rootDir/gradle/bom.gradle"
ext.IDE_GRADLE = "$rootDir/gradle/ide.gradle"
ext.JAVA_GRADLE = "$rootDir/gradle/java.gradle"
ext.MAVEN_GRADLE = "$rootDir/gradle/publish-maven.gradle"
ext.SAMPLE_GRADLE = "$rootDir/gradle/sample.gradle"
ext.TOMCAT_GRADLE = "$rootDir/gradle/tomcat.gradle"
ext.TOMCAT_6_GRADLE = "$rootDir/gradle/tomcat6.gradle"
ext.TOMCAT_7_GRADLE = "$rootDir/gradle/tomcat7.gradle"

View File

@@ -1,17 +1,16 @@
package build;
package build
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.bundling.Zip
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.TaskAction
public class GemFireServerPlugin implements Plugin<Project> {
class GemFireServerPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
project.tasks.create('gemFireServer', GemFireServerTask)
void apply(Project project) {
project.tasks.create('gemfireServer', GemFireServerTask)
project.tasks.integrationTest.doLast {
println 'Stopping GemFire Server...'
@@ -19,7 +18,7 @@ public class GemFireServerPlugin implements Plugin<Project> {
}
project.tasks.prepareAppServerForIntegrationTests {
dependsOn project.tasks.gemFireServer
dependsOn project.tasks.gemfireServer
doFirst {
project.gretty {
jvmArgs = ["-Dspring.session.data.gemfire.port=${project.tasks.gemFireServer.port}"]
@@ -35,6 +34,7 @@ public class GemFireServerPlugin implements Plugin<Project> {
}
static class GemFireServerTask extends DefaultTask {
def mainClassName = "sample.ServerConfig"
def process
def port
@@ -42,6 +42,7 @@ public class GemFireServerPlugin implements Plugin<Project> {
@TaskAction
def greet() {
port = availablePort()
println "Starting GemFire Server on port [$port]..."
@@ -57,7 +58,7 @@ public class GemFireServerPlugin implements Plugin<Project> {
//"-Dgemfire.log-level=config",
"-Dspring.session.data.gemfire.log-level=" + gemfireLogLevel,
"-Dspring.session.data.gemfire.port=${port}",
'sample.ServerConfig'
mainClassName
]
//println commandLine

View File

@@ -0,0 +1,163 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<!-- Suppressions -->
<module name="SuppressionFilter">
<property name="file" value="${configDir}/suppressions.xml"/>
</module>
<!-- Root Checks -->
<module name="RegexpHeader">
<property name="headerFile" value="${configDir}/header.txt"/>
<property name="fileExtensions" value="java"/>
</module>
<module name="NewlineAtEndOfFile">
<property name="lineSeparator" value="lf"/>
<property name="fileExtensions" value="java,xml"/>
</module>
<!-- TreeWalker Checks -->
<module name="TreeWalker">
<!-- Annotations -->
<module name="AnnotationUseStyle">
<property name="elementStyle" value="compact"/>
</module>
<module name="MissingOverride"/>
<module name="PackageAnnotation"/>
<module name="AnnotationLocation">
<property name="allowSamelineSingleParameterlessAnnotation" value="false" />
</module>
<!-- Block Checks -->
<module name="EmptyBlock">
<property name="option" value="text"/>
</module>
<module name="LeftCurly"/>
<module name="RightCurly">
<property name="option" value="alone"/>
</module>
<module name="NeedBraces"/>
<module name="AvoidNestedBlocks"/>
<!-- Class Design -->
<module name="FinalClass"/>
<module name="InterfaceIsType"/>
<module name="HideUtilityClassConstructor"/>
<module name="MutableException"/>
<module name="InnerTypeLast"/>
<module name="OneTopLevelClass"/>
<!-- Coding -->
<module name="CovariantEquals"/>
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="InnerAssignment"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>
<module name="StringLiteralEquality"/>
<module name="NestedForDepth">
<property name="max" value="3"/>
</module>
<module name="NestedIfDepth">
<property name="max" value="3"/>
</module>
<module name="NestedTryDepth">
<property name="max" value="3"/>
</module>
<module name="MultipleVariableDeclarations"/>
<module name="RequireThis">
<property name="checkMethods" value="false"/>
</module>
<module name="OneStatementPerLine"/>
<!-- Imports -->
<module name="AvoidStarImport"/>
<module name="AvoidStaticImport"/>
<module name="IllegalImport"/>
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="true"/>
</module>
<module name="ImportOrder">
<property name="groups" value="java,/^javax?\./,*,org.springframework"/>
<property name="ordered" value="true"/>
<property name="separated" value="true"/>
<property name="option" value="bottom"/>
<property name="sortStaticImportsAlphabetically" value="true"/>
</module>
<!-- Javadoc Comments -->
<module name="JavadocType">
<property name="scope" value="package"/>
<property name="authorFormat" value=".+\s.+"/>
</module>
<module name="JavadocMethod">
<property name="allowMissingJavadoc" value="true"/>
</module>
<module name="JavadocVariable">
<property name="scope" value="public"/>
</module>
<module name="JavadocStyle">
<property name="checkEmptyJavadoc" value="true"/>
</module>
<module name="NonEmptyAtclauseDescription"/>
<module name="JavadocTagContinuationIndentation">
<property name="offset" value="0"/>
</module>
<module name="AtclauseOrder">
<property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF"/>
<property name="tagOrder" value="@param, @author, @since, @see, @version, @serial, @deprecated"/>
</module>
<module name="AtclauseOrder">
<property name="target" value="METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
<property name="tagOrder" value="@param, @return, @throws, @since, @deprecated, @see"/>
</module>
<!-- Miscellaneous -->
<module name="CommentsIndentation"/>
<module name="UpperEll"/>
<module name="ArrayTypeStyle"/>
<module name="OuterTypeFilename"/>
<!-- Modifiers -->
<module name="RedundantModifier"/>
<!-- Regexp -->
<module name="RegexpSinglelineJava">
<property name="format" value="^\t* +\t*\S"/>
<property name="message" value="Line has leading space characters; indentation should be performed with tabs only."/>
<property name="ignoreComments" value="true"/>
</module>
<module name="RegexpSinglelineJava">
<property name="maximum" value="0"/>
<property name="format" value="org\.mockito\.Mockito\.(when|doThrow|doAnswer)"/>
<property name="message"
value="Please use BDDMockto imports."/>
<property name="ignoreComments" value="true"/>
</module>
<module name="RegexpSinglelineJava">
<property name="maximum" value="0"/>
<property name="format" value="org\.junit\.Assert\.assert"/>
<property name="message" value="Please use AssertJ imports."/>
<property name="ignoreComments" value="true"/>
</module>
<module name="Regexp">
<property name="format" value="[ \t]+$"/>
<property name="illegalPattern" value="true"/>
<property name="message" value="Trailing whitespace"/>
</module>
<!-- Whitespace -->
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter">
<property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS, UNARY_PLUS, ARRAY_DECLARATOR"/>
</module>
<module name="NoWhitespaceBefore"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>
</module>
</module>

View File

@@ -3,21 +3,21 @@ apply plugin: 'io.spring.convention.spring-test'
dependencies {
testCompile project(':spring-session-data-geode')
testCompile "junit:junit"
testCompile "org.mockito:mockito-core"
testCompile "org.springframework:spring-test"
testCompile "org.assertj:assertj-core"
testCompile "org.springframework.security:spring-security-test"
testCompile "org.springframework.security:spring-security-web"
testCompile "javax.servlet:javax.servlet-api"
testCompile slf4jDependencies
testCompile "junit:junit"
testCompile "org.assertj:assertj-core"
testCompile "org.mockito:mockito-core"
testCompile "edu.umd.cs.mtc:multithreadedtc"
testCompile "org.springframework:spring-test"
}
def versions = dependencyManagement.managedVersions
asciidoctor {
def ghTag = snapshotBuild ? 'master' : project.version
def ghUrl = "https://github.com/spring-projects/spring-session/tree/$ghTag"
attributes 'version-snapshot': snapshotBuild,
'version-milestone': milestoneBuild,
'version-release': releaseBuild,

View File

@@ -1,6 +1,5 @@
= Spring Session
Rob Winch, Vedran Pavić, Jakub Kubrynski
John Blum, Rob Winch
:doctype: book
:indexdoc-tests: {docs-test-dir}docs/IndexDocTests.java
:websocketdoc-test-dir: {docs-test-dir}docs/websocket/
@@ -8,37 +7,27 @@ Rob Winch, Vedran Pavić, Jakub Kubrynski
[[abstract]]
Spring Session provides an API and implementations for managing a user's session information.
_Spring Session_ provides an API and implementations for managing a user's session information.
[[introduction]]
== Introduction
Spring Session provides an API and implementations for managing a user's session information. It also provides transparent integration with:
_Spring Session_ provides an API and implementations for managing a user's session information.
It also provides transparent integration with:
* <<httpsession,HttpSession>> - allows replacing the HttpSession in an application container (e.g. Tomcat) neutral way.
* <<httpsession,HttpSession>> - allows replacing the HttpSession in an application container (i.e. Tomcat) neutral way.
Additional features include:
** **Clustered Sessions** - Spring Session makes it trivial to support <<httpsession-redis,clustered sessions>> without being tied to an application container specific solution.
** **Multiple Browser Sessions** - Spring Session supports <<httpsession-multi,managing multiple users' sessions>> in a single browser instance (i.e. multiple authenticated accounts similar to Google).
** **RESTful APIs** - Spring Session allows providing session ids in headers to work with <<httpsession-rest,RESTful APIs>>
** **Clustered Sessions** - _Spring Session_ makes it trivial to support <<httpsession-gemfire,clustered sessions>>
without being tied to an application container specific solution.
** **Multiple Browser Sessions** - _Spring Session_ supports <<httpsession-multi,managing multiple users' sessions>>
in a single browser instance (i.e. multiple authenticated accounts similar to Google).
** **RESTful APIs** - _Spring Session_ allows providing session ids in headers to work
with <<httpsession-rest,RESTful APIs>>
* <<websocket,WebSocket>> - provides the ability to keep the `HttpSession` alive when receiving WebSocket messages
== What's New in 1.3
Below are the highlights of what is new in Spring Session 1.3. You can find a complete list of what's new by referring to the changelogs of
https://github.com/spring-projects/spring-session/milestone/6?closed=1[1.3.0.M1],
https://github.com/spring-projects/spring-session/milestone/18?closed=1[1.3.0.M2],
https://github.com/spring-projects/spring-session/milestone/16?closed=1[1.3.0.RC1], and
https://github.com/spring-projects/spring-session/milestone/19?closed=1[1.3.0.RELEASE].
* First class support for http://docs.spring.io/spring-session/docs/1.3.0.RELEASE/reference/html5/#httpsession-hazelcast[Hazelcast]
* First class support for http://docs.spring.io/spring-session/docs/1.3.0.RELEASE/reference/html5/#spring-security-concurrent-sessions-how[Spring Security's concurrent session management]
* Added https://github.com/maseev/spring-session-orientdb[OrientDB Community Extension]
* https://github.com/spring-projects/spring-session/tree/1.3.0.RELEASE/samples/httpsession-redis-json[GenericJackson2JsonRedisSerializer sample] with Spring Security's new Jackson Support
* Guides now https://github.com/spring-projects/spring-session/pull/652[use Lettuce]
* `spring.session.cleanup.cron.expression` can be used to override the cleanup tasks cron expression
* Lots of performance improvements and bug fixes
[[samples]]
== Samples and Guides (Start Here)
@@ -48,22 +37,10 @@ If you are looking to get started with Spring Session, the best place to start i
|===
| Source | Description | Guide
| {gh-samples-url}boot/redis[HttpSession with Redis]
| Demonstrates how to use Spring Session to replace the `HttpSession` with Redis.
| link:guides/boot-redis.html[HttpSession with Redis Guide]
| {gh-samples-url}boot/gemfire[HttpSession with GemFire]
| Demonstrates how to use Spring Session to replace the `HttpSession` with GemFire using a Client/Server topology.
| link:guides/boot-gemfire.html[HttpSession with GemFire Guide]
| {gh-samples-url}boot/mongo[HttpSession with Mongo]
| Demonstrates how to use Spring Session to replace the `HttpSession` with Mongo.
| link:guides/boot-mongo.html[HttpSession with Mongo Guide]
| {gh-samples-url}boot/jdbc[HttpSession with JDBC]
| Demonstrates how to use Spring Session to replace the `HttpSession` with a relational database store.
| link:guides/boot-jdbc.html[HttpSession with JDBC Guide]
| {gh-samples-url}boot/findbyusername[Find by Username]
| Demonstrates how to use Spring Session to find sessions by username.
| link:guides/boot-findbyusername.html[Find by Username Guide]
@@ -78,14 +55,10 @@ If you are looking to get started with Spring Session, the best place to start i
|===
.Sample Applications using Spring Java based configuration
.Sample Applications using _Spring_ Java-based configuration
|===
| Source | Description | Guide
| {gh-samples-url}javaconfig/redis[HttpSession with Redis]
| Demonstrates how to use Spring Session to replace the `HttpSession` with Redis.
| link:guides/java-redis.html[HttpSession with Redis Guide]
| {gh-samples-url}javaconfig/gemfire-clientserver[HttpSession with GemFire (Client/Server)]
| Demonstrates how to use Spring Session to replace the `HttpSession` with GemFire using a Client/Server topology.
| link:guides/java-gemfire-clientserver.html[HttpSession with GemFire (Client/Server) Guide]
@@ -94,40 +67,12 @@ If you are looking to get started with Spring Session, the best place to start i
| Demonstrates how to use Spring Session to replace the `HttpSession` with GemFire using a P2P topology.
| link:guides/java-gemfire-p2p.html[HttpSession with GemFire (P2P) Guide]
| {gh-samples-url}javaconfig/jdbc[HttpSession with JDBC]
| Demonstrates how to use Spring Session to replace the `HttpSession` with a relational database store.
| link:guides/java-jdbc.html[HttpSession with JDBC Guide]
| {gh-samples-url}javaconfig/hazelcast[HttpSession with Hazelcast]
| Demonstrates how to use Spring Session to replace the `HttpSession` with Hazelcast.
| link:guides/java-hazelcast.html[HttpSession with Hazelcast Guide]
| {gh-samples-url}javaconfig/custom-cookie[Custom Cookie]
| Demonstrates how to use Spring Session and customize the cookie.
| link:guides/java-custom-cookie.html[Custom Cookie Guide]
| {gh-samples-url}javaconfig/security[Spring Security]
| Demonstrates how to use Spring Session with an existing Spring Security application.
| link:guides/java-security.html[Spring Security Guide]
| {gh-samples-url}javaconfig/rest[REST]
| Demonstrates how to use Spring Session in a REST application to support authenticating with a header.
| link:guides/java-rest.html[REST Guide]
| {gh-samples-url}javaconfig/users[Multiple Users]
| Demonstrates how to use Spring Session to manage multiple simultaneous browser sessions (i.e Google Accounts).
| link:guides/java-users.html[Multiple Users Guide]
|===
.Sample Applications using Spring XML based configuration
.Sample Applications using _Spring_ XML-based configuration
|===
| Source | Description | Guide
| {gh-samples-url}xml/redis[HttpSession with Redis]
| Demonstrates how to use Spring Session to replace the `HttpSession` with a Redis store.
| link:guides/xml-redis.html[HttpSession with Redis Guide]
| {gh-samples-url}xml/gemfire-clientserver[HttpSession with GemFire (Client/Server)]
| Demonstrates how to use Spring Session to replace the `HttpSession` with GemFire using a Client/Server topology.
| link:guides/xml-gemfire-clientserver.html[HttpSession with GemFire (Client/Server) Guide]
@@ -136,88 +81,49 @@ If you are looking to get started with Spring Session, the best place to start i
| Demonstrates how to use Spring Session to replace the `HttpSession` with GemFire using a P2P topology.
| link:guides/xml-gemfire-p2p.html[HttpSession with GemFire (P2P) Guide]
| {gh-samples-url}xml/jdbc[HttpSession with JDBC]
| Demonstrates how to use Spring Session to replace the `HttpSession` with a relational database store.
| link:guides/xml-jdbc.html[HttpSession with JDBC Guide]
|===
.Misc sample Applications
|===
| Source | Description | Guide
| {gh-samples-url}misc/grails3[Grails 3]
| Demonstrates how to use Spring Session with Grails 3.
| link:guides/grails3.html[Grails 3 Guide]
| {gh-samples-url}misc/hazelcast[Hazelcast]
| Demonstrates how to use Spring Session with Hazelcast in a Java EE application.
| TBD
|===
[[httpsession]]
== HttpSession Integration
Spring Session provides transparent integration with `HttpSession`.
This means that developers can switch the `HttpSession` implementation out with an implementation that is backed by Spring Session.
_Spring Session_ provides transparent integration with `HttpSession`. This means that developers
can switch the `HttpSession` implementation out with an implementation that is backed by _Spring Session_.
[[httpsession-why]]
=== Why Spring Session & HttpSession?
We have already mentioned that Spring Session provides transparent integration with `HttpSession`, but what benefits do we get out of this?
We have already mentioned that _Spring Session_ provides transparent integration with `HttpSession`,
but what benefits do we get out of this?
* **Clustered Sessions** - Spring Session makes it trivial to support <<httpsession-redis,clustered sessions>> without being tied to an application container specific solution.
* **Multiple Browser Sessions** - Spring Session supports <<httpsession-multi,managing multiple users' sessions>> in a single browser instance (i.e. multiple authenticated accounts similar to Google).
* **RESTful APIs** - Spring Session allows providing session ids in headers to work with <<httpsession-rest,RESTful APIs>>
[[httpsession-redis]]
=== HttpSession with Redis
Using Spring Session with `HttpSession` is enabled by adding a Servlet Filter before anything that uses the `HttpSession`.
You can choose from enabling this using either:
* <<httpsession-redis-jc,Java Based Configuration>>
* <<httpsession-redis-xml,XML Based Configuration>>
[[httpsession-redis-jc]]
==== Redis Java Based Configuration
This section describes how to use Redis to back `HttpSession` using Java based configuration.
NOTE: The <<samples, HttpSession Sample>> provides a working sample on how to integrate Spring Session and `HttpSession` using Java configuration.
You can read the basic steps for integration below, but you are encouraged to follow along with the detailed HttpSession Guide when integrating with your own application.
include::guides/java-redis.adoc[tags=config,leveloffset=+3]
[[httpsession-redis-xml]]
==== Redis XML Based Configuration
This section describes how to use Redis to back `HttpSession` using XML based configuration.
NOTE: The <<samples, HttpSession XML Sample>> provides a working sample on how to integrate Spring Session and `HttpSession` using XML configuration.
You can read the basic steps for integration below, but you are encouraged to follow along with the detailed HttpSession XML Guide when integrating with your own application.
include::guides/xml-redis.adoc[tags=config,leveloffset=+3]
* **Clustered Sessions** - _Spring Session_ makes it trivial to support <<httpsession-gemfire,clustered sessions>>
without being tied to an application container specific solution.
* **Multiple Browser Sessions** - _Spring Session_ supports <<httpsession-multi,managing multiple users' sessions>>
in a single browser instance (i.e. multiple authenticated accounts similar to Google).
* **RESTful APIs** - _Spring Session_ allows providing session ids in headers to work
with <<httpsession-rest,RESTful APIs>>
[[httpsession-gemfire]]
=== HttpSession with Pivotal GemFire
When https://pivotal.io/big-data/pivotal-gemfire[Pivotal GemFire] is used with Spring Session, a web application's
`HttpSession` can be replaced with a **clustered** implementation managed by GemFire and conveniently accessed
with Spring Session's API.
When https://pivotal.io/big-data/pivotal-gemfire[Pivotal GemFire] is used with _Spring Session_, a web application's
`HttpSession` can be replaced with a **clustered** implementation managed by _Pivotal GemFire_ and conveniently
accessed with _Spring Session's_ API.
The two most common topologies to manage Spring Sessions using GemFire include:
The two most common topologies to manage _Spring Sessions_ using _Pivotal GemFire_ include:
* <<httpsession-gemfire-clientserver,Client-Server>>
* <<httpsession-gemfire-p2p,Peer-To-Peer (P2P)>>
Additionally, GemFire supports site-to-site replication using http://gemfire.docs.pivotal.io/docs-gemfire/topologies_and_comm/multi_site_configuration/chapter_overview.html[WAN functionality].
The ability to configure and use GemFire's WAN support is independent of Spring Session, and is beyond the scope
of this document. More details on GemFire WAN functionality can be found http://docs.spring.io/spring-data-gemfire/docs/current/reference/html/#bootstrap:gateway[here].
Additionally, _Pivotal GemFire_ supports site-to-site replication using
http://gemfire.docs.pivotal.io/docs-gemfire/topologies_and_comm/multi_site_configuration/chapter_overview.html[WAN functionality].
The ability to configure and use _Pivotal GemFire's_ WAN support is independent of _Spring Session_,
and is beyond the scope of this document.
More details on _Pivotal GemFire_ WAN functionality can be found
http://docs.spring.io/spring-data-gemfire/docs/current/reference/html/#bootstrap:gateway[here].
[[httpsession-gemfire-clientserver]]
==== GemFire Client-Server
==== Pivotal GemFire Client-Server
The http://gemfire.docs.pivotal.io/docs-gemfire/latest/topologies_and_comm/cs_configuration/chapter_overview.html[Client-Server]
topology will probably be the more common configuration preference for users when using GemFire as a provider in
@@ -234,7 +140,7 @@ You can configure a Client-Server topology with either:
* <<httpsession-gemfire-clientserver-xml,XML-based Configuration>>
[[httpsession-gemfire-clientserver-java]]
===== GemFire Client-Server Java-based Configuration
===== Pivotal GemFire Client-Server Java-based Configuration
This section describes how to use GemFire's Client-Server topology to back an `HttpSession` with Java-based configuration.
@@ -246,7 +152,7 @@ Guide when integrating with your own application.
include::guides/java-gemfire-clientserver.adoc[tags=config,leveloffset=+3]
[[http-session-gemfire-clientserver-xml]]
===== GemFire Client-Server XML-based Configuration
===== Pivotal GemFire Client-Server XML-based Configuration
This section describes how to use GemFire's Client-Server topology to back an `HttpSession` with XML-based configuration.
@@ -258,7 +164,7 @@ using XML Guide when integrating with your own application.
include::guides/xml-gemfire-clientserver.adoc[tags=config,leveloffset=+3]
[[httpsession-gemfire-p2p]]
==== GemFire Peer-To-Peer (P2P)
==== Pivotal GemFire Peer-To-Peer (P2P)
Perhaps less common would be to configure the Spring Session application as a peer member in the GemFire cluster using
the http://gemfire.docs.pivotal.io/docs-gemfire/latest/topologies_and_comm/p2p_configuration/chapter_overview.html[Peer-To-Peer (P2P)] topology.
@@ -281,7 +187,7 @@ You can configure a Peer-To-Peer (P2P) topology with either:
* <<httpsession-gemfire-p2p-xml,XML-based Configuration>>
[[httpsession-gemfire-p2p-java]]
===== GemFire Peer-To-Peer (P2P) Java-based Configuration
===== Pivotal GemFire Peer-To-Peer (P2P) Java-based Configuration
This section describes how to use GemFire's Peer-To-Peer (P2P) topology to back an `HttpSession` using Java-based configuration.
@@ -293,7 +199,7 @@ when integrating with your own application.
include::guides/java-gemfire-p2p.adoc[tags=config,leveloffset=+3]
[[httpsession-gemfire-p2p-xml]]
===== GemFire Peer-To-Peer (P2P) XML-based Configuration
===== Pivotal GemFire Peer-To-Peer (P2P) XML-based Configuration
This section describes how to use GemFire's Peer-To-Peer (P2P) topology to back an `HttpSession` using XML-based configuration.
@@ -304,58 +210,6 @@ Guide when integrating with your own application.
include::guides/xml-gemfire-p2p.adoc[tags=config,leveloffset=+3]
[[httpsession-jdbc]]
=== HttpSession with JDBC
Using Spring Session with `HttpSession` is enabled by adding a Servlet Filter before anything that uses the `HttpSession`.
You can choose from enabling this using either:
* <<httpsession-jdbc-jc,Java Based Configuration>>
* <<httpsession-jdbc-xml,XML Based Configuration>>
* <<httpsession-jdbc-boot,Spring Boot Based Configuration>>
[[httpsession-jdbc-jc]]
==== JDBC Java Based Configuration
This section describes how to use a relational database to back `HttpSession` using Java based configuration.
NOTE: The <<samples, HttpSession JDBC Sample>> provides a working sample on how to integrate Spring Session and `HttpSession` using Java configuration.
You can read the basic steps for integration below, but you are encouraged to follow along with the detailed HttpSession JDBC Guide when integrating with your own application.
include::guides/java-jdbc.adoc[tags=config,leveloffset=+3]
[[httpsession-jdbc-xml]]
==== JDBC XML Based Configuration
This section describes how to use a relational database to back `HttpSession` using XML based configuration.
NOTE: The <<samples, HttpSession JDBC XML Sample>> provides a working sample on how to integrate Spring Session and `HttpSession` using XML configuration.
You can read the basic steps for integration below, but you are encouraged to follow along with the detailed HttpSession JDBC XML Guide when integrating with your own application.
include::guides/xml-jdbc.adoc[tags=config,leveloffset=+3]
[[httpsession-jdbc-boot]]
==== JDBC Spring Boot Based Configuration
This section describes how to use a relational database to back `HttpSession` when using Spring Boot.
NOTE: The <<samples, HttpSession JDBC Spring Boot Sample>> provides a working sample on how to integrate Spring Session and `HttpSession` using Spring Boot.
You can read the basic steps for integration below, but you are encouraged to follow along with the detailed HttpSession JDBC Spring Boot Guide when integrating with your own application.
include::guides/boot-jdbc.adoc[tags=config,leveloffset=+3]
[[httpsession-hazelcast]]
=== HttpSession with Hazelcast
Using Spring Session with `HttpSession` is enabled by adding a Servlet Filter before anything that uses the `HttpSession`.
This section describes how to use Hazelcast to back `HttpSession` using Java based configuration.
NOTE: The <<samples, Hazelcast Spring Sample>> provides a working sample on how to integrate Spring Session and `HttpSession` using Java configuration.
You can read the basic steps for integration below, but you are encouraged to follow along with the detailed Hazelcast Spring Guide when integrating with your own application.
include::guides/java-hazelcast.adoc[tags=config,leveloffset=+2]
[[httpsession-how]]
=== How HttpSession Integration Works
@@ -412,28 +266,6 @@ public class SessionRepositoryFilter implements Filter {
By passing in a custom `HttpServletRequest` implementation into the `FilterChain` we ensure that anything invoked after our `Filter` uses the custom `HttpSession` implementation.
This highlights why it is important that Spring Session's `SessionRepositoryFilter` must be placed before anything that interacts with the `HttpSession`.
[[httpsession-multi]]
=== Multiple HttpSessions in Single Browser
Spring Session has the ability to support multiple sessions in a single browser instance.
This provides the ability to support authenticating with multiple users in the same browser instance (i.e. Google Accounts).
NOTE: The <<samples,Manage Multiple Users Guide>> provides a complete working example of managing multiple users in the same browser instance.
You can follow the basic steps for integration below, but you are encouraged to follow along with the detailed Manage Multiple Users Guide when integrating with your own application.
include::guides/java-users.adoc[tags=how-does-it-work,leveloffset=+1]
[[httpsession-rest]]
=== HttpSession & RESTful APIs
Spring Session can work with RESTful APIs by allowing the session to be provided in a header.
NOTE: The <<samples, REST Sample>> provides a working sample on how to use Spring Session in a REST application to support authenticating with a header.
You can follow the basic steps for integration below, but you are encouraged to follow along with the detailed REST Guide when integrating with your own application.
include::guides/java-rest.adoc[tags=config,leveloffset=+2]
[[httpsession-httpsessionlistener]]
=== HttpSessionListener
@@ -460,117 +292,10 @@ In XML configuration, this might look like:
include::{docs-test-resources-dir}docs/http/HttpSessionListenerXmlTests-context.xml[tags=config]
----
[[websocket]]
== WebSocket Integration
Spring Session provides transparent integration with Spring's WebSocket support.
include::guides/boot-websocket.adoc[tags=disclaimer,leveloffset=+1]
[[websocket-why]]
=== Why Spring Session & WebSockets?
So why do we need Spring Session when using WebSockets?
Consider an email application that does much of its work through HTTP requests.
However, there is also a chat application embedded within it that works over WebSocket APIs.
If a user is actively chatting with someone, we should not timeout the `HttpSession` since this would be pretty poor user experience.
However, this is exactly what https://java.net/jira/browse/WEBSOCKET_SPEC-175[JSR-356] does.
Another issue is that according to JSR-356 if the `HttpSession` times out any WebSocket that was created with that HttpSession and an authenticated user should be forcibly closed.
This means that if we are actively chatting in our application and are not using the HttpSession, then we will also disconnect from our conversation!
[[websocket-usage]]
=== WebSocket Usage
The <<samples, WebSocket Sample>> provides a working sample on how to integrate Spring Session with WebSockets.
You can follow the basic steps for integration below, but you are encouraged to follow along with the detailed WebSocket Guide when integrating with your own application:
[[websocket-httpsession]]
==== HttpSession Integration
Before using WebSocket integration, you should be sure that you have <<httpsession>> working first.
include::guides/boot-websocket.adoc[tags=config,leveloffset=+2]
[[spring-security]]
== Spring Security Integration
Spring Session provides integration with Spring Security.
[[spring-security-rememberme]]
=== Spring Security Remember-Me Support
Spring Session provides integration with http://docs.spring.io/spring-security/site/docs/4.2.x/reference/htmlsingle/#remember-me[Spring Security's Remember-Me Authentication].
The support will:
* Change the session expiration length
* Ensure the session cookie expires at `Integer.MAX_VALUE`.
The cookie expiration is set to the largest possible value because the cookie is only set when the session is created.
If it were set to the same value as the session expiration, then the session would get renewed when the user used it but the cookie expiration would not be updated causing the expiration to be fixed.
To configure Spring Session with Spring Security in Java Configuration use the following as a guide:
[source,java,indent=0]
----
include::{docs-test-dir}docs/security/RememberMeSecurityConfiguration.java[tags=http-rememberme]
}
include::{docs-test-dir}docs/security/RememberMeSecurityConfiguration.java[tags=rememberme-bean]
----
An XML based configuration would look something like this:
[source,xml,indent=0]
----
include::{docs-test-resources-dir}docs/security/RememberMeSecurityConfigurationXmlTests-context.xml[tags=config]
----
[[spring-security-concurrent-sessions]]
=== Spring Security Concurrent Session Control
Spring Session provides integration with Spring Security to support its concurrent session control.
This allows limiting the number of active sessions that a single user can have concurrently, but unlike the default
Spring Security support this will also work in a clustered environment. This is done by providing a custom
implementation of Spring Security's `SessionRegistry` interface.
When using Spring Security's Java config DSL, you can configure the custom `SessionRegistry` through the
`SessionManagementConfigurer` like this:
[source,java,indent=0]
----
include::{docs-test-dir}docs/security/SecurityConfiguration.java[tags=class]
----
This assumes that you've also configured Spring Session to provide a `FindByIndexNameSessionRepository` that
returns `ExpiringSession` instances.
When using XML configuration, it would look something like this:
[source,xml,indent=0]
----
include::{docs-test-resources-dir}docs/security/security-config.xml[tags=config]
----
This assumes that your Spring Session `SessionRegistry` bean is called `sessionRegistry`, which is the name used by all
`SpringHttpSessionConfiguration` subclasses.
[[spring-security-concurrent-sessions-limitations]]
=== Limitations
Spring Session's implementation of Spring Security's `SessionRegistry` interface does not support the `getAllPrincipals`
method, as this information cannot be retrieved using Spring Session. This method is never called by Spring Security,
so this only affects applications that access the `SessionRegistry` themselves.
[[api]]
== API Documentation
You can browse the complete link:../../api/[Javadoc] online. The key APIs are described below:
[[api-session]]
=== Session
A `Session` is a simplified `Map` of name value pairs.
A `Session` is a simplified `Map` of key value pairs.
Typical usage might look like the following:
@@ -667,240 +392,6 @@ It is important to note that no infrastructure for session expirations is config
This is because things like session expiration are highly implementation dependent.
This means if you require cleaning up expired sessions, you are responsible for cleaning up the expired sessions.
[[api-redisoperationssessionrepository]]
=== RedisOperationsSessionRepository
`RedisOperationsSessionRepository` is a `SessionRepository` that is implemented using Spring Data's `RedisOperations`.
In a web environment, this is typically used in combination with `SessionRepositoryFilter`.
The implementation supports `SessionDestroyedEvent` and `SessionCreatedEvent` through `SessionMessageListener`.
[[api-redisoperationssessionrepository-new]]
==== Instantiating a RedisOperationsSessionRepository
A typical example of how to create a new instance can be seen below:
[source,java,indent=0]
----
include::{indexdoc-tests}[tags=new-redisoperationssessionrepository]
----
For additional information on how to create a `RedisConnectionFactory`, refer to the Spring Data Redis Reference.
[[api-redisoperationssessionrepository-config]]
==== EnableRedisHttpSession
In a web environment, the simplest way to create a new `RedisOperationsSessionRepository` is to use `@EnableRedisHttpSession`.
Complete example usage can be found in the <<samples>>
You can use the following attributes to customize the configuration:
* **maxInactiveIntervalInSeconds** - the amount of time before the session will expire in seconds
* **redisNamespace** - allows configuring an application specific namespace for the sessions. Redis keys and channel ids will start with the prefix of `spring:session:<redisNamespace>:`.
* **redisFlushMode** - allows specifying when data will be written to Redis. The default is only when `save` is invoked on `SessionRepository`.
A value of `RedisFlushMode.IMMEDIATE` will write to Redis as soon as possible.
===== Custom RedisSerializer
You can customize the serialization by creating a Bean named `springSessionDefaultRedisSerializer` that implements `RedisSerializer<Object>`.
==== Redis TaskExecutor
`RedisOperationsSessionRepository` is subscribed to receive events from redis using a `RedisMessageListenerContainer`.
You can customize the way those events are dispatched, by creating a Bean named `springSessionRedisTaskExecutor` and/or a Bean `springSessionRedisSubscriptionExecutor`.
More details on configuring redis task executors can be found http://docs.spring.io/spring-data-redis/docs/current/reference/html/#redis:pubsub:subscribe:containers[here].
[[api-redisoperationssessionrepository-storage]]
==== Storage Details
The sections below outline how Redis is updated for each operation.
An example of creating a new session can be found below.
The subsequent sections describe the details.
----
HMSET spring:session:sessions:33fdd1b6-b496-4b33-9f7d-df96679d32fe creationTime 1404360000000 \
maxInactiveInterval 1800 \
lastAccessedTime 1404360000000 \
sessionAttr:attrName someAttrValue \
sessionAttr2:attrName someAttrValue2
EXPIRE spring:session:sessions:33fdd1b6-b496-4b33-9f7d-df96679d32fe 2100
APPEND spring:session:sessions:expires:33fdd1b6-b496-4b33-9f7d-df96679d32fe ""
EXPIRE spring:session:sessions:expires:33fdd1b6-b496-4b33-9f7d-df96679d32fe 1800
SADD spring:session:expirations:1439245080000 expires:33fdd1b6-b496-4b33-9f7d-df96679d32fe
EXPIRE spring:session:expirations1439245080000 2100
----
===== Saving a Session
Each session is stored in Redis as a Hash.
Each session is set and updated using the HMSET command.
An example of how each session is stored can be seen below.
----
HMSET spring:session:sessions:33fdd1b6-b496-4b33-9f7d-df96679d32fe creationTime 1404360000000 \
maxInactiveInterval 1800 \
lastAccessedTime 1404360000000 \
sessionAttr:attrName someAttrValue \
sessionAttr2:attrName someAttrValue2
----
In this example, the session following statements are true about the session:
* The session id is 33fdd1b6-b496-4b33-9f7d-df96679d32fe
* The session was created at 1404360000000 in milliseconds since midnight of 1/1/1970 GMT.
* The session expires in 1800 seconds (30 minutes).
* The session was last accessed at 1404360000000 in milliseconds since midnight of 1/1/1970 GMT.
* The session has two attributes.
The first is "attrName" with the value of "someAttrValue".
The second session attribute is named "attrName2" with the value of "someAttrValue2".
[[api-redisoperationssessionrepository-writes]]
===== Optimized Writes
The `Session` instances managed by `RedisOperationsSessionRepository` keeps track of the properties that have changed and only updates those.
This means if an attribute is written once and read many times we only need to write that attribute once.
For example, assume the session attribute "sessionAttr2" from earlier was updated.
The following would be executed upon saving:
----
HMSET spring:session:sessions:33fdd1b6-b496-4b33-9f7d-df96679d32fe sessionAttr:attrName2 newValue
----
[[api-redisoperationssessionrepository-expiration]]
===== Session Expiration
An expiration is associated to each session using the EXPIRE command based upon the `ExpiringSession.getMaxInactiveInterval()`.
For example:
----
EXPIRE spring:session:sessions:33fdd1b6-b496-4b33-9f7d-df96679d32fe 2100
----
You will note that the expiration that is set is 5 minutes after the session actually expires.
This is necessary so that the value of the session can be accessed when the session expires.
An expiration is set on the session itself five minutes after it actually expires to ensure it is cleaned up, but only after we perform any necessary processing.
[NOTE]
====
The `SessionRepository.getSession(String)` method ensures that no expired sessions will be returned.
This means there is no need to check the expiration before using a session.
====
Spring Session relies on the delete and expired http://redis.io/topics/notifications[keyspace notifications] from Redis to fire a <<api-redisoperationssessionrepository-sessiondestroyedevent,SessionDeletedEvent>> and <<api-redisoperationssessionrepository-sessiondestroyedevent,SessionExpiredEvent>> respectively.
It is the `SessionDeletedEvent` or `SessionExpiredEvent` that ensures resources associated with the Session are cleaned up.
For example, when using Spring Session's WebSocket support the Redis expired or delete event is what triggers any WebSocket connections associated with the session to be closed.
Expiration is not tracked directly on the session key itself since this would mean the session data would no longer be available. Instead a special session expires key is used. In our example the expires key is:
----
APPEND spring:session:sessions:expires:33fdd1b6-b496-4b33-9f7d-df96679d32fe ""
EXPIRE spring:session:sessions:expires:33fdd1b6-b496-4b33-9f7d-df96679d32fe 1800
----
When a session expires key is deleted or expires, the keyspace notification triggers a lookup of the actual session and a SessionDestroyedEvent is fired.
One problem with relying on Redis expiration exclusively is that Redis makes no guarantee of when the expired event will be fired if they key has not been accessed.
Specifically the background task that Redis uses to clean up expired keys is a low priority task and may not trigger the key expiration.
For additional details see http://redis.io/topics/notifications[Timing of expired events] section in the Redis documentation.
To circumvent the fact that expired events are not guaranteed to happen we can ensure that each key is accessed when it is expected to expire.
This means that if the TTL is expired on the key, Redis will remove the key and fire the expired event when we try to access they key.
For this reason, each session expiration is also tracked to the nearest minute.
This allows a background task to access the potentially expired sessions to ensure that Redis expired events are fired in a more deterministic fashion.
For example:
----
SADD spring:session:expirations:1439245080000 expires:33fdd1b6-b496-4b33-9f7d-df96679d32fe
EXPIRE spring:session:expirations1439245080000 2100
----
The background task will then use these mappings to explicitly request each key.
By accessing they key, rather than deleting it, we ensure that Redis deletes the key for us only if the TTL is expired.
[NOTE]
====
We do not explicitly delete the keys since in some instances there may be a race condition that incorrectly identifies a key as expired when it is not.
Short of using distributed locks (which would kill our performance) there is no way to ensure the consistency of the expiration mapping.
By simply accessing the key, we ensure that the key is only removed if the TTL on that key is expired.
====
[[api-redisoperationssessionrepository-sessiondestroyedevent]]
==== SessionDeletedEvent and SessionExpiredEvent
`SessionDeletedEvent` and `SessionExpiredEvent` are both types of `SessionDestroyedEvent`.
`RedisOperationsSessionRepository` supports firing a `SessionDeletedEvent` whenever a `Session` is deleted or a `SessionExpiredEvent` when it expires.
This is necessary to ensure resources associated with the `Session` are properly cleaned up.
For example, when integrating with WebSockets the `SessionDestroyedEvent` is in charge of closing any active WebSocket connections.
Firing `SessionDeletedEvent` or `SessionExpiredEvent` is made available through the `SessionMessageListener` which listens to http://redis.io/topics/notifications[Redis Keyspace events].
In order for this to work, Redis Keyspace events for Generic commands and Expired events needs to be enabled.
For example:
[source,bash]
----
redis-cli config set notify-keyspace-events Egx
----
If you are using `@EnableRedisHttpSession` the `SessionMessageListener` and enabling the necessary Redis Keyspace events is done automatically.
However, in a secured Redis enviornment the config command is disabled.
This means that Spring Session cannot configure Redis Keyspace events for you.
To disable the automatic configuration add `ConfigureRedisAction.NO_OP` as a bean.
For example, Java Configuration can use the following:
[source,java,indent=0]
----
include::{docs-test-dir}docs/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java[tags=configure-redis-action]
----
XML Configuration can use the following:
[source,xml,indent=0]
----
include::{docs-test-resources-dir}docs/HttpSessionConfigurationNoOpConfigureRedisActionXmlTests-context.xml[tags=configure-redis-action]
----
[[api-redisoperationssessionrepository-sessioncreatedevent]]
==== SessionCreatedEvent
When a session is created an event is sent to Redis with the channel of `spring:session:channel:created:33fdd1b6-b496-4b33-9f7d-df96679d32fe`
such that `33fdd1b6-b496-4b33-9f7d-df96679d32fe` is the session id. The body of the event will be the session that was created.
If registered as a MessageListener (default), then `RedisOperationsSessionRepository` will then translate the Redis message into a `SessionCreatedEvent`.
[[api-redisoperationssessionrepository-cli]]
==== Viewing the Session in Redis
After http://redis.io/topics/quickstart[installing redis-cli], you can inspect the values in Redis http://redis.io/commands#hash[using the redis-cli].
For example, enter the following into a terminal:
[source,bash]
----
$ redis-cli
redis 127.0.0.1:6379> keys *
1) "spring:session:sessions:4fc39ce3-63b3-4e17-b1c4-5e1ed96fb021" <1>
2) "spring:session:expirations:1418772300000" <2>
----
<1> The suffix of this key is the session identifier of the Spring Session.
<2> This key contains all the session ids that should be deleted at the time `1418772300000`.
You can also view the attributes of each session.
[source,bash]
----
redis 127.0.0.1:6379> hkeys spring:session:sessions:4fc39ce3-63b3-4e17-b1c4-5e1ed96fb021
1) "lastAccessedTime"
2) "creationTime"
3) "maxInactiveInterval"
4) "sessionAttr:username"
redis 127.0.0.1:6379> hget spring:session:sessions:4fc39ce3-63b3-4e17-b1c4-5e1ed96fb021 sessionAttr:username
"\xac\xed\x00\x05t\x00\x03rob"
----
[[api-gemfireoperationssessionrepository]]
=== GemFireOperationsSessionRepository
@@ -1001,144 +492,6 @@ Creating a new instance is as simple as:
include::{indexdoc-tests}[tags=new-mapsessionrepository]
----
[[api-mapsessionrepository-hazelcast]]
==== Using Spring Session and Hazlecast
The <<samples,Hazelcast Sample>> is a complete application demonstrating using Spring Session with Hazelcast.
To run it use the following:
./gradlew :samples:hazelcast:tomcatRun
The <<samples,Hazelcast Spring Sample>> is a complete application demonstrating using Spring Session with Hazelcast and Spring Security.
It includes example Hazelcast `MapListener` implementations that support firing `SessionCreatedEvent`, `SessionDeletedEvent` and `SessionExpiredEvent`.
To run it use the following:
./gradlew :samples:hazelcast-spring:tomcatRun
[[api-jdbcoperationssessionrepository]]
=== JdbcOperationsSessionRepository
`JdbcOperationsSessionRepository` is a `SessionRepository` implementation that uses Spring's `JdbcOperations` to store sessions in a relational database.
In a web environment, this is typically used in combination with `SessionRepositoryFilter`.
Please note that this implementation does not support publishing of session events.
[[api-jdbcoperationssessionrepository-new]]
==== Instantiating a JdbcOperationsSessionRepository
A typical example of how to create a new instance can be seen below:
[source,java,indent=0]
----
include::{indexdoc-tests}[tags=new-jdbcoperationssessionrepository]
----
For additional information on how to create and configure `JdbcTemplate` and `PlatformTransactionManager`, refer to the http://docs.spring.io/spring/docs/current/spring-framework-reference/html/spring-data-tier.html[Spring Framework Reference Documentation].
[[api-jdbcoperationssessionrepository-config]]
==== EnableJdbcHttpSession
In a web environment, the simplest way to create a new `JdbcOperationsSessionRepository` is to use `@EnableJdbcHttpSession`.
Complete example usage can be found in the <<samples>>
You can use the following attributes to customize the configuration:
* **tableName** - the name of database table used by Spring Session to store sessions
* **maxInactiveIntervalInSeconds** - the amount of time before the session will expire in seconds
===== Custom LobHandler
You can customize the BLOB handling by creating a Bean named `springSessionLobHandler` that implements `LobHandler`.
===== Custom ConversionService
You can customize the default serialization and deserialization of the session by providing a `ConversionService` instance.
When working in a typical Spring environment, the default `ConversionService` Bean (named `conversionService`) will be automatically picked up and used for serialization and deserialization.
However, you can override the default `ConversionService` by providing a Bean named `springSessionConversionService`.
[[api-jdbcoperationssessionrepository-storage]]
==== Storage Details
By default, this implementation uses `SPRING_SESSION` and `SPRING_SESSION_ATTRIBUTES` tables to store sessions.
Note that the table name can be easily customized as already described. In that case the table used to store attributes will be named using the provided table name, suffixed with `_ATTRIBUTES`.
If further customizations are needed, SQL queries used by the repository can be customized using `set*Query` setter methods. In this case you need to manually configure the `sessionRepository` bean.
Due to the differences between the various database vendors, especially when it comes to storing binary data, make sure to use SQL script specific to your database.
Scripts for most major database vendors are packaged as `org/springframework/session/jdbc/schema-\*.sql`, where `*` is the target database type.
For example, with PostgreSQL database you would use the following schema script:
[source,sql,indent=0]
----
include::{session-main-resources-dir}org/springframework/session/jdbc/schema-postgresql.sql[]
----
And with MySQL database:
[source,sql,indent=0]
----
include::{session-main-resources-dir}org/springframework/session/jdbc/schema-mysql.sql[]
----
==== Transaction management
All JDBC operations in `JdbcOperationsSessionRepository` are executed in a transactional manner.
Transactions are executed with propagation set to `REQUIRES_NEW` in order to avoid unexpected behavior due to interference with existing transactions (for example, executing `save` operation in a thread that already participates in a read-only transaction).
[[api-hazelcastsessionrepository]]
=== HazelcastSessionRepository
`HazelcastSessionRepository` is a `SessionRepository` implementation that stores sessions in Hazelcast's distributed `IMap`.
In a web environment, this is typically used in combination with `SessionRepositoryFilter`.
[[api-hazelcastsessionrepository-new]]
==== Instantiating a HazelcastSessionRepository
A typical example of how to create a new instance can be seen below:
[source,java,indent=0]
----
include::{indexdoc-tests}[tags=new-hazelcastsessionrepository]
----
For additional information on how to create and configure Hazelcast instance, refer to the http://docs.hazelcast.org/docs/latest/manual/html-single/index.html#hazelcast-configuration[Hazelcast documentation].
[[api-enablehazelcasthttpsession]]
==== EnableHazelcastHttpSession
If you wish to use http://hazelcast.org/[Hazelcast] as your backing source for the `SessionRepository`, then the `@EnableHazelcastHttpSession` annotation
can be added to an `@Configuration` class. This extends the functionality provided by the `@EnableSpringHttpSession` annotation but makes the `SessionRepository` for you in Hazelcast.
You must provide a single `HazelcastInstance` bean for the configuration to work.
Complete configuration example can be found in the <<samples>>
[[api-enablehazelcasthttpsession-customize]]
==== Basic Customization
You can use the following attributes on `@EnableHazelcastHttpSession` to customize the configuration:
* **maxInactiveIntervalInSeconds** - the amount of time before the session will expire in seconds. Default is 1800 seconds (30 minutes)
* **sessionMapName** - the name of the distributed `Map` that will be used in Hazelcast to store the session data.
[[api-enablehazelcasthttpsession-events]]
==== Session Events
Using a `MapListener` to respond to entries being added, evicted, and removed from the distributed `Map`, these events will trigger
publishing `SessionCreatedEvent`, `SessionExpiredEvent`, and `SessionDeletedEvent` events respectively using the `ApplicationEventPublisher`.
[[api-enablehazelcasthttpsession-storage]]
==== Storage Details
Sessions will be stored in a distributed `IMap` in Hazelcast.
The `IMap` interface methods will be used to `get()` and `put()` Sessions.
Additionally, `values()` method is used to support `FindByIndexNameSessionRepository#findByIndexNameAndIndexValue` operation, together with appropriate `ValueExtractor` that needs to be registered with Hazelcast. Refer to <<samples, Hazelcast Spring Sample>> for more details on this configuration.
The expiration of a session in the `IMap` is handled by Hazelcast's support for setting the time to live on an entry when it is `put()` into the `IMap`. Entries (sessions) that have been idle longer than the time to live will be automatically removed from the `IMap`.
You shouldn't need to configure any settings such as `max-idle-seconds` or `time-to-live-seconds` for the `IMap` within the Hazelcast configuration.
Note that if you use Hazelcast's `MapStore` to persist your sessions `IMap` there are some limitations when reloading the sessions from `MapStore`:
* reload triggers `EntryAddedListener` which results in `SessionCreatedEvent` being re-published
* reload uses default TTL for a given `IMap` which results in sessions losing their original TTL
[[community]]
== Spring Session Community

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,9 @@
* limitations under the License.
*/
package docs.http.gemfire.indexablesessionattributes;
package docs.gemfire.indexing;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
@@ -29,15 +31,13 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Winch
* @author John Blum
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = HttpSessionGemFireIndexingCustomITests.Config.class)
public class HttpSessionGemFireIndexingCustomITests {
@ContextConfiguration(classes = HttpSessionGemFireCustomIndexingIntegrationTests.TestConfiguration.class)
public class HttpSessionGemFireCustomIndexingIntegrationTests {
@Autowired
private GemFireOperationsSessionRepository sessionRepository;
@@ -45,7 +45,7 @@ public class HttpSessionGemFireIndexingCustomITests {
@Test
public void findByIndexName() {
ExpiringSession session = this.sessionRepository.createSession();
String attrValue = "HttpSessionGemFireIndexingCustomITests-findByIndexName";
String attrValue = "HttpSessionGemFireCustomIndexingIntegrationTests-findByIndexName";
// tag::findbyindexname-set[]
String indexName = "name1";
@@ -64,9 +64,9 @@ public class HttpSessionGemFireIndexingCustomITests {
this.sessionRepository.delete(session.getId());
}
@PeerCacheApplication(name = "HttpSessionGemFireIndexingCustomITests", logLevel = "error")
@PeerCacheApplication(name = "HttpSessionGemFireCustomIndexingIntegrationTests", logLevel = "error")
@EnableGemFireHttpSession(indexableSessionAttributes = { "name1", "name2", "name3" },
regionName = "HttpSessionGemFireIndexingCustomTestRegion")
static class Config {
static class TestConfiguration {
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,9 @@
* limitations under the License.
*/
package docs.http;
package docs.gemfire.indexing;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
@@ -35,15 +37,13 @@ import org.springframework.session.data.gemfire.config.annotation.web.http.Enabl
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Winch
* @author John Blum
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = HttpSessionGemFireIndexingITests.Config.class)
public class HttpSessionGemFireIndexingITests {
@ContextConfiguration(classes = HttpSessionGemFireIndexingIntegrationTests.Config.class)
public class HttpSessionGemFireIndexingIntegrationTests {
@Autowired
private GemFireOperationsSessionRepository sessionRepository;
@@ -51,7 +51,7 @@ public class HttpSessionGemFireIndexingITests {
@Test
public void findByIndexName() {
ExpiringSession session = this.sessionRepository.createSession();
String username = "HttpSessionGemFireIndexingITests-findByIndexName-username";
String username = "HttpSessionGemFireIndexingIntegrationTests-findByIndexName-username";
// tag::findbyindexname-set[]
String indexName = FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME;
@@ -72,7 +72,7 @@ public class HttpSessionGemFireIndexingITests {
}
@Test
@WithMockUser("HttpSessionGemFireIndexingITests-findBySpringSecurityIndexName")
@WithMockUser("HttpSessionGemFireIndexingIntegrationTests-findBySpringSecurityIndexName")
public void findBySpringSecurityIndexName() {
ExpiringSession session = this.sessionRepository.createSession();
@@ -95,7 +95,7 @@ public class HttpSessionGemFireIndexingITests {
this.sessionRepository.delete(session.getId());
}
@PeerCacheApplication(name = "HttpSessionGemFireIndexingITests", logLevel = "error")
@PeerCacheApplication(name = "HttpSessionGemFireIndexingIntegrationTests", logLevel = "error")
@EnableGemFireHttpSession(regionName = "HttpSessionGemFireIndexingTestRegion")
static class Config {
}

View File

@@ -1,3 +1,10 @@
assertjVersion=3.8.0
jstlVersion=1.2.1
junitVersion=4.12
mockitoVersion=2.8.9
seleniumVersion=3.4
springBootVersion=2.0.0.BUILD-SNAPSHOT
version=2.0.0.BUILD-SNAPSHOT
springDataGemFireVersion=2.0.0.M3
springDataGeodeVersion=1.0.0.INCUBATING-RELEASE
springIoVersion=Cairo-BUILD-SNAPSHOT
version=2.0.0.BUILD-SNAPSHOT

View File

@@ -0,0 +1,172 @@
dependencyManagement {
dependencies {
dependency 'com.maxmind.geoip2:geoip2:2.3.1'
dependency 'edu.umd.cs.mtc:multithreadedtc:1.01'
dependency 'org.springframework.shell:spring-shell:1.1.0.RELEASE'
dependency 'org.webjars:bootstrap:2.3.2'
dependency 'org.webjars:html5shiv:3.7.3'
dependency 'org.webjars:knockout:2.3.0'
dependency 'org.webjars:sockjs-client:0.3.4'
dependency 'org.webjars:stomp-websocket:2.3.0'
dependency 'org.webjars:webjars-taglib:0.3'
}
}
dependencyManagement {
imports {
mavenBom 'org.springframework:spring-framework-bom:5.0.0.RC1'
mavenBom 'org.springframework.data:spring-data-releasetrain:Kay-M3'
mavenBom 'org.springframework.security:spring-security-bom:5.0.0.M1'
}
dependencies {
dependency 'antlr:antlr:2.7.7'
dependency 'aopalliance:aopalliance:1.0'
dependency 'cglib:cglib-nodep:2.1_3'
dependency 'cglib:cglib-nodep:3.2.4'
dependency 'ch.qos.logback:logback-classic:1.1.11'
dependency 'ch.qos.logback:logback-classic:1.2.3'
dependency 'ch.qos.logback:logback-core:1.1.11'
dependency 'ch.qos.logback:logback-core:1.2.3'
dependency 'com.fasterxml.jackson.core:jackson-annotations:2.8.0'
dependency 'com.fasterxml.jackson.core:jackson-annotations:2.9.0.pr3'
dependency 'com.fasterxml.jackson.core:jackson-core:2.8.8'
dependency 'com.fasterxml.jackson.core:jackson-core:2.9.0.pr3'
dependency 'com.fasterxml.jackson.core:jackson-databind:2.8.8'
dependency 'com.fasterxml.jackson.core:jackson-databind:2.9.0.pr3'
dependency 'com.fasterxml:classmate:1.3.3'
dependency 'com.google.code.findbugs:jsr305:3.0.2'
dependency 'com.google.code.gson:gson:2.8.0'
dependency 'com.google.guava:guava:20.0'
dependency 'com.google.http-client:google-http-client:1.20.0'
dependency 'com.h2database:h2:1.4.195'
dependency 'com.jayway.jsonpath:json-path:2.2.0'
dependency 'com.maxmind.db:maxmind-db:1.0.0'
dependency 'com.maxmind.geoip2:geoip2:2.3.1'
dependency 'com.vaadin.external.google:android-json:0.0.20131108.vaadin1'
dependency 'commons-cli:commons-cli:1.3.1'
dependency 'commons-codec:commons-codec:1.10'
dependency 'commons-collections:commons-collections:3.2.2'
dependency 'commons-io:commons-io:2.5'
dependency 'dom4j:dom4j:1.6.1'
dependency 'edu.umd.cs.mtc:multithreadedtc:1.01'
dependency 'io.lettuce:lettuce-core:5.0.0.M2'
dependency 'io.netty:netty-buffer:4.1.10.Final'
dependency 'io.netty:netty-codec:4.1.10.Final'
dependency 'io.netty:netty-common:4.1.10.Final'
dependency 'io.netty:netty-handler:4.1.10.Final'
dependency 'io.netty:netty-resolver:4.1.10.Final'
dependency 'io.netty:netty-transport:4.1.10.Final'
dependency 'io.projectreactor:reactor-core:3.1.0.M1'
dependency 'io.reactivex:rxjava:1.3.0'
dependency 'javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:1.2.1'
dependency 'javax.servlet.jsp:javax.servlet.jsp-api:2.3.2-b02'
dependency 'javax.servlet:javax.servlet-api:3.1.0'
dependency 'javax.transaction:javax.transaction-api:1.2'
dependency 'javax.validation:validation-api:1.1.0.Final'
dependency 'junit:junit:4.12'
dependency 'net.bytebuddy:byte-buddy-agent:1.6.11'
dependency 'net.bytebuddy:byte-buddy:1.6.12'
dependency 'net.java.dev.jna:jna-platform:4.1.0'
dependency 'net.java.dev.jna:jna:4.2.2'
dependency 'net.minidev:accessors-smart:1.1'
dependency 'net.minidev:json-smart:2.2.1'
dependency 'net.sourceforge.cssparser:cssparser:0.9.18'
dependency 'net.sourceforge.cssparser:cssparser:0.9.22'
dependency 'net.sourceforge.htmlunit:htmlunit-core-js:2.17'
dependency 'net.sourceforge.htmlunit:htmlunit-core-js:2.26'
dependency 'net.sourceforge.htmlunit:htmlunit:2.21'
dependency 'net.sourceforge.htmlunit:htmlunit:2.26'
dependency 'net.sourceforge.htmlunit:neko-htmlunit:2.21'
dependency 'net.sourceforge.htmlunit:neko-htmlunit:2.25'
dependency 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:1.4.0'
dependency 'ognl:ognl:3.0.8'
dependency 'org.akhikhl.gretty:gretty-runner-tomcat8:1.4.2'
dependency 'org.akhikhl.gretty:gretty-runner-tomcat:1.4.2'
dependency 'org.akhikhl.gretty:gretty-runner:1.4.2'
dependency 'org.apache.commons:commons-compress:1.9'
dependency 'org.apache.commons:commons-exec:1.3'
dependency 'org.apache.commons:commons-lang3:3.5'
dependency 'org.apache.commons:commons-pool2:2.4.2'
dependency 'org.apache.derby:derby:10.13.1.1'
dependency 'org.apache.httpcomponents:httpclient:4.5.3'
dependency 'org.apache.httpcomponents:httpcore:4.4.6'
dependency 'org.apache.httpcomponents:httpmime:4.5.3'
dependency 'org.apache.taglibs:taglibs-standard-impl:1.2.5'
dependency 'org.apache.taglibs:taglibs-standard-jstlel:1.2.5'
dependency 'org.apache.taglibs:taglibs-standard-spec:1.2.5'
dependency 'org.apache.tomcat.embed:tomcat-embed-core:8.5.14'
dependency 'org.apache.tomcat.embed:tomcat-embed-el:8.5.14'
dependency 'org.apache.tomcat.embed:tomcat-embed-jasper:8.5.14'
dependency 'org.apache.tomcat.embed:tomcat-embed-logging-log4j:8.0.33'
dependency 'org.apache.tomcat.embed:tomcat-embed-websocket:8.5.14'
dependency 'org.apache.tomcat:tomcat-jdbc:8.5.14'
dependency 'org.apache.tomcat:tomcat-juli:8.5.14'
dependency 'org.aspectj:aspectjweaver:1.8.10'
dependency 'org.assertj:assertj-core:3.6.2'
dependency 'org.codehaus.groovy:groovy-json:2.4.11'
dependency 'org.codehaus.groovy:groovy:2.4.10'
dependency 'org.codehaus.groovy:groovy:2.4.11'
dependency 'org.eclipse.jdt.core.compiler:ecj:4.6.1'
dependency 'org.eclipse.jetty.websocket:websocket-api:9.4.4.v20170414'
dependency 'org.eclipse.jetty.websocket:websocket-api:9.4.5.v20170502'
dependency 'org.eclipse.jetty.websocket:websocket-client:9.4.4.v20170414'
dependency 'org.eclipse.jetty.websocket:websocket-client:9.4.5.v20170502'
dependency 'org.eclipse.jetty.websocket:websocket-common:9.4.4.v20170414'
dependency 'org.eclipse.jetty.websocket:websocket-common:9.4.5.v20170502'
dependency 'org.eclipse.jetty:jetty-client:9.4.4.v20170414'
dependency 'org.eclipse.jetty:jetty-client:9.4.5.v20170502'
dependency 'org.eclipse.jetty:jetty-http:9.4.4.v20170414'
dependency 'org.eclipse.jetty:jetty-http:9.4.5.v20170502'
dependency 'org.eclipse.jetty:jetty-io:9.4.4.v20170414'
dependency 'org.eclipse.jetty:jetty-io:9.4.5.v20170502'
dependency 'org.eclipse.jetty:jetty-util:9.4.4.v20170414'
dependency 'org.eclipse.jetty:jetty-util:9.4.5.v20170502'
dependency 'org.hamcrest:hamcrest-core:1.3'
dependency 'org.hamcrest:hamcrest-library:1.3'
dependency 'org.hibernate.common:hibernate-commons-annotations:5.0.1.Final'
dependency 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
dependency 'org.hibernate:hibernate-core:5.0.12.Final'
dependency 'org.hibernate:hibernate-entitymanager:5.0.12.Final'
dependency 'org.hibernate:hibernate-validator:5.3.5.Final'
dependency 'org.hsqldb:hsqldb:2.4.0'
dependency 'org.javassist:javassist:3.21.0-GA'
dependency 'org.jboss.logging:jboss-logging:3.3.1.Final'
dependency 'org.jboss:jandex:2.0.0.Final'
dependency 'org.mockito:mockito-core:2.7.22'
dependency 'org.objenesis:objenesis:2.5.1'
dependency 'org.ow2.asm:asm:5.0.3'
dependency 'org.reactivestreams:reactive-streams:1.0.0'
dependency 'org.seleniumhq.selenium:htmlunit-driver:2.21'
dependency 'org.seleniumhq.selenium:htmlunit-driver:2.26'
dependency 'org.seleniumhq.selenium:selenium-api:2.53.1'
dependency 'org.seleniumhq.selenium:selenium-api:3.3.1'
dependency 'org.seleniumhq.selenium:selenium-remote-driver:2.53.1'
dependency 'org.seleniumhq.selenium:selenium-remote-driver:3.3.1'
dependency 'org.seleniumhq.selenium:selenium-support:2.53.1'
dependency 'org.seleniumhq.selenium:selenium-support:3.3.1'
dependency 'org.skyscreamer:jsonassert:1.4.0'
dependency 'org.slf4j:jcl-over-slf4j:1.7.25'
dependency 'org.slf4j:jul-to-slf4j:1.7.25'
dependency 'org.slf4j:log4j-over-slf4j:1.7.25'
dependency 'org.slf4j:slf4j-api:1.7.25'
dependency 'org.thymeleaf:thymeleaf-spring4:2.1.5.RELEASE'
dependency 'org.thymeleaf:thymeleaf:2.1.5.RELEASE'
dependency 'org.unbescape:unbescape:1.1.0.RELEASE'
dependency 'org.w3c.css:sac:1.3'
dependency 'org.webjars:bootstrap:2.3.2'
dependency 'org.webjars:html5shiv:3.7.3'
dependency 'org.webjars:jquery:1.9.0'
dependency 'org.webjars:knockout:2.3.0'
dependency 'org.webjars:sockjs-client:0.3.4'
dependency 'org.webjars:stomp-websocket:2.3.0'
dependency 'org.webjars:webjars-locator-core:0.30'
dependency 'org.webjars:webjars-locator-core:0.32'
dependency 'org.webjars:webjars-locator:0.32-1'
dependency 'org.webjars:webjars-taglib:0.3'
dependency 'org.yaml:snakeyaml:1.17'
dependency 'xalan:serializer:2.7.2'
dependency 'xalan:xalan:2.7.2'
dependency 'xerces:xercesImpl:2.11.0'
dependency 'xml-apis:xml-apis:1.4.01'
}
}

56
gradle/ide.gradle Normal file
View File

@@ -0,0 +1,56 @@
apply plugin: "propdeps-eclipse"
apply plugin: "propdeps-idea"
eclipse {
jdt {
javaRuntimeName = "J2SE-1.5"
}
}
eclipse.project.buildCommand "net.sf.eclipsecs.core.CheckstyleBuilder"
eclipse.project.natures "net.sf.eclipsecs.core.CheckstyleNature"
// Include project specific settings
task cleanEclipseJdtUi(type: Delete) {
delete project.file(".settings/org.eclipse.jdt.core.prefs")
delete project.file(".settings/org.eclipse.jdt.ui.prefs")
delete project.file(".settings/org.eclipse.wst.common.component")
delete project.file(".settings/org.eclipse.wst.common.project.facet.core.xml")
}
task eclipseCheckstyle(type: Copy) {
from rootProject.files(
"eclipse/.checkstyle")
into project.projectDir
expand(configDir: rootProject.file('config/checkstyle').absolutePath)
}
task eclipseJdtPrepare(type: Copy) {
from rootProject.file("eclipse/org.eclipse.jdt.core.prefs")
into project.file(".settings/")
outputs.upToDateWhen { false }
}
task eclipseSettings(type: Copy) {
from rootProject.files(
"eclipse/org.eclipse.jdt.ui.prefs",
"eclipse/org.eclipse.wst.common.project.facet.core.xml")
into project.file('.settings/')
outputs.upToDateWhen { false }
}
task eclipseWstComponent(type: Copy) {
from rootProject.files(
"eclipse/org.eclipse.wst.common.component")
into project.file('.settings/')
expand(deployname: project.name)
outputs.upToDateWhen { false }
}
task eclipseConfiguration(dependsOn: [eclipseCheckstyle, eclipseJdtPrepare, eclipseSettings, eclipseWstComponent]) {
group 'ide'
}
tasks["eclipseJdt"].dependsOn(eclipseJdtPrepare)
tasks["cleanEclipse"].dependsOn(cleanEclipseJdtUi)
tasks["eclipse"].dependsOn(eclipseConfiguration)

92
gradle/java.gradle Normal file
View File

@@ -0,0 +1,92 @@
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'eclipse-wtp'
apply plugin: 'propdeps'
apply plugin: 'propdeps-idea'
apply plugin: 'propdeps-eclipse'
apply plugin: 'checkstyle'
apply from: IDE_GRADLE
group = 'org.springframework.session'
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext.springIoVersion = project.hasProperty('platformVersion') ? platformVersion : 'Cairo-BUILD-SNAPSHOT'
ext.seleniumDependencies = [
"org.seleniumhq.selenium:htmlunit-driver:$htmlUnitVersion",
"org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
]
ext.jstlDependencies = [
"javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:$jstlVersion",
"org.apache.taglibs:taglibs-standard-jstlel:1.2.1"
]
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/libs-snapshot' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.springframework') {
details.useVersion springVersion
}
}
}
// Integration test setup
configurations {
integrationTestCompile {
extendsFrom testCompile, optional, provided
}
integrationTestRuntime {
extendsFrom integrationTestCompile, testRuntime
}
}
sourceSets {
integrationTest {
java.srcDir file('src/integration-test/java')
groovy.srcDirs file('src/integration-test/groovy')
resources.srcDir file('src/integration-test/resources')
compileClasspath = sourceSets.main.output + sourceSets.test.output + configurations.integrationTestCompile
runtimeClasspath = output + compileClasspath + configurations.integrationTestRuntime
}
}
task integrationTest(type: Test, dependsOn: jar) {
testClassesDir = sourceSets.integrationTest.output.classesDir
logging.captureStandardOutput(LogLevel.INFO)
classpath = sourceSets.integrationTest.runtimeClasspath
maxParallelForks = 1
reports {
html.destination = project.file("$project.buildDir/reports/integration-tests/")
junitXml.destination = project.file("$project.buildDir/integration-test-results/")
}
}
check.dependsOn integrationTest
checkstyle {
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
configProperties.configDir = configFile.parentFile
toolVersion = '6.16.1'
}
task checkstyle {
dependsOn project.tasks.findAll { task -> task.name.matches('checkstyle\\w+') }
}
eclipse {
classpath {
plusConfigurations += [ configurations.integrationTestCompile ]
}
}
project.idea.module {
scopes.TEST.plus += [project.configurations.integrationTestRuntime]
}

View File

@@ -0,0 +1,58 @@
apply plugin: 'propdeps-maven'
install {
repositories.mavenInstaller {
customizePom(pom, project)
}
}
def customizePom(pom, gradleProject) {
pom.whenConfigured { generatedPom ->
// sort to make pom dependencies order consistent to ease comparison of older poms
generatedPom.dependencies = generatedPom.dependencies.sort { dep ->
"$dep.scope:$dep.groupId:$dep.artifactId"
}
// add all items necessary for maven central publication
generatedPom.project {
name = gradleProject.description
description = gradleProject.description
url = "https://github.com/spring-projects/spring-session"
licenses {
license {
name "The Apache Software License, Version 2.0"
url "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution "repo"
}
}
organization {
name = "Spring IO"
url = "http://projects.spring.io/spring-session"
}
developers {
developer {
id = "jblum"
name = "John Blum"
email = "jblum@pivotal.io"
}
}
scm {
url = "https://github.com/spring-projects/spring-session-data-geode"
connection = "scm:git:git://github.com/spring-projects/spring-session-data-geode"
developerConnection = "scm:git:git://github.com/spring-projects/spring-session-data-geode"
}
issueManagement {
system = "GitHub"
url = "https://github.com/spring-projects/spring-session-data-geode/issues"
}
}
}
}

5
gradle/sample.gradle Normal file
View File

@@ -0,0 +1,5 @@
tasks.findByPath("artifactoryPublish")?.enabled = false
sonarqube {
skipProject = true
}

View File

@@ -1,39 +0,0 @@
configurations {
spring3TestRuntime.extendsFrom testRuntime
}
configurations.spring3TestRuntime {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.springframework'
&& details.requested.name != 'spring-websocket'
&& details.requested.name != 'spring-messaging') {
details.useVersion '3.2.18.RELEASE'
}
if (details.requested.group == 'org.springframework.data') {
if (details.requested.name == 'spring-data-commons') {
details.useVersion '1.12.1.RELEASE'
}
if (details.requested.name == 'spring-data-gemfire') {
details.useVersion '1.8.1.RELEASE'
}
if (details.requested.name == 'spring-data-keyvalue') {
details.useVersion '1.1.1.RELEASE'
}
if (details.requested.name == 'spring-data-redis') {
details.useVersion '1.7.1.RELEASE'
}
}
}
}
task spring3Test(type: Test) {
jvmArgs = ['-ea', '-Xmx500m', '-XX:MaxPermSize=128M']
classpath = sourceSets.test.output + sourceSets.main.output + configurations.spring3TestRuntime
exclude "org/springframework/session/web/socket/**"
reports {
html.destination = project.file("$buildDir/spring3-test-results/")
junitXml.destination = project.file("$buildDir/reports/spring3-tests/")
}
}
//check.dependsOn spring3Test

View File

@@ -1,24 +1,30 @@
rootProject.name = 'spring-session-data-geode-build'
FileTree buildFiles = fileTree(rootDir) {
include '**/*.gradle'
exclude '**/gradle', 'settings.gradle', 'buildSrc', '/build.gradle', '.*'
exclude '/build.gradle', 'settings.gradle', '**/gradle', 'buildSrc', '.*'
}
String rootDirPath = rootDir.absolutePath + File.separator
buildFiles.each { File buildFile ->
boolean isDefaultName = 'build.gradle'.equals(buildFile.name)
if(isDefaultName) {
if (isDefaultName) {
String buildFilePath = buildFile.parentFile.absolutePath
String projectPath = buildFilePath.replace(rootDirPath, '').replaceAll(File.separator, ':')
include projectPath
} else {
}
else {
String projectName = buildFile.name.replace('.gradle', '');
String projectPath = ':' + projectName;
include projectPath
def project = findProject("${projectPath}")
project.name = projectName
project.projectDir = buildFile.parentFile
project.buildFileName = buildFile.name

View File

@@ -3,19 +3,26 @@ apply plugin: 'io.spring.convention.spring-module'
description = "Spring Session Data Geode"
dependencies {
compile "org.springframework.session:spring-session"
compile "org.springframework:spring-context-support"
compile "org.springframework:spring-jcl"
compile "org.springframework.data:spring-data-gemfire"
compile "org.springframework.data:spring-data-geode:$springDataGeodeVersion"
compile "org.springframework.session:spring-session"
optional "org.springframework.security:spring-security-core"
optional "org.springframework.security:spring-security-web"
provided "javax.servlet:javax.servlet-api"
integrationTestRuntime "org.springframework.shell:spring-shell"
testCompile "edu.umd.cs.mtc:multithreadedtc"
testCompile "junit:junit"
testCompile "junit:junit:$junitVersion"
testCompile "org.assertj:assertj-core"
testCompile "org.mockito:mockito-core"
testCompile "org.springframework.security:spring-security-core"
testCompile "edu.umd.cs.mtc:multithreadedtc"
testCompile "org.springframework:spring-test"
testCompile "org.springframework:spring-web"
testCompile "org.springframework.security:spring-security-test"
testCompile slf4jDependencies
integrationTestRuntime "org.springframework.shell:spring-shell"
}

View File

@@ -16,20 +16,22 @@
package org.springframework.session.data.gemfire.config.annotation.web.http;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.ExpirationAction;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionShortcut;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.ExpirationAction;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionShortcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.CacheFactoryBean;
@@ -45,8 +47,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The EnableGemFireHttpSessionEventsIntegrationTests class is a test suite of test cases
* testing the Session Event functionality and behavior of the

View File

@@ -33,8 +33,6 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geode.DataSerializable;
import org.apache.geode.DataSerializer;
import org.apache.geode.Delta;
@@ -68,12 +66,14 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* {@link AbstractGemFireOperationsSessionRepository} is an abstract base class encapsulating functionality
* common to all implementations that support {@link SessionRepository} operations backed by GemFire.
* common to all implementations that support {@link SessionRepository} operations backed by Apache Geode.
*
* @author John Blum
* @since 1.1.0
* @see org.apache.geode.DataSerializable
* @see org.apache.geode.DataSerializer
* @see org.apache.geode.Delta
@@ -84,12 +84,14 @@ import org.springframework.util.StringUtils;
* @see org.springframework.context.ApplicationEventPublisher
* @see org.springframework.context.ApplicationEventPublisherAware
* @see org.springframework.data.gemfire.GemfireOperations
* @see org.springframework.expression.Expression
* @see org.springframework.session.ExpiringSession
* @see org.springframework.session.FindByIndexNameSessionRepository
* @see org.springframework.session.Session
* @see org.springframework.session.SessionRepository
* @see org.springframework.session.FindByIndexNameSessionRepository
* @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration
* @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession
* @since 1.1.0
*/
public abstract class AbstractGemFireOperationsSessionRepository extends CacheListenerAdapter<Object, ExpiringSession>
implements ApplicationEventPublisherAware, FindByIndexNameSessionRepository<ExpiringSession>, InitializingBean {
@@ -217,6 +219,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
* @throws Exception if an error occurs during the initialization process.
*/
public void afterPropertiesSet() throws Exception {
GemfireOperations template = getTemplate();
Assert.isInstanceOf(GemfireAccessor.class, template);
@@ -345,6 +348,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
* @see #publishEvent(ApplicationEvent)
*/
protected void handleCreated(String sessionId, ExpiringSession session) {
remember(sessionId);
publishEvent(session != null ? new SessionCreatedEvent(this, session)
@@ -361,6 +365,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
* @see #publishEvent(ApplicationEvent)
*/
protected void handleDeleted(String sessionId, ExpiringSession session) {
forget(sessionId);
publishEvent(session != null ? new SessionDeletedEvent(this, session)
@@ -377,6 +382,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
* @see #publishEvent(ApplicationEvent)
*/
protected void handleDestroyed(String sessionId, ExpiringSession session) {
forget(sessionId);
publishEvent(session != null ? new SessionDestroyedEvent(this, session)
@@ -393,6 +399,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
* @see #publishEvent(ApplicationEvent)
*/
protected void handleExpired(String sessionId, ExpiringSession session) {
forget(sessionId);
publishEvent(session != null ? new SessionExpiredEvent(this, session)
@@ -435,8 +442,8 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
* state information across the GemFire cluster.
*/
@SuppressWarnings("serial")
public static class GemFireSession implements Comparable<ExpiringSession>,
DataSerializable, Delta, ExpiringSession {
public static class GemFireSession
implements Comparable<ExpiringSession>, DataSerializable, Delta, ExpiringSession {
protected static final boolean DEFAULT_ALLOW_JAVA_SERIALIZATION = true;
@@ -471,6 +478,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
protected GemFireSession(ExpiringSession session) {
Assert.notNull(session, "The ExpiringSession to copy cannot be null");
this.id = session.getId();
@@ -544,6 +552,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public synchronized boolean isExpired() {
long lastAccessedTime = getLastAccessedTime();
long maxInactiveIntervalInSeconds = getMaxInactiveIntervalInSeconds();
@@ -585,6 +594,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public synchronized String getPrincipalName() {
String principalName = getAttribute(PRINCIPAL_NAME_INDEX_NAME);
if (principalName == null) {
@@ -601,6 +611,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public synchronized void toData(DataOutput out) throws IOException {
out.writeUTF(getId());
out.writeLong(getCreationTime());
out.writeLong(getLastAccessedTime());
@@ -628,6 +639,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public synchronized void fromData(DataInput in) throws ClassNotFoundException, IOException {
this.id = in.readUTF();
this.creationTime = in.readLong();
setLastAccessedTime(in.readLong());
@@ -679,7 +691,8 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
@Override
public boolean equals(final Object obj) {
if (obj == this) {
if (this == obj) {
return true;
}
@@ -695,14 +708,18 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
@Override
public int hashCode() {
int hashValue = 17;
hashValue = 37 * hashValue + getId().hashCode();
return hashValue;
}
/* (non-Javadoc) */
@Override
public synchronized String toString() {
return String.format("{ @type = %1$s, id = %2$s, creationTime = %3$s, lastAccessedTime = %4$s"
+ ", maxInactiveIntervalInSeconds = %5$s, principalName = %6$s }",
getClass().getName(), getId(), toString(getCreationTime()), toString(getLastAccessedTime()),
@@ -771,6 +788,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void setAttribute(String attributeName, Object attributeValue) {
synchronized (this.lock) {
if (attributeValue != null) {
if (!attributeValue.equals(this.sessionAttributes.put(attributeName, attributeValue))) {
@@ -785,6 +803,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void removeAttribute(String attributeName) {
synchronized (this.lock) {
if (this.sessionAttributes.remove(attributeName) != null) {
this.sessionAttributeDeltas.put(attributeName, null);
@@ -795,6 +814,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
@SuppressWarnings("unchecked")
public <T> T getAttribute(String attributeName) {
synchronized (this.lock) {
return (T) this.sessionAttributes.get(attributeName);
}
@@ -802,6 +822,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public Set<String> getAttributeNames() {
synchronized (this.lock) {
return Collections.unmodifiableSet(new HashSet<String>(this.sessionAttributes.keySet()));
}
@@ -816,6 +837,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
@Override
@SuppressWarnings("all")
public Set<Entry<String, Object>> entrySet() {
return new AbstractSet<Entry<String, Object>>() {
@Override
public Iterator<Entry<String, Object>> iterator() {
@@ -832,6 +854,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void from(Session session) {
synchronized (this.lock) {
for (String attributeName : session.getAttributeNames()) {
setAttribute(attributeName, session.getAttribute(attributeName));
@@ -841,6 +864,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void from(GemFireSessionAttributes sessionAttributes) {
synchronized (this.lock) {
for (String attributeName : sessionAttributes.getAttributeNames()) {
setAttribute(attributeName, sessionAttributes.getAttribute(attributeName));
@@ -850,6 +874,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void toData(DataOutput out) throws IOException {
synchronized (this.lock) {
Set<String> attributeNames = getAttributeNames();
@@ -869,6 +894,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
synchronized (this.lock) {
for (int count = in.readInt(); count > 0; count--) {
setAttribute(in.readUTF(), readObject(in));
@@ -885,6 +911,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public boolean hasDelta() {
synchronized (this.lock) {
return !this.sessionAttributeDeltas.isEmpty();
}
@@ -892,7 +919,9 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void toDelta(DataOutput out) throws IOException {
synchronized (this.lock) {
out.writeInt(this.sessionAttributeDeltas.size());
for (Map.Entry<String, Object> entry : this.sessionAttributeDeltas.entrySet()) {
@@ -906,6 +935,7 @@ public abstract class AbstractGemFireOperationsSessionRepository extends CacheLi
/* (non-Javadoc) */
public void fromDelta(DataInput in) throws InvalidDeltaException, IOException {
synchronized (this.lock) {
try {
int count = in.readInt();

View File

@@ -30,18 +30,20 @@ import org.springframework.session.SessionRepository;
* that interfaces with and uses GemFire to back and store Spring Sessions.
*
* @author John Blum
* @since 1.1.0
* @see org.springframework.data.gemfire.GemfireOperations
* @see org.springframework.session.ExpiringSession
* @see org.springframework.session.data.gemfire.AbstractGemFireOperationsSessionRepository
* @since 1.1.0
*/
public class GemFireOperationsSessionRepository extends AbstractGemFireOperationsSessionRepository {
// GemFire OQL query used to lookup Sessions by arbitrary attributes.
protected static final String FIND_SESSIONS_BY_INDEX_NAME_VALUE_QUERY = "SELECT s FROM %1$s s WHERE s.attributes['%2$s'] = $1";
protected static final String FIND_SESSIONS_BY_INDEX_NAME_VALUE_QUERY =
"SELECT s FROM %1$s s WHERE s.attributes['%2$s'] = $1";
// GemFire OQL query used to look up Sessions by principal name.
protected static final String FIND_SESSIONS_BY_PRINCIPAL_NAME_QUERY = "SELECT s FROM %1$s s WHERE s.principalName = $1";
protected static final String FIND_SESSIONS_BY_PRINCIPAL_NAME_QUERY =
"SELECT s FROM %1$s s WHERE s.principalName = $1";
/**
* Constructs an instance of GemFireOperationsSessionRepository initialized with the
@@ -71,6 +73,7 @@ public class GemFireOperationsSessionRepository extends AbstractGemFireOperation
* @see #prepareQuery(String)
*/
public Map<String, ExpiringSession> findByIndexNameAndIndexValue(String indexName, String indexValue) {
SelectResults<ExpiringSession> results = getTemplate().find(prepareQuery(indexName), indexValue);
Map<String, ExpiringSession> sessions = new HashMap<String, ExpiringSession>(results.size());
@@ -91,6 +94,7 @@ public class GemFireOperationsSessionRepository extends AbstractGemFireOperation
* Session attribute.
*/
protected String prepareQuery(String indexName) {
return (PRINCIPAL_NAME_INDEX_NAME.equals(indexName)
? String.format(FIND_SESSIONS_BY_PRINCIPAL_NAME_QUERY, getFullyQualifiedRegionName())
: String.format(FIND_SESSIONS_BY_INDEX_NAME_VALUE_QUERY, getFullyQualifiedRegionName(), indexName));
@@ -119,6 +123,7 @@ public class GemFireOperationsSessionRepository extends AbstractGemFireOperation
* @see #delete(String)
*/
public ExpiringSession getSession(String sessionId) {
ExpiringSession storedSession = getTemplate().get(sessionId);
if (storedSession != null) {

View File

@@ -22,18 +22,21 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.servlet.http.HttpSession;
import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.session.web.http.SessionRepositoryFilter;
/**
* Add this annotation to a Spring {@code @Configuration} class to expose the SessionRepositoryFilter
* as a bean named "springSessionRepositoryFilter" and backed by Pivotal GemFire or Apache Geode.
* Add this annotation to a Spring {@code @Configuration} class to expose the {@link SessionRepositoryFilter}
* as a bean named {@literal springSessionRepositoryFilter} back the {@link HttpSession}
* by Pivotal GemFire or Apache Geode.
*
* In order to leverage the annotation, a single Pivotal GemFire/Apache Geode
* {@link org.apache.geode.cache.Cache}
* In order to use this annotation, a single Pivotal GemFire/Apache Geode {@link org.apache.geode.cache.Cache}
* or {@link org.apache.geode.cache.client.ClientCache} instance must be provided.
*
* For example:
@@ -46,24 +49,31 @@ import org.springframework.context.annotation.Import;
*
* {@literal @Bean}
* public Properties gemfireProperties() {
*
* Properties gemfireProperties = new Properties();
*
* gemfireProperties.setProperty("name", "ExamplePeer");
* gemfireProperties.setProperty("mcast-port", "0");
* gemfireProperties.setProperty("log-level", "warning");
*
* return gemfireProperties;
* }
*
* {@literal @Bean}
* public CacheFactoryBean gemfireCache() throws Exception {
*
* CacheFactoryBean cache = new CacheFactoryBean();
*
* cache.setClose(true);
* cache.setProperties(gemfireProperties());
*
* return cache;
* }
* }
* </code> </pre>
*
* Alternatively, Spring Session can be configured to use Pivotal GemFire (Apache Geode) as a client
* using a dedicated GemFire Server cluster and a {@link org.apache.geode.cache.client.ClientCache}.
* Alternatively, Spring Session can be configured to use Pivotal GemFire/Apache Geode as a cache client
* with a dedicated Pivotal GemFire/Apache Geode cluster and a {@link org.apache.geode.cache.client.ClientCache}.
*
* For example:
*
@@ -74,24 +84,33 @@ import org.springframework.context.annotation.Import;
*
* {@literal @Bean}
* public Properties gemfireProperties() {
*
* Properties gemfireProperties = new Properties();
*
* gemfireProperties.setProperty("name", "ExampleClient");
* gemfireProperties.setProperty("log-level", "warning");
*
* return gemfireProperties;
* }
*
* {@literal @Bean}
* public ClientCacheFactoryBean gemfireCache() throws Exception {
*
* ClientCacheFactoryBean clientCache = new ClientCacheFactoryBean();
*
* clientCache.setClose(true)
* clientCache.setProperties(gemfireProperties());
*
* return clientCache;
* }
*
* {@literal @Bean}
* public PoolFactoryBean gemfirePool() {
*
* PoolFactoryBean pool = new PoolFactoryBean();
* pool.addServer(new ConnectionEndpoint("serverHost", 40404);
*
* pool.addServer(new ConnectionEndpoint("localhost", 40404);
*
* return pool;
* }
* }

View File

@@ -16,6 +16,7 @@
package org.springframework.session.data.gemfire.config.annotation.web.http;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import org.apache.geode.cache.ExpirationAction;
@@ -52,26 +53,37 @@ import org.springframework.util.StringUtils;
/**
* The {@link GemFireHttpSessionConfiguration} class is a Spring {@link Configuration @Configuration} class
* used to configure and initialize Pivotal GemFire (or Apache Geode) as a clustered, replicated
* used to configure and initialize Pivotal GemFire/Apache Geode as a clustered, replicated and distributed
* {@link javax.servlet.http.HttpSession} provider implementation in Spring {@link ExpiringSession}.
*
* @author John Blum
* @see org.apache.geode.cache.ExpirationAttributes
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.Region
* @see org.apache.geode.cache.RegionAttributes
* @see org.apache.geode.cache.RegionShortcut
* @see org.apache.geode.cache.client.ClientRegionShortcut
* @see org.apache.geode.cache.client.Pool
* @see org.springframework.beans.factory.BeanClassLoaderAware
* @see org.springframework.context.annotation.Bean
* @see org.springframework.context.annotation.Configuration
* @see org.springframework.context.annotation.ImportAware
* @see org.springframework.core.type.AnnotationMetadata
* @see org.springframework.data.gemfire.GemfireOperations
* @see org.springframework.data.gemfire.GemfireTemplate
* @see org.springframework.data.gemfire.IndexFactoryBean
* @see org.springframework.data.gemfire.IndexType
* @see org.springframework.data.gemfire.RegionAttributesFactoryBean
* @see org.springframework.session.ExpiringSession
* @see org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration
* @see org.springframework.session.data.gemfire.GemFireOperationsSessionRepository
* @see org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.GemFireCacheTypeAwareRegionFactoryBean
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionAttributesIndexFactoryBean
* @since 1.1.0
*/
@Configuration
@SuppressWarnings("unused")
public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfiguration
implements BeanClassLoaderAware, ImportAware {
@@ -171,7 +183,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* @see EnableGemFireHttpSession#clientRegionShortcut()
*/
protected ClientRegionShortcut getClientRegionShortcut() {
return (this.clientRegionShortcut != null ? this.clientRegionShortcut : DEFAULT_CLIENT_REGION_SHORTCUT);
return Optional.ofNullable(this.clientRegionShortcut).orElse(DEFAULT_CLIENT_REGION_SHORTCUT);
}
/**
@@ -193,8 +205,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* @see EnableGemFireHttpSession#indexableSessionAttributes()
*/
protected String[] getIndexableSessionAttributes() {
return (this.indexableSessionAttributes != null ? this.indexableSessionAttributes
: DEFAULT_INDEXABLE_SESSION_ATTRIBUTES);
return Optional.ofNullable(this.indexableSessionAttributes).orElse(DEFAULT_INDEXABLE_SESSION_ATTRIBUTES);
}
/**
@@ -240,7 +251,10 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* @see Pool#getName()
*/
protected String getPoolName() {
return (StringUtils.hasText(this.poolName) ? this.poolName : DEFAULT_GEMFIRE_POOL_NAME);
return Optional.ofNullable(this.poolName)
.filter(StringUtils::hasText)
.orElse(DEFAULT_GEMFIRE_POOL_NAME);
}
/**
@@ -263,7 +277,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* @see EnableGemFireHttpSession#serverRegionShortcut()
*/
protected RegionShortcut getServerRegionShortcut() {
return (this.serverRegionShortcut != null ? this.serverRegionShortcut : DEFAULT_SERVER_REGION_SHORTCUT);
return Optional.ofNullable(this.serverRegionShortcut).orElse(DEFAULT_SERVER_REGION_SHORTCUT);
}
/**
@@ -286,8 +300,10 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* @see EnableGemFireHttpSession#regionName()
*/
protected String getSpringSessionGemFireRegionName() {
return (StringUtils.hasText(this.springSessionGemFireRegionName) ? this.springSessionGemFireRegionName
: DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME);
return Optional.ofNullable(this.springSessionGemFireRegionName)
.filter(StringUtils::hasText)
.orElse(DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME);
}
/**
@@ -298,25 +314,26 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
* this @Configuration class.
*/
public void setImportMetadata(AnnotationMetadata importMetadata) {
AnnotationAttributes enableGemFireHttpSessionAnnotationAttributes =
AnnotationAttributes enableGemFireHttpSessionAttributes =
AnnotationAttributes.fromMap(importMetadata.getAnnotationAttributes(
EnableGemFireHttpSession.class.getName()));
setClientRegionShortcut(ClientRegionShortcut.class.cast(enableGemFireHttpSessionAnnotationAttributes
setClientRegionShortcut(ClientRegionShortcut.class.cast(enableGemFireHttpSessionAttributes
.getEnum("clientRegionShortcut")));
setIndexableSessionAttributes(enableGemFireHttpSessionAnnotationAttributes
setIndexableSessionAttributes(enableGemFireHttpSessionAttributes
.getStringArray("indexableSessionAttributes"));
setMaxInactiveIntervalInSeconds(enableGemFireHttpSessionAnnotationAttributes
setMaxInactiveIntervalInSeconds(enableGemFireHttpSessionAttributes
.getNumber("maxInactiveIntervalInSeconds").intValue());
setPoolName(enableGemFireHttpSessionAnnotationAttributes.getString("poolName"));
setPoolName(enableGemFireHttpSessionAttributes.getString("poolName"));
setServerRegionShortcut(RegionShortcut.class.cast(enableGemFireHttpSessionAnnotationAttributes
setServerRegionShortcut(RegionShortcut.class.cast(enableGemFireHttpSessionAttributes
.getEnum("serverRegionShortcut")));
setSpringSessionGemFireRegionName(enableGemFireHttpSessionAnnotationAttributes
setSpringSessionGemFireRegionName(enableGemFireHttpSessionAttributes
.getString("regionName"));
}
@@ -407,6 +424,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
@Bean
@SuppressWarnings({ "unchecked", "deprecation" })
public RegionAttributesFactoryBean sessionRegionAttributes(GemFireCache gemfireCache) {
RegionAttributesFactoryBean regionAttributes = new RegionAttributesFactoryBean();
regionAttributes.setKeyConstraint(SPRING_SESSION_GEMFIRE_REGION_KEY_CONSTRAINT);
@@ -414,8 +432,8 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
if (isExpirationAllowed(gemfireCache)) {
regionAttributes.setStatisticsEnabled(true);
regionAttributes.setEntryIdleTimeout(
new ExpirationAttributes(Math.max(getMaxInactiveIntervalInSeconds(), 0), ExpirationAction.INVALIDATE));
regionAttributes.setEntryIdleTimeout(new ExpirationAttributes(
Math.max(getMaxInactiveIntervalInSeconds(), 0), ExpirationAction.INVALIDATE));
}
return regionAttributes;
@@ -450,6 +468,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
@Bean
@DependsOn(DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME)
public IndexFactoryBean principalNameIndex(GemFireCache gemfireCache) {
IndexFactoryBean index = new IndexFactoryBean();
index.setCache(gemfireCache);
@@ -476,6 +495,7 @@ public class GemFireHttpSessionConfiguration extends SpringHttpSessionConfigurat
@Bean
@DependsOn(DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME)
public SessionAttributesIndexFactoryBean sessionAttributesIndex(GemFireCache gemfireCache) {
SessionAttributesIndexFactoryBean sessionAttributesIndex = new SessionAttributesIndexFactoryBean();
sessionAttributesIndex.setGemFireCache(gemfireCache);

View File

@@ -16,6 +16,8 @@
package org.springframework.session.data.gemfire.config.annotation.web.http.support;
import java.util.Optional;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.InterestResultPolicy;
import org.apache.geode.cache.Region;
@@ -41,14 +43,23 @@ import org.springframework.util.StringUtils;
* used to construct, configure and initialize the GemFire cache {@link Region} used to
* store and manage Session state.
*
* @author John Blum
* @param <K> the type of keys
* @param <V> the type of values
* @author John Blum
* @since 1.1.0
* @see org.springframework.data.gemfire.GenericRegionFactoryBean
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.Region
* @see org.apache.geode.cache.RegionAttributes
* @see org.apache.geode.cache.RegionShortcut
* @see org.apache.geode.cache.client.ClientRegionShortcut
* @see org.apache.geode.cache.client.Pool
* @see org.springframework.beans.factory.BeanFactory
* @see org.springframework.beans.factory.BeanFactoryAware
* @see org.springframework.beans.factory.FactoryBean
* @see org.springframework.beans.factory.InitializingBean
* @see org.springframework.data.gemfire.GenericRegionFactoryBean
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
* @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration
* @since 1.1.0
*/
public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
implements BeanFactoryAware, FactoryBean<Region<K, V>>, InitializingBean {
@@ -93,6 +104,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
* @see #newServerRegion(GemFireCache)
*/
public void afterPropertiesSet() throws Exception {
GemFireCache gemfireCache = getGemfireCache();
this.region = (GemFireUtils.isClient(gemfireCache) ? newClientRegion(gemfireCache)
@@ -118,6 +130,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
* @see #getServerRegionShortcut()
*/
protected Region<K, V> newServerRegion(GemFireCache gemfireCache) throws Exception {
GenericRegionFactoryBean<K, V> serverRegion = new GenericRegionFactoryBean<K, V>();
serverRegion.setAttributes(getRegionAttributes());
@@ -149,6 +162,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
* @see #registerInterests(boolean)
*/
protected Region<K, V> newClientRegion(GemFireCache gemfireCache) throws Exception {
ClientRegionFactoryBean<K, V> clientRegion = new ClientRegionFactoryBean<K, V>();
ClientRegionShortcut shortcut = getClientRegionShortcut();
@@ -176,7 +190,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
@SuppressWarnings("unchecked")
protected Interest<K>[] registerInterests(boolean register) {
return (!register ? new Interest[0] : new Interest[] {
new Interest<String>("ALL_KEYS", InterestResultPolicy.KEYS)
new Interest<>("ALL_KEYS", InterestResultPolicy.KEYS)
});
}
@@ -200,8 +214,9 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
* @see org.apache.geode.cache.Region
* @see java.lang.Class
*/
@SuppressWarnings("unuchecked")
public Class<?> getObjectType() {
return (this.region != null ? this.region.getClass() : Region.class);
return Optional.ofNullable(this.region).map(Object::getClass).orElse((Class) Region.class);
}
/**
@@ -224,7 +239,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
* @see org.springframework.beans.factory.BeanFactory
*/
public void setBeanFactory(BeanFactory beanFactory) {
Assert.notNull(beanFactory, "BeanFactory must not be null");
Assert.notNull(beanFactory, "BeanFactory is required");
this.beanFactory = beanFactory;
}
@@ -238,8 +253,8 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
* @see org.springframework.beans.factory.BeanFactory
*/
protected BeanFactory getBeanFactory() {
Assert.state(this.beanFactory != null, "A reference to the BeanFactory was not properly configured");
return this.beanFactory;
return Optional.ofNullable(this.beanFactory).orElseThrow(() ->
new IllegalStateException("A reference to the BeanFactory was not properly configured"));
}
/**
@@ -264,7 +279,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
* @see org.apache.geode.cache.client.ClientRegionShortcut
*/
protected ClientRegionShortcut getClientRegionShortcut() {
return (this.clientRegionShortcut != null ? this.clientRegionShortcut : DEFAULT_CLIENT_REGION_SHORTCUT);
return Optional.ofNullable(this.clientRegionShortcut).orElse(DEFAULT_CLIENT_REGION_SHORTCUT);
}
/**
@@ -275,8 +290,8 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
* @throws IllegalArgumentException if the {@link GemFireCache} reference is null.
*/
public void setGemfireCache(GemFireCache gemfireCache) {
Assert.notNull(gemfireCache, "GemFireCache must not be null");
this.gemfireCache = gemfireCache;
this.gemfireCache = Optional.ofNullable(gemfireCache).orElseThrow(() ->
new IllegalArgumentException("GemFireCache is required"));
}
/**
@@ -287,8 +302,8 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
* @throws IllegalStateException if the {@link GemFireCache} reference is null.
*/
protected GemFireCache getGemfireCache() {
Assert.state(this.gemfireCache != null, "A reference to the GemFireCache was not properly configured");
return this.gemfireCache;
return Optional.ofNullable(this.gemfireCache).orElseThrow(() ->
new IllegalStateException("A reference to the GemFireCache was not properly configured"));
}
/**
@@ -310,7 +325,7 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
* @see Pool#getName()
*/
protected String getPoolName() {
return (StringUtils.hasText(this.poolName) ? this.poolName : DEFAULT_GEMFIRE_POOL_NAME);
return Optional.ofNullable(this.poolName).filter(StringUtils::hasText).orElse(DEFAULT_GEMFIRE_POOL_NAME);
}
/**
@@ -355,7 +370,8 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
* @see org.apache.geode.cache.Region#getName()
*/
protected String getRegionName() {
return (StringUtils.hasText(this.regionName) ? this.regionName : DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME);
return Optional.ofNullable(this.regionName).filter(StringUtils::hasText)
.orElse(DEFAULT_SPRING_SESSION_GEMFIRE_REGION_NAME);
}
/**
@@ -379,6 +395,6 @@ public class GemFireCacheTypeAwareRegionFactoryBean<K, V>
* @see org.apache.geode.cache.RegionShortcut
*/
protected RegionShortcut getServerRegionShortcut() {
return (this.serverRegionShortcut != null ? this.serverRegionShortcut : DEFAULT_SERVER_REGION_SHORTCUT);
return Optional.ofNullable(this.serverRegionShortcut).orElse(DEFAULT_SERVER_REGION_SHORTCUT);
}
}

View File

@@ -16,6 +16,8 @@
package org.springframework.session.data.gemfire.config.annotation.web.http.support;
import java.util.Optional;
import javax.servlet.http.HttpSession;
import org.apache.geode.cache.GemFireCache;
@@ -43,8 +45,8 @@ import org.springframework.util.ObjectUtils;
* @see org.springframework.beans.factory.InitializingBean
* @see org.apache.geode.cache.query.Index
*/
public class SessionAttributesIndexFactoryBean implements FactoryBean<Index>,
InitializingBean, BeanFactoryAware, BeanNameAware {
public class SessionAttributesIndexFactoryBean
implements FactoryBean<Index>, InitializingBean, BeanFactoryAware, BeanNameAware {
protected static final String[] DEFAULT_INDEXABLE_SESSION_ATTRIBUTES = {};
@@ -61,6 +63,7 @@ public class SessionAttributesIndexFactoryBean implements FactoryBean<Index>,
/* (non-Javadoc) */
public void afterPropertiesSet() throws Exception {
if (isIndexableSessionAttributesConfigured()) {
this.sessionAttributesIndex = newIndex();
}
@@ -85,6 +88,7 @@ public class SessionAttributesIndexFactoryBean implements FactoryBean<Index>,
* @see org.springframework.data.gemfire.IndexFactoryBean
*/
protected Index newIndex() throws Exception {
IndexFactoryBean indexFactory = new IndexFactoryBean();
indexFactory.setBeanFactory(this.beanFactory);
@@ -110,6 +114,7 @@ public class SessionAttributesIndexFactoryBean implements FactoryBean<Index>,
* @see org.apache.geode.cache.query.Index#getIndexedExpression()
*/
protected String getIndexableSessionAttributesAsGemFireIndexExpression() {
StringBuilder builder = new StringBuilder();
for (String sessionAttribute : getIndexableSessionAttributes()) {
@@ -128,8 +133,9 @@ public class SessionAttributesIndexFactoryBean implements FactoryBean<Index>,
}
/* (non-Javadoc) */
@SuppressWarnings("unchecked")
public Class<?> getObjectType() {
return (this.sessionAttributesIndex != null ? this.sessionAttributesIndex.getClass() : Index.class);
return Optional.ofNullable(this.sessionAttributesIndex).map(Object::getClass).orElse((Class) Index.class);
}
/* (non-Javadoc) */
@@ -159,8 +165,7 @@ public class SessionAttributesIndexFactoryBean implements FactoryBean<Index>,
/* (non-Javadoc) */
protected String[] getIndexableSessionAttributes() {
return (this.indexableSessionAttributes != null ? this.indexableSessionAttributes
: DEFAULT_INDEXABLE_SESSION_ATTRIBUTES);
return Optional.ofNullable(this.indexableSessionAttributes).orElse(DEFAULT_INDEXABLE_SESSION_ATTRIBUTES);
}
/* (non-Javadoc) */

View File

@@ -46,6 +46,7 @@ public abstract class GemFireUtils {
* @see java.io.Closeable
*/
public static boolean close(Closeable obj) {
if (obj != null) {
try {
obj.close();
@@ -93,15 +94,16 @@ public abstract class GemFireUtils {
* @see org.apache.geode.cache.client.ClientRegionShortcut
*/
public static boolean isLocal(ClientRegionShortcut shortcut) {
switch (shortcut) {
case LOCAL:
case LOCAL_HEAP_LRU:
case LOCAL_OVERFLOW:
case LOCAL_PERSISTENT:
case LOCAL_PERSISTENT_OVERFLOW:
return true;
default:
return false;
case LOCAL:
case LOCAL_HEAP_LRU:
case LOCAL_OVERFLOW:
case LOCAL_PERSISTENT:
case LOCAL_PERSISTENT_OVERFLOW:
return true;
default:
return false;
}
}
@@ -115,11 +117,12 @@ public abstract class GemFireUtils {
* @see org.apache.geode.cache.client.ClientRegionShortcut
*/
public static boolean isProxy(ClientRegionShortcut shortcut) {
switch (shortcut) {
case PROXY:
return true;
default:
return false;
case PROXY:
return true;
default:
return false;
}
}
@@ -146,13 +149,14 @@ public abstract class GemFireUtils {
* @see org.apache.geode.cache.RegionShortcut
*/
public static boolean isProxy(RegionShortcut shortcut) {
switch (shortcut) {
case PARTITION_PROXY:
case PARTITION_PROXY_REDUNDANT:
case REPLICATE_PROXY:
return true;
default:
return false;
case PARTITION_PROXY:
case PARTITION_PROXY_REDUNDANT:
case REPLICATE_PROXY:
return true;
default:
return false;
}
}

View File

@@ -16,14 +16,9 @@
package org.springframework.session.data.gemfire.config.annotation.web.http.support;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.InterestResultPolicy;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientRegionShortcut;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -32,13 +27,19 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.InterestResultPolicy;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.data.gemfire.client.Interest;
import org.springframework.session.ExpiringSession;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
* The GemFireCacheTypeAwareRegionFactoryBeanTest class is a test suite of test cases
* testing the contract and functionality of the GemFireCacheTypeAwareRegionFactoryBean
@@ -162,7 +163,7 @@ public class GemFireCacheTypeAwareRegionFactoryBeanTest {
@Test
public void setBeanFactoryToNullThrowsIllegalArgumentException() {
this.exception.expect(IllegalArgumentException.class);
this.exception.expectMessage("BeanFactory must not be null");
this.exception.expectMessage("BeanFactory is required");
this.regionFactoryBean.setBeanFactory(null);
}
@@ -201,7 +202,7 @@ public class GemFireCacheTypeAwareRegionFactoryBeanTest {
@Test
public void setGemfireCacheToNullThrowsIllegalArgumentException() {
this.exception.expect(IllegalArgumentException.class);
this.exception.expectMessage("GemFireCache must not be null");
this.exception.expectMessage("GemFireCache is required");
this.regionFactoryBean.setGemfireCache(null);
}