Skip to content

Commit 8fa031c

Browse files
authoredDec 16, 2021
Springboot-Registration-Project
1 parent 877a206 commit 8fa031c

21 files changed

+1522
-0
lines changed
 

‎Springboot-Registration-Project/mvnw

+322
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,322 @@
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+
# Maven 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*)
57+
darwin=true
58+
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
59+
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
60+
if [ -z "$JAVA_HOME" ]; then
61+
if [ -x "/usr/libexec/java_home" ]; then
62+
export JAVA_HOME="$(/usr/libexec/java_home)"
63+
else
64+
export JAVA_HOME="/Library/Java/Home"
65+
fi
66+
fi
67+
;;
68+
esac
69+
70+
if [ -z "$JAVA_HOME" ]; then
71+
if [ -r /etc/gentoo-release ]; then
72+
JAVA_HOME=$(java-config --jre-home)
73+
fi
74+
fi
75+
76+
if [ -z "$M2_HOME" ]; then
77+
## resolve links - $0 may be a link to maven's home
78+
PRG="$0"
79+
80+
# need this for relative symlinks
81+
while [ -h "$PRG" ]; do
82+
ls=$(ls -ld "$PRG")
83+
link=$(expr "$ls" : '.*-> \(.*\)$')
84+
if expr "$link" : '/.*' >/dev/null; then
85+
PRG="$link"
86+
else
87+
PRG="$(dirname "$PRG")/$link"
88+
fi
89+
done
90+
91+
saveddir=$(pwd)
92+
93+
M2_HOME=$(dirname "$PRG")/..
94+
95+
# make it fully qualified
96+
M2_HOME=$(cd "$M2_HOME" && pwd)
97+
98+
cd "$saveddir"
99+
# echo Using m2 at $M2_HOME
100+
fi
101+
102+
# For Cygwin, ensure paths are in UNIX format before anything is touched
103+
if $cygwin; then
104+
[ -n "$M2_HOME" ] &&
105+
M2_HOME=$(cygpath --unix "$M2_HOME")
106+
[ -n "$JAVA_HOME" ] &&
107+
JAVA_HOME=$(cygpath --unix "$JAVA_HOME")
108+
[ -n "$CLASSPATH" ] &&
109+
CLASSPATH=$(cygpath --path --unix "$CLASSPATH")
110+
fi
111+
112+
# For Mingw, ensure paths are in UNIX format before anything is touched
113+
if $mingw; then
114+
[ -n "$M2_HOME" ] &&
115+
M2_HOME="$( (
116+
cd "$M2_HOME"
117+
pwd
118+
))"
119+
[ -n "$JAVA_HOME" ] &&
120+
JAVA_HOME="$( (
121+
cd "$JAVA_HOME"
122+
pwd
123+
))"
124+
fi
125+
126+
if [ -z "$JAVA_HOME" ]; then
127+
javaExecutable="$(which javac)"
128+
if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then
129+
# readlink(1) is not available as standard on Solaris 10.
130+
readLink=$(which readlink)
131+
if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then
132+
if $darwin; then
133+
javaHome="$(dirname \"$javaExecutable\")"
134+
javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac"
135+
else
136+
javaExecutable="$(readlink -f \"$javaExecutable\")"
137+
fi
138+
javaHome="$(dirname \"$javaExecutable\")"
139+
javaHome=$(expr "$javaHome" : '\(.*\)/bin')
140+
JAVA_HOME="$javaHome"
141+
export JAVA_HOME
142+
fi
143+
fi
144+
fi
145+
146+
if [ -z "$JAVACMD" ]; then
147+
if [ -n "$JAVA_HOME" ]; then
148+
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
149+
# IBM's JDK on AIX uses strange locations for the executables
150+
JAVACMD="$JAVA_HOME/jre/sh/java"
151+
else
152+
JAVACMD="$JAVA_HOME/bin/java"
153+
fi
154+
else
155+
JAVACMD="$(which java)"
156+
fi
157+
fi
158+
159+
if [ ! -x "$JAVACMD" ]; then
160+
echo "Error: JAVA_HOME is not defined correctly." >&2
161+
echo " We cannot execute $JAVACMD" >&2
162+
exit 1
163+
fi
164+
165+
if [ -z "$JAVA_HOME" ]; then
166+
echo "Warning: JAVA_HOME environment variable is not set."
167+
fi
168+
169+
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
170+
171+
# traverses directory structure from process work directory to filesystem root
172+
# first directory with .mvn subdirectory is considered project base directory
173+
find_maven_basedir() {
174+
175+
if [ -z "$1" ]; then
176+
echo "Path not specified to find_maven_basedir"
177+
return 1
178+
fi
179+
180+
basedir="$1"
181+
wdir="$1"
182+
while [ "$wdir" != '/' ]; do
183+
if [ -d "$wdir"/.mvn ]; then
184+
basedir=$wdir
185+
break
186+
fi
187+
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
188+
if [ -d "${wdir}" ]; then
189+
wdir=$(
190+
cd "$wdir/.."
191+
pwd
192+
)
193+
fi
194+
# end of workaround
195+
done
196+
echo "${basedir}"
197+
}
198+
199+
# concatenates all lines of a file
200+
concat_lines() {
201+
if [ -f "$1" ]; then
202+
echo "$(tr -s '\n' ' ' <"$1")"
203+
fi
204+
}
205+
206+
BASE_DIR=$(find_maven_basedir "$(pwd)")
207+
if [ -z "$BASE_DIR" ]; then
208+
exit 1
209+
fi
210+
211+
##########################################################################################
212+
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
213+
# This allows using the maven wrapper in projects that prohibit checking in binary data.
214+
##########################################################################################
215+
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
216+
if [ "$MVNW_VERBOSE" = true ]; then
217+
echo "Found .mvn/wrapper/maven-wrapper.jar"
218+
fi
219+
else
220+
if [ "$MVNW_VERBOSE" = true ]; then
221+
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
222+
fi
223+
if [ -n "$MVNW_REPOURL" ]; then
224+
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
225+
else
226+
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
227+
fi
228+
while IFS="=" read key value; do
229+
case "$key" in wrapperUrl)
230+
jarUrl="$value"
231+
break
232+
;;
233+
esac
234+
done <"$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
235+
if [ "$MVNW_VERBOSE" = true ]; then
236+
echo "Downloading from: $jarUrl"
237+
fi
238+
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
239+
if $cygwin; then
240+
wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath")
241+
fi
242+
243+
if command -v wget >/dev/null; then
244+
if [ "$MVNW_VERBOSE" = true ]; then
245+
echo "Found wget ... using wget"
246+
fi
247+
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
248+
wget "$jarUrl" -O "$wrapperJarPath"
249+
else
250+
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
251+
fi
252+
elif command -v curl >/dev/null; then
253+
if [ "$MVNW_VERBOSE" = true ]; then
254+
echo "Found curl ... using curl"
255+
fi
256+
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
257+
curl -o "$wrapperJarPath" "$jarUrl" -f
258+
else
259+
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
260+
fi
261+
262+
else
263+
if [ "$MVNW_VERBOSE" = true ]; then
264+
echo "Falling back to using Java to download"
265+
fi
266+
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
267+
# For Cygwin, switch paths to Windows format before running javac
268+
if $cygwin; then
269+
javaClass=$(cygpath --path --windows "$javaClass")
270+
fi
271+
if [ -e "$javaClass" ]; then
272+
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
273+
if [ "$MVNW_VERBOSE" = true ]; then
274+
echo " - Compiling MavenWrapperDownloader.java ..."
275+
fi
276+
# Compiling the Java class
277+
("$JAVA_HOME/bin/javac" "$javaClass")
278+
fi
279+
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
280+
# Running the downloader
281+
if [ "$MVNW_VERBOSE" = true ]; then
282+
echo " - Running MavenWrapperDownloader.java ..."
283+
fi
284+
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
285+
fi
286+
fi
287+
fi
288+
fi
289+
##########################################################################################
290+
# End of extension
291+
##########################################################################################
292+
293+
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
294+
if [ "$MVNW_VERBOSE" = true ]; then
295+
echo $MAVEN_PROJECTBASEDIR
296+
fi
297+
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
298+
299+
# For Cygwin, switch paths to Windows format before running java
300+
if $cygwin; then
301+
[ -n "$M2_HOME" ] &&
302+
M2_HOME=$(cygpath --path --windows "$M2_HOME")
303+
[ -n "$JAVA_HOME" ] &&
304+
JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME")
305+
[ -n "$CLASSPATH" ] &&
306+
CLASSPATH=$(cygpath --path --windows "$CLASSPATH")
307+
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
308+
MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR")
309+
fi
310+
311+
# Provide a "standardized" way to retrieve the CLI args that will
312+
# work with both Windows and non-Windows executions.
313+
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
314+
export MAVEN_CMD_LINE_ARGS
315+
316+
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
317+
318+
exec "$JAVACMD" \
319+
$MAVEN_OPTS \
320+
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
321+
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
322+
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
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 Maven 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 keystroke 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 set title of command window
39+
title %0
40+
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
41+
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
42+
43+
@REM set %HOME% to equivalent of $HOME
44+
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
45+
46+
@REM Execute a user defined script before this one
47+
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
48+
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
49+
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
50+
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
51+
:skipRcPre
52+
53+
@setlocal
54+
55+
set ERROR_CODE=0
56+
57+
@REM To isolate internal variables from possible post scripts, we use another setlocal
58+
@setlocal
59+
60+
@REM ==== START VALIDATION ====
61+
if not "%JAVA_HOME%" == "" goto OkJHome
62+
63+
echo.
64+
echo Error: JAVA_HOME not found in your environment. >&2
65+
echo Please set the JAVA_HOME variable in your environment to match the >&2
66+
echo location of your Java installation. >&2
67+
echo.
68+
goto error
69+
70+
:OkJHome
71+
if exist "%JAVA_HOME%\bin\java.exe" goto init
72+
73+
echo.
74+
echo Error: JAVA_HOME is set to an invalid directory. >&2
75+
echo JAVA_HOME = "%JAVA_HOME%" >&2
76+
echo Please set the JAVA_HOME variable in your environment to match the >&2
77+
echo location of your Java installation. >&2
78+
echo.
79+
goto error
80+
81+
@REM ==== END VALIDATION ====
82+
83+
:init
84+
85+
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
86+
@REM Fallback to current working directory if not found.
87+
88+
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
89+
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
90+
91+
set EXEC_DIR=%CD%
92+
set WDIR=%EXEC_DIR%
93+
:findBaseDir
94+
IF EXIST "%WDIR%"\.mvn goto baseDirFound
95+
cd ..
96+
IF "%WDIR%"=="%CD%" goto baseDirNotFound
97+
set WDIR=%CD%
98+
goto findBaseDir
99+
100+
:baseDirFound
101+
set MAVEN_PROJECTBASEDIR=%WDIR%
102+
cd "%EXEC_DIR%"
103+
goto endDetectBaseDir
104+
105+
:baseDirNotFound
106+
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
107+
cd "%EXEC_DIR%"
108+
109+
:endDetectBaseDir
110+
111+
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
112+
113+
@setlocal EnableExtensions EnableDelayedExpansion
114+
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
115+
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
116+
117+
:endReadAdditionalConfig
118+
119+
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
120+
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
121+
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
122+
123+
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
124+
125+
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
126+
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
127+
)
128+
129+
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
130+
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
131+
if exist %WRAPPER_JAR% (
132+
if "%MVNW_VERBOSE%" == "true" (
133+
echo Found %WRAPPER_JAR%
134+
)
135+
) else (
136+
if not "%MVNW_REPOURL%" == "" (
137+
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
138+
)
139+
if "%MVNW_VERBOSE%" == "true" (
140+
echo Couldn't find %WRAPPER_JAR%, downloading it ...
141+
echo Downloading from: %DOWNLOAD_URL%
142+
)
143+
144+
powershell -Command "&{"^
145+
"$webclient = new-object System.Net.WebClient;"^
146+
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
147+
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
148+
"}"^
149+
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
150+
"}"
151+
if "%MVNW_VERBOSE%" == "true" (
152+
echo Finished downloading %WRAPPER_JAR%
153+
)
154+
)
155+
@REM End of extension
156+
157+
@REM Provide a "standardized" way to retrieve the CLI args that will
158+
@REM work with both Windows and non-Windows executions.
159+
set MAVEN_CMD_LINE_ARGS=%*
160+
161+
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
162+
if ERRORLEVEL 1 goto error
163+
goto end
164+
165+
:error
166+
set ERROR_CODE=1
167+
168+
:end
169+
@endlocal & set ERROR_CODE=%ERROR_CODE%
170+
171+
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
172+
@REM check for post script, once with legacy .bat ending and once with .cmd ending
173+
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
174+
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
175+
:skipRcPost
176+
177+
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
178+
if "%MAVEN_BATCH_PAUSE%" == "on" pause
179+
180+
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
181+
182+
exit /B %ERROR_CODE%
+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.6.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>spring</groupId>
12+
<artifactId>security</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>security</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>11</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.thymeleaf.extras</groupId>
24+
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-data-jpa</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-security</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.springframework.boot</groupId>
40+
<artifactId>spring-boot-starter-web</artifactId>
41+
</dependency>
42+
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-devtools</artifactId>
46+
<scope>runtime</scope>
47+
<optional>true</optional>
48+
</dependency>
49+
<dependency>
50+
<groupId>mysql</groupId>
51+
<artifactId>mysql-connector-java</artifactId>
52+
<scope>runtime</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.springframework.boot</groupId>
56+
<artifactId>spring-boot-starter-test</artifactId>
57+
<scope>test</scope>
58+
<exclusions>
59+
<exclusion>
60+
<groupId>org.junit.vintage</groupId>
61+
<artifactId>junit-vintage-engine</artifactId>
62+
</exclusion>
63+
</exclusions>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.springframework.security</groupId>
67+
<artifactId>spring-security-test</artifactId>
68+
<scope>test</scope>
69+
</dependency>
70+
71+
<!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
72+
<dependency>
73+
<groupId>commons-beanutils</groupId>
74+
<artifactId>commons-beanutils</artifactId>
75+
<version>1.9.3</version>
76+
</dependency>
77+
78+
<!-- bootstrap and jquery -->
79+
<dependency>
80+
<groupId>org.webjars</groupId>
81+
<artifactId>bootstrap</artifactId>
82+
<version>3.3.7</version>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.webjars</groupId>
86+
<artifactId>jquery</artifactId>
87+
<version>3.2.1</version>
88+
</dependency>
89+
<dependency>
90+
<groupId>com.h2database</groupId>
91+
<artifactId>h2</artifactId>
92+
<scope>test</scope>
93+
</dependency>
94+
</dependencies>
95+
96+
<build>
97+
<plugins>
98+
<plugin>
99+
<groupId>org.springframework.boot</groupId>
100+
<artifactId>spring-boot-maven-plugin</artifactId>
101+
</plugin>
102+
</plugins>
103+
</build>
104+
105+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package spring.security;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SecurityApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(SecurityApplication.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package spring.security.config;
2+
3+
/**
4+
* @Created 29 / 04 / 2020 - 3:51 PM
5+
* @project SpringRegistor
6+
* @Author Hamdamboy
7+
*/
8+
public class SecurityConfiguration {
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package spring.security.constraint;
2+
3+
import javax.validation.Constraint;
4+
import javax.validation.Payload;
5+
import java.lang.annotation.Documented;
6+
import java.lang.annotation.Retention;
7+
import java.lang.annotation.Target;
8+
9+
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
10+
import static java.lang.annotation.ElementType.TYPE;
11+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
12+
13+
/**
14+
* @Created 29 / 04 / 2020 - 5:37 PM
15+
* @project SpringRegistor
16+
* @Author Hamdamboy
17+
*/
18+
@Target({
19+
TYPE,
20+
ANNOTATION_TYPE
21+
})
22+
@Retention(RUNTIME)
23+
@Constraint(validatedBy = FieldMatchValidator.class)
24+
@Documented
25+
public @interface FieldMatch {
26+
27+
String message() default "{constraints.field-match}";
28+
Class < ? > [] groups() default {};
29+
Class < ? extends Payload> [] payload() default {};
30+
String first();
31+
String second();
32+
33+
@Target({
34+
TYPE,
35+
ANNOTATION_TYPE
36+
})
37+
@Retention(RUNTIME)
38+
@Documented
39+
@interface List {
40+
FieldMatch[] value();
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package spring.security.constraint;
2+
3+
import org.apache.commons.beanutils.BeanUtils;
4+
5+
import javax.validation.ConstraintValidator;
6+
import javax.validation.ConstraintValidatorContext;
7+
8+
/**
9+
* @Created 29 / 04 / 2020 - 5:39 PM
10+
* @project SpringRegistor
11+
* @Author Hamdamboy
12+
*/
13+
public class FieldMatchValidator implements ConstraintValidator<FieldMatch, Object> {
14+
15+
private String firstFieldName;
16+
private String secondFieldName;
17+
18+
@Override
19+
public void initialize(final FieldMatch constraintAnnotation) {
20+
firstFieldName = constraintAnnotation.first();
21+
secondFieldName = constraintAnnotation.second();
22+
}
23+
24+
@Override
25+
public boolean isValid(final Object value, final ConstraintValidatorContext context) {
26+
try {
27+
final Object firstObj = BeanUtils.getProperty(value, firstFieldName);
28+
final Object secondObj = BeanUtils.getProperty(value, secondFieldName);
29+
return firstObj == null && secondObj == null || firstObj != null && firstObj.equals(secondObj);
30+
} catch (final Exception ignore) {}
31+
return true;
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package spring.security.model;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.GenerationType;
6+
import javax.persistence.Id;
7+
8+
/**
9+
* @Created 29 / 04 / 2020 - 3:51 PM
10+
* @project SpringRegistor
11+
* @Author Hamdamboy
12+
*/
13+
14+
@Entity
15+
public class Role {
16+
17+
@Id
18+
@GeneratedValue(strategy = GenerationType.AUTO)
19+
private Long id;
20+
private String name;
21+
22+
23+
24+
public Role(){}
25+
26+
public Long getId() {
27+
return id;
28+
}
29+
30+
public void setId(Long id) {
31+
this.id = id;
32+
}
33+
34+
public String getName() {
35+
return name;
36+
}
37+
38+
public void setName(String name) {
39+
this.name = name;
40+
}
41+
42+
public Role(String name){
43+
this.name = name;
44+
}
45+
46+
@Override
47+
public String toString() {
48+
return "Role{" +
49+
"id=" + id +
50+
", name='" + name + '\'' +
51+
'}';
52+
}
53+
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package spring.security.model;
2+
3+
import javax.persistence.*;
4+
import java.util.Collection;
5+
6+
/**
7+
* @Created 29 / 04 / 2020 - 3:51 PM
8+
* @project SpringRegistor
9+
* @Author Hamdamboy
10+
*/
11+
12+
13+
14+
//@Table(uniqueContraints = @UniqueConstraint(columnNames = "email"))
15+
@Entity
16+
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"email"})})
17+
public class User {
18+
19+
@Id
20+
@GeneratedValue(strategy = GenerationType.AUTO)
21+
private Long id;
22+
23+
private String firstName;
24+
private String lastName;
25+
private String email;
26+
private String password;
27+
28+
29+
30+
public void setId(Long id) {
31+
this.id = id;
32+
}
33+
34+
public String getFirstName() {
35+
return firstName;
36+
}
37+
38+
public void setFirstName(String firstName) {
39+
this.firstName = firstName;
40+
}
41+
42+
public String getLastName() {
43+
return lastName;
44+
}
45+
46+
public void setLastName(String lastName) {
47+
this.lastName = lastName;
48+
}
49+
50+
public String getEmail() {
51+
return email;
52+
}
53+
54+
public void setEmail(String email) {
55+
this.email = email;
56+
}
57+
58+
public String getPassword() {
59+
return password;
60+
}
61+
62+
public void setPassword(String password) {
63+
this.password = password;
64+
}
65+
66+
public Collection<Role> getRoles() {
67+
return roles;
68+
}
69+
70+
71+
public void setRoles(Collection<Role> roles) {
72+
this.roles = roles;
73+
}
74+
75+
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
76+
@JoinTable(
77+
name = "users_roles",
78+
joinColumns = @JoinColumn(
79+
name = "user_id", referencedColumnName = "id"),
80+
inverseJoinColumns = @JoinColumn(
81+
name = "role_id", referencedColumnName = "id"))
82+
83+
private Collection<Role> roles;
84+
85+
public User() {
86+
}
87+
88+
public User(String firstName, String lastName, String email, String password) {
89+
this.firstName = firstName;
90+
this.lastName = lastName;
91+
this.email = email;
92+
this.password = password;
93+
}
94+
95+
public User(String firstName, String lastName, String email, String password, Collection<Role> roles) {
96+
this.firstName = firstName;
97+
this.lastName = lastName;
98+
this.email = email;
99+
this.password = password;
100+
this.roles = roles;
101+
}
102+
103+
public Long getId() {
104+
return id;
105+
}
106+
107+
@Override
108+
public String toString() {
109+
return "User{" +
110+
"id=" + id +
111+
", firstName='" + firstName + '\'' +
112+
", lastName='" + lastName + '\'' +
113+
", email='" + email + '\'' +
114+
", password='" + "admin123" + '\'' +
115+
", roles=" + roles +
116+
'}';
117+
}
118+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package spring.security.repisitory;
2+
3+
import spring.security.constraint.FieldMatch;
4+
5+
import javax.validation.constraints.AssertTrue;
6+
import javax.validation.constraints.Email;
7+
import javax.validation.constraints.NotEmpty;
8+
9+
/**
10+
* @Created 29 / 04 / 2020 - 5:33 PM
11+
* @project SpringRegistor
12+
* @Author Hamdamboy
13+
*/
14+
15+
@FieldMatch.List({
16+
@FieldMatch(first = "password", second = "confirmPassword", message = "The password fields must match"),
17+
@FieldMatch(first = "email", second = "confirmEmail", message = "The email fields must match")
18+
})
19+
public class UserRegistrationDto {
20+
21+
@NotEmpty
22+
private String firstName;
23+
24+
@NotEmpty
25+
private String lastName;
26+
27+
@NotEmpty
28+
private String password;
29+
30+
@NotEmpty
31+
private String confirmPassword;
32+
33+
@Email
34+
@NotEmpty
35+
private String email;
36+
37+
@Email
38+
@NotEmpty
39+
private String confirmEmail;
40+
41+
@AssertTrue
42+
private Boolean terms;
43+
44+
public String getFirstName() {
45+
return firstName;
46+
}
47+
48+
public void setFirstName(String firstName) {
49+
this.firstName = firstName;
50+
}
51+
52+
public String getLastName() {
53+
return lastName;
54+
}
55+
56+
public void setLastName(String lastName) {
57+
this.lastName = lastName;
58+
}
59+
60+
public String getPassword() {
61+
return password;
62+
}
63+
64+
public void setPassword(String password) {
65+
this.password = password;
66+
}
67+
68+
public String getConfirmPassword() {
69+
return confirmPassword;
70+
}
71+
72+
public void setConfirmPassword(String confirmPassword) {
73+
this.confirmPassword = confirmPassword;
74+
}
75+
76+
public String getEmail() {
77+
return email;
78+
}
79+
80+
public void setEmail(String email) {
81+
this.email = email;
82+
}
83+
84+
public String getConfirmEmail() {
85+
return confirmEmail;
86+
}
87+
88+
public void setConfirmEmail(String confirmEmail) {
89+
this.confirmEmail = confirmEmail;
90+
}
91+
92+
public Boolean getTerms() {
93+
return terms;
94+
}
95+
96+
public void setTerms(Boolean terms) {
97+
this.terms = terms;
98+
}
99+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package spring.security.repisitory;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.stereotype.Repository;
5+
import spring.security.model.User;
6+
7+
/**
8+
* @Created 29 / 04 / 2020 - 3:51 PM
9+
* @project SpringRegistor
10+
* @Author Hamdamboy
11+
*/
12+
@Repository
13+
public interface UserRepository extends JpaRepository<User, Long> {
14+
15+
User findByEmail(String email);
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package spring.security.security;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
7+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
8+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
9+
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
10+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
11+
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
12+
import spring.security.service.UserService;
13+
14+
/**
15+
* @Created 29 / 04 / 2020 - 3:54 PM
16+
* @project SpringRegistor
17+
* @Author Hamdamboy Urunov
18+
*/
19+
20+
@Configuration
21+
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
22+
//
23+
@Autowired
24+
private UserService userService;
25+
26+
@Override
27+
protected void configure(HttpSecurity http) throws Exception {
28+
http
29+
.authorizeRequests()
30+
.antMatchers(
31+
"/registration**",
32+
"/js",
33+
"/css",
34+
"/img/**",
35+
"/webjars/**").permitAll()
36+
.anyRequest().authenticated()
37+
.and()
38+
.formLogin()
39+
.loginPage("/login")
40+
.permitAll()
41+
.and()
42+
.logout()
43+
.invalidateHttpSession(true)
44+
.clearAuthentication(true)
45+
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
46+
.logoutSuccessUrl("/login?logout")
47+
.permitAll();
48+
}
49+
50+
51+
@Bean
52+
public BCryptPasswordEncoder passwordEncoder() {
53+
return new BCryptPasswordEncoder();
54+
}
55+
56+
@Bean
57+
public DaoAuthenticationProvider authenticationProvider(){
58+
DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
59+
authenticationProvider.setUserDetailsService(userService);
60+
authenticationProvider.setPasswordEncoder(passwordEncoder());
61+
return authenticationProvider;
62+
}
63+
64+
@Override
65+
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
66+
auth.authenticationProvider(authenticationProvider());
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package spring.security.service;
2+
3+
import org.springframework.security.core.userdetails.User;
4+
import org.springframework.security.core.userdetails.UserDetailsService;
5+
import spring.security.repisitory.UserRegistrationDto;
6+
7+
/**
8+
* @Created 29 / 04 / 2020 - 4:37 PM
9+
* @project SpringRegistor
10+
* @Author Hamdamboy
11+
*/
12+
13+
14+
public interface UserService extends UserDetailsService {
15+
16+
User findByEmail(String email);
17+
18+
User save(UserRegistrationDto registration);
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package spring.security.service;
2+
3+
import org.hibernate.mapping.Collection;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.security.core.GrantedAuthority;
6+
import org.springframework.security.core.authority.SimpleGrantedAuthority;
7+
8+
import org.springframework.security.core.userdetails.UserDetails;
9+
import org.springframework.security.core.userdetails.UsernameNotFoundException;
10+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
11+
import org.springframework.stereotype.Service;
12+
import spring.security.model.Role;
13+
import spring.security.model.User;
14+
import spring.security.repisitory.UserRegistrationDto;
15+
import spring.security.repisitory.UserRepository;
16+
17+
import java.util.Arrays;
18+
import java.util.stream.Collectors;
19+
20+
/**
21+
* @Created 29 / 04 / 2020 - 4:39 PM
22+
* @project SpringRegistor
23+
* @Author Hamdamboy
24+
*/
25+
26+
@Service
27+
public class UserServiceImpl implements UserService{
28+
29+
@Autowired
30+
private UserRepository userRepository;
31+
32+
@Autowired
33+
private BCryptPasswordEncoder passwordEncoder;
34+
35+
public User findByEmail(String email) {
36+
return userRepository.findByEmail(email);
37+
}
38+
39+
public User save(UserRegistrationDto registration) {
40+
User user = new User();
41+
user.setFirstName(registration.getFirstName());
42+
user.setLastName(registration.getLastName());
43+
user.setEmail(registration.getEmail());
44+
user.setPassword(passwordEncoder.encode(registration.getPassword()));
45+
user.setRoles(Arrays.asList(new Role("ROLE_USER")));
46+
return userRepository.save(user);
47+
}
48+
49+
@Override
50+
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
51+
User user = userRepository.findByEmail(email);
52+
if (user == null) {
53+
throw new UsernameNotFoundException("Invalid username or password.");
54+
}
55+
return new org.springframework.security.core.userdetails.User(user.getEmail(),
56+
user.getPassword(),
57+
mapRolesToAuthorities(user.getRoles()));
58+
}
59+
60+
private Collection <<? extends GrantedAuthority> mapRolesToAuthorities(Collection <Role> roles) {
61+
return roles.stream()
62+
.map(role -> new SimpleGrantedAuthority(role.getName()))
63+
.collect(Collectors.toList());
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package spring.security.web;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.ui.Model;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
7+
/**
8+
* @Created 29 / 04 / 2020 - 5:31 PM
9+
* @project SpringRegistor
10+
* @Author Hamdamboy
11+
*/
12+
13+
@Controller
14+
public class MainController {
15+
16+
@GetMapping("/")
17+
public String root(){
18+
return "index";
19+
}
20+
21+
@GetMapping("/login")
22+
public String login(Model model){
23+
return "login";
24+
}
25+
26+
@GetMapping("/user")
27+
public String userIndex(){
28+
return "user/index";
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package spring.security.web;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.security.core.userdetails.User;
5+
import org.springframework.stereotype.Controller;
6+
import org.springframework.ui.Model;
7+
import org.springframework.validation.BindingResult;
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.ModelAttribute;
10+
import org.springframework.web.bind.annotation.PostMapping;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import spring.security.repisitory.UserRegistrationDto;
13+
import spring.security.service.UserService;
14+
15+
import javax.validation.Valid;
16+
17+
/**
18+
* @Created 29 / 04 / 2020 - 4:36 PM
19+
* @project SpringRegistor
20+
* @Author Hamdamboy
21+
*/
22+
23+
@Controller
24+
@RequestMapping("/registration")
25+
public class UserRegistrationController {
26+
27+
@Autowired
28+
private UserService userService;
29+
30+
@ModelAttribute("user")
31+
public UserRegistrationDto userRegistrationDto() {
32+
return new UserRegistrationDto();
33+
}
34+
35+
@GetMapping
36+
public String showRegistrationForm(Model model) {
37+
return "registration";
38+
}
39+
40+
@PostMapping
41+
public String registerUserAccount(@ModelAttribute("user") @Valid UserRegistrationDto userDto,
42+
BindingResult result) {
43+
44+
User existing = userService.findByEmail(userDto.getEmail());
45+
if (existing != null) {
46+
result.rejectValue("email", null, "There is already an account registered with that email");
47+
}
48+
49+
if (result.hasErrors()) {
50+
return "registration";
51+
}
52+
53+
userService.save(userDto);
54+
return "redirect:/registration?success";
55+
}
56+
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
## Spring view resolver set up
3+
spring.mvc.view.prefix=/WEB-INF/jsp/
4+
spring.mvc.view.suffix=.jsp
5+
6+
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
7+
spring.datasource.url = jdbc:mysql://localhost:3306/world?useSSL=false
8+
spring.datasource.username = root
9+
spring.datasource.password = posilka2020
10+
11+
## Hibernate Properties
12+
# The SQL dialect makes Hibernate generate better SQL for the chosen database
13+
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
14+
15+
# Hibernate ddl auto (create, create-drop, validate, update)
16+
spring.jpa.hibernate.ddl-auto = update
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html xmlns:th="http://www.thymeleaf.org"
3+
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1" />
8+
9+
<link rel="stylesheet" type="text/css"
10+
th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}" />
11+
12+
<title>Registration</title>
13+
</head>
14+
<body>
15+
<nav class="navbar navbar-inverse navbar-fixed-top">
16+
<div class="container">
17+
<div class="navbar-header">
18+
<button type="button" class="navbar-toggle collapsed"
19+
data-toggle="collapse" data-target="#navbar" aria-expanded="false"
20+
aria-controls="navbar">
21+
<span class="sr-only">Toggle navigation</span> <span
22+
class="icon-bar"></span> <span class="icon-bar"></span> <span
23+
class="icon-bar"></span>
24+
</button>
25+
<a class="navbar-brand" href="#" th:href="@{/}">Registration and
26+
Login Module</a>
27+
</div>
28+
<div id="navbar" class="collapse navbar-collapse">
29+
<ul class="nav navbar-nav">
30+
<li sec:authorize="isAuthenticated()"><a th:href="@{/logout}">Logout</a></li>
31+
</ul>
32+
</div>
33+
</div>
34+
</nav>
35+
36+
<br>
37+
<br>
38+
<div class="container">
39+
<h2>User Registration and Login Module using Spring Boot, Spring
40+
MVC, Spring Security, JPA/Hibernate and Thymeleaf</h2>
41+
42+
<p>
43+
Welcome <span sec:authentication="principal.username">User</span>
44+
</p>
45+
</div>
46+
47+
<script type="text/javascript"
48+
th:src="@{/webjars/jquery/3.2.1/jquery.min.js/}"></script>
49+
<script type="text/javascript"
50+
th:src="@{/webjars/bootstrap/3.3.7/js/bootstrap.min.js}"></script>
51+
52+
</body>
53+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<!DOCTYPE html>
2+
<html xmlns:th="http://www.thymeleaf.org">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
8+
<link rel="stylesheet" type="text/css"
9+
th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}" />
10+
11+
<title>Registration</title>
12+
</head>
13+
<body>
14+
15+
<nav class="navbar navbar-inverse navbar-fixed-top">
16+
<div class="container">
17+
<div class="navbar-header">
18+
<button type="button" class="navbar-toggle collapsed"
19+
data-toggle="collapse" data-target="#navbar" aria-expanded="false"
20+
aria-controls="navbar">
21+
<span class="sr-only">Toggle navigation</span> <span
22+
class="icon-bar"></span> <span class="icon-bar"></span> <span
23+
class="icon-bar"></span>
24+
</button>
25+
<a class="navbar-brand" href="#" th:href="@{/}">Registration and
26+
Login Module</a>
27+
</div>
28+
</div>
29+
</nav>
30+
31+
<br>
32+
<br>
33+
34+
<div class="container">
35+
36+
<div class="row">
37+
<div class="col-md-6 col-md-offset-3">
38+
<h1>Login page</h1>
39+
<form th:action="@{/login}" method="post">
40+
<div th:if="${param.error}">
41+
<div class="alert alert-danger">Invalid username or
42+
password.</div>
43+
</div>
44+
<div th:if="${param.logout}">
45+
<div class="alert alert-info">You have been logged out.</div>
46+
</div>
47+
<div class="form-group">
48+
<label for="username">Username</label>: <input type="text"
49+
id="username" name="username" class="form-control"
50+
autofocus="autofocus" placeholder="Username" />
51+
</div>
52+
<div class="form-group">
53+
<label for="password">Password</label>: <input type="password"
54+
id="password" name="password" class="form-control"
55+
placeholder="Password" />
56+
</div>
57+
<div class="form-group">
58+
<div class="row">
59+
<div class="col-sm-6 col-sm-offset-3">
60+
<input type="submit" name="login-submit" id="login-submit"
61+
class="form-control btn btn-primary" value="Log In" />
62+
</div>
63+
</div>
64+
</div>
65+
<div class="form-group">
66+
<span>New user? <a href="/" th:href="@{/registration}">Register
67+
here</a></span>
68+
</div>
69+
</form>
70+
</div>
71+
</div>
72+
73+
74+
</div>
75+
76+
<script type="text/javascript"
77+
th:src="@{/webjars/jquery/3.2.1/jquery.min.js/}"></script>
78+
<script type="text/javascript"
79+
th:src="@{/webjars/bootstrap/3.3.7/js/bootstrap.min.js}"></script>
80+
81+
</body>
82+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<!DOCTYPE html>
2+
<html xmlns:th="http://www.thymeleaf.org">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
8+
<link rel="stylesheet" type="text/css"
9+
th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}" />
10+
11+
<title>Registration</title>
12+
</head>
13+
<body>
14+
<nav class="navbar navbar-inverse navbar-fixed-top">
15+
<div class="container">
16+
<div class="navbar-header">
17+
<button type="button" class="navbar-toggle collapsed"
18+
data-toggle="collapse" data-target="#navbar" aria-expanded="false"
19+
aria-controls="navbar">
20+
<span class="sr-only">Toggle navigation</span> <span
21+
class="icon-bar"></span> <span class="icon-bar"></span> <span
22+
class="icon-bar"></span>
23+
</button>
24+
<a class="navbar-brand" href="#" th:href="@{/}">Registration and
25+
Login Module</a>
26+
</div>
27+
</div>
28+
</nav>
29+
30+
<br>
31+
<br>
32+
33+
<div class="container">
34+
<div class="row">
35+
<div class="col-md-6 col-md-offset-3">
36+
37+
<div th:if="${param.success}">
38+
<div class="alert alert-info">You've successfully registered
39+
to our awesome app!</div>
40+
</div>
41+
42+
<h1>Registration</h1>
43+
<form th:action="@{/registration}" th:object="${user}" method="post">
44+
45+
<p class="error-message" th:if="${#fields.hasGlobalErrors()}"
46+
th:each="error : ${#fields.errors('global')}" th:text="${error}">Validation
47+
error</p>
48+
49+
<div class="form-group"
50+
th:classappend="${#fields.hasErrors('firstName')}? 'has-error':''">
51+
<label for="firstName" class="control-label">First name</label> <input
52+
id="firstName" class="form-control" th:field="*{firstName}" />
53+
<p class="error-message"
54+
th:each="error: ${#fields.errors('firstName')}"
55+
th:text="${error}">Validation error</p>
56+
</div>
57+
<div class="form-group"
58+
th:classappend="${#fields.hasErrors('lastName')}? 'has-error':''">
59+
<label for="lastName" class="control-label">Last name</label> <input
60+
id="lastName" class="form-control" th:field="*{lastName}" />
61+
<p class="error-message"
62+
th:each="error : ${#fields.errors('lastName')}"
63+
th:text="${error}">Validation error</p>
64+
</div>
65+
<div class="form-group"
66+
th:classappend="${#fields.hasErrors('email')}? 'has-error':''">
67+
<label for="email" class="control-label">E-mail</label> <input
68+
id="email" class="form-control" th:field="*{email}" />
69+
<p class="error-message"
70+
th:each="error : ${#fields.errors('email')}" th:text="${error}">Validation
71+
error</p>
72+
</div>
73+
<div class="form-group"
74+
th:classappend="${#fields.hasErrors('confirmEmail')}? 'has-error':''">
75+
<label for="confirmEmail" class="control-label">Confirm
76+
e-mail</label> <input id="confirmEmail" class="form-control"
77+
th:field="*{confirmEmail}" />
78+
<p class="error-message"
79+
th:each="error : ${#fields.errors('confirmEmail')}"
80+
th:text="${error}">Validation error</p>
81+
</div>
82+
<div class="form-group"
83+
th:classappend="${#fields.hasErrors('password')}? 'has-error':''">
84+
<label for="password" class="control-label">Password</label> <input
85+
id="password" class="form-control" type="password"
86+
th:field="*{password}" />
87+
<p class="error-message"
88+
th:each="error : ${#fields.errors('password')}"
89+
th:text="${error}">Validation error</p>
90+
</div>
91+
<div class="form-group"
92+
th:classappend="${#fields.hasErrors('confirmPassword')}? 'has-error':''">
93+
<label for="confirmPassword" class="control-label">Confirm
94+
password</label> <input id="confirmPassword" class="form-control"
95+
type="password" th:field="*{confirmPassword}" />
96+
<p class="error-message"
97+
th:each="error : ${#fields.errors('confirmPassword')}"
98+
th:text="${error}">Validation error</p>
99+
</div>
100+
<div class="form-group"
101+
th:classappend="${#fields.hasErrors('terms')}? 'has-error':''">
102+
<input id="terms" type="checkbox" th:field="*{terms}" /> <label
103+
class="control-label" for="terms"> I agree with the <a
104+
href="#">terms and conditions</a> for Registration.
105+
</label>
106+
<p class="error-message"
107+
th:each="error : ${#fields.errors('terms')}" th:text="${error}">Validation
108+
error</p>
109+
</div>
110+
<div class="form-group">
111+
<button type="submit" class="btn btn-success">Register</button>
112+
<span>Already registered? <a href="/" th:href="@{/login}">Login
113+
here</a></span>
114+
</div>
115+
116+
</form>
117+
</div>
118+
</div>
119+
</div>
120+
121+
<script type="text/javascript"
122+
th:src="@{/webjars/jquery/3.2.1/jquery.min.js/}"></script>
123+
<script type="text/javascript"
124+
th:src="@{/webjars/bootstrap/3.3.7/js/bootstrap.min.js}"></script>
125+
</body>
126+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package spring.security;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class SecurityApplicationTests {
8+
9+
@Test
10+
void contextLoads() {
11+
}
12+
13+
}

0 commit comments

Comments
 (0)
Please sign in to comment.