Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Align Spring Session MongoDB with WebSession API. #54

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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/]
8 changes: 4 additions & 4 deletions CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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].
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
"https://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<!-- Suppressions -->
<module name="SuppressionFilter">
Expand Down
2 changes: 1 addition & 1 deletion config/checkstyle/header.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand Down
2 changes: 1 addition & 1 deletion config/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
"https://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress files=".+Application\.java" checks="HideUtilityClassConstructor"/>
<suppress files=".+Configuration\.java" checks="HideUtilityClassConstructor"/>
Expand Down
2 changes: 1 addition & 1 deletion mvnw
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mvnw.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-mongodb</artifactId>
<version>2.1.2.BUILD-SNAPSHOT</version>

<name>Spring Session MongoDB</name>
<url>http://spring.io/projects/spring-session-data-mongodb</url>
<url>https://spring.io/projects/spring-session-data-mongodb</url>
<description>
Persist session data in MongoDB
</description>
Expand Down Expand Up @@ -45,15 +45,15 @@
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
<comments>
Copyright 2011-2018 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.
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,
Expand Down Expand Up @@ -99,7 +99,7 @@
<repositories>
<repository>
<id>spring-libs-snapshot</id>
<url>http://repo.spring.io/libs-snapshot</url>
<url>https://repo.spring.io/libs-snapshot</url>
</repository>
</repositories>
</profile>
Expand Down Expand Up @@ -223,7 +223,7 @@
<archives>*:*:*:*@zip zip.name:spring-session-data-mongodb, zip.displayname:Spring Session MongoDB, zip.deployed:false</archives>
</deployProperties>
<publisher>
<contextUrl>http://repo.spring.io</contextUrl>
<contextUrl>https://repo.spring.io</contextUrl>
<username>{{USERNAME}}</username>
<password>{{PASSWORD}}</password>
<repoKey>libs-milestone-local</repoKey>
Expand Down Expand Up @@ -258,7 +258,7 @@
<archives>*:*:*:*@zip zip.name:spring-session-data-mongodb, zip.displayname:Spring Session MongoDB, zip.deployed:false</archives>
</deployProperties>
<publisher>
<contextUrl>http://repo.spring.io</contextUrl>
<contextUrl>https://repo.spring.io</contextUrl>
<username>{{USERNAME}}</username>
<password>{{PASSWORD}}</password>
<repoKey>libs-release-local</repoKey>
Expand Down Expand Up @@ -648,8 +648,8 @@
<quiet>true</quiet>
<additionalparam>-Xdoclint:none</additionalparam>
<links>
<link>http://static.springframework.org/spring/docs/4.1.x/javadoc-api</link>
<link>http://docs.oracle.com/javase/6/docs/api</link>
<link>https://docs.spring.io/spring/docs/4.1.x/javadoc-api</link>
<link>https://docs.oracle.com/javase/6/docs/api</link>
</links>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion settings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
https://maven.apache.org/xsd/settings-1.0.0.xsd">

<servers>
<server>
Expand Down
2 changes: 1 addition & 1 deletion src/main/asciidoc/guides/boot-mongo.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]]
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -95,7 +95,19 @@ public MongoSession createSession() {

@Override
public void save(MongoSession session) {
this.mongoOperations.save(convertToDBObject(this.mongoSessionConverter, session), this.collectionName);

Copy link
Contributor

Choose a reason for hiding this comment

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

The reported issue and this PR are for alignment with WebSession API, which is a reactive thing, so we likely shouldn't make changes to MongoOperationsSessionRepository.

We can revisit that depending on outcome of spring-projects/spring-session#1277 as ideally we'd make the behavior switch for all SessionRepository implementations in sync.

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -51,6 +51,7 @@ public class MongoSession implements Session {
private long intervalSeconds;
@Getter @Setter private Date expireAt;
private Map<String, Object> attrs = new HashMap<>();
private boolean isNew = true;

public MongoSession() {
this(MongoOperationsSessionRepository.DEFAULT_INACTIVE_INTERVAL);
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -107,9 +107,18 @@ public Mono<MongoSession> createSession() {
@Override
public Mono<Void> 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())
Copy link
Contributor

Choose a reason for hiding this comment

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

While this works, you could do probably do a ReactiveMongoOperations#collectionExists to optimize by removing deserialization cost from the mix, right?

You could also compose the implementation of this method in such way to avoid writing the duplicate ReactiveMongoOperations#save call - see ReactiveRedisOperationsSessionRepository#save for inspiration.

.map(document -> this.mongoOperations.save(convertToDBObject(this.mongoSessionConverter, session), this.collectionName))
.switchIfEmpty(Mono.error(new IllegalStateException("Session was invalidated")))
.then();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading