diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java index fa4f7b49..2e394d5b 100755 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -7,7 +7,7 @@ Licensed to the Apache Software Foundation (ASF) under one "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an diff --git a/CODE_OF_CONDUCT.adoc b/CODE_OF_CONDUCT.adoc index f013d6f3..17783c7c 100644 --- a/CODE_OF_CONDUCT.adoc +++ b/CODE_OF_CONDUCT.adoc @@ -40,5 +40,5 @@ appropriate to the circumstances. Maintainers are obligated to maintain confiden with regard to the reporter of an incident. This Code of Conduct is adapted from the -http://contributor-covenant.org[Contributor Covenant], version 1.3.0, available at -http://contributor-covenant.org/version/1/3/0/[contributor-covenant.org/version/1/3/0/] +https://contributor-covenant.org[Contributor Covenant], version 1.3.0, available at +https://contributor-covenant.org/version/1/3/0/[contributor-covenant.org/version/1/3/0/] diff --git a/CONTRIBUTING.adoc b/CONTRIBUTING.adoc index 164f775f..6ae09c13 100644 --- a/CONTRIBUTING.adoc +++ b/CONTRIBUTING.adoc @@ -12,21 +12,21 @@ By participating, you are expected to uphold this code. Please report unaccepta None of these is essential for a pull request, but they will all help. They can also be added after the original pull request but before a merge. -* Use the Spring Data code format conventions. If you use Eclipse you can import formatter settings using the `eclipse-code-formatter.xml` file from the https://raw.githubusercontent.com/spring-projects/spring-data-build/master/etc/ide/eclipse-formatting.xml[Spring Data Build] project. If using IntelliJ, you can use the http://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter Plugin] to import the same file. +* Use the Spring Data code format conventions. If you use Eclipse you can import formatter settings using the `eclipse-code-formatter.xml` file from the https://raw.githubusercontent.com/spring-projects/spring-data-build/master/etc/ide/eclipse-formatting.xml[Spring Data Build] project. If using IntelliJ, you can use the https://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter Plugin] to import the same file. * Make sure all new `.java` files to have a simple Javadoc class comment with at least an `@author` tag identifying you, and preferably at least a paragraph on what the class is for. * Add the ASF license header comment to all new `.java` files (copy from existing files in the project) * Add yourself as an `@author` to the .java files that you modify substantially (more than cosmetic changes). * Add some Javadocs and, if you change the namespace, some XSD doc elements. * A few unit tests would help a lot as well -- someone has to do it. * If no-one else is using your branch, please rebase it against the current master (or other target branch in the main project). -* When writing a commit message please follow http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions], if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit message (where XXXX is the issue number). +* When writing a commit message please follow https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions], if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit message (where XXXX is the issue number). * By the way, any contributions are likely to be polished. Don't worry! Just use it as a learning experience as you are slowly jürgenized. == Using GitHub issues We use GitHub issues to track bugs and enhancements. If you have a general usage question -please ask on http://stackoverflow.com[Stack Overflow]. The Spring Session team and the -broader community monitor the http://stackoverflow.com/tags/spring-session[`spring-session`] +please ask on https://stackoverflow.com[Stack Overflow]. The Spring Session team and the +broader community monitor the https://stackoverflow.com/tags/spring-session[`spring-session`] tag. If you are reporting a bug, please help to speed up problem diagnosis by providing as much diff --git a/LICENSE.txt b/LICENSE.txt index d6456956..62589edd 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,7 +1,7 @@ Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/ + https://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION @@ -193,7 +193,7 @@ you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/README.adoc b/README.adoc index 30a71ba1..826f3c48 100644 --- a/README.adoc +++ b/README.adoc @@ -130,8 +130,8 @@ By participating, you are expected to uphold this code. Please report unaccepta = Spring Session Project Site -You can find the documentation, issue management, support, samples, and guides for using Spring Session MongoDB at http://projects.spring.io/spring-session-data-mongodb/ +You can find the documentation, issue management, support, samples, and guides for using Spring Session MongoDB at https://projects.spring.io/spring-session-data-mongodb/ = License -Spring Session is Open Source software released under the http://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0 license]. +Spring Session is Open Source software released under the https://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0 license]. diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 23c7eb61..f077801a 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -1,6 +1,6 @@ + "https://www.puppycrawl.com/dtds/configuration_1_3.dtd"> diff --git a/config/checkstyle/header.txt b/config/checkstyle/header.txt index 501a5343..dcb4cc6e 100644 --- a/config/checkstyle/header.txt +++ b/config/checkstyle/header.txt @@ -5,7 +5,7 @@ ^\Q * you may not use this file except in compliance with the License.\E$ ^\Q * You may obtain a copy of the License at\E$ ^\Q *\E$ -^\Q * http://www.apache.org/licenses/LICENSE-2.0\E$ +^\Q * https://www.apache.org/licenses/LICENSE-2.0\E$ ^\Q *\E$ ^\Q * Unless required by applicable law or agreed to in writing, software\E$ ^\Q * distributed under the License is distributed on an "AS IS" BASIS,\E$ diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml index 915c20fb..cf19e974 100644 --- a/config/checkstyle/suppressions.xml +++ b/config/checkstyle/suppressions.xml @@ -1,6 +1,6 @@ + "https://www.puppycrawl.com/dtds/suppressions_1_1.dtd"> diff --git a/mvnw b/mvnw index 5551fde8..8b9da3b8 100755 --- a/mvnw +++ b/mvnw @@ -8,7 +8,7 @@ # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an diff --git a/mvnw.cmd b/mvnw.cmd index e5cfb0ae..fef5a8f7 100755 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -7,7 +7,7 @@ @REM "License"); you may not use this file except in compliance @REM with the License. You may obtain a copy of the License at @REM -@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM https://www.apache.org/licenses/LICENSE-2.0 @REM @REM Unless required by applicable law or agreed to in writing, @REM software distributed under the License is distributed on an diff --git a/pom.xml b/pom.xml index 09c213e2..63b678da 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,5 @@ - + 4.0.0 org.springframework.session @@ -7,7 +7,7 @@ 2.1.2.BUILD-SNAPSHOT Spring Session MongoDB - http://spring.io/projects/spring-session-data-mongodb + https://spring.io/projects/spring-session-data-mongodb Persist session data in MongoDB @@ -45,7 +45,7 @@ Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0 + https://www.apache.org/licenses/LICENSE-2.0 Copyright 2011-2018 the original author or authors. @@ -53,7 +53,7 @@ you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -99,7 +99,7 @@ spring-libs-snapshot - http://repo.spring.io/libs-snapshot + https://repo.spring.io/libs-snapshot @@ -223,7 +223,7 @@ *:*:*:*@zip zip.name:spring-session-data-mongodb, zip.displayname:Spring Session MongoDB, zip.deployed:false - http://repo.spring.io + https://repo.spring.io {{USERNAME}} {{PASSWORD}} libs-milestone-local @@ -258,7 +258,7 @@ *:*:*:*@zip zip.name:spring-session-data-mongodb, zip.displayname:Spring Session MongoDB, zip.deployed:false - http://repo.spring.io + https://repo.spring.io {{USERNAME}} {{PASSWORD}} libs-release-local @@ -648,8 +648,8 @@ true -Xdoclint:none - http://static.springframework.org/spring/docs/4.1.x/javadoc-api - http://docs.oracle.com/javase/6/docs/api + https://docs.spring.io/spring/docs/4.1.x/javadoc-api + https://docs.oracle.com/javase/6/docs/api diff --git a/settings.xml b/settings.xml index cf86357e..829f33c3 100644 --- a/settings.xml +++ b/settings.xml @@ -1,7 +1,7 @@ + https://maven.apache.org/xsd/settings-1.0.0.xsd"> diff --git a/src/main/asciidoc/guides/boot-mongo.adoc b/src/main/asciidoc/guides/boot-mongo.adoc index 4502056e..0ea0d939 100644 --- a/src/main/asciidoc/guides/boot-mongo.adoc +++ b/src/main/asciidoc/guides/boot-mongo.adoc @@ -92,7 +92,7 @@ spring.data.mongodb.port=27018 spring.data.mongodb.database=prod ---- -For more information, refer to http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-connecting-to-mongodb[Connecting to MongoDB] portion of the Spring Boot documentation. +For more information, refer to https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-connecting-to-mongodb[Connecting to MongoDB] portion of the Spring Boot documentation. [[boot-servlet-configuration]] == Servlet Container Initialization diff --git a/src/main/asciidoc/index.adoc b/src/main/asciidoc/index.adoc index 6e6a8694..6e1125ed 100644 --- a/src/main/asciidoc/index.adoc +++ b/src/main/asciidoc/index.adoc @@ -12,7 +12,7 @@ Spring Session MongoDB provides an API and implementations for managing a user's [[introduction]] == Introduction -For an introduction to Spring Session as a whole, visit http://docs.spring.io/spring-session/docs/{spring-session-version}/reference/html5/[Spring Session] itself. +For an introduction to Spring Session as a whole, visit https://docs.spring.io/spring-session/docs/{spring-session-version}/reference/html5/[Spring Session] itself. [[samples]] == Samples and Guides (Start Here) @@ -104,7 +104,7 @@ Please find additional information below. [[community-support]] === Support -You can get help by asking questions on http://stackoverflow.com/questions/tagged/spring-session[StackOverflow with the tag spring-session]. +You can get help by asking questions on https://stackoverflow.com/questions/tagged/spring-session[StackOverflow with the tag spring-session]. Similarly we encourage helping others by answering questions on StackOverflow. [[community-source]] @@ -125,7 +125,7 @@ We appreciate https://help.github.com/articles/using-pull-requests/[Pull Request [[community-license]] === License -Spring Session is Open Source software released under the http://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0 license]. +Spring Session is Open Source software released under the https://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0 license]. [[minimum-requirements]] == Minimum Requirements diff --git a/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java b/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java index 40d29d3f..8844f9bb 100644 --- a/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java +++ b/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/main/java/org/springframework/session/data/mongo/AuthenticationParser.java b/src/main/java/org/springframework/session/data/mongo/AuthenticationParser.java index 816fb049..e3f96ab0 100644 --- a/src/main/java/org/springframework/session/data/mongo/AuthenticationParser.java +++ b/src/main/java/org/springframework/session/data/mongo/AuthenticationParser.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/main/java/org/springframework/session/data/mongo/JacksonMongoSessionConverter.java b/src/main/java/org/springframework/session/data/mongo/JacksonMongoSessionConverter.java index e0acbf2e..3897fcdd 100644 --- a/src/main/java/org/springframework/session/data/mongo/JacksonMongoSessionConverter.java +++ b/src/main/java/org/springframework/session/data/mongo/JacksonMongoSessionConverter.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/main/java/org/springframework/session/data/mongo/JdkMongoSessionConverter.java b/src/main/java/org/springframework/session/data/mongo/JdkMongoSessionConverter.java index 09187bb8..e436a6a6 100644 --- a/src/main/java/org/springframework/session/data/mongo/JdkMongoSessionConverter.java +++ b/src/main/java/org/springframework/session/data/mongo/JdkMongoSessionConverter.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/main/java/org/springframework/session/data/mongo/MongoOperationsSessionRepository.java b/src/main/java/org/springframework/session/data/mongo/MongoOperationsSessionRepository.java index 3d802c74..9e7a33ba 100644 --- a/src/main/java/org/springframework/session/data/mongo/MongoOperationsSessionRepository.java +++ b/src/main/java/org/springframework/session/data/mongo/MongoOperationsSessionRepository.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -95,7 +95,19 @@ public MongoSession createSession() { @Override public void save(MongoSession session) { - this.mongoOperations.save(convertToDBObject(this.mongoSessionConverter, session), this.collectionName); + + if (session.isNew()) { + + session.setNew(false); + this.mongoOperations.save(convertToDBObject(this.mongoSessionConverter, session), this.collectionName); + } else { + + if (findSession(session.getId()) == null) { + throw new IllegalStateException("Session was invalidated"); + } else { + this.mongoOperations.save(convertToDBObject(this.mongoSessionConverter, session), this.collectionName); + } + } } @Override diff --git a/src/main/java/org/springframework/session/data/mongo/MongoSession.java b/src/main/java/org/springframework/session/data/mongo/MongoSession.java index 6dc91a81..99685fe5 100644 --- a/src/main/java/org/springframework/session/data/mongo/MongoSession.java +++ b/src/main/java/org/springframework/session/data/mongo/MongoSession.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -51,6 +51,7 @@ public class MongoSession implements Session { private long intervalSeconds; @Getter @Setter private Date expireAt; private Map attrs = new HashMap<>(); + private boolean isNew = true; public MongoSession() { this(MongoOperationsSessionRepository.DEFAULT_INACTIVE_INTERVAL); @@ -129,6 +130,14 @@ public boolean isExpired() { return this.intervalSeconds >= 0 && new Date().after(this.expireAt); } + public void setNew(boolean isNew) { + this.isNew = isNew; + } + + public boolean isNew() { + return this.isNew; + } + static String coverDot(String attributeName) { return attributeName.replace('.', DOT_COVER_CHAR); } diff --git a/src/main/java/org/springframework/session/data/mongo/MongoSessionUtils.java b/src/main/java/org/springframework/session/data/mongo/MongoSessionUtils.java index e8f27078..7debd9c4 100644 --- a/src/main/java/org/springframework/session/data/mongo/MongoSessionUtils.java +++ b/src/main/java/org/springframework/session/data/mongo/MongoSessionUtils.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java b/src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java index 83fa6b5e..84bddb59 100644 --- a/src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java +++ b/src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -107,9 +107,18 @@ public Mono createSession() { @Override public Mono save(MongoSession session) { - return this.mongoOperations - .save(convertToDBObject(this.mongoSessionConverter, session), this.collectionName) - .then(); + if (session.isNew()) { + + session.setNew(false); + return this.mongoOperations.save(convertToDBObject(this.mongoSessionConverter, session), this.collectionName) + .then(); + } else { + + return findSession(session.getId()) + .map(document -> this.mongoOperations.save(convertToDBObject(this.mongoSessionConverter, session), this.collectionName)) + .switchIfEmpty(Mono.error(new IllegalStateException("Session was invalidated"))) + .then(); + } } /** diff --git a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/EnableMongoHttpSession.java b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/EnableMongoHttpSession.java index de1b761d..589b42a9 100644 --- a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/EnableMongoHttpSession.java +++ b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/EnableMongoHttpSession.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.java b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.java index c8df9134..107a2617 100644 --- a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.java +++ b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/EnableMongoWebSession.java b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/EnableMongoWebSession.java index 492c712d..1e3fb991 100644 --- a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/EnableMongoWebSession.java +++ b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/EnableMongoWebSession.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java index 40274c70..abf59db2 100644 --- a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java +++ b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/AbstractMongoSessionConverterTest.java b/src/test/java/org/springframework/session/data/mongo/AbstractMongoSessionConverterTest.java index c641612d..755bef97 100644 --- a/src/test/java/org/springframework/session/data/mongo/AbstractMongoSessionConverterTest.java +++ b/src/test/java/org/springframework/session/data/mongo/AbstractMongoSessionConverterTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/AuthenticationParserTest.java b/src/test/java/org/springframework/session/data/mongo/AuthenticationParserTest.java index f4d76a61..7e4324de 100644 --- a/src/test/java/org/springframework/session/data/mongo/AuthenticationParserTest.java +++ b/src/test/java/org/springframework/session/data/mongo/AuthenticationParserTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/JacksonMongoSessionConverterTest.java b/src/test/java/org/springframework/session/data/mongo/JacksonMongoSessionConverterTest.java index 244e225c..bf918483 100644 --- a/src/test/java/org/springframework/session/data/mongo/JacksonMongoSessionConverterTest.java +++ b/src/test/java/org/springframework/session/data/mongo/JacksonMongoSessionConverterTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/JdkMongoSessionConverterTest.java b/src/test/java/org/springframework/session/data/mongo/JdkMongoSessionConverterTest.java index f03e5199..d7932fe7 100644 --- a/src/test/java/org/springframework/session/data/mongo/JdkMongoSessionConverterTest.java +++ b/src/test/java/org/springframework/session/data/mongo/JdkMongoSessionConverterTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/MongoOperationsSessionRepositoryTest.java b/src/test/java/org/springframework/session/data/mongo/MongoOperationsSessionRepositoryTest.java index 56653276..e99bd201 100644 --- a/src/test/java/org/springframework/session/data/mongo/MongoOperationsSessionRepositoryTest.java +++ b/src/test/java/org/springframework/session/data/mongo/MongoOperationsSessionRepositoryTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -62,36 +62,42 @@ public class MongoOperationsSessionRepositoryTest { private MongoOperationsSessionRepository repository; @Before - public void setUp() throws Exception { + public void setUp() { + this.repository = new MongoOperationsSessionRepository(this.mongoOperations); this.repository.setMongoSessionConverter(this.converter); } @Test - public void shouldCreateSession() throws Exception { + public void shouldCreateSession() { + // when MongoSession session = this.repository.createSession(); // then assertThat(session.getId()).isNotEmpty(); + assertThat(session.isNew()).isTrue(); assertThat(session.getMaxInactiveInterval().getSeconds()) .isEqualTo(MongoOperationsSessionRepository.DEFAULT_INACTIVE_INTERVAL); } @Test - public void shouldCreateSessionWhenMaxInactiveIntervalNotDefined() throws Exception { + public void shouldCreateSessionWhenMaxInactiveIntervalNotDefined() { + // when this.repository.setMaxInactiveIntervalInSeconds(null); MongoSession session = this.repository.createSession(); // then assertThat(session.getId()).isNotEmpty(); + assertThat(session.isNew()).isTrue(); assertThat(session.getMaxInactiveInterval().getSeconds()) .isEqualTo(MongoOperationsSessionRepository.DEFAULT_INACTIVE_INTERVAL); } @Test - public void shouldSaveSession() throws Exception { + public void shouldSaveNewSession() { + // given MongoSession session = new MongoSession(); BasicDBObject dbSession = new BasicDBObject(); @@ -99,15 +105,54 @@ public void shouldSaveSession() throws Exception { given(this.converter.convert(session, TypeDescriptor.valueOf(MongoSession.class), TypeDescriptor.valueOf(DBObject.class))).willReturn(dbSession); + // when this.repository.save(session); // then verify(this.mongoOperations).save(dbSession, MongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME); + + assertThat(session.isNew()).isFalse(); } @Test - public void shouldGetSession() throws Exception { + public void shouldHandleInvalidatedSession() { + + MongoSession session = new MongoSession(); + session.setNew(false); + + assertThatIllegalStateException().isThrownBy(() -> { + this.repository.save(session); + }).withMessage("Session was invalidated"); + } + + @Test + public void shouldSaveExistingSession() { + + // given + MongoSession session = new MongoSession(); + session.setNew(false); + BasicDBObject dbSession = new BasicDBObject(); + + Document sessionDocument = new Document(); + + given(this.mongoOperations.findById(session.getId(), Document.class, + MongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(sessionDocument); + + given(this.converter.convert(session, + TypeDescriptor.valueOf(MongoSession.class), + TypeDescriptor.valueOf(DBObject.class))).willReturn(dbSession); + + // when + this.repository.save(session); + + // then + verify(this.mongoOperations).save(dbSession, MongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME); + } + + @Test + public void shouldGetSession() { + // given String sessionId = UUID.randomUUID().toString(); Document sessionDocument = new Document(); @@ -128,7 +173,8 @@ public void shouldGetSession() throws Exception { } @Test - public void shouldHandleExpiredSession() throws Exception { + public void shouldHandleExpiredSession() { + // given String sessionId = UUID.randomUUID().toString(); Document sessionDocument = new Document(); @@ -152,7 +198,8 @@ public void shouldHandleExpiredSession() throws Exception { } @Test - public void shouldDeleteSession() throws Exception { + public void shouldDeleteSession() { + // given String sessionId = UUID.randomUUID().toString(); @@ -175,7 +222,8 @@ public void shouldDeleteSession() throws Exception { } @Test - public void shouldGetSessionsMapByPrincipal() throws Exception { + public void shouldGetSessionsMapByPrincipal() { + // given String principalNameIndexName = FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME; @@ -203,7 +251,8 @@ public void shouldGetSessionsMapByPrincipal() throws Exception { } @Test - public void shouldReturnEmptyMapForNotSupportedIndex() throws Exception { + public void shouldReturnEmptyMapForNotSupportedIndex() { + // given String index = "some_not_supported_index_name"; diff --git a/src/test/java/org/springframework/session/data/mongo/MongoSessionTest.java b/src/test/java/org/springframework/session/data/mongo/MongoSessionTest.java index 43411b19..0da68bee 100644 --- a/src/test/java/org/springframework/session/data/mongo/MongoSessionTest.java +++ b/src/test/java/org/springframework/session/data/mongo/MongoSessionTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepositoryTest.java b/src/test/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepositoryTest.java index c6a3aa66..c636faab 100644 --- a/src/test/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepositoryTest.java +++ b/src/test/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepositoryTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,6 +23,7 @@ import static org.mockito.BDDMockito.mock; import static org.mockito.BDDMockito.times; import static org.mockito.Mockito.verify; +import static org.springframework.session.data.mongo.ReactiveMongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME; import java.util.UUID; @@ -84,6 +85,7 @@ public void shouldCreateSession() { .as(StepVerifier::create) .expectNextMatches(mongoSession -> { assertThat(mongoSession.getId()).isNotEmpty(); + assertThat(mongoSession.isNew()).isTrue(); assertThat(mongoSession.getMaxInactiveInterval().getSeconds()) .isEqualTo(ReactiveMongoOperationsSessionRepository.DEFAULT_INACTIVE_INTERVAL); return true; @@ -102,6 +104,7 @@ public void shouldCreateSessionWhenMaxInactiveIntervalNotDefined() { .as(StepVerifier::create) .expectNextMatches(mongoSession -> { assertThat(mongoSession.getId()).isNotEmpty(); + assertThat(mongoSession.isNew()).isTrue(); assertThat(mongoSession.getMaxInactiveInterval().getSeconds()) .isEqualTo(ReactiveMongoOperationsSessionRepository.DEFAULT_INACTIVE_INTERVAL); return true; @@ -114,8 +117,12 @@ public void shouldSaveSession() { // given MongoSession session = new MongoSession(); + Document sessionDocument = new Document(); BasicDBObject dbSession = new BasicDBObject(); + given(this.mongoOperations.findById(session.getId(), Document.class, + DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument)); + given(this.converter.convert(session, TypeDescriptor.valueOf(MongoSession.class), TypeDescriptor.valueOf(DBObject.class))).willReturn(dbSession); @@ -127,7 +134,30 @@ public void shouldSaveSession() { .as(StepVerifier::create) .verifyComplete(); - verify(this.mongoOperations).save(dbSession, ReactiveMongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME); + assertThat(session.isNew()).isFalse(); + verify(this.mongoOperations).save(dbSession, DEFAULT_COLLECTION_NAME); + verifyNoMoreInteractions(this.mongoOperations); + } + + @Test + public void shouldCreateAnErrorWhenSavingSessionNotInMongo() { + + // given + MongoSession session = new MongoSession(); + session.setNew(false); + + given(this.mongoOperations.findById(session.getId(), Document.class, + DEFAULT_COLLECTION_NAME)).willReturn(Mono.empty()); + + // when + this.repository.save(session) + .as(StepVerifier::create) + .verifyErrorMessage("Session was invalidated"); + + assertThat(session.isNew()).isFalse(); + + verify(this.mongoOperations).findById(session.getId(), Document.class, DEFAULT_COLLECTION_NAME); + verifyNoMoreInteractions(this.mongoOperations); } @Test @@ -138,7 +168,7 @@ public void shouldGetSession() { Document sessionDocument = new Document(); given(this.mongoOperations.findById(sessionId, Document.class, - ReactiveMongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument)); + DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument)); MongoSession session = new MongoSession(); @@ -160,9 +190,9 @@ public void shouldHandleExpiredSession() { Document sessionDocument = new Document(); given(this.mongoOperations.findById(sessionId, Document.class, - ReactiveMongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument)); + DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument)); - given(this.mongoOperations.remove(sessionDocument, ReactiveMongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME)) + given(this.mongoOperations.remove(sessionDocument, DEFAULT_COLLECTION_NAME)) .willReturn(Mono.just(DeleteResult.acknowledged(1))); MongoSession session = mock(MongoSession.class); @@ -177,8 +207,7 @@ public void shouldHandleExpiredSession() { .verifyComplete(); // then - verify(this.mongoOperations).remove(any(Document.class), - eq(ReactiveMongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME)); + verify(this.mongoOperations).remove(any(Document.class), eq(DEFAULT_COLLECTION_NAME)); } @Test @@ -189,7 +218,7 @@ public void shouldDeleteSession() { Document sessionDocument = new Document(); given(this.mongoOperations.findById(sessionId, Document.class, - ReactiveMongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument)); + DEFAULT_COLLECTION_NAME)).willReturn(Mono.just(sessionDocument)); given(this.mongoOperations.remove(sessionDocument, "sessions")) .willReturn(Mono.just(DeleteResult.acknowledged(1))); @@ -204,9 +233,7 @@ public void shouldDeleteSession() { .as(StepVerifier::create) .verifyComplete(); - verify(this.mongoOperations).remove(any(Document.class), - eq(ReactiveMongoOperationsSessionRepository.DEFAULT_COLLECTION_NAME)); - + verify(this.mongoOperations).remove(any(Document.class), eq(DEFAULT_COLLECTION_NAME)); verify(this.eventPublisher).publishEvent(any(SessionDeletedEvent.class)); } @@ -225,5 +252,8 @@ public void shouldInvokeMethodToCreateIndexesImperatively() { // then verify(this.blockingMongoOperations, times(1)).indexOps((String) any()); verify(this.converter, times(1)).ensureIndexes(indexOperations); + + verifyNoMoreInteractions(this.blockingMongoOperations); + verifyNoMoreInteractions(this.converter); } } diff --git a/src/test/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfigurationTest.java b/src/test/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfigurationTest.java index f7525e85..f1d31c17 100644 --- a/src/test/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfigurationTest.java +++ b/src/test/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfigurationTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java b/src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java index 8b862d90..4c203bf2 100644 --- a/src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java +++ b/src/test/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfigurationTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/integration/AbstractClassLoaderTest.java b/src/test/java/org/springframework/session/data/mongo/integration/AbstractClassLoaderTest.java index 77a7f1b3..44895d51 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/AbstractClassLoaderTest.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/AbstractClassLoaderTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/integration/AbstractITest.java b/src/test/java/org/springframework/session/data/mongo/integration/AbstractITest.java index ec48ecbb..83b8c595 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/AbstractITest.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/AbstractITest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/integration/AbstractMongoRepositoryITest.java b/src/test/java/org/springframework/session/data/mongo/integration/AbstractMongoRepositoryITest.java index b36df66c..7cf6650c 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/AbstractMongoRepositoryITest.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/AbstractMongoRepositoryITest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/integration/MongoITestUtils.java b/src/test/java/org/springframework/session/data/mongo/integration/MongoITestUtils.java index c1008f44..ef04de31 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/MongoITestUtils.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/MongoITestUtils.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/integration/MongoRepositoryJacksonITest.java b/src/test/java/org/springframework/session/data/mongo/integration/MongoRepositoryJacksonITest.java index 8a77ef6b..b6e2042d 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/MongoRepositoryJacksonITest.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/MongoRepositoryJacksonITest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/integration/MongoRepositoryJdkSerializationITest.java b/src/test/java/org/springframework/session/data/mongo/integration/MongoRepositoryJdkSerializationITest.java index 3460eaba..b48fe122 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/MongoRepositoryJdkSerializationITest.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/MongoRepositoryJdkSerializationITest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/integration/ReactiveConfigurationTest.java b/src/test/java/org/springframework/session/data/mongo/integration/ReactiveConfigurationTest.java index 3f2f18b9..39beb2c5 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/ReactiveConfigurationTest.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/ReactiveConfigurationTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/integration/SessionEventRegistry.java b/src/test/java/org/springframework/session/data/mongo/integration/SessionEventRegistry.java index 9e98bc7f..68fd5a3f 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/SessionEventRegistry.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/SessionEventRegistry.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/test/java/org/springframework/session/data/mongo/integration/TraditionalConfigurationTest.java b/src/test/java/org/springframework/session/data/mongo/integration/TraditionalConfigurationTest.java index f7dab9ac..d7133c5d 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/TraditionalConfigurationTest.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/TraditionalConfigurationTest.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS,