├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .travis.yml ├── CODE_OF_CONDUCT.adoc ├── LICENSE ├── README.adoc ├── mvnw ├── mvnw.cmd ├── pom.xml ├── spring-session-data-mongodb-reactive-boot ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── springframework │ │ │ └── session │ │ │ └── mongodb │ │ │ └── examples │ │ │ ├── SessionAttributeForm.java │ │ │ ├── SessionController.java │ │ │ └── SpringSessionMongoReactiveApplication.java │ └── resources │ │ ├── application.yml │ │ └── templates │ │ └── index.html │ └── test │ └── java │ └── org │ └── springframework │ └── session │ └── mongodb │ └── examples │ ├── AttributeTests.java │ └── pages │ └── HomePage.java └── spring-session-data-mongodb-traditional-boot ├── README.adoc ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── springframework │ │ └── session │ │ └── mongodb │ │ └── examples │ │ ├── EmbeddedMongoPortLogger.java │ │ ├── SpringSessionMongoTraditionalBoot.java │ │ ├── config │ │ ├── HttpSessionConfig.java │ │ └── SecurityConfig.java │ │ └── mvc │ │ └── IndexController.java └── resources │ ├── application.properties │ ├── static │ └── resources │ │ └── img │ │ ├── favicon.ico │ │ └── logo.png │ └── templates │ ├── index.html │ └── layout.html └── test └── java └── org └── springframework └── session └── mongodb └── examples ├── BootTests.java └── pages ├── BasePage.java ├── HomePage.java └── LoginPage.java /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-projects/spring-session-data-mongodb-examples/9c1ed981a65f47a4b8e440e519c65b58d8f8bc11/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | env: 5 | matrix: 6 | - PROFILE=non-existent 7 | - PROFILE=spring5-next 8 | cache: 9 | directories: 10 | - $HOME/.m2 11 | os: 12 | - linux 13 | branches: 14 | except: 15 | - gh-pages 16 | sudo: false 17 | notifications: 18 | slack: 19 | secure: R8MhMPd+FsUZonvk8D9S6QC9Qj/iXn6CptAW9Smfn6pjLVm5QeLsg2eLyY4wQDNZsku8mCG4YmJ9PuyBFaiRswqhlrMhQ+/e+79E5FHuOL/tTPV01/slOgunZmnCigLSNN0tHYNNSPTgpdxwjnjpmRhppu3ehp+VQloG+NZp1Irmp3yn06gXPMIrT31urqRvCxrF5zkY/1zAMjZX0pCvZMPzpmpZM3JHVxbxmaLfiOhJWPo4rFYd/eqPg89JCpPxH0Oca80UnXSMC5SBeRvledCqyUwMqsuADTD822Xnh9SD1Vc8QRcud+c8OW99U6+XMIJQRFESNtR8WckLNVwJc7kz3f25Lz0HURemK/z/sdryXPxoym0+YM+D3jZ31tHT6tRFed2VNFkTKeuH3IA8NccxMYqdwt2QTFQTQwEmWo7HKihbLaEWd4K3AHt8kTVukwSrQE4Mg2jf4rBsIu1PDXCq8tv7FPviwmN/CbKVda1FIlAIfi9a7yu2ONjEEDhBsix+i7YbbLdBR9qONwgBwJJCLlIRJZ5TQBwMzhhtTfsjqJ00UBDOLFKQ864qKvcpDjOoMOSg9L7nqGAtstNeAA3HMyoOAC4EGvfvsBprhY/HhQmdfP7uzCha600dylDtpqJxzseJ/rHqxBMP23RrnU2hx5RrXMAi/3RAEniJu3M= 20 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.adoc: -------------------------------------------------------------------------------- 1 | = Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of fostering an open 4 | and welcoming community, we pledge to respect all people who contribute through reporting 5 | issues, posting feature requests, updating documentation, submitting pull requests or 6 | patches, and other activities. 7 | 8 | We are committed to making participation in this project a harassment-free experience for 9 | everyone, regardless of level of experience, gender, gender identity and expression, 10 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, 11 | religion, or nationality. 12 | 13 | Examples of unacceptable behavior by participants include: 14 | 15 | * The use of sexualized language or imagery 16 | * Personal attacks 17 | * Trolling or insulting/derogatory comments 18 | * Public or private harassment 19 | * Publishing other's private information, such as physical or electronic addresses, 20 | without explicit permission 21 | * Other unethical or unprofessional conduct 22 | 23 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 24 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 25 | Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors 26 | that they deem inappropriate, threatening, offensive, or harmful. 27 | 28 | By adopting this Code of Conduct, project maintainers commit themselves to fairly and 29 | consistently applying these principles to every aspect of managing this project. Project 30 | maintainers who do not follow or enforce the Code of Conduct may be permanently removed 31 | from the project team. 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an 34 | individual is representing the project or its community. 35 | 36 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 37 | contacting a project maintainer at spring-code-of-conduct@pivotal.io . All complaints will 38 | be reviewed and investigated and will result in a response that is deemed necessary and 39 | appropriate to the circumstances. Maintainers are obligated to maintain confidentiality 40 | with regard to the reporter of an incident. 41 | 42 | This Code of Conduct is adapted from the 43 | https://contributor-covenant.org[Contributor Covenant], version 1.3.0, available at 44 | https://contributor-covenant.org/version/1/3/0/[contributor-covenant.org/version/1/3/0/] 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | https://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | https://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = Spring Session MongoDB Examples 2 | 3 | image:https://travis-ci.org/spring-projects/spring-session-data-mongodb-examples.svg?branch=main["Build Status", link="https://travis-ci.org/spring-projects/spring-session-data-mongodb-examples"] 4 | 5 | This repository is a collection of examples using Spring Session MongoDB, allowing you to persist session data in a MongoDB instance. 6 | 7 | == Examples 8 | 9 | * link:spring-session-data-mongodb-reactive-boot[Spring Session MongoDB in a Reactive Spring Boot application (Spring WebFlux)] 10 | * link:spring-session-data-mongodb-traditional-boot[Spring Session MongoDB in a traditional Spring Boot application (Spring MVC)] 11 | 12 | == Contributing 13 | 14 | Spring Session MongoDB Examples is released under the non-restrictive Apache 2.0 license, 15 | and follows a very standard Github development process, using Github 16 | tracker for issues and merging pull requests into main. If you want 17 | to contribute even something trivial please do not hesitate, but 18 | follow the guidelines below. 19 | 20 | === Sign the Contributor License Agreement 21 | 22 | Before we accept a non-trivial patch or pull request we will need you to sign the 23 | https://cla.pivotal.io/sign/spring[Contributor License Agreement]. 24 | Signing the contributor's agreement does not grant anyone commit rights to the main 25 | repository, but it does mean that we can accept your contributions, and you will get an 26 | author credit if we do. Active contributors might be asked to join the core team, and 27 | given the ability to merge pull requests. 28 | 29 | === Code of Conduct 30 | 31 | This project adheres to the Contributor Covenant https://github.com/spring-projects/spring-session-data-mongodb/blob/main/CODE_OF_CONDUCT.adoc[code of conduct]. By participating, you are expected to uphold this code. Please report unacceptable behavior to spring-code-of-conduct@pivotal.io. 32 | 33 | === Code Conventions and Housekeeping 34 | 35 | None of these is essential for a pull request, but they will all help. They can also be 36 | added after the original pull request but before a merge. 37 | 38 | * 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/main/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. 39 | * 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. 40 | * Add the ASF license header comment to all new `.java` files (copy from existing files in the project) 41 | * Add yourself as an `@author` to the .java files that you modify substantially (more than cosmetic changes). 42 | * Add some Javadocs and, if you change the namespace, some XSD doc elements. 43 | * A few unit tests would help a lot as well -- someone has to do it. 44 | * If no-one else is using your branch, please rebase it against the current main (or other target branch in the main project). 45 | * 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). 46 | * 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. -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.session.data.mongodb 7 | spring-session-data-mongodb-examples 8 | 1.0.0.BUILD-SNAPSHOT 9 | pom 10 | 11 | Spring Session MongoDB - Examples 12 | Examples of Spring Session MongoDB 13 | 14 | 15 | 16 | gturnquist 17 | Greg Turnquist 18 | gturnquist@vmware.com 19 | VMware 20 | 21 | Project Lead 22 | 23 | 24 | 25 | 26 | 27 | spring-session-data-mongodb-traditional-boot 28 | spring-session-data-mongodb-reactive-boot 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-parent 34 | 2.4.5 35 | 36 | 37 | 38 | 39 | UTF-8 40 | UTF-8 41 | 1.8 42 | 2.5.0 43 | 2.5.0 44 | 2021.0.0 45 | 46 | 47 | 48 | 49 | 50 | org.springframework.session 51 | spring-session-data-mongodb 52 | ${spring-session-data-mongodb.version} 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-reactive-boot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | org.springframework.session.data.mongodb 9 | spring-session-data-mongodb-examples 10 | 1.0.0.BUILD-SNAPSHOT 11 | 12 | 13 | org.springframework.session.data.mongodb 14 | spring-session-data-mongodb-reactive-boot 15 | 16 | Spring Session MongoDB - Examples - Reactive Spring Boot 17 | 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-data-mongodb-reactive 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-webflux 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-thymeleaf 31 | 32 | 33 | de.flapdoodle.embed 34 | de.flapdoodle.embed.mongo 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | org.seleniumhq.selenium 44 | htmlunit-driver 45 | test 46 | 47 | 48 | org.seleniumhq.selenium 49 | selenium-support 50 | test 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-reactive-boot/src/main/java/org/springframework/session/mongodb/examples/SessionAttributeForm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.session.mongodb.examples; 18 | 19 | import java.util.Objects; 20 | 21 | /** 22 | * @author Rob Winch 23 | * @author Greg Turnquist 24 | * @since 5.0 25 | */ 26 | public class SessionAttributeForm { 27 | 28 | private String attributeName; 29 | private String attributeValue; 30 | 31 | public String getAttributeName() { 32 | return attributeName; 33 | } 34 | 35 | public void setAttributeName(String attributeName) { 36 | this.attributeName = attributeName; 37 | } 38 | 39 | public String getAttributeValue() { 40 | return attributeValue; 41 | } 42 | 43 | public void setAttributeValue(String attributeValue) { 44 | this.attributeValue = attributeValue; 45 | } 46 | 47 | @Override 48 | public boolean equals(Object o) { 49 | 50 | if (this == o) 51 | return true; 52 | if (!(o instanceof SessionAttributeForm)) 53 | return false; 54 | SessionAttributeForm that = (SessionAttributeForm) o; 55 | return Objects.equals(attributeName, that.attributeName) && Objects.equals(attributeValue, that.attributeValue); 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | return Objects.hash(attributeName, attributeValue); 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | 66 | return "SessionAttributeForm{" + "attributeName='" + attributeName + '\'' + ", attributeValue='" + attributeValue 67 | + '\'' + '}'; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-reactive-boot/src/main/java/org/springframework/session/mongodb/examples/SessionController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.session.mongodb.examples; 18 | 19 | import org.springframework.stereotype.Controller; 20 | import org.springframework.ui.Model; 21 | import org.springframework.web.bind.annotation.GetMapping; 22 | import org.springframework.web.bind.annotation.ModelAttribute; 23 | import org.springframework.web.bind.annotation.PostMapping; 24 | import org.springframework.web.server.WebSession; 25 | 26 | /** 27 | * @author Rob Winch 28 | * @author Greg Turnquist 29 | */ 30 | // tag::class[] 31 | @Controller 32 | public class SessionController { 33 | 34 | @PostMapping("/session") 35 | public String setAttribute(@ModelAttribute SessionAttributeForm sessionAttributeForm, WebSession session) { 36 | 37 | session.getAttributes().put(sessionAttributeForm.getAttributeName(), sessionAttributeForm.getAttributeValue()); 38 | return "redirect:/"; 39 | } 40 | 41 | @GetMapping("/") 42 | public String index(Model model, WebSession webSession) { 43 | 44 | model.addAttribute("webSession", webSession); 45 | return "index"; 46 | } 47 | } 48 | // tag::end[] 49 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-reactive-boot/src/main/java/org/springframework/session/mongodb/examples/SpringSessionMongoReactiveApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.session.mongodb.examples; 17 | 18 | import org.springframework.boot.SpringApplication; 19 | import org.springframework.boot.autoconfigure.SpringBootApplication; 20 | import org.springframework.session.data.mongo.config.annotation.web.reactive.EnableMongoWebSession; 21 | 22 | /** 23 | * Pure Spring-based application (using Spring Boot for dependency management), hence no autoconfiguration. 24 | * 25 | * @author Rob Winch 26 | * @author Greg Turnquist 27 | */ 28 | @SpringBootApplication 29 | @EnableMongoWebSession 30 | public class SpringSessionMongoReactiveApplication { 31 | 32 | public static void main(String[] args) { 33 | SpringApplication.run(SpringSessionMongoReactiveApplication.class); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-reactive-boot/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | level: 3 | org.springframework.data.mongodb: DEBUG 4 | org.springframework.session: DEBUG 5 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-reactive-boot/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Session Attributes 5 | 6 | 7 | 8 |
9 |

Description

10 |

This application demonstrates how to use a MongoDB instance to back your session. Notice that there is no 11 | JSESSIONID cookie. We are also able to customize the way of identifying what the requested session id is.

12 | 13 |

Try it

14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 37 | 38 |
Attribute NameAttribute Value
35 | 36 |
39 |
40 | 41 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-reactive-boot/src/test/java/org/springframework/session/mongodb/examples/AttributeTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.session.mongodb.examples; 18 | 19 | import static org.assertj.core.api.Assertions.*; 20 | 21 | import java.util.List; 22 | 23 | import org.junit.jupiter.api.AfterEach; 24 | import org.junit.jupiter.api.BeforeEach; 25 | import org.junit.jupiter.api.Test; 26 | import org.junit.jupiter.api.extension.ExtendWith; 27 | import org.openqa.selenium.WebDriver; 28 | import org.openqa.selenium.htmlunit.HtmlUnitDriver; 29 | import org.springframework.boot.test.context.SpringBootTest; 30 | import org.springframework.boot.web.server.LocalServerPort; 31 | import org.springframework.session.mongodb.examples.pages.HomePage; 32 | import org.springframework.session.mongodb.examples.pages.HomePage.Attribute; 33 | import org.springframework.test.context.junit.jupiter.SpringExtension; 34 | 35 | /** 36 | * @author Eddú Meléndez 37 | * @author Rob Winch 38 | */ 39 | @ExtendWith(SpringExtension.class) 40 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 41 | public class AttributeTests { 42 | 43 | @LocalServerPort int port; 44 | 45 | private WebDriver driver; 46 | 47 | @BeforeEach 48 | public void setup() { 49 | this.driver = new HtmlUnitDriver(); 50 | } 51 | 52 | @AfterEach 53 | public void tearDown() { 54 | this.driver.quit(); 55 | } 56 | 57 | @Test 58 | public void home() { 59 | 60 | HomePage home = HomePage.go(this.driver, this.port); 61 | home.assertAt(); 62 | } 63 | 64 | @Test 65 | public void noAttributes() { 66 | 67 | HomePage home = HomePage.go(this.driver, this.port); 68 | assertThat(home.attributes()).isEmpty(); 69 | } 70 | 71 | @Test 72 | public void createAttribute() { 73 | 74 | HomePage home = HomePage.go(this.driver, this.port); 75 | home = home.form().attributeName("a").attributeValue("b").submit(HomePage.class); 76 | 77 | List attributes = home.attributes(); 78 | assertThat(attributes).hasSize(1); 79 | 80 | Attribute row = attributes.get(0); 81 | assertThat(row.getAttributeName()).isEqualTo("a"); 82 | assertThat(row.getAttributeValue()).isEqualTo("b"); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-reactive-boot/src/test/java/org/springframework/session/mongodb/examples/pages/HomePage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.session.mongodb.examples.pages; 18 | 19 | import static org.assertj.core.api.Assertions.*; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | import java.util.stream.Collectors; 24 | 25 | import org.openqa.selenium.SearchContext; 26 | import org.openqa.selenium.WebDriver; 27 | import org.openqa.selenium.WebElement; 28 | import org.openqa.selenium.support.FindBy; 29 | import org.openqa.selenium.support.PageFactory; 30 | import org.openqa.selenium.support.pagefactory.DefaultElementLocatorFactory; 31 | 32 | /** 33 | * @author Eddú Meléndez 34 | * @author Rob Winch 35 | */ 36 | public class HomePage { 37 | 38 | private WebDriver driver; 39 | 40 | @FindBy(css = "form") 41 | WebElement form; 42 | 43 | @FindBy(css = "table tbody tr") 44 | List trs; 45 | 46 | List attributes; 47 | 48 | public HomePage(WebDriver driver) { 49 | 50 | this.driver = driver; 51 | this.attributes = new ArrayList<>(); 52 | } 53 | 54 | private static void get(WebDriver driver, int port, String get) { 55 | 56 | String baseUrl = "http://localhost:" + port; 57 | driver.get(baseUrl + get); 58 | } 59 | 60 | public static HomePage go(WebDriver driver, int port) { 61 | 62 | get(driver, port, "/"); 63 | return PageFactory.initElements(driver, HomePage.class); 64 | } 65 | 66 | public void assertAt() { 67 | assertThat(this.driver.getTitle()).isEqualTo("Session Attributes"); 68 | } 69 | 70 | public List attributes() { 71 | 72 | List rows = this.trs.stream() // 73 | .map(Attribute::new) // 74 | .collect(Collectors.toList()); 75 | 76 | this.attributes.addAll(rows); 77 | 78 | return this.attributes; 79 | } 80 | 81 | public Form form() { 82 | return new Form(this.form); 83 | } 84 | 85 | public class Form { 86 | 87 | @FindBy(name = "attributeName") 88 | WebElement attributeName; 89 | 90 | @FindBy(name = "attributeValue") 91 | WebElement attributeValue; 92 | 93 | @FindBy(css = "input[type=\"submit\"]") 94 | WebElement submit; 95 | 96 | public Form(SearchContext context) { 97 | PageFactory.initElements(new DefaultElementLocatorFactory(context), this); 98 | } 99 | 100 | public Form attributeName(String text) { 101 | 102 | this.attributeName.sendKeys(text); 103 | return this; 104 | } 105 | 106 | public Form attributeValue(String text) { 107 | 108 | this.attributeValue.sendKeys(text); 109 | return this; 110 | } 111 | 112 | public T submit(Class page) { 113 | 114 | this.submit.click(); 115 | return PageFactory.initElements(HomePage.this.driver, page); 116 | } 117 | } 118 | 119 | public static class Attribute { 120 | 121 | @FindBy(xpath = ".//td[1]") 122 | WebElement attributeName; 123 | 124 | @FindBy(xpath = ".//td[2]") 125 | WebElement attributeValue; 126 | 127 | public Attribute(SearchContext context) { 128 | PageFactory.initElements(new DefaultElementLocatorFactory(context), this); 129 | } 130 | 131 | /** 132 | * @return the attributeName 133 | */ 134 | public String getAttributeName() { 135 | return this.attributeName.getText(); 136 | } 137 | 138 | /** 139 | * @return the attributeValue 140 | */ 141 | public String getAttributeValue() { 142 | return this.attributeValue.getText(); 143 | } 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/README.adoc: -------------------------------------------------------------------------------- 1 | Demonstrates using Spring Session with Spring Boot and Spring Security. You can log in with the username "user" and the password "password". -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | org.springframework.session.data.mongodb 9 | spring-session-data-mongodb-examples 10 | 1.0.0.BUILD-SNAPSHOT 11 | 12 | 13 | org.springframework.session.data.mongodb 14 | spring-session-data-mongodb-traditional-boot 15 | 16 | Spring Session MongoDB - Examples - Traditional Spring Boot 17 | 18 | 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-data-mongodb 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-security 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-thymeleaf 37 | 38 | 39 | nz.net.ultraq.thymeleaf 40 | thymeleaf-layout-dialect 41 | 42 | 43 | org.thymeleaf.extras 44 | thymeleaf-extras-springsecurity5 45 | 46 | 47 | de.flapdoodle.embed 48 | de.flapdoodle.embed.mongo 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-starter-test 54 | test 55 | 56 | 57 | org.seleniumhq.selenium 58 | htmlunit-driver 59 | test 60 | 61 | 62 | org.seleniumhq.selenium 63 | selenium-support 64 | test 65 | 66 | 67 | org.springframework.security 68 | spring-security-test 69 | test 70 | 71 | 72 | 73 | 74 | 75 | 76 | org.springframework.boot 77 | spring-boot-maven-plugin 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/main/java/org/springframework/session/mongodb/examples/EmbeddedMongoPortLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.session.mongodb.examples; 17 | 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | import org.springframework.boot.ApplicationArguments; 22 | import org.springframework.boot.ApplicationRunner; 23 | import org.springframework.context.EnvironmentAware; 24 | import org.springframework.core.env.Environment; 25 | import org.springframework.stereotype.Component; 26 | 27 | @Component 28 | class EmbeddedMongoPortLogger implements ApplicationRunner, EnvironmentAware { 29 | 30 | private static final Logger logger = LoggerFactory.getLogger(EmbeddedMongoPortLogger.class); 31 | 32 | private Environment environment; 33 | 34 | public void run(ApplicationArguments args) throws Exception { 35 | String port = this.environment.getProperty("local.mongo.port"); 36 | logger.info("Embedded Mongo started on port " + port + 37 | ", use 'mongo --port " + port + "' command to connect"); 38 | } 39 | 40 | public void setEnvironment(Environment environment) { 41 | this.environment = environment; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/main/java/org/springframework/session/mongodb/examples/SpringSessionMongoTraditionalBoot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.session.mongodb.examples; 17 | 18 | import org.springframework.boot.SpringApplication; 19 | import org.springframework.boot.autoconfigure.SpringBootApplication; 20 | 21 | /** 22 | * @author Rob Winch 23 | */ 24 | @SpringBootApplication 25 | public class SpringSessionMongoTraditionalBoot { 26 | 27 | public static void main(String[] args) { 28 | SpringApplication.run(SpringSessionMongoTraditionalBoot.class, args); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/main/java/org/springframework/session/mongodb/examples/config/HttpSessionConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.session.mongodb.examples.config; 17 | 18 | import java.time.Duration; 19 | 20 | import org.springframework.context.annotation.Bean; 21 | import org.springframework.session.data.mongo.JdkMongoSessionConverter; 22 | import org.springframework.session.data.mongo.config.annotation.web.http.EnableMongoHttpSession; 23 | 24 | // tag::class[] 25 | @EnableMongoHttpSession // <1> 26 | public class HttpSessionConfig { 27 | 28 | @Bean 29 | public JdkMongoSessionConverter jdkMongoSessionConverter() { 30 | return new JdkMongoSessionConverter(Duration.ofMinutes(30)); // <2> 31 | } 32 | } 33 | // end::class[] 34 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/main/java/org/springframework/session/mongodb/examples/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.session.mongodb.examples.config; 17 | 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 20 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 21 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 22 | import org.springframework.security.core.userdetails.User; 23 | 24 | /** 25 | * @author Rob Winch 26 | */ 27 | @EnableWebSecurity 28 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 29 | 30 | @Autowired 31 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 32 | 33 | auth.inMemoryAuthentication().withUser(User.withDefaultPasswordEncoder() 34 | .username("user") 35 | .password("password") 36 | .roles("USER") 37 | .build()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/main/java/org/springframework/session/mongodb/examples/mvc/IndexController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.session.mongodb.examples.mvc; 17 | 18 | import org.springframework.stereotype.Controller; 19 | import org.springframework.web.bind.annotation.GetMapping; 20 | 21 | /** 22 | * Controller for sending the user to the login view. 23 | * 24 | * @author Rob Winch 25 | * 26 | */ 27 | @Controller 28 | public class IndexController { 29 | 30 | @GetMapping("/") 31 | public String index() { 32 | return "index"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.thymeleaf.cache=false 2 | spring.template.cache=false 3 | spring.data.mongodb.port=0 4 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/main/resources/static/resources/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-projects/spring-session-data-mongodb-examples/9c1ed981a65f47a4b8e440e519c65b58d8f8bc11/spring-session-data-mongodb-traditional-boot/src/main/resources/static/resources/img/favicon.ico -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/main/resources/static/resources/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-projects/spring-session-data-mongodb-examples/9c1ed981a65f47a4b8e440e519c65b58d8f8bc11/spring-session-data-mongodb-traditional-boot/src/main/resources/static/resources/img/logo.png -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Secured Content 4 | 5 | 6 |
7 |

Secured Page

8 |

This page is secured using Spring Boot, Spring Session, and Spring Security.

9 |
10 | 11 | 12 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/main/resources/templates/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | Spring Session Sample 7 | 8 | 9 | 68 | 69 | 70 | 71 | 74 | 75 | 76 | 77 | 78 |
79 | 101 | 102 |
103 |
106 | Some Success message 107 |
108 |
109 | Fake content 110 |
111 |
112 | 113 |
114 |
115 | 116 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/test/java/org/springframework/session/mongodb/examples/BootTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.session.mongodb.examples; 18 | 19 | import static org.assertj.core.api.Assertions.*; 20 | 21 | import java.util.Set; 22 | 23 | import org.junit.jupiter.api.AfterEach; 24 | import org.junit.jupiter.api.BeforeEach; 25 | import org.junit.jupiter.api.Test; 26 | import org.junit.jupiter.api.extension.ExtendWith; 27 | import org.openqa.selenium.By; 28 | import org.openqa.selenium.Cookie; 29 | import org.openqa.selenium.WebDriver; 30 | import org.openqa.selenium.WebElement; 31 | import org.springframework.beans.factory.annotation.Autowired; 32 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 33 | import org.springframework.boot.test.context.SpringBootTest; 34 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 35 | import org.springframework.session.mongodb.examples.pages.HomePage; 36 | import org.springframework.session.mongodb.examples.pages.LoginPage; 37 | import org.springframework.test.context.junit.jupiter.SpringExtension; 38 | import org.springframework.test.web.servlet.MockMvc; 39 | import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder; 40 | 41 | /** 42 | * @author Pool Dolorier 43 | */ 44 | @ExtendWith(SpringExtension.class) 45 | @AutoConfigureMockMvc 46 | @SpringBootTest(webEnvironment = WebEnvironment.MOCK) 47 | public class BootTests { 48 | 49 | @Autowired private MockMvc mockMvc; 50 | 51 | private WebDriver driver; 52 | 53 | @BeforeEach 54 | public void setUp() { 55 | this.driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(this.mockMvc).build(); 56 | } 57 | 58 | @AfterEach 59 | public void tearDown() { 60 | this.driver.quit(); 61 | } 62 | 63 | @Test 64 | public void unauthenticatedUserSentToLogInPage() { 65 | 66 | HomePage homePage = HomePage.go(this.driver); 67 | LoginPage loginPage = homePage.unauthenticated(); 68 | loginPage.assertAt(); 69 | } 70 | 71 | @Test 72 | public void logInViewsHomePage() { 73 | 74 | LoginPage loginPage = LoginPage.go(this.driver); 75 | loginPage.assertAt(); 76 | 77 | HomePage homePage = loginPage.login("user", "password"); 78 | homePage.assertAt(); 79 | 80 | WebElement username = homePage.getDriver().findElement(By.id("un")); 81 | assertThat(username.getText()).isEqualTo("user"); 82 | Set cookies = homePage.getDriver().manage().getCookies(); 83 | assertThat(cookies).extracting("name").contains("SESSION"); 84 | assertThat(cookies).extracting("name").doesNotContain("JSESSIONID"); 85 | } 86 | 87 | @Test 88 | public void logoutSuccess() { 89 | 90 | LoginPage loginPage = LoginPage.go(this.driver); 91 | HomePage homePage = loginPage.login("user", "password"); 92 | LoginPage successLogoutPage = homePage.logout(); 93 | 94 | successLogoutPage.assertAt(); 95 | } 96 | 97 | @Test 98 | public void loggedOutUserSentToLoginPage() { 99 | 100 | LoginPage loginPage = LoginPage.go(this.driver); 101 | HomePage homePage = loginPage.login("user", "password"); 102 | homePage.logout(); 103 | 104 | HomePage backHomePage = HomePage.go(this.driver); 105 | LoginPage backLoginPage = backHomePage.unauthenticated(); 106 | 107 | backLoginPage.assertAt(); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/test/java/org/springframework/session/mongodb/examples/pages/BasePage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.session.mongodb.examples.pages; 18 | 19 | import org.openqa.selenium.WebDriver; 20 | 21 | /** 22 | * @author Pool Dolorier 23 | */ 24 | public abstract class BasePage { 25 | 26 | private WebDriver driver; 27 | 28 | public BasePage(WebDriver driver) { 29 | this.driver = driver; 30 | } 31 | 32 | public WebDriver getDriver() { 33 | return this.driver; 34 | } 35 | 36 | public static void get(WebDriver driver, String get) { 37 | 38 | String baseUrl = "http://localhost"; 39 | driver.get(baseUrl + get); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/test/java/org/springframework/session/mongodb/examples/pages/HomePage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.session.mongodb.examples.pages; 18 | 19 | import static org.assertj.core.api.Assertions.*; 20 | 21 | import org.openqa.selenium.WebDriver; 22 | import org.openqa.selenium.WebElement; 23 | import org.openqa.selenium.support.FindBy; 24 | import org.openqa.selenium.support.PageFactory; 25 | 26 | /** 27 | * @author Pool Dolorier 28 | */ 29 | public class HomePage extends BasePage { 30 | 31 | @FindBy(css = "input[type='submit']") private WebElement submit; 32 | 33 | public HomePage(WebDriver driver) { 34 | super(driver); 35 | } 36 | 37 | public static HomePage go(WebDriver driver) { 38 | 39 | get(driver, "/"); 40 | return PageFactory.initElements(driver, HomePage.class); 41 | } 42 | 43 | public LoginPage unauthenticated() { 44 | return LoginPage.go(getDriver()); 45 | } 46 | 47 | public LoginPage logout() { 48 | 49 | this.submit.click(); 50 | return LoginPage.go(getDriver()); 51 | } 52 | 53 | public void assertAt() { 54 | assertThat(getDriver().getTitle()).isEqualTo("Spring Session Sample - Secured Content"); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /spring-session-data-mongodb-traditional-boot/src/test/java/org/springframework/session/mongodb/examples/pages/LoginPage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.session.mongodb.examples.pages; 18 | 19 | import static org.assertj.core.api.Assertions.*; 20 | 21 | import org.openqa.selenium.WebDriver; 22 | import org.openqa.selenium.WebElement; 23 | import org.openqa.selenium.support.FindBy; 24 | import org.openqa.selenium.support.PageFactory; 25 | 26 | /** 27 | * @author Pool Dolorier 28 | */ 29 | public class LoginPage extends BasePage { 30 | 31 | @FindBy(name = "username") private WebElement username; 32 | 33 | @FindBy(name = "password") private WebElement password; 34 | 35 | @FindBy(css = "button[type='submit']") private WebElement submit; 36 | 37 | public LoginPage(WebDriver driver) { 38 | super(driver); 39 | } 40 | 41 | public static LoginPage go(WebDriver driver) { 42 | 43 | get(driver, "/login"); 44 | return PageFactory.initElements(driver, LoginPage.class); 45 | } 46 | 47 | public void assertAt() { 48 | assertThat(getDriver().getTitle()).isEqualTo("Please sign in"); 49 | } 50 | 51 | public HomePage login(String user, String password) { 52 | 53 | this.username.sendKeys(user); 54 | this.password.sendKeys(password); 55 | this.submit.click(); 56 | return HomePage.go(getDriver()); 57 | } 58 | } 59 | --------------------------------------------------------------------------------