From a940aa71afb31b220119e0ba9eb902b72ad685c2 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Thu, 23 Jan 2025 11:33:01 -0500 Subject: [PATCH 001/100] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b2588bc51..29b628996 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ My groupmembers are: -- XXXX +- Yassine Bihi - XXXX - XXXX - XXXX From 72561d1ac3f311835ce5895ff61a5c27477505c3 Mon Sep 17 00:00:00 2001 From: Diego Rivera <159937690+DiegoRiveraa@users.noreply.github.com> Date: Thu, 23 Jan 2025 11:35:17 -0500 Subject: [PATCH 002/100] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 29b628996..5c682451f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ My groupmembers are: - Yassine Bihi -- XXXX +- Diego Rivera - XXXX - XXXX From 3de2db4a17e0229c2a9956e13bad677d4a3d7347 Mon Sep 17 00:00:00 2001 From: ChrisJackson0313 Date: Thu, 23 Jan 2025 11:35:45 -0500 Subject: [PATCH 003/100] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c682451f..e466c1f20 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ My groupmembers are: - Yassine Bihi - Diego Rivera -- XXXX +- Christian Jackson - XXXX From 7a4f2b4a316ba1e7db234d788b3efd56f2709506 Mon Sep 17 00:00:00 2001 From: jadelmasri00 Date: Thu, 23 Jan 2025 11:36:03 -0500 Subject: [PATCH 004/100] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e466c1f20..3f8a6a9cf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ My groupmembers are: - Yassine Bihi - Diego Rivera - Christian Jackson -- XXXX +- Jad El Masri ------------------ Fill in some information about your project under this ------------------ From f9399453092d32937f9ed5c2e8b9e3094ca54b5e Mon Sep 17 00:00:00 2001 From: Diego Rivera <159937690+DiegoRiveraa@users.noreply.github.com> Date: Thu, 23 Jan 2025 11:40:10 -0500 Subject: [PATCH 005/100] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f8a6a9cf..30fea0955 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,6 @@ My groupmembers are: - Diego Rivera - Christian Jackson - Jad El Masri - +- ------------------ Fill in some information about your project under this ------------------ From 206c74eb6b08d231c19d6b22a814399b2da24431 Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:30:01 -0500 Subject: [PATCH 006/100] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 30fea0955..573ed80cc 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,6 @@ My groupmembers are: - Diego Rivera - Christian Jackson - Jad El Masri -- +- Ozi Jawad ------------------ Fill in some information about your project under this ------------------ From a45d3aa238be4dc29ec4aa09493461d9d9dafb04 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Mon, 24 Mar 2025 20:06:41 -0400 Subject: [PATCH 007/100] Skeleton Prototype --- Sprint 1/deliverable3.zip | Bin 0 -> 25604 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Sprint 1/deliverable3.zip diff --git a/Sprint 1/deliverable3.zip b/Sprint 1/deliverable3.zip new file mode 100644 index 0000000000000000000000000000000000000000..271fa57c4875ea58c73f8bd38e676d0a6633b4d4 GIT binary patch literal 25604 zcmbtc1zgoh*S@rLcS?7+v~;I*cXvrB9a7TW-JOC;BOLE^-x@vHQv=1%%fP7dY<&Q8XT4Aw3-u0&48ZcaqTwpP4WCNR|W zhSo-Z{>IP&_`93xZzOpDxT!u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o^t0=Ieh0cCtpLc#-Bx|Sx8pX5 zLSk_l_Agp<|4N|WL5P4L(?16R+U|c`5Of>RU?%6mU-#8-^xeOs<~Cp>&`AGDtM1%b za~rV>rw|1 z*~t5slH3L(09vCzq4m}kCAaYuhW>8I{nm~5?+3Y!2L@bae}Z@CwvaoBztq(GJ4q;j z-w|(y!xF-eh&M;LZ)1?iIRA3U{kVaHa|Z(n@n;ynAN#(I)mH2J3#^|V4*$J9HzQB{ zZ?XRBsQ7Ievap{1QidC?xqE*2whTqUh~u4Jy#3+kH1TaXdi7r`&HZD!x8dHR`~dgA zL%O$77Df$!*{J)69dDzI0@F`#x8wVbbhjarTU34tanq2yDXq65WPu;*?kA6UqDls=H@2b7yg=xqpeJ^NoYzp(dX?Z0c`&BUAiPhsznaa#r{56fEQU+C!l`21}dj{cPlx1#m8#o7Ec z-~Uf+z`HU1-^IC^yJdj;mUmivzw3XpYbpFU5&qlq{gd%_KeGP2d^cTY%KC5Q`)#-D zwj?CeA29xYa(Mu_AC3QAk{hO4|AQpoH^^=V?ro9QN`5600B}E8{kupvh4_yB)%MDvA|4EkHTL$-d`lW1u?-6F85P!Ug?##~#!1R`%E7qUU z>f3BEN~4tg%6q#X)4t8d`+tD=^WfEOIW$L6e<8=uLe9U-aibw^!2R`Kwfuhp=-a@6 zp^R+$za2dHfvN9M4hBq@_!aPf5b;i{1zS_e Date: Tue, 25 Mar 2025 09:06:14 -0400 Subject: [PATCH 008/100] Skeleton Prototype --- Sprint 1/deliverable3/HELP.md | 29 ++ Sprint 1/deliverable3/deliverable3.iml | 13 + Sprint 1/deliverable3/mvnw | 259 ++++++++++++++++++ Sprint 1/deliverable3/mvnw.cmd | 149 ++++++++++ Sprint 1/deliverable3/pom.xml | 104 +++++++ .../Controller/indexController.java | 44 +++ .../deliverable3/Deliverable3Application.java | 13 + .../com/jydoc/deliverable3/Model/User.java | 34 +++ .../Repository/UserRepository.java | 8 + .../deliverable3/Service/UserService.java | 13 + .../src/main/resources/application.properties | 6 + .../src/main/resources/templates/error.html | 10 + .../src/main/resources/templates/index.html | 28 ++ .../src/main/resources/templates/login.html | 23 ++ .../resources/templates/loginSuccess.html | 10 + .../src/main/resources/templates/styles.css | 0 .../Deliverable3ApplicationTests.java | 13 + .../target/classes/application.properties | 6 + .../Controller/indexController.class | Bin 0 -> 1602 bytes .../Deliverable3Application.class | Bin 0 -> 769 bytes .../com/jydoc/deliverable3/Model/User.class | Bin 0 -> 2016 bytes .../Repository/UserRepository.class | Bin 0 -> 353 bytes .../deliverable3/Service/UserService.class | Bin 0 -> 320 bytes .../target/classes/templates/error.html | 10 + .../target/classes/templates/index.html | 28 ++ .../target/classes/templates/login.html | 23 ++ .../classes/templates/loginSuccess.html | 10 + .../target/classes/templates/styles.css | 0 28 files changed, 833 insertions(+) create mode 100644 Sprint 1/deliverable3/HELP.md create mode 100644 Sprint 1/deliverable3/deliverable3.iml create mode 100644 Sprint 1/deliverable3/mvnw create mode 100644 Sprint 1/deliverable3/mvnw.cmd create mode 100644 Sprint 1/deliverable3/pom.xml create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/User.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java create mode 100644 Sprint 1/deliverable3/src/main/resources/application.properties create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/error.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/index.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/login.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/styles.css create mode 100644 Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java create mode 100644 Sprint 1/deliverable3/target/classes/application.properties create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Model/User.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class create mode 100644 Sprint 1/deliverable3/target/classes/templates/error.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/index.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/login.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/loginSuccess.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/styles.css diff --git a/Sprint 1/deliverable3/HELP.md b/Sprint 1/deliverable3/HELP.md new file mode 100644 index 000000000..786794155 --- /dev/null +++ b/Sprint 1/deliverable3/HELP.md @@ -0,0 +1,29 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.4/maven-plugin) +* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.4/maven-plugin/build-image.html) +* [Spring Web](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html) +* [Thymeleaf](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html#web.servlet.spring-mvc.template-engines) +* [htmx](https://github.com/wimdeblauwe/htmx-spring-boot) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) +* [Handling Form Submission](https://spring.io/guides/gs/handling-form-submission/) +* [htmx](https://www.youtube.com/watch?v=j-rfPoXe5aE) +* [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/) + +### Maven Parent overrides + +Due to Maven's design, elements are inherited from the parent POM to the project POM. +While most of the inheritance is fine, it also inherits unwanted elements like `` and `` from the parent. +To prevent this, the project POM contains empty overrides for these elements. +If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. + diff --git a/Sprint 1/deliverable3/deliverable3.iml b/Sprint 1/deliverable3/deliverable3.iml new file mode 100644 index 000000000..2cf3f920f --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/mvnw b/Sprint 1/deliverable3/mvnw new file mode 100644 index 000000000..19529ddf8 --- /dev/null +++ b/Sprint 1/deliverable3/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/Sprint 1/deliverable3/mvnw.cmd b/Sprint 1/deliverable3/mvnw.cmd new file mode 100644 index 000000000..249bdf382 --- /dev/null +++ b/Sprint 1/deliverable3/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/Sprint 1/deliverable3/pom.xml b/Sprint 1/deliverable3/pom.xml new file mode 100644 index 000000000..53a26bf67 --- /dev/null +++ b/Sprint 1/deliverable3/pom.xml @@ -0,0 +1,104 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.4 + + + com.jydoc + deliverable3 + 0.0.1-SNAPSHOT + deliverable3 + Demo project for Spring Boot + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-web + + + io.github.wimdeblauwe + htmx-spring-boot-thymeleaf + 4.0.1 + + + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.modelmapper + modelmapper + 3.2.0 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java new file mode 100644 index 000000000..5c4c1fd0a --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java @@ -0,0 +1,44 @@ +package com.jydoc.deliverable3.Controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.time.LocalDate; + + + + +@Controller +public class indexController { + + // This method maps to the root URL ("/") + @GetMapping("/") + public String index(Model model) { + // Add the user's name to the model (this can be dynamic) + model.addAttribute("userName", "Guest"); + + // Add the current date to the model + model.addAttribute("currentDate", LocalDate.now()); + + // Return the name of the Thymeleaf template ("index") + return "index"; + } + + @GetMapping("/login") + public String login(Model model) { + return "login"; + } + + @PostMapping("/login") + public String handleLogin(@RequestParam String username, @RequestParam String password, Model model) { + // Here, you would usually authenticate the user, for now we just show the data + model.addAttribute("username", username); + model.addAttribute("password", password); + // You can create a new page to show after login success + return "loginSuccess"; + } +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java new file mode 100644 index 000000000..64bf1de75 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java @@ -0,0 +1,13 @@ +package com.jydoc.deliverable3; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Deliverable3Application { + + public static void main(String[] args) { + SpringApplication.run(Deliverable3Application.class, args); + } + +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/User.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/User.java new file mode 100644 index 000000000..4bd68786a --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/User.java @@ -0,0 +1,34 @@ +package com.jydoc.deliverable3.Model; +import jakarta.persistence.*; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Getter +@Setter +@NoArgsConstructor + +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name="user-id") + private Long id; + + @Column(name="user-firstname") + private String firstName; + + @Column(name="user-lastname") + private String lastName; + + @Column(name="user-email") + private String email; + + @Column(name="user-password") + private String password; + +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java new file mode 100644 index 000000000..dbfdb323b --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java @@ -0,0 +1,8 @@ +package com.jydoc.deliverable3.Repository; + +import com.jydoc.deliverable3.Model.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserRepository extends JpaRepository { + +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java new file mode 100644 index 000000000..010351af7 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java @@ -0,0 +1,13 @@ +package com.jydoc.deliverable3.Service; + +public class UserService { + + + + + + + + + +} diff --git a/Sprint 1/deliverable3/src/main/resources/application.properties b/Sprint 1/deliverable3/src/main/resources/application.properties new file mode 100644 index 000000000..60ae6054f --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.application.name=deliverable3 +spring.jpa.hibernate.ddl-auto=create +spring.datasource.url=jdbc:mysql://localhost:3306/user_database +spring.datasource.username=root +spring.datasource.password=siAZ10xD0r7f5DL@ +spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/src/main/resources/templates/error.html b/Sprint 1/deliverable3/src/main/resources/templates/error.html new file mode 100644 index 000000000..130701ba9 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/error.html @@ -0,0 +1,10 @@ + + + + + Error + + +Error + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/index.html b/Sprint 1/deliverable3/src/main/resources/templates/index.html new file mode 100644 index 000000000..b2b410bd7 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/index.html @@ -0,0 +1,28 @@ + + + + + Thymeleaf Example + + + + + + + Thymeleaf Example + + +

Welcome to Thymeleaf!

+ +

+ +
+

Current Date and Time:

+
+ + +
+ +
+ + diff --git a/Sprint 1/deliverable3/src/main/resources/templates/login.html b/Sprint 1/deliverable3/src/main/resources/templates/login.html new file mode 100644 index 000000000..795d5cb8c --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/login.html @@ -0,0 +1,23 @@ + + + + + Login + + +

Login

+
+
+ + +
+
+ + +
+
+ +
+
+ + diff --git a/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html b/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html new file mode 100644 index 000000000..7a517bfcb --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html @@ -0,0 +1,10 @@ + + + + + Title + + +Login Success + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/styles.css b/Sprint 1/deliverable3/src/main/resources/templates/styles.css new file mode 100644 index 000000000..e69de29bb diff --git a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java new file mode 100644 index 000000000..b233ee828 --- /dev/null +++ b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java @@ -0,0 +1,13 @@ +package com.jydoc.deliverable3; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Deliverable3ApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/Sprint 1/deliverable3/target/classes/application.properties b/Sprint 1/deliverable3/target/classes/application.properties new file mode 100644 index 000000000..60ae6054f --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/application.properties @@ -0,0 +1,6 @@ +spring.application.name=deliverable3 +spring.jpa.hibernate.ddl-auto=create +spring.datasource.url=jdbc:mysql://localhost:3306/user_database +spring.datasource.username=root +spring.datasource.password=siAZ10xD0r7f5DL@ +spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class new file mode 100644 index 0000000000000000000000000000000000000000..724c3359f1f42543fbc34eae46a1102522409e29 GIT binary patch literal 1602 zcmb7ET~pIQ6g^8?8r$+=Kq^=f@Pn2Dk#Dt(GYpKp6lB1u4?d;MT7v1OCL54{rB8l5 z_yhb=j(3yV7KiB|Gwkl&y?f3*XK(uJ_m7_dcCeks0JIbmStK#YFnVU4Tc&G?hWWa7 z#_N({aN7}%e952{id7vtgB}LlKeU=$N17qIAM!wEki}36!&!`Alp*i=4Krx@j%d91 zDf7bfKbWCo9(Xo)8M2mb??~x8wNP?~y+WnSdqUfyQSRA^D=8N%{Xok)42DcS^nEVm zo+Wu24*RWf+Snq|@YP#j9JcN+D6gyI{x_iZS2SW5S#wfsU~GCmnfOx?aN( zI;Ptuh{%K)idt3>kVsp{9LbB)PQrSf2SEyt7*^_D(>%Mhy}C&TIOp8AYA#e(2o{rl{1=k;x~YppPP zy0zoa#*K9xc|nhmxvSoEY`bF8=8eIR`A7AEMlfVk`os(UI)CM;P8$EG>6Xlk}zMBjkzrb{m;+ zP{JZHEKz2X1k$uj|HHJU>U{bREWiq_@|_a4C{iV8#=S0AT>Wehht}cHZo;ujsB2g! zuarj(Dm_7SZppY`ij^%H4;I@RXS=+y#(AWPZJbI}?k&VuJN!9JV}sxc4l}e;#pj}$ rv`F`mMhT!JT+zQtS7QCE*rKx$jW(XqA|92?&nX(fi^wwNKpFT0ogIQ} literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class new file mode 100644 index 0000000000000000000000000000000000000000..efcd494a354085320bc8fee605438a97b7adbd6f GIT binary patch literal 769 zcmb7CO;6iE5PcgG970+ke3h0SxP=^8BqT1WkkX)@3{*{(9(r0ki`iiBM(Z^nKZ{eV z9{2(MQB`MMBzy>mTJnr$X6Mb!oB93c*CT)d-nUT0LV$W34JR_=shp}Rj0&}2A>O~$A96BF}^Ox2CFB1+{EKdl&p*(_DDaLVWwT38OyZsQeR zGxUs2cs{dACzn=a^48dE9vS2KsB~5`sirM7L(~nQ`x>Sq&->pio{{rl{rzwra%{Ad zca9H@zEnw3wpuAcZXfP5)Q4sw8CF82<#~}s(th=0F?2!`i*zik^7fOn?ygkMa2Wm{ z7rss=6wS2Noj1am;=(3`ygnyP`#F>D%1k~B&zzH%9=1lNu(AB4e6PDN?BKxj$FTFI z&`xD?ta3%O474_`+!5iN%%!hfj3}HT9!vh@)0#fg#wtAav4?&rJLK&(B{(v_o&=6rr9N^=cHQK1TCpyQZHtDt1|~ za8q1z$0(V6T|cm4>L)ID7)3;dQ96HSTpGG*SXDi5Th&bk>enbv2}bcx!g1xHQR9p< zO@YVK5kaV?QA&mOn}#2$_77^5Rv)9hW(ZS#$!Ij}g#Q*L6bPf z^(o$$&Ujfe>e~{QklT!UvP(rqlOO7q6g6HHuE14xEX$UL6t?9un!wr44M!UK1$SKG zN^X_8o~vv!S`2l);}#T=yizpGI!9Q)E0tYsbl8D>g~o-qBlmXiu#hW!WHb|+W7jt8 zH4E%s%M&nGhw7_J^8s(=Y3sXE-Up?iZznw46OWPaywVM#R=Lc9lF2SLmBgzZa_yqP zj0W?<;)nHGi8}>VcvU{TY?wvE5y}oe_R3QM`4;jWy9L*n4hoR7E<;L?$(weqWS{H* zq{S8uN8P_}p^+OW4w{Hj5>fe}dr%2jd#Y`G$5GHPxVP)ydpO&AZPgy>11?YP%8}tf zY>6&Fc5GV2euhS=v?YdLu`$DN1KS3?mRL}me`g>?r+1R9c zH2)|@G>SJSlNe3GnxY<>#(M_#ET>y^o93{bcj*q|Fnd8<67RsV00$FLUvRl00w*fxYhTjaw z4|I$7yFb9E+wfcA_@Qp`{tN~9;Wj+}zfi85bM%8oTIs0{Jrbc;UN3BWKM-p6UK9NV D6~K-? zo~h#6)5EHiyi0KEFjw=`HWq5XHr~p!+J*}5n97F92I5`A1JGf-48G=WXX5aZ{YIzR zzp#t!53_rXqPPp?yl$x?Tg%WbG)n#-T=S6|tpsKZgLllVqpgrx6h825AX E2}WjdmH+?% literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class new file mode 100644 index 0000000000000000000000000000000000000000..0850eb76753fa40e700d45378184f69c74d75b94 GIT binary patch literal 320 zcma)1O-sW-5Pg%6rpDF=|ADt!#65Ua1Q9$1Jyd(&YzEzsW?`EK{8^p~9{d6RC~>y* z;L#a)GjC>?$NT>I`~q-?B1eQcLoz{%5us@GpjE58SM^jiY + + + + Error + + +Error + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/index.html b/Sprint 1/deliverable3/target/classes/templates/index.html new file mode 100644 index 000000000..b2b410bd7 --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/templates/index.html @@ -0,0 +1,28 @@ + + + + + Thymeleaf Example + + + + + + + Thymeleaf Example + + +

Welcome to Thymeleaf!

+ +

+ +
+

Current Date and Time:

+
+ + +
+ +
+ + diff --git a/Sprint 1/deliverable3/target/classes/templates/login.html b/Sprint 1/deliverable3/target/classes/templates/login.html new file mode 100644 index 000000000..795d5cb8c --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/templates/login.html @@ -0,0 +1,23 @@ + + + + + Login + + +

Login

+
+
+ + +
+
+ + +
+
+ +
+
+ + diff --git a/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html b/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html new file mode 100644 index 000000000..7a517bfcb --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html @@ -0,0 +1,10 @@ + + + + + Title + + +Login Success + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/styles.css b/Sprint 1/deliverable3/target/classes/templates/styles.css new file mode 100644 index 000000000..e69de29bb From 3eccb6b69bc486b5e78512aeda037b39e446be2c Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Tue, 25 Mar 2025 09:12:48 -0400 Subject: [PATCH 009/100] Update application.properties --- .../deliverable3/src/main/resources/application.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint 1/deliverable3/src/main/resources/application.properties b/Sprint 1/deliverable3/src/main/resources/application.properties index 60ae6054f..79c9efc14 100644 --- a/Sprint 1/deliverable3/src/main/resources/application.properties +++ b/Sprint 1/deliverable3/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.application.name=deliverable3 spring.jpa.hibernate.ddl-auto=create spring.datasource.url=jdbc:mysql://localhost:3306/user_database -spring.datasource.username=root -spring.datasource.password=siAZ10xD0r7f5DL@ +spring.datasource.username= +spring.datasource.password= spring.datasource.driverClassName=com.mysql.jdbc.Driver From eeb4c08a38523c73343b7823343e0d7b1f06bead Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Tue, 25 Mar 2025 11:35:29 -0400 Subject: [PATCH 010/100] Delete Sprint 1/deliverable3 directory --- Sprint 1/deliverable3/HELP.md | 29 -- Sprint 1/deliverable3/deliverable3.iml | 13 - Sprint 1/deliverable3/mvnw | 259 ------------------ Sprint 1/deliverable3/mvnw.cmd | 149 ---------- Sprint 1/deliverable3/pom.xml | 104 ------- .../Controller/indexController.java | 44 --- .../deliverable3/Deliverable3Application.java | 13 - .../com/jydoc/deliverable3/Model/User.java | 34 --- .../Repository/UserRepository.java | 8 - .../deliverable3/Service/UserService.java | 13 - .../src/main/resources/application.properties | 6 - .../src/main/resources/templates/error.html | 10 - .../src/main/resources/templates/index.html | 28 -- .../src/main/resources/templates/login.html | 23 -- .../resources/templates/loginSuccess.html | 10 - .../src/main/resources/templates/styles.css | 0 .../Deliverable3ApplicationTests.java | 13 - .../target/classes/application.properties | 6 - .../Controller/indexController.class | Bin 1602 -> 0 bytes .../Deliverable3Application.class | Bin 769 -> 0 bytes .../com/jydoc/deliverable3/Model/User.class | Bin 2016 -> 0 bytes .../Repository/UserRepository.class | Bin 353 -> 0 bytes .../deliverable3/Service/UserService.class | Bin 320 -> 0 bytes .../target/classes/templates/error.html | 10 - .../target/classes/templates/index.html | 28 -- .../target/classes/templates/login.html | 23 -- .../classes/templates/loginSuccess.html | 10 - .../target/classes/templates/styles.css | 0 28 files changed, 833 deletions(-) delete mode 100644 Sprint 1/deliverable3/HELP.md delete mode 100644 Sprint 1/deliverable3/deliverable3.iml delete mode 100644 Sprint 1/deliverable3/mvnw delete mode 100644 Sprint 1/deliverable3/mvnw.cmd delete mode 100644 Sprint 1/deliverable3/pom.xml delete mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java delete mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java delete mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/User.java delete mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java delete mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java delete mode 100644 Sprint 1/deliverable3/src/main/resources/application.properties delete mode 100644 Sprint 1/deliverable3/src/main/resources/templates/error.html delete mode 100644 Sprint 1/deliverable3/src/main/resources/templates/index.html delete mode 100644 Sprint 1/deliverable3/src/main/resources/templates/login.html delete mode 100644 Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html delete mode 100644 Sprint 1/deliverable3/src/main/resources/templates/styles.css delete mode 100644 Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java delete mode 100644 Sprint 1/deliverable3/target/classes/application.properties delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Model/User.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class delete mode 100644 Sprint 1/deliverable3/target/classes/templates/error.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/index.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/login.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/loginSuccess.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/styles.css diff --git a/Sprint 1/deliverable3/HELP.md b/Sprint 1/deliverable3/HELP.md deleted file mode 100644 index 786794155..000000000 --- a/Sprint 1/deliverable3/HELP.md +++ /dev/null @@ -1,29 +0,0 @@ -# Getting Started - -### Reference Documentation -For further reference, please consider the following sections: - -* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) -* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.4/maven-plugin) -* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.4/maven-plugin/build-image.html) -* [Spring Web](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html) -* [Thymeleaf](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html#web.servlet.spring-mvc.template-engines) -* [htmx](https://github.com/wimdeblauwe/htmx-spring-boot) - -### Guides -The following guides illustrate how to use some features concretely: - -* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) -* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) -* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) -* [Handling Form Submission](https://spring.io/guides/gs/handling-form-submission/) -* [htmx](https://www.youtube.com/watch?v=j-rfPoXe5aE) -* [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/) - -### Maven Parent overrides - -Due to Maven's design, elements are inherited from the parent POM to the project POM. -While most of the inheritance is fine, it also inherits unwanted elements like `` and `` from the parent. -To prevent this, the project POM contains empty overrides for these elements. -If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. - diff --git a/Sprint 1/deliverable3/deliverable3.iml b/Sprint 1/deliverable3/deliverable3.iml deleted file mode 100644 index 2cf3f920f..000000000 --- a/Sprint 1/deliverable3/deliverable3.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/mvnw b/Sprint 1/deliverable3/mvnw deleted file mode 100644 index 19529ddf8..000000000 --- a/Sprint 1/deliverable3/mvnw +++ /dev/null @@ -1,259 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Apache Maven Wrapper startup batch script, version 3.3.2 -# -# Optional ENV vars -# ----------------- -# JAVA_HOME - location of a JDK home dir, required when download maven via java source -# MVNW_REPOURL - repo url base for downloading maven distribution -# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output -# ---------------------------------------------------------------------------- - -set -euf -[ "${MVNW_VERBOSE-}" != debug ] || set -x - -# OS specific support. -native_path() { printf %s\\n "$1"; } -case "$(uname)" in -CYGWIN* | MINGW*) - [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" - native_path() { cygpath --path --windows "$1"; } - ;; -esac - -# set JAVACMD and JAVACCMD -set_java_home() { - # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched - if [ -n "${JAVA_HOME-}" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - JAVACCMD="$JAVA_HOME/jre/sh/javac" - else - JAVACMD="$JAVA_HOME/bin/java" - JAVACCMD="$JAVA_HOME/bin/javac" - - if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then - echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 - echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 - return 1 - fi - fi - else - JAVACMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v java - )" || : - JAVACCMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v javac - )" || : - - if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then - echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 - return 1 - fi - fi -} - -# hash string like Java String::hashCode -hash_string() { - str="${1:-}" h=0 - while [ -n "$str" ]; do - char="${str%"${str#?}"}" - h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) - str="${str#?}" - done - printf %x\\n $h -} - -verbose() { :; } -[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } - -die() { - printf %s\\n "$1" >&2 - exit 1 -} - -trim() { - # MWRAPPER-139: - # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. - # Needed for removing poorly interpreted newline sequences when running in more - # exotic environments such as mingw bash on Windows. - printf "%s" "${1}" | tr -d '[:space:]' -} - -# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties -while IFS="=" read -r key value; do - case "${key-}" in - distributionUrl) distributionUrl=$(trim "${value-}") ;; - distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; - esac -done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" -[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" - -case "${distributionUrl##*/}" in -maven-mvnd-*bin.*) - MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ - case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in - *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; - :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; - :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; - :Linux*x86_64*) distributionPlatform=linux-amd64 ;; - *) - echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 - distributionPlatform=linux-amd64 - ;; - esac - distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" - ;; -maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; -*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; -esac - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" -distributionUrlName="${distributionUrl##*/}" -distributionUrlNameMain="${distributionUrlName%.*}" -distributionUrlNameMain="${distributionUrlNameMain%-bin}" -MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" -MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" - -exec_maven() { - unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : - exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" -} - -if [ -d "$MAVEN_HOME" ]; then - verbose "found existing MAVEN_HOME at $MAVEN_HOME" - exec_maven "$@" -fi - -case "${distributionUrl-}" in -*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; -*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; -esac - -# prepare tmp dir -if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then - clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } - trap clean HUP INT TERM EXIT -else - die "cannot create temp dir" -fi - -mkdir -p -- "${MAVEN_HOME%/*}" - -# Download and Install Apache Maven -verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -verbose "Downloading from: $distributionUrl" -verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -# select .zip or .tar.gz -if ! command -v unzip >/dev/null; then - distributionUrl="${distributionUrl%.zip}.tar.gz" - distributionUrlName="${distributionUrl##*/}" -fi - -# verbose opt -__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' -[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v - -# normalize http auth -case "${MVNW_PASSWORD:+has-password}" in -'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; -has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; -esac - -if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then - verbose "Found wget ... using wget" - wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" -elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then - verbose "Found curl ... using curl" - curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" -elif set_java_home; then - verbose "Falling back to use Java to download" - javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" - targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" - cat >"$javaSource" <<-END - public class Downloader extends java.net.Authenticator - { - protected java.net.PasswordAuthentication getPasswordAuthentication() - { - return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); - } - public static void main( String[] args ) throws Exception - { - setDefault( new Downloader() ); - java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); - } - } - END - # For Cygwin/MinGW, switch paths to Windows format before running javac and java - verbose " - Compiling Downloader.java ..." - "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" - verbose " - Running Downloader.java ..." - "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" -fi - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -if [ -n "${distributionSha256Sum-}" ]; then - distributionSha256Result=false - if [ "$MVN_CMD" = mvnd.sh ]; then - echo "Checksum validation is not supported for maven-mvnd." >&2 - echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - elif command -v sha256sum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - elif command -v shasum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - else - echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 - echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - fi - if [ $distributionSha256Result = false ]; then - echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 - echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 - exit 1 - fi -fi - -# unzip and move -if command -v unzip >/dev/null; then - unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" -else - tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" -fi -printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" -mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" - -clean || : -exec_maven "$@" diff --git a/Sprint 1/deliverable3/mvnw.cmd b/Sprint 1/deliverable3/mvnw.cmd deleted file mode 100644 index 249bdf382..000000000 --- a/Sprint 1/deliverable3/mvnw.cmd +++ /dev/null @@ -1,149 +0,0 @@ -<# : batch portion -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.3.2 -@REM -@REM Optional ENV vars -@REM MVNW_REPOURL - repo url base for downloading maven distribution -@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output -@REM ---------------------------------------------------------------------------- - -@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) -@SET __MVNW_CMD__= -@SET __MVNW_ERROR__= -@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% -@SET PSModulePath= -@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( - IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) -) -@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% -@SET __MVNW_PSMODULEP_SAVE= -@SET __MVNW_ARG0_NAME__= -@SET MVNW_USERNAME= -@SET MVNW_PASSWORD= -@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) -@echo Cannot start maven from wrapper >&2 && exit /b 1 -@GOTO :EOF -: end batch / begin powershell #> - -$ErrorActionPreference = "Stop" -if ($env:MVNW_VERBOSE -eq "true") { - $VerbosePreference = "Continue" -} - -# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties -$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl -if (!$distributionUrl) { - Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" -} - -switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { - "maven-mvnd-*" { - $USE_MVND = $true - $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" - $MVN_CMD = "mvnd.cmd" - break - } - default { - $USE_MVND = $false - $MVN_CMD = $script -replace '^mvnw','mvn' - break - } -} - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -if ($env:MVNW_REPOURL) { - $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } - $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" -} -$distributionUrlName = $distributionUrl -replace '^.*/','' -$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' -$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" -if ($env:MAVEN_USER_HOME) { - $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" -} -$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' -$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" - -if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { - Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" - Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" - exit $? -} - -if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { - Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" -} - -# prepare tmp dir -$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile -$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" -$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null -trap { - if ($TMP_DOWNLOAD_DIR.Exists) { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } - } -} - -New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null - -# Download and Install Apache Maven -Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -Write-Verbose "Downloading from: $distributionUrl" -Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -$webclient = New-Object System.Net.WebClient -if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { - $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) -} -[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum -if ($distributionSha256Sum) { - if ($USE_MVND) { - Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." - } - Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash - if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { - Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." - } -} - -# unzip and move -Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null -Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null -try { - Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null -} catch { - if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { - Write-Error "fail to move MAVEN_HOME" - } -} finally { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } -} - -Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/Sprint 1/deliverable3/pom.xml b/Sprint 1/deliverable3/pom.xml deleted file mode 100644 index 53a26bf67..000000000 --- a/Sprint 1/deliverable3/pom.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.4.4 - - - com.jydoc - deliverable3 - 0.0.1-SNAPSHOT - deliverable3 - Demo project for Spring Boot - - - - - - - - - - - - - - - 21 - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-web - - - io.github.wimdeblauwe - htmx-spring-boot-thymeleaf - 4.0.1 - - - - com.mysql - mysql-connector-j - runtime - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.modelmapper - modelmapper - 3.2.0 - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.projectlombok - lombok - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - - - diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java deleted file mode 100644 index 5c4c1fd0a..000000000 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.jydoc.deliverable3.Controller; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import java.time.LocalDate; - - - - -@Controller -public class indexController { - - // This method maps to the root URL ("/") - @GetMapping("/") - public String index(Model model) { - // Add the user's name to the model (this can be dynamic) - model.addAttribute("userName", "Guest"); - - // Add the current date to the model - model.addAttribute("currentDate", LocalDate.now()); - - // Return the name of the Thymeleaf template ("index") - return "index"; - } - - @GetMapping("/login") - public String login(Model model) { - return "login"; - } - - @PostMapping("/login") - public String handleLogin(@RequestParam String username, @RequestParam String password, Model model) { - // Here, you would usually authenticate the user, for now we just show the data - model.addAttribute("username", username); - model.addAttribute("password", password); - // You can create a new page to show after login success - return "loginSuccess"; - } -} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java deleted file mode 100644 index 64bf1de75..000000000 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.jydoc.deliverable3; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Deliverable3Application { - - public static void main(String[] args) { - SpringApplication.run(Deliverable3Application.class, args); - } - -} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/User.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/User.java deleted file mode 100644 index 4bd68786a..000000000 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/User.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.jydoc.deliverable3.Model; -import jakarta.persistence.*; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Entity -@Getter -@Setter -@NoArgsConstructor - -public class User { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name="user-id") - private Long id; - - @Column(name="user-firstname") - private String firstName; - - @Column(name="user-lastname") - private String lastName; - - @Column(name="user-email") - private String email; - - @Column(name="user-password") - private String password; - -} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java deleted file mode 100644 index dbfdb323b..000000000 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.jydoc.deliverable3.Repository; - -import com.jydoc.deliverable3.Model.User; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface UserRepository extends JpaRepository { - -} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java deleted file mode 100644 index 010351af7..000000000 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.jydoc.deliverable3.Service; - -public class UserService { - - - - - - - - - -} diff --git a/Sprint 1/deliverable3/src/main/resources/application.properties b/Sprint 1/deliverable3/src/main/resources/application.properties deleted file mode 100644 index 79c9efc14..000000000 --- a/Sprint 1/deliverable3/src/main/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.application.name=deliverable3 -spring.jpa.hibernate.ddl-auto=create -spring.datasource.url=jdbc:mysql://localhost:3306/user_database -spring.datasource.username= -spring.datasource.password= -spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/src/main/resources/templates/error.html b/Sprint 1/deliverable3/src/main/resources/templates/error.html deleted file mode 100644 index 130701ba9..000000000 --- a/Sprint 1/deliverable3/src/main/resources/templates/error.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Error - - -Error - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/index.html b/Sprint 1/deliverable3/src/main/resources/templates/index.html deleted file mode 100644 index b2b410bd7..000000000 --- a/Sprint 1/deliverable3/src/main/resources/templates/index.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Thymeleaf Example - - - - - - - Thymeleaf Example - - -

Welcome to Thymeleaf!

- -

- -
-

Current Date and Time:

-
- - -
- -
- - diff --git a/Sprint 1/deliverable3/src/main/resources/templates/login.html b/Sprint 1/deliverable3/src/main/resources/templates/login.html deleted file mode 100644 index 795d5cb8c..000000000 --- a/Sprint 1/deliverable3/src/main/resources/templates/login.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - Login - - -

Login

-
-
- - -
-
- - -
-
- -
-
- - diff --git a/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html b/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html deleted file mode 100644 index 7a517bfcb..000000000 --- a/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - -Login Success - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/styles.css b/Sprint 1/deliverable3/src/main/resources/templates/styles.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java deleted file mode 100644 index b233ee828..000000000 --- a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.jydoc.deliverable3; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class Deliverable3ApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/Sprint 1/deliverable3/target/classes/application.properties b/Sprint 1/deliverable3/target/classes/application.properties deleted file mode 100644 index 60ae6054f..000000000 --- a/Sprint 1/deliverable3/target/classes/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.application.name=deliverable3 -spring.jpa.hibernate.ddl-auto=create -spring.datasource.url=jdbc:mysql://localhost:3306/user_database -spring.datasource.username=root -spring.datasource.password=siAZ10xD0r7f5DL@ -spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class deleted file mode 100644 index 724c3359f1f42543fbc34eae46a1102522409e29..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1602 zcmb7ET~pIQ6g^8?8r$+=Kq^=f@Pn2Dk#Dt(GYpKp6lB1u4?d;MT7v1OCL54{rB8l5 z_yhb=j(3yV7KiB|Gwkl&y?f3*XK(uJ_m7_dcCeks0JIbmStK#YFnVU4Tc&G?hWWa7 z#_N({aN7}%e952{id7vtgB}LlKeU=$N17qIAM!wEki}36!&!`Alp*i=4Krx@j%d91 zDf7bfKbWCo9(Xo)8M2mb??~x8wNP?~y+WnSdqUfyQSRA^D=8N%{Xok)42DcS^nEVm zo+Wu24*RWf+Snq|@YP#j9JcN+D6gyI{x_iZS2SW5S#wfsU~GCmnfOx?aN( zI;Ptuh{%K)idt3>kVsp{9LbB)PQrSf2SEyt7*^_D(>%Mhy}C&TIOp8AYA#e(2o{rl{1=k;x~YppPP zy0zoa#*K9xc|nhmxvSoEY`bF8=8eIR`A7AEMlfVk`os(UI)CM;P8$EG>6Xlk}zMBjkzrb{m;+ zP{JZHEKz2X1k$uj|HHJU>U{bREWiq_@|_a4C{iV8#=S0AT>Wehht}cHZo;ujsB2g! zuarj(Dm_7SZppY`ij^%H4;I@RXS=+y#(AWPZJbI}?k&VuJN!9JV}sxc4l}e;#pj}$ rv`F`mMhT!JT+zQtS7QCE*rKx$jW(XqA|92?&nX(fi^wwNKpFT0ogIQ} diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class deleted file mode 100644 index efcd494a354085320bc8fee605438a97b7adbd6f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 769 zcmb7CO;6iE5PcgG970+ke3h0SxP=^8BqT1WkkX)@3{*{(9(r0ki`iiBM(Z^nKZ{eV z9{2(MQB`MMBzy>mTJnr$X6Mb!oB93c*CT)d-nUT0LV$W34JR_=shp}Rj0&}2A>O~$A96BF}^Ox2CFB1+{EKdl&p*(_DDaLVWwT38OyZsQeR zGxUs2cs{dACzn=a^48dE9vS2KsB~5`sirM7L(~nQ`x>Sq&->pio{{rl{rzwra%{Ad zca9H@zEnw3wpuAcZXfP5)Q4sw8CF82<#~}s(th=0F?2!`i*zik^7fOn?ygkMa2Wm{ z7rss=6wS2Noj1am;=(3`ygnyP`#F>D%1k~B&zzH%9=1lNu(AB4e6PDN?BKxj$FTFI z&`xD?ta3%O474_`+!5iN%%!hfj3}HT9!vh@)0#fg#wtAav4?&rJLK&(B{(v_o&=6rr9N^=cHQK1TCpyQZHtDt1|~ za8q1z$0(V6T|cm4>L)ID7)3;dQ96HSTpGG*SXDi5Th&bk>enbv2}bcx!g1xHQR9p< zO@YVK5kaV?QA&mOn}#2$_77^5Rv)9hW(ZS#$!Ij}g#Q*L6bPf z^(o$$&Ujfe>e~{QklT!UvP(rqlOO7q6g6HHuE14xEX$UL6t?9un!wr44M!UK1$SKG zN^X_8o~vv!S`2l);}#T=yizpGI!9Q)E0tYsbl8D>g~o-qBlmXiu#hW!WHb|+W7jt8 zH4E%s%M&nGhw7_J^8s(=Y3sXE-Up?iZznw46OWPaywVM#R=Lc9lF2SLmBgzZa_yqP zj0W?<;)nHGi8}>VcvU{TY?wvE5y}oe_R3QM`4;jWy9L*n4hoR7E<;L?$(weqWS{H* zq{S8uN8P_}p^+OW4w{Hj5>fe}dr%2jd#Y`G$5GHPxVP)ydpO&AZPgy>11?YP%8}tf zY>6&Fc5GV2euhS=v?YdLu`$DN1KS3?mRL}me`g>?r+1R9c zH2)|@G>SJSlNe3GnxY<>#(M_#ET>y^o93{bcj*q|Fnd8<67RsV00$FLUvRl00w*fxYhTjaw z4|I$7yFb9E+wfcA_@Qp`{tN~9;Wj+}zfi85bM%8oTIs0{Jrbc;UN3BWKM-p6UK9NV D6~K-? zo~h#6)5EHiyi0KEFjw=`HWq5XHr~p!+J*}5n97F92I5`A1JGf-48G=WXX5aZ{YIzR zzp#t!53_rXqPPp?yl$x?Tg%WbG)n#-T=S6|tpsKZgLllVqpgrx6h825AX E2}WjdmH+?% diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class deleted file mode 100644 index 0850eb76753fa40e700d45378184f69c74d75b94..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 320 zcma)1O-sW-5Pg%6rpDF=|ADt!#65Ua1Q9$1Jyd(&YzEzsW?`EK{8^p~9{d6RC~>y* z;L#a)GjC>?$NT>I`~q-?B1eQcLoz{%5us@GpjE58SM^jiY - - - - Error - - -Error - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/index.html b/Sprint 1/deliverable3/target/classes/templates/index.html deleted file mode 100644 index b2b410bd7..000000000 --- a/Sprint 1/deliverable3/target/classes/templates/index.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Thymeleaf Example - - - - - - - Thymeleaf Example - - -

Welcome to Thymeleaf!

- -

- -
-

Current Date and Time:

-
- - -
- -
- - diff --git a/Sprint 1/deliverable3/target/classes/templates/login.html b/Sprint 1/deliverable3/target/classes/templates/login.html deleted file mode 100644 index 795d5cb8c..000000000 --- a/Sprint 1/deliverable3/target/classes/templates/login.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - Login - - -

Login

-
-
- - -
-
- - -
-
- -
-
- - diff --git a/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html b/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html deleted file mode 100644 index 7a517bfcb..000000000 --- a/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - -Login Success - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/styles.css b/Sprint 1/deliverable3/target/classes/templates/styles.css deleted file mode 100644 index e69de29bb..000000000 From b5f3c78debe02e828d7a3f788592a26a158bb2c8 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Tue, 25 Mar 2025 11:35:57 -0400 Subject: [PATCH 011/100] Add files via upload --- Sprint 1/deliverable3/HELP.md | 29 ++ Sprint 1/deliverable3/deliverable3.iml | 13 + Sprint 1/deliverable3/mvnw | 259 ++++++++++++++++++ Sprint 1/deliverable3/mvnw.cmd | 149 ++++++++++ Sprint 1/deliverable3/pom.xml | 104 +++++++ .../Controller/indexController.java | 44 +++ .../com/jydoc/deliverable3/DTO/UserDTO.java | 16 ++ .../deliverable3/Deliverable3Application.java | 13 + .../jydoc/deliverable3/Model/UserModel.java | 37 +++ .../Repository/UserRepository.java | 19 ++ .../deliverable3/Service/UserService.java | 13 + .../src/main/resources/application.properties | 9 + .../src/main/resources/templates/error.html | 10 + .../src/main/resources/templates/index.html | 28 ++ .../src/main/resources/templates/login.html | 23 ++ .../resources/templates/loginSuccess.html | 10 + .../src/main/resources/templates/styles.css | 0 .../Deliverable3ApplicationTests.java | 13 + .../target/classes/application.properties | 9 + .../Controller/indexController.class | Bin 0 -> 1602 bytes .../com/jydoc/deliverable3/DTO/UserDTO.class | Bin 0 -> 3876 bytes .../Deliverable3Application.class | Bin 0 -> 769 bytes .../jydoc/deliverable3/Model/UserModel.class | Bin 0 -> 2295 bytes .../Repository/UserRepository.class | Bin 0 -> 358 bytes .../deliverable3/Service/UserService.class | Bin 0 -> 320 bytes .../target/classes/templates/error.html | 10 + .../target/classes/templates/index.html | 28 ++ .../target/classes/templates/login.html | 23 ++ .../classes/templates/loginSuccess.html | 10 + .../target/classes/templates/styles.css | 0 30 files changed, 869 insertions(+) create mode 100644 Sprint 1/deliverable3/HELP.md create mode 100644 Sprint 1/deliverable3/deliverable3.iml create mode 100644 Sprint 1/deliverable3/mvnw create mode 100644 Sprint 1/deliverable3/mvnw.cmd create mode 100644 Sprint 1/deliverable3/pom.xml create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java create mode 100644 Sprint 1/deliverable3/src/main/resources/application.properties create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/error.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/index.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/login.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/styles.css create mode 100644 Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java create mode 100644 Sprint 1/deliverable3/target/classes/application.properties create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class create mode 100644 Sprint 1/deliverable3/target/classes/templates/error.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/index.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/login.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/loginSuccess.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/styles.css diff --git a/Sprint 1/deliverable3/HELP.md b/Sprint 1/deliverable3/HELP.md new file mode 100644 index 000000000..786794155 --- /dev/null +++ b/Sprint 1/deliverable3/HELP.md @@ -0,0 +1,29 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.4/maven-plugin) +* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.4/maven-plugin/build-image.html) +* [Spring Web](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html) +* [Thymeleaf](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html#web.servlet.spring-mvc.template-engines) +* [htmx](https://github.com/wimdeblauwe/htmx-spring-boot) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) +* [Handling Form Submission](https://spring.io/guides/gs/handling-form-submission/) +* [htmx](https://www.youtube.com/watch?v=j-rfPoXe5aE) +* [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/) + +### Maven Parent overrides + +Due to Maven's design, elements are inherited from the parent POM to the project POM. +While most of the inheritance is fine, it also inherits unwanted elements like `` and `` from the parent. +To prevent this, the project POM contains empty overrides for these elements. +If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. + diff --git a/Sprint 1/deliverable3/deliverable3.iml b/Sprint 1/deliverable3/deliverable3.iml new file mode 100644 index 000000000..2cf3f920f --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/mvnw b/Sprint 1/deliverable3/mvnw new file mode 100644 index 000000000..19529ddf8 --- /dev/null +++ b/Sprint 1/deliverable3/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/Sprint 1/deliverable3/mvnw.cmd b/Sprint 1/deliverable3/mvnw.cmd new file mode 100644 index 000000000..249bdf382 --- /dev/null +++ b/Sprint 1/deliverable3/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/Sprint 1/deliverable3/pom.xml b/Sprint 1/deliverable3/pom.xml new file mode 100644 index 000000000..53a26bf67 --- /dev/null +++ b/Sprint 1/deliverable3/pom.xml @@ -0,0 +1,104 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.4 + + + com.jydoc + deliverable3 + 0.0.1-SNAPSHOT + deliverable3 + Demo project for Spring Boot + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-web + + + io.github.wimdeblauwe + htmx-spring-boot-thymeleaf + 4.0.1 + + + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.modelmapper + modelmapper + 3.2.0 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java new file mode 100644 index 000000000..36e25712b --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java @@ -0,0 +1,44 @@ +package com.jydoc.deliverable3.Controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.time.LocalDate; + + + + +@Controller +public class indexController { + + // This method maps to the root URL ("/") + @GetMapping("/") + public String index(Model model) { + // Add the user's name to the model (this can be dynamic) + model.addAttribute("userName", "Guest"); + + // Add the current date to the model + model.addAttribute("currentDate", LocalDate.now()); + + // Return the name of the Thymeleaf template ("index") + return "index"; + } + + @GetMapping("/login") + public String login(Model model) { + return "login"; + } + + @PostMapping("/login") + public String handleLogin(@RequestParam String username, @RequestParam String password, Model model) { + // Here, you would usually authenticate the user using the Security package, for now we just show the data + model.addAttribute("username", username); + model.addAttribute("password", password); + + return "loginSuccess"; + } +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java new file mode 100644 index 000000000..6525448dd --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java @@ -0,0 +1,16 @@ +// This DTO accepts user input to fill variables, then is converted by +// UserService into a UserModel. + +package com.jydoc.deliverable3.DTO; +import lombok.Data; + +@Data public class UserDTO { //@Data automatically applies all Getters, Setters, NoArgConstructor, and ArgConstructor + + private int id; + private boolean admin; + private String email; + private String password; + private String firstName; + private String lastName; + +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java new file mode 100644 index 000000000..64bf1de75 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java @@ -0,0 +1,13 @@ +package com.jydoc.deliverable3; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Deliverable3Application { + + public static void main(String[] args) { + SpringApplication.run(Deliverable3Application.class, args); + } + +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java new file mode 100644 index 000000000..0bc424e01 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java @@ -0,0 +1,37 @@ +package com.jydoc.deliverable3.Model; +import jakarta.persistence.*; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Getter +@Setter +@NoArgsConstructor + +public class UserModel { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name="user-id") + private int id; + + @Column(name="user-isadmin") + private boolean admin; + + @Column(name="user-firstname") + private String firstName; + + @Column(name="user-lastname") + private String lastName; + + @Column(name="user-email") + private String email; + + @Column(name="user-password") + private String password; + +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java new file mode 100644 index 000000000..fd4c38813 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java @@ -0,0 +1,19 @@ +package com.jydoc.deliverable3.Repository; +import com.jydoc.deliverable3.Model.UserModel; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface UserRepository extends CrudRepository { + + public List findById(int id); + public List findByEmail(String email); + public List findByFirstName(String firstName); + public List findByLastName(String lastName); + + + + +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java new file mode 100644 index 000000000..010351af7 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java @@ -0,0 +1,13 @@ +package com.jydoc.deliverable3.Service; + +public class UserService { + + + + + + + + + +} diff --git a/Sprint 1/deliverable3/src/main/resources/application.properties b/Sprint 1/deliverable3/src/main/resources/application.properties new file mode 100644 index 000000000..05b2eb8a6 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/application.properties @@ -0,0 +1,9 @@ + +#Server Configuration + +spring.application.name=deliverable3 +spring.jpa.hibernate.ddl-auto=create-drop +spring.datasource.url=jdbc:mysql://localhost:3306/user_database +spring.datasource.username=root +spring.datasource.password=radmin +spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/src/main/resources/templates/error.html b/Sprint 1/deliverable3/src/main/resources/templates/error.html new file mode 100644 index 000000000..130701ba9 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/error.html @@ -0,0 +1,10 @@ + + + + + Error + + +Error + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/index.html b/Sprint 1/deliverable3/src/main/resources/templates/index.html new file mode 100644 index 000000000..b2b410bd7 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/index.html @@ -0,0 +1,28 @@ + + + + + Thymeleaf Example + + + + + + + Thymeleaf Example + + +

Welcome to Thymeleaf!

+ +

+ +
+

Current Date and Time:

+
+ + +
+ +
+ + diff --git a/Sprint 1/deliverable3/src/main/resources/templates/login.html b/Sprint 1/deliverable3/src/main/resources/templates/login.html new file mode 100644 index 000000000..795d5cb8c --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/login.html @@ -0,0 +1,23 @@ + + + + + Login + + +

Login

+
+
+ + +
+
+ + +
+
+ +
+
+ + diff --git a/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html b/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html new file mode 100644 index 000000000..7a517bfcb --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html @@ -0,0 +1,10 @@ + + + + + Title + + +Login Success + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/styles.css b/Sprint 1/deliverable3/src/main/resources/templates/styles.css new file mode 100644 index 000000000..e69de29bb diff --git a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java new file mode 100644 index 000000000..b233ee828 --- /dev/null +++ b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java @@ -0,0 +1,13 @@ +package com.jydoc.deliverable3; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Deliverable3ApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/Sprint 1/deliverable3/target/classes/application.properties b/Sprint 1/deliverable3/target/classes/application.properties new file mode 100644 index 000000000..05b2eb8a6 --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/application.properties @@ -0,0 +1,9 @@ + +#Server Configuration + +spring.application.name=deliverable3 +spring.jpa.hibernate.ddl-auto=create-drop +spring.datasource.url=jdbc:mysql://localhost:3306/user_database +spring.datasource.username=root +spring.datasource.password=radmin +spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class new file mode 100644 index 0000000000000000000000000000000000000000..724c3359f1f42543fbc34eae46a1102522409e29 GIT binary patch literal 1602 zcmb7ET~pIQ6g^8?8r$+=Kq^=f@Pn2Dk#Dt(GYpKp6lB1u4?d;MT7v1OCL54{rB8l5 z_yhb=j(3yV7KiB|Gwkl&y?f3*XK(uJ_m7_dcCeks0JIbmStK#YFnVU4Tc&G?hWWa7 z#_N({aN7}%e952{id7vtgB}LlKeU=$N17qIAM!wEki}36!&!`Alp*i=4Krx@j%d91 zDf7bfKbWCo9(Xo)8M2mb??~x8wNP?~y+WnSdqUfyQSRA^D=8N%{Xok)42DcS^nEVm zo+Wu24*RWf+Snq|@YP#j9JcN+D6gyI{x_iZS2SW5S#wfsU~GCmnfOx?aN( zI;Ptuh{%K)idt3>kVsp{9LbB)PQrSf2SEyt7*^_D(>%Mhy}C&TIOp8AYA#e(2o{rl{1=k;x~YppPP zy0zoa#*K9xc|nhmxvSoEY`bF8=8eIR`A7AEMlfVk`os(UI)CM;P8$EG>6Xlk}zMBjkzrb{m;+ zP{JZHEKz2X1k$uj|HHJU>U{bREWiq_@|_a4C{iV8#=S0AT>Wehht}cHZo;ujsB2g! zuarj(Dm_7SZppY`ij^%H4;I@RXS=+y#(AWPZJbI}?k&VuJN!9JV}sxc4l}e;#pj}$ rv`F`mMhT!JT+zQtS7QCE*rKx$jW(XqA|92?&nX(fi^wwNKpFT0ogIQ} literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class new file mode 100644 index 0000000000000000000000000000000000000000..02ffdf4a040d26c4604d420ce0524931664af9b7 GIT binary patch literal 3876 zcmbVP+jA3j6#h2Z&2G{yv|xc)#9P5$fXGGBlp;`CiMFM-1+^fuO%}Q|*{#`a9sU7F zN5^ON#W#772c1!v;lay;IOFgqiTItpq-h#y$C+;T{LcA)-=6b3m)-pJ&;4HjoWW`i zDWr9%CNyLebltR8twPmuZxk*p+_cMqg3L+Bb%Ik0()|OMvM`Xvtl;d$;aTkhCLD;A&B)8F){DB$6Nc>%v@q7VD&(+xW)(SHVC68%di`Z1tD zclaVT=)1rsleD;Zn-@P+uOiDR<8gWIR$07d_b ziC0B$Qa_%=D2CTeyq;{BXoQ)S#?L&u~H2d z9eUL_v3Z3JE9jkBaRaAjm)upycgS+ab-lm}9L6UPsCu;pZ>jL6?Xp4xyTUD+A0<}p zFAZE`;ZNGZqF0%=>MWtau5+6~M4V%_e_lYMiBr3-a^lPiq=S$oeM}lxjig1!BvmYa zZ+)r9^+(sdV9~BC$jKS>#ZA!>Dw9=bXi6GE!M4cSqzD0xrr^0ph$cC72ReXn1H^uQRBF)-jZF2e2jWz+$slN{g#5Sng>M;jNChKxs|Hz_f2@-(#rDi z6B}mT#<^R|b{qKRCWd4pHK}5XQL9>=bpo4(Y?fSB^(e#iZC?lLX8(qm+PSKO8Qk|| zC{rB8h37eOQXC{1{^#hYl#)>%-Z{L(JEwDa=Rgkc9KpPIgB2a_JHu6hD}{G$@E(*O zL)cmV&xA@Hqm<1EfO8n*YCN{S$ve}9{e19xqMxAOp)rLuqU@$b9O7+=I$Mcyn-X#6 zw;}5Op~a()O^G=D+Yt4%5}BJ4@paLLXiqCq=cYt_y|f|fZ6(^aDbab9kPfp}Bw<)a zgS|gPZ=e5N5hBjN)P@wCg13028iy#WZhcX_jfr;jom-`sI&RR*Vmyu;Vs5^IAUB1Ug>S2|8Xh^16VG z7^LToCeVpumY@^GTs|wHTnx(Qa|uY5X_IamThaVmj^b?8|3l1RmWR}Xdzj-)OyLy1 z#6{}T#C(cNlvG$)!n>3-+<=YuC}r>oEBSp&I=;YZ%u_P(Jx}y9r7V6#FRoC^;RE{d z8oG7kZ*0?HnC2tw(vjkyp*+H#NX-6+nDpgLOY&6t+KwCNb-FKYuSwQgXKWO8)b&~; zYK^f<)N$9(wXiGlkxNd#3Y1@Y*UA26*YHVoWN+8-q7=ckL^|*_jIIl}p>o~6y_b~#rzK@!}BKE}x-8|9L><{@|xXw-iJ3_%t QUW-`fDo5!f_*g;yU)O_~xBvhE literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class new file mode 100644 index 0000000000000000000000000000000000000000..efcd494a354085320bc8fee605438a97b7adbd6f GIT binary patch literal 769 zcmb7CO;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X5cn0B8E}Q^xwHh=;?f6*cia?sWZuObPT?wloiqT~aGll->%GZU z;1+J@fJ$%a>;%p91pS6PIiPZPMsqzucXL4#-Jr8QLHBY&m2S{NPtbBMXu2D8z9;BD z9#B-KYxh{If@#FkrH>HryQ=LZq*G~xZJTLnD$a+DE^-7h+11NOc$~q{e?+NYe5z@S zAIacX@OuW&?92V))5);-u?&7SA3xDAKAkU%Kas&d$;Vgv#ivth@lzT6T0VZdUwk_2 i7C)20^S?VYUH{^AH+`&!1PfSCr1muV!kKTxAHX*e?`;48 literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class new file mode 100644 index 0000000000000000000000000000000000000000..fc64b660b2ad6dacc0086c973b97bede525f7eb0 GIT binary patch literal 358 zcmbV|Jx;?w5QX1{ACu4^aStX^l*$nj4FxhnBH{oOd$L-`@mOOgC^fgD-~b#7vA8iH z(NN4^^X7f;{p0lwzzxn5j2x!9ZmB#Jno}WF*o*P1k{LZpqiyKa4)oND4QGO5hl`T; zOcmFj9#*B~U4m1Gxtgc8u~7T9@m8MIHdJuOR5naDDBd+Z2s(_H!PngFOdMXa-_mLJ zFWE)*2id(w&>pJa(r*tlt$li(I!uy* z;L#a)GjC>?$NT>I`~q-?B1eQcLoz{%5us@GpjE58SM^jiY + + + + Error + + +Error + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/index.html b/Sprint 1/deliverable3/target/classes/templates/index.html new file mode 100644 index 000000000..b2b410bd7 --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/templates/index.html @@ -0,0 +1,28 @@ + + + + + Thymeleaf Example + + + + + + + Thymeleaf Example + + +

Welcome to Thymeleaf!

+ +

+ +
+

Current Date and Time:

+
+ + +
+ +
+ + diff --git a/Sprint 1/deliverable3/target/classes/templates/login.html b/Sprint 1/deliverable3/target/classes/templates/login.html new file mode 100644 index 000000000..795d5cb8c --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/templates/login.html @@ -0,0 +1,23 @@ + + + + + Login + + +

Login

+
+
+ + +
+
+ + +
+
+ +
+
+ + diff --git a/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html b/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html new file mode 100644 index 000000000..7a517bfcb --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html @@ -0,0 +1,10 @@ + + + + + Title + + +Login Success + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/styles.css b/Sprint 1/deliverable3/target/classes/templates/styles.css new file mode 100644 index 000000000..e69de29bb From 77b75b5792e74987362bb8854beb50b45f6610cd Mon Sep 17 00:00:00 2001 From: ybihi2 Date: Tue, 25 Mar 2025 12:06:02 -0400 Subject: [PATCH 012/100] Deleted unnecessary files --- .../target/classes/application.properties | 9 ------ .../Controller/indexController.class | Bin 1602 -> 0 bytes .../com/jydoc/deliverable3/DTO/UserDTO.class | Bin 3876 -> 0 bytes .../Deliverable3Application.class | Bin 769 -> 0 bytes .../jydoc/deliverable3/Model/UserModel.class | Bin 2295 -> 0 bytes .../Repository/UserRepository.class | Bin 358 -> 0 bytes .../deliverable3/Service/UserService.class | Bin 320 -> 0 bytes .../target/classes/templates/error.html | 10 ------- .../target/classes/templates/index.html | 28 ------------------ .../target/classes/templates/login.html | 23 -------------- .../classes/templates/loginSuccess.html | 10 ------- .../target/classes/templates/styles.css | 0 12 files changed, 80 deletions(-) delete mode 100644 Sprint 1/deliverable3/target/classes/application.properties delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class delete mode 100644 Sprint 1/deliverable3/target/classes/templates/error.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/index.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/login.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/loginSuccess.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/styles.css diff --git a/Sprint 1/deliverable3/target/classes/application.properties b/Sprint 1/deliverable3/target/classes/application.properties deleted file mode 100644 index 05b2eb8a6..000000000 --- a/Sprint 1/deliverable3/target/classes/application.properties +++ /dev/null @@ -1,9 +0,0 @@ - -#Server Configuration - -spring.application.name=deliverable3 -spring.jpa.hibernate.ddl-auto=create-drop -spring.datasource.url=jdbc:mysql://localhost:3306/user_database -spring.datasource.username=root -spring.datasource.password=radmin -spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class deleted file mode 100644 index 724c3359f1f42543fbc34eae46a1102522409e29..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1602 zcmb7ET~pIQ6g^8?8r$+=Kq^=f@Pn2Dk#Dt(GYpKp6lB1u4?d;MT7v1OCL54{rB8l5 z_yhb=j(3yV7KiB|Gwkl&y?f3*XK(uJ_m7_dcCeks0JIbmStK#YFnVU4Tc&G?hWWa7 z#_N({aN7}%e952{id7vtgB}LlKeU=$N17qIAM!wEki}36!&!`Alp*i=4Krx@j%d91 zDf7bfKbWCo9(Xo)8M2mb??~x8wNP?~y+WnSdqUfyQSRA^D=8N%{Xok)42DcS^nEVm zo+Wu24*RWf+Snq|@YP#j9JcN+D6gyI{x_iZS2SW5S#wfsU~GCmnfOx?aN( zI;Ptuh{%K)idt3>kVsp{9LbB)PQrSf2SEyt7*^_D(>%Mhy}C&TIOp8AYA#e(2o{rl{1=k;x~YppPP zy0zoa#*K9xc|nhmxvSoEY`bF8=8eIR`A7AEMlfVk`os(UI)CM;P8$EG>6Xlk}zMBjkzrb{m;+ zP{JZHEKz2X1k$uj|HHJU>U{bREWiq_@|_a4C{iV8#=S0AT>Wehht}cHZo;ujsB2g! zuarj(Dm_7SZppY`ij^%H4;I@RXS=+y#(AWPZJbI}?k&VuJN!9JV}sxc4l}e;#pj}$ rv`F`mMhT!JT+zQtS7QCE*rKx$jW(XqA|92?&nX(fi^wwNKpFT0ogIQ} diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class deleted file mode 100644 index 02ffdf4a040d26c4604d420ce0524931664af9b7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3876 zcmbVP+jA3j6#h2Z&2G{yv|xc)#9P5$fXGGBlp;`CiMFM-1+^fuO%}Q|*{#`a9sU7F zN5^ON#W#772c1!v;lay;IOFgqiTItpq-h#y$C+;T{LcA)-=6b3m)-pJ&;4HjoWW`i zDWr9%CNyLebltR8twPmuZxk*p+_cMqg3L+Bb%Ik0()|OMvM`Xvtl;d$;aTkhCLD;A&B)8F){DB$6Nc>%v@q7VD&(+xW)(SHVC68%di`Z1tD zclaVT=)1rsleD;Zn-@P+uOiDR<8gWIR$07d_b ziC0B$Qa_%=D2CTeyq;{BXoQ)S#?L&u~H2d z9eUL_v3Z3JE9jkBaRaAjm)upycgS+ab-lm}9L6UPsCu;pZ>jL6?Xp4xyTUD+A0<}p zFAZE`;ZNGZqF0%=>MWtau5+6~M4V%_e_lYMiBr3-a^lPiq=S$oeM}lxjig1!BvmYa zZ+)r9^+(sdV9~BC$jKS>#ZA!>Dw9=bXi6GE!M4cSqzD0xrr^0ph$cC72ReXn1H^uQRBF)-jZF2e2jWz+$slN{g#5Sng>M;jNChKxs|Hz_f2@-(#rDi z6B}mT#<^R|b{qKRCWd4pHK}5XQL9>=bpo4(Y?fSB^(e#iZC?lLX8(qm+PSKO8Qk|| zC{rB8h37eOQXC{1{^#hYl#)>%-Z{L(JEwDa=Rgkc9KpPIgB2a_JHu6hD}{G$@E(*O zL)cmV&xA@Hqm<1EfO8n*YCN{S$ve}9{e19xqMxAOp)rLuqU@$b9O7+=I$Mcyn-X#6 zw;}5Op~a()O^G=D+Yt4%5}BJ4@paLLXiqCq=cYt_y|f|fZ6(^aDbab9kPfp}Bw<)a zgS|gPZ=e5N5hBjN)P@wCg13028iy#WZhcX_jfr;jom-`sI&RR*Vmyu;Vs5^IAUB1Ug>S2|8Xh^16VG z7^LToCeVpumY@^GTs|wHTnx(Qa|uY5X_IamThaVmj^b?8|3l1RmWR}Xdzj-)OyLy1 z#6{}T#C(cNlvG$)!n>3-+<=YuC}r>oEBSp&I=;YZ%u_P(Jx}y9r7V6#FRoC^;RE{d z8oG7kZ*0?HnC2tw(vjkyp*+H#NX-6+nDpgLOY&6t+KwCNb-FKYuSwQgXKWO8)b&~; zYK^f<)N$9(wXiGlkxNd#3Y1@Y*UA26*YHVoWN+8-q7=ckL^|*_jIIl}p>o~6y_b~#rzK@!}BKE}x-8|9L><{@|xXw-iJ3_%t QUW-`fDo5!f_*g;yU)O_~xBvhE diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class deleted file mode 100644 index efcd494a354085320bc8fee605438a97b7adbd6f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 769 zcmb7CO;6iE5PcgG970+ke3h0SxP=^8BqT1WkkX)@3{*{(9(r0ki`iiBM(Z^nKZ{eV z9{2(MQB`MMBzy>mTJnr$X6Mb!oB93c*CT)d-nUT0LV$W34JR_=shp}Rj0&}2A>O~$A96BF}^Ox2CFB1+{EKdl&p*(_DDaLVWwT38O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+11NOc$~q{e?+NYe5z@S zAIacX@OuW&?92V))5);-u?&7SA3xDAKAkU%Kas&d$;Vgv#ivth@lzT6T0VZdUwk_2 i7C)20^S?VYUH{^AH+`&!1PfSCr1muV!kKTxAHX*e?`;48 diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class deleted file mode 100644 index fc64b660b2ad6dacc0086c973b97bede525f7eb0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 358 zcmbV|Jx;?w5QX1{ACu4^aStX^l*$nj4FxhnBH{oOd$L-`@mOOgC^fgD-~b#7vA8iH z(NN4^^X7f;{p0lwzzxn5j2x!9ZmB#Jno}WF*o*P1k{LZpqiyKa4)oND4QGO5hl`T; zOcmFj9#*B~U4m1Gxtgc8u~7T9@m8MIHdJuOR5naDDBd+Z2s(_H!PngFOdMXa-_mLJ zFWE)*2id(w&>pJa(r*tlt$li(I!uy* z;L#a)GjC>?$NT>I`~q-?B1eQcLoz{%5us@GpjE58SM^jiY - - - - Error - - -Error - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/index.html b/Sprint 1/deliverable3/target/classes/templates/index.html deleted file mode 100644 index b2b410bd7..000000000 --- a/Sprint 1/deliverable3/target/classes/templates/index.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Thymeleaf Example - - - - - - - Thymeleaf Example - - -

Welcome to Thymeleaf!

- -

- -
-

Current Date and Time:

-
- - -
- -
- - diff --git a/Sprint 1/deliverable3/target/classes/templates/login.html b/Sprint 1/deliverable3/target/classes/templates/login.html deleted file mode 100644 index 795d5cb8c..000000000 --- a/Sprint 1/deliverable3/target/classes/templates/login.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - Login - - -

Login

-
-
- - -
-
- - -
-
- -
-
- - diff --git a/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html b/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html deleted file mode 100644 index 7a517bfcb..000000000 --- a/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - -Login Success - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/styles.css b/Sprint 1/deliverable3/target/classes/templates/styles.css deleted file mode 100644 index e69de29bb..000000000 From 61c5d05c17e49655cdc876f1765d8cf254e8a2a8 Mon Sep 17 00:00:00 2001 From: ybihi2 Date: Tue, 25 Mar 2025 14:11:05 -0400 Subject: [PATCH 013/100] Documentation added. --- .../Controller/indexController.java | 6 ++-- .../com/jydoc/deliverable3/DTO/UserDTO.java | 2 +- .../jydoc/deliverable3/Model/UserModel.java | 3 ++ .../Repository/UserRepository.java | 7 +++- .../deliverable3/Service/UserService.java | 35 +++++++++++++++---- 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java index 36e25712b..0685a1d9e 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java @@ -1,5 +1,7 @@ -package com.jydoc.deliverable3.Controller; +//This controller "listens" for user responses. + +package com.jydoc.deliverable3.Controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -35,7 +37,7 @@ public String login(Model model) { @PostMapping("/login") public String handleLogin(@RequestParam String username, @RequestParam String password, Model model) { - // Here, you would usually authenticate the user using the Security package, for now we just show the data + //TODO: Implement User authentication model.addAttribute("username", username); model.addAttribute("password", password); diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java index 6525448dd..2316fc1ef 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java @@ -1,6 +1,6 @@ // This DTO accepts user input to fill variables, then is converted by // UserService into a UserModel. - +// Also used for business logic. package com.jydoc.deliverable3.DTO; import lombok.Data; diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java index 0bc424e01..741a80ecf 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java @@ -1,3 +1,6 @@ +//The User Model is used to interact and create the database + + package com.jydoc.deliverable3.Model; import jakarta.persistence.*; import jakarta.persistence.Entity; diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java index fd4c38813..d0cc3d3ec 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java @@ -1,3 +1,5 @@ +//This is where the backend interacts with the database to retrieve or add data + package com.jydoc.deliverable3.Repository; import com.jydoc.deliverable3.Model.UserModel; import org.springframework.data.repository.CrudRepository; @@ -8,10 +10,13 @@ @Repository public interface UserRepository extends CrudRepository { - public List findById(int id); + + //Custom Queries + public List findById(int id); //TODO: Switch this to Long type public List findByEmail(String email); public List findByFirstName(String firstName); public List findByLastName(String lastName); + public List findByFirstNameAndLastName(String firstName, String lastName); diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java index 010351af7..267b34c01 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java @@ -1,13 +1,34 @@ -package com.jydoc.deliverable3.Service; - -public class UserService { - - - - +//This is where user data is processed. +package com.jydoc.deliverable3.Service; +import com.jydoc.deliverable3.DTO.UserDTO; +import com.jydoc.deliverable3.Model.UserModel; +public class UserService { + public UserModel convertToEntity(UserDTO UserDto) { + + UserModel user = new UserModel(); + user.setId(UserDto.getId()); + user.setAdmin(UserDto.isAdmin()); + user.setFirstName(UserDto.getFirstName()); + user.setLastName(UserDto.getLastName()); + user.setEmail(UserDto.getEmail()); + user.setPassword(UserDto.getPassword()); + return user; + } + + public UserDTO convertToDTO(UserModel UserModel) { + + UserDTO user = new UserDTO(); + user.setId(UserModel.getId()); + user.setAdmin(UserModel.isAdmin()); + user.setFirstName(UserModel.getFirstName()); + user.setLastName(UserModel.getLastName()); + user.setEmail(UserModel.getEmail()); + user.setPassword(UserModel.getPassword()); + return user; + } } From 912ea138030cd7b5d37bb4e62629daa22ad05f13 Mon Sep 17 00:00:00 2001 From: ybihi2 Date: Tue, 25 Mar 2025 16:20:58 -0400 Subject: [PATCH 014/100] Documentation added, and repository methods --- .../jydoc/deliverable3/Controller/indexController.java | 2 +- .../java/com/jydoc/deliverable3/Model/UserModel.java | 2 +- .../jydoc/deliverable3/Repository/UserRepository.java | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java index 0685a1d9e..1c82d7946 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java @@ -1,5 +1,5 @@ //This controller "listens" for user responses. - +//TODO: We need to figure out how to set the user input into a DTO, then convert to Model and add into database package com.jydoc.deliverable3.Controller; import org.springframework.stereotype.Controller; diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java index 741a80ecf..7bfb69bea 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java @@ -16,7 +16,7 @@ @NoArgsConstructor public class UserModel { - +//Each row in the database is a unique user containing all of these columns @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="user-id") diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java index d0cc3d3ec..412dfcfb7 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java @@ -12,11 +12,11 @@ public interface UserRepository extends CrudRepository { //Custom Queries - public List findById(int id); //TODO: Switch this to Long type - public List findByEmail(String email); - public List findByFirstName(String firstName); - public List findByLastName(String lastName); - public List findByFirstNameAndLastName(String firstName, String lastName); + List findById(int id); //TODO: Switch this to Long type + List findByEmail(String email); + List findByFirstName(String firstName); + List findByLastName(String lastName); + List findByFirstNameAndLastName(String firstName, String lastName); From db5f3daf1572c14c3a2f6a4257c58c3c18b4647f Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Tue, 25 Mar 2025 17:11:10 -0400 Subject: [PATCH 015/100] Update pom.xml --- Sprint 1/deliverable3/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint 1/deliverable3/pom.xml b/Sprint 1/deliverable3/pom.xml index 53a26bf67..2a9077de2 100644 --- a/Sprint 1/deliverable3/pom.xml +++ b/Sprint 1/deliverable3/pom.xml @@ -69,6 +69,10 @@ org.springframework.boot spring-boot-starter-data-jpa + + org.springframework.boot + spring-boot-starter-validation + From 15d528cc6e71c0511b5664a82448238ba98c806a Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Tue, 25 Mar 2025 17:17:28 -0400 Subject: [PATCH 016/100] Update UserDTO.java --- .../com/jydoc/deliverable3/DTO/UserDTO.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java index 2316fc1ef..9d195cbf6 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java @@ -2,15 +2,35 @@ // UserService into a UserModel. // Also used for business logic. package com.jydoc.deliverable3.DTO; + +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; import lombok.Data; -@Data public class UserDTO { //@Data automatically applies all Getters, Setters, NoArgConstructor, and ArgConstructor +@Data +public class UserDTO { //@Data applies Getters, Setters, NoArgsConstructor, and AllArgsConstructor private int id; private boolean admin; + + @NotBlank(message = "Email cannot be empty") + @Email(message = "Invalid email format") private String email; + + @NotBlank(message = "Password cannot be empty") + @Size(min = 6, message = "Password must be at least 6 characters") + @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", + message = "Password must contain at least one letter and one number") private String password; + + @NotBlank(message = "First name cannot be empty") + @Size(min = 2, max = 30, message = "First name must be between 2 and 30 characters") private String firstName; - private String lastName; + @NotBlank(message = "Last name cannot be empty") + @Size(min = 2, max = 30, message = "Last name must be between 2 and 30 characters") + private String lastName; } + From 04954338e670aa821c880218539af7f6c7045c69 Mon Sep 17 00:00:00 2001 From: ybihi2 Date: Tue, 25 Mar 2025 17:20:52 -0400 Subject: [PATCH 017/100] Documentation added, and repository methods --- .idea/jarRepositories.xml | 20 +++++++++++ .idea/misc.xml | 14 ++++++++ .../Controller/indexController.java | 8 +++++ .../src/main/resources/templates/index.html | 14 ++++---- .../main/resources/templates/register.html | 34 +++++++++++++++++++ 5 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/register.html diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 000000000..712ab9d98 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..4f77693ca --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java index 1c82d7946..efffabb9e 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java @@ -43,4 +43,12 @@ public String handleLogin(@RequestParam String username, @RequestParam String pa return "loginSuccess"; } + + @GetMapping("/register") + public String register(Model model) { + //TODO: Implement registration system + + + return "register"; + } } diff --git a/Sprint 1/deliverable3/src/main/resources/templates/index.html b/Sprint 1/deliverable3/src/main/resources/templates/index.html index b2b410bd7..fae1fc07c 100644 --- a/Sprint 1/deliverable3/src/main/resources/templates/index.html +++ b/Sprint 1/deliverable3/src/main/resources/templates/index.html @@ -1,15 +1,9 @@ - - - - Thymeleaf Example - - - Thymeleaf Example +

Welcome to Thymeleaf!

@@ -24,5 +18,11 @@

Welcome to Thymeleaf!

+ + +
+ +
+ diff --git a/Sprint 1/deliverable3/src/main/resources/templates/register.html b/Sprint 1/deliverable3/src/main/resources/templates/register.html new file mode 100644 index 000000000..b448e8307 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/register.html @@ -0,0 +1,34 @@ + + + + + Registration + + + +
+

Registration Form

+ +
+ + + + + + + + + + + + + + + + + + +
+
+ + From 4c4d4133b2f811ede2e56c490bddb75525f877fc Mon Sep 17 00:00:00 2001 From: ChrisJackson0313 Date: Tue, 25 Mar 2025 17:29:58 -0400 Subject: [PATCH 018/100] TEST Update UserDTO.java --- .../src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java index 9d195cbf6..2ff515b46 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java @@ -1,6 +1,7 @@ // This DTO accepts user input to fill variables, then is converted by // UserService into a UserModel. // Also used for business logic. +//test package com.jydoc.deliverable3.DTO; import jakarta.validation.constraints.Email; From 0299c533bda565b8d8fe1115193feb26ffe2808d Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Tue, 25 Mar 2025 17:33:05 -0400 Subject: [PATCH 019/100] Update indexController.java --- .../Controller/indexController.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java index 1c82d7946..1ec6fdf1f 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java @@ -30,17 +30,22 @@ public String index(Model model) { return "index"; } - @GetMapping("/login") +@GetMapping("/login") public String login(Model model) { + model.addAttribute("userDTO", new UserDTO()); return "login"; } @PostMapping("/login") - public String handleLogin(@RequestParam String username, @RequestParam String password, Model model) { - //TODO: Implement User authentication - model.addAttribute("username", username); - model.addAttribute("password", password); - - return "loginSuccess"; + public String handleLogin(@Valid @ModelAttribute("userDTO") UserDTO userDTO, Model model) { + boolean isAuthenticated = userService.authenticate(userDTO.getEmail(), userDTO.getPassword()); + + if (isAuthenticated) { + model.addAttribute("username", userDTO.getEmail()); + return "loginSuccess"; + } else { + model.addAttribute("error", "Invalid email or password"); + return "login"; // Return back to login page with error message + } } } From aa0cd7e507a6faad8db9e1b971dfaf5f3f45aff7 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Tue, 25 Mar 2025 17:38:26 -0400 Subject: [PATCH 020/100] Update --- Sprint 1/deliverable3/src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint 1/deliverable3/src/main/resources/application.properties b/Sprint 1/deliverable3/src/main/resources/application.properties index 05b2eb8a6..731b3ff73 100644 --- a/Sprint 1/deliverable3/src/main/resources/application.properties +++ b/Sprint 1/deliverable3/src/main/resources/application.properties @@ -5,5 +5,5 @@ spring.application.name=deliverable3 spring.jpa.hibernate.ddl-auto=create-drop spring.datasource.url=jdbc:mysql://localhost:3306/user_database spring.datasource.username=root -spring.datasource.password=radmin +spring.datasource.password= spring.datasource.driverClassName=com.mysql.jdbc.Driver From 821ba3641cab495e551d01bd962734a0b0a0df03 Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Tue, 25 Mar 2025 17:43:59 -0400 Subject: [PATCH 021/100] Create GlobalExceptionHandler.java --- .../deliverable3/GlobalExceptionHandler.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java new file mode 100644 index 000000000..0f7a69e4f --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java @@ -0,0 +1,48 @@ +package com.jydoc.deliverable3.Exception; + +import jakarta.validation.ConstraintViolationException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.validation.FieldError; + +import java.util.HashMap; +import java.util.Map; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + // Handle validation errors (MethodArgumentNotValidException) + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity> handleValidationErrors(MethodArgumentNotValidException ex) { + Map errors = new HashMap<>(); + + ex.getBindingResult().getAllErrors().forEach((error) -> { + String fieldName = ((FieldError) error).getField(); + String errorMessage = error.getDefaultMessage(); + errors.put(fieldName, errorMessage); + }); + + return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); // Return errors with 400 status + } + + // Handle ConstraintViolationException (if needed for specific validation annotations) + @ExceptionHandler(ConstraintViolationException.class) + public ResponseEntity> handleConstraintViolation(ConstraintViolationException ex) { + Map errors = new HashMap<>(); + + ex.getConstraintViolations().forEach(violation -> { + errors.put(violation.getPropertyPath().toString(), violation.getMessage()); + }); + + return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); + } + + // Global exception handler for all other exceptions + @ExceptionHandler(Exception.class) + public ResponseEntity handleGlobalException(Exception ex) { + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); // 500 status for internal errors + } +} From 619a4edf5291176e242c0a63a0fb4dbda88f8326 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Wed, 26 Mar 2025 00:16:57 -0400 Subject: [PATCH 022/100] Add files via upload --- Sprint 1/deliverable3/deliverable3/HELP.md | 29 ++ .../deliverable3/deliverable3.iml | 13 + Sprint 1/deliverable3/deliverable3/mvnw | 259 ++++++++++++++++++ Sprint 1/deliverable3/deliverable3/mvnw.cmd | 149 ++++++++++ Sprint 1/deliverable3/deliverable3/pom.xml | 108 ++++++++ .../Controller/indexController.java | 87 ++++++ .../com/jydoc/deliverable3/DTO/UserDTO.java | 37 +++ .../deliverable3/Deliverable3Application.java | 13 + .../deliverable3/GlobalExceptionHandler.java | 48 ++++ .../jydoc/deliverable3/Model/UserModel.java | 40 +++ .../Repository/UserRepository.java | 24 ++ .../deliverable3/Service/UserService.java | 47 ++++ .../src/main/resources/application.properties | 9 + .../src/main/resources/templates/error.html | 10 + .../src/main/resources/templates/index.html | 28 ++ .../src/main/resources/templates/login.html | 23 ++ .../resources/templates/loginSuccess.html | 10 + .../main/resources/templates/register.html | 7 + .../src/main/resources/templates/styles.css | 0 .../Deliverable3ApplicationTests.java | 13 + .../Controller/indexController.class | Bin 0 -> 2663 bytes .../com/jydoc/deliverable3/DTO/UserDTO.class | Bin 0 -> 4814 bytes .../Deliverable3Application.class | Bin 0 -> 769 bytes .../deliverable3/GlobalExceptionHandler.class | Bin 0 -> 4467 bytes .../jydoc/deliverable3/Model/UserModel.class | Bin 0 -> 2244 bytes .../Repository/UserRepository.class | Bin 0 -> 1034 bytes .../deliverable3/Service/UserService.class | Bin 0 -> 2290 bytes .../target/classes/templates/error.html | 10 + .../target/classes/templates/index.html | 28 ++ .../target/classes/templates/login.html | 23 ++ .../classes/templates/loginSuccess.html | 10 + .../target/classes/templates/register.html | 7 + .../target/classes/templates/styles.css | 0 33 files changed, 1032 insertions(+) create mode 100644 Sprint 1/deliverable3/deliverable3/HELP.md create mode 100644 Sprint 1/deliverable3/deliverable3/deliverable3.iml create mode 100644 Sprint 1/deliverable3/deliverable3/mvnw create mode 100644 Sprint 1/deliverable3/deliverable3/mvnw.cmd create mode 100644 Sprint 1/deliverable3/deliverable3/pom.xml create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/application.properties create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/templates/error.html create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/templates/index.html create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/templates/login.html create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/templates/loginSuccess.html create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/templates/register.html create mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/templates/styles.css create mode 100644 Sprint 1/deliverable3/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/GlobalExceptionHandler.class create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/templates/error.html create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/templates/index.html create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/templates/login.html create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/templates/loginSuccess.html create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/templates/register.html create mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/templates/styles.css diff --git a/Sprint 1/deliverable3/deliverable3/HELP.md b/Sprint 1/deliverable3/deliverable3/HELP.md new file mode 100644 index 000000000..6bed04940 --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/HELP.md @@ -0,0 +1,29 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.4/maven-plugin) +* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.4/maven-plugin/build-image.html) +* [Spring Web](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html) +* [Thymeleaf](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html#web.servlet.spring-mvc.template-engines) +* [htmx](https://github.com/wimdeblauwe/htmx-spring-boot) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) +* [Handling Form Submission](https://spring.io/guides/gs/handling-form-submission/) +* [htmx](https://www.youtube.com/watch?v=j-rfPoXe5aE) +* [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/) + +### Maven Parent overrides + +Due to Maven's design, elements are inherited from the parent POM to the project POM. +While most of the inheritance is fine, it also inherits unwanted elements like `` and `` from the parent. +To prevent this, the project POM contains empty overrides for these elements. +If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. + diff --git a/Sprint 1/deliverable3/deliverable3/deliverable3.iml b/Sprint 1/deliverable3/deliverable3/deliverable3.iml new file mode 100644 index 000000000..2cf3f920f --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/deliverable3.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/mvnw b/Sprint 1/deliverable3/deliverable3/mvnw new file mode 100644 index 000000000..b9a45d76e --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/Sprint 1/deliverable3/deliverable3/mvnw.cmd b/Sprint 1/deliverable3/deliverable3/mvnw.cmd new file mode 100644 index 000000000..b150b91ed --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/Sprint 1/deliverable3/deliverable3/pom.xml b/Sprint 1/deliverable3/deliverable3/pom.xml new file mode 100644 index 000000000..d8a68814f --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/pom.xml @@ -0,0 +1,108 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.4 + + + com.jydoc + deliverable3 + 0.0.1-SNAPSHOT + deliverable3 + Demo project for Spring Boot + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-web + + + io.github.wimdeblauwe + htmx-spring-boot-thymeleaf + 4.0.1 + + + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.modelmapper + modelmapper + 3.2.0 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-validation + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java new file mode 100644 index 000000000..0b8789684 --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java @@ -0,0 +1,87 @@ +//This controller "listens" for user responses. +//TODO: We need to figure out how to set the user input into a DTO, then convert to Model and add into database + +package com.jydoc.deliverable3.Controller; +import com.jydoc.deliverable3.DTO.UserDTO; +import com.jydoc.deliverable3.Model.UserModel; +import com.jydoc.deliverable3.Repository.UserRepository; +import com.jydoc.deliverable3.Service.UserService; +import jakarta.validation.Valid; +import org.antlr.v4.runtime.misc.LogManager; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.time.LocalDate; + + + + +@Controller +public class indexController { + + private final UserRepository userRepository; + private final UserService userService; + + public indexController(UserRepository userRepository) { + this.userRepository = userRepository; + this.userService = new UserService(); + } + + // This method maps to the root URL ("/") + @GetMapping("/") + public String index(Model model) { + + // Add the current date to the model + model.addAttribute("currentDate", LocalDate.now()); + + // Return the name of the Thymeleaf template ("index") + return "index"; + } + + @GetMapping("/login") + public String login(Model model) { + return "login"; + } + + @PostMapping("/login") + public String handleLogin(@Valid @ModelAttribute("userDTO") UserDTO userDTO, Model model) { + UserService UserService = new UserService(); + boolean isAuthenticated = UserService.authenticate(userDTO.getEmail(), userDTO.getPassword()); + + if (isAuthenticated) { + model.addAttribute("username", userDTO.getEmail()); + return "loginSuccess"; + } else { + model.addAttribute("error", "Invalid email or password"); + return "login"; // Return back to login page with error message + } + } + + @GetMapping("/register") + public String showRegistrationForm(Model model) { + model.addAttribute("user", new UserDTO()); + return "register"; + } + + @PostMapping("/register") + public String registerUser(@ModelAttribute("user") UserDTO userDTO, BindingResult result, Model model) { + //TODO: Implement registration system + if (result.hasErrors()) { + return "register"; // TODO: Implement register error to bring popup then refresh + } + + UserModel user = new UserModel(); + user.setEmail(userDTO.getEmail()); + user.setPassword(userDTO.getPassword()); + user.setFirstName(userDTO.getFirstName()); //TODO: Transfer to Service package + user.setLastName(userDTO.getLastName()); + userRepository.save(user); + + return "redirect:/index"; + } +} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java new file mode 100644 index 000000000..2ff515b46 --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java @@ -0,0 +1,37 @@ +// This DTO accepts user input to fill variables, then is converted by +// UserService into a UserModel. +// Also used for business logic. +//test +package com.jydoc.deliverable3.DTO; + +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; +import lombok.Data; + +@Data +public class UserDTO { //@Data applies Getters, Setters, NoArgsConstructor, and AllArgsConstructor + + private int id; + private boolean admin; + + @NotBlank(message = "Email cannot be empty") + @Email(message = "Invalid email format") + private String email; + + @NotBlank(message = "Password cannot be empty") + @Size(min = 6, message = "Password must be at least 6 characters") + @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", + message = "Password must contain at least one letter and one number") + private String password; + + @NotBlank(message = "First name cannot be empty") + @Size(min = 2, max = 30, message = "First name must be between 2 and 30 characters") + private String firstName; + + @NotBlank(message = "Last name cannot be empty") + @Size(min = 2, max = 30, message = "Last name must be between 2 and 30 characters") + private String lastName; +} + diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java new file mode 100644 index 000000000..64ce3b1c7 --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java @@ -0,0 +1,13 @@ +package com.jydoc.deliverable3; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Deliverable3Application { + + public static void main(String[] args) { + SpringApplication.run(Deliverable3Application.class, args); + } + +} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java new file mode 100644 index 000000000..cc52e6d56 --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java @@ -0,0 +1,48 @@ +package com.jydoc.deliverable3; + +import jakarta.validation.ConstraintViolationException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.validation.FieldError; + +import java.util.HashMap; +import java.util.Map; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + // Handle validation errors (MethodArgumentNotValidException) + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity> handleValidationErrors(MethodArgumentNotValidException ex) { + Map errors = new HashMap<>(); + + ex.getBindingResult().getAllErrors().forEach((error) -> { + String fieldName = ((FieldError) error).getField(); + String errorMessage = error.getDefaultMessage(); + errors.put(fieldName, errorMessage); + }); + + return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); // Return errors with 400 status + } + + // Handle ConstraintViolationException (if needed for specific validation annotations) + @ExceptionHandler(ConstraintViolationException.class) + public ResponseEntity> handleConstraintViolation(ConstraintViolationException ex) { + Map errors = new HashMap<>(); + + ex.getConstraintViolations().forEach(violation -> { + errors.put(violation.getPropertyPath().toString(), violation.getMessage()); + }); + + return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); + } + + // Global exception handler for all other exceptions + @ExceptionHandler(Exception.class) + public ResponseEntity handleGlobalException(Exception ex) { + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); // 500 status for internal errors + } +} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java new file mode 100644 index 000000000..e5bc23680 --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java @@ -0,0 +1,40 @@ +//The User Model is used to interact and create the database + + +package com.jydoc.deliverable3.Model; +import jakarta.persistence.*; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Getter +@Setter +@NoArgsConstructor + +public class UserModel { +//Each row in the database is a unique user containing all of these columns + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name="userid") + private int id; + + @Column(name="userisadmin") + private boolean admin; + + @Column(name="userfirstname") + private String firstName; + + @Column(name="userlastname") + private String lastName; + + @Column(name="useremail") + private String email; + + @Column(name="userpassword") + private String password; + +} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java new file mode 100644 index 000000000..ec8913523 --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java @@ -0,0 +1,24 @@ +//This is where the backend interacts with the database to retrieve or add data + +package com.jydoc.deliverable3.Repository; +import com.jydoc.deliverable3.Model.UserModel; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface UserRepository extends CrudRepository { + + + //Custom Queries + List findById(int id); //TODO: Switch this to Long type + //static List findByEmail(String email); + List findByFirstName(String firstName); + List findByLastName(String lastName); + List findByFirstNameAndLastName(String firstName, String lastName); + + + + +} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java new file mode 100644 index 000000000..c70d4bfbf --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java @@ -0,0 +1,47 @@ +//This is where user data is processed. + +package com.jydoc.deliverable3.Service; +import com.jydoc.deliverable3.DTO.UserDTO; +import com.jydoc.deliverable3.Model.UserModel; +import com.jydoc.deliverable3.Repository.UserRepository; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; + +public class UserService { + + + public UserModel convertToEntity(UserDTO UserDto) { + + UserModel user = new UserModel(); + user.setId(UserDto.getId()); + user.setAdmin(UserDto.isAdmin()); + user.setFirstName(UserDto.getFirstName()); + user.setLastName(UserDto.getLastName()); + user.setEmail(UserDto.getEmail()); + user.setPassword(UserDto.getPassword()); + return user; + } + + public UserDTO convertToDTO(UserModel UserModel) { + + UserDTO user = new UserDTO(); + user.setId(UserModel.getId()); + user.setAdmin(UserModel.isAdmin()); + user.setFirstName(UserModel.getFirstName()); + user.setLastName(UserModel.getLastName()); + user.setEmail(UserModel.getEmail()); + user.setPassword(UserModel.getPassword()); + return user; + } + + + + + + public boolean authenticate(@NotBlank(message = "Email cannot be empty") @Email(message = "Invalid email format") String email, @NotBlank(message = "Password cannot be empty") @Size(min = 6, message = "Password must be at least 6 characters") @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", + message = "Password must contain at least one letter and one number") String password) { + return true; + } +} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/application.properties b/Sprint 1/deliverable3/deliverable3/src/main/resources/application.properties new file mode 100644 index 000000000..0cc001234 --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/resources/application.properties @@ -0,0 +1,9 @@ + +#Server Configuration + +spring.application.name=deliverable3 +spring.jpa.hibernate.ddl-auto=create-drop +spring.datasource.url=jdbc:mysql://localhost:3306/userdatabase +spring.datasource.username=root +spring.datasource.password=JYDOC +spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/error.html b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/error.html new file mode 100644 index 000000000..130701ba9 --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/error.html @@ -0,0 +1,10 @@ + + + + + Error + + +Error + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/index.html b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/index.html new file mode 100644 index 000000000..fae1fc07c --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/index.html @@ -0,0 +1,28 @@ + + + + + Thymeleaf Example + + + +

Welcome to Thymeleaf!

+ +

+ +
+

Current Date and Time:

+
+ + +
+ +
+ + +
+ +
+ + + diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/login.html b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/login.html new file mode 100644 index 000000000..795d5cb8c --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/login.html @@ -0,0 +1,23 @@ + + + + + Login + + +

Login

+
+
+ + +
+
+ + +
+
+ +
+
+ + diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/loginSuccess.html b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/loginSuccess.html new file mode 100644 index 000000000..7a517bfcb --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/loginSuccess.html @@ -0,0 +1,10 @@ + + + + + Title + + +Login Success + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/register.html b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/register.html new file mode 100644 index 000000000..abf6b9f58 --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/register.html @@ -0,0 +1,7 @@ +
+ + + + + +
\ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/styles.css b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/styles.css new file mode 100644 index 000000000..e69de29bb diff --git a/Sprint 1/deliverable3/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java b/Sprint 1/deliverable3/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java new file mode 100644 index 000000000..496abea0b --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java @@ -0,0 +1,13 @@ +package com.jydoc.deliverable3; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Deliverable3ApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class b/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class new file mode 100644 index 0000000000000000000000000000000000000000..2bbe8f2a4402d96228d63e231577ab1ef3b89523 GIT binary patch literal 2663 zcmbVOZC4XV6n=&cWC=lNf+#8!QEMQ;mKPC>wM7tW4KF1K75j2F$utZkyPVk#)bITh z{TH?$)YfzQ1NxuZ(>t?E5_%F2m2)<;^K$QV?{l9!%U}Qe@h5;q{18JMj3^>;w4;Ne z_rN~3t+MTutd0BuFZc`{4}~NAM+`=4bjO6r&{e2P$sK>$_IV63bVU)5qZ^kPlG@%E z6>eqSf?ZZe$kK677_Ov7vrV=$UFgL}Q6%C>qL1N*D@&GlB!yG@QQ8%L;>ts-Dy%iP z$jc0IyI5TGeJS!)<$5_4_|zfiXxS-c8dicNGNak^oMue)Gqek*$bT|%m0rtkNjOnl zV;C#A73<(t(Jfd6FOIpi^JP9`<+wZ+1#Ug}xD4N87=R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tlm?TO9yxwW4QN^U-S%aLC0pomE2qR{wsdm8nAb G9{3l4T$3RH literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class b/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class new file mode 100644 index 0000000000000000000000000000000000000000..f40fe2906c3b14eb901f827428740a632b9b39ef GIT binary patch literal 4814 zcmbVQSyLR>75;i=dZrl~36PL9LPBF1VfL|>Nb(?LYr~oZkSt`BAX`y0(?E-vZam#+ zbDZ5 zzyFNS%VqOq?()rRxz}B@%C~};RZ^f7#C4aB-RM@J8l{S5Q@SM5 zULAX|mr}E0SY-vhvs+OtcvZ_@of5NsI`)g1wqdyL1E*RNVMfP65q7LtRo9z0DyB#e z={W40mW@D|rtpZ4ES{r((Xg+)wQ2B6eZzI13KE_gSrX&tbqwMdV_G%60^?`$1(Cm? zV;Ca}QkHum$blN)V@$_5CJ0ZDD?uWAhezu0!&GF&b2?s>P?Dy^;R^5x9Vf-TlkV5U z1V#QG9j8UEQ$7>rD2lT>UWy!MYiY(XrQ@7LuB{pF+9juC_OjCFb-avM6zs1U>*giL zE*jn~%cI(MJ;U}~1$TxEORd5Ff08y?E6Ci~v^}e0E?Ta|Cb?kSj%RolBTyg?>qgZx za`%n0Rr1BTq6AkpEQXhxcf5=2%JnI(e8qHKW7TB!{AJFvoP^3Qn_086;XP6?v>lr7 zN2t98+y5RN*?8F%r&=-C@rN5Dz4>UPG1>!BeOf<#Y`ae{SdUG9InMTvvo73nLp8L@ zrt7C+c-gYaie^t|i)%*JD0*g(FVv?lsP{;uVlXb>Xn#-p5z%=db2_O38iw((Uq@~+}E11~Q?FcI&yFkJ2S<5!( z{pfGXn36%`6piwtQMH5*g$ZxX;%X1hZa>?&(*0qtu#?*Kb? z7lASw5*)iuA4J&ccaXcA08$n524L?W`?*{4G&ssYYh!-9&OSN|>qH^MC8Jzkusj)JdckH_Ut*fB z>89|Zf@51TG<>l!)D%8aF!1fBEOC$*p5s{;lTpdvymZKDkxPXC=Cy&`1=8}q2nCm1 zT*j4vn8B;m96)RjYC4iNZA|VHq5lhrM>bbcpzyl|d{5A3F-LCR#Wmrs`;ZfeZ$Vxq z+2BCF(IqBVl<+$Pe1~zqMz^?p=LQxExGC_j`|wBWBYw??Z?TKX1*a8ru@&=HE9PQ5 z%vq7XHr^ojW~jZxH`^P>T7dqH z)Ke!>=a(cNezBa3;arZ_`aRO%e1M%?{9%$Z4ZB7r|>dl zYVZeJ;Mdy2_wN*5=1mR$a0@*Do(a}o`Gj53$qx8xZ1fLM6Hmwf4()eP<4?!_25oM9 z^ceeZZZw~m_$N9ui7(Of1o}iK@eGrZ@A14!ljHehMiran zm*{C;LyXd)QAZ{n86{-e#9QXy zMv!N%|G$ETdt9VGe2#U_#2C)wW0Wb2^Hll(6;cWAj&<0iR7k}gQc1jr8ElYB;n#Qt zZ;{gQN3Lj%5UvENJNNA-$LuY_5^CTad(=U(Rndp3uxVAPmr2;hP*F7o==D(lL$4MG)AC0l~;Wg zd%}0pGHRqclTZ4pWKG3Rq1U1I#l0Ft8m1Y?N7(d-n~D!{pHz(h2w1@brXJ@FWDXBW zC0O(mctlF2WD4H8O~7 z5{;tJELmr^W!WqZjZ=-rTlQ@fbZMHmZ`Y2Ut4vca3j_%Yuazwk3YKf(Lt(xg7Xuee__{{;ogr0f6y literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class b/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class new file mode 100644 index 0000000000000000000000000000000000000000..efcd494a354085320bc8fee605438a97b7adbd6f GIT binary patch literal 769 zcmb7CO;6iE5PcgG970+ke3h0SxP=^8BqT1WkkX)@3{*{(9(r0ki`iiBM(Z^nKZ{eV z9{2(MQB`MMBzy>mTJnr$X6Mb!oB93c*CT)d-nUT0LV$W34JR_=shp}Rj0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FZ~bsk2d+*uycx%MW!nZRRsOT{yI zwgc~QP{lXMtE8e&ns`r|cwfZ@To`g@OUT$wBreWR|5f@$CJDh&@qVyU-=TR z^<3-y70Q__ST{QGGZIVa;1>G@n}H?VQior$^~~;{u>A^pf1qr=Z@7R7SiH7TXr3SYEJR?$K`{jV zObEI=0(yXW_es2WT@&widhS6dkyY?^ui)(_jHi5bTh`!}E3tUp7`)O*30{bIm{(c3 zc9}>f_`pv{hPjN^YOjxJb0E5cshyb0G`A*C3o(An9SOOuDK43Disg`gyZQ%~z<(et z;V5_e5>Cjk57pyzg)Q>m5Wo(;O7D!I=<>6`2k62go`#@#HlEP@9L+cIS?9p-82=d= z$(={W`giYHZG1x@#?;@8R+`$3TYM+|;ku-T{OQDVc%H_aN!u52iI7^6z>EAQ9lb<} pI=t*hExG>+?_cFdChQ|hyoNXMcKGdGe1I?bEJ3+1@io3h*Wc{uB%uHR literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class b/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class new file mode 100644 index 0000000000000000000000000000000000000000..920da29aae991d869023d1bfb396604eda652cdb GIT binary patch literal 2244 zcma)-+foxj5Qcj~LI_zPAm@XEAO=uY#Unu!Ihm?}l!R2t-I9zju-T<{Cs@3b7g{A{ zl@~sM4`un!?jo37E4g8&r+dHY>Ha(X`u*c45v@=@MKNkgQe2}1wKAG6+g1JeykeL2 z3OB_WcZ>s*FX&q~OnuMgj<;hJ6BS0x`@Bt~6ty!-7?rB9aJsLcnnoSe$td+vIIi3_ zs+>_z;n+Acbknd7^oBK6Ga7ZP&^FWXBh}#zje6B#f>#Y;s*`?=2E4FS!*xH| zPNkiOXgEnD8jaEzqs$fj-N7+0OGd3r!V+?sQA>8F#AxV!&61+ZOTra+){14>(vZTo zTtP?b-68#kzUhqAmn`(c{0RWW@trA)7kj6Bz6 z0a4vUF7x1_K6%`-iZ(OqDhP{j*Qy8HDXR9X#@S`VEE$eac5oP%M*@Y*7MjxxUNI8X zKX08ybfBkT+SLR5ME_e^e3BIIiZ3gqxR3mi@Wz#*db2ZOO`$x9DgZ-75R>x zKt6cA>%Tsp%`16iwzxd9D?5gRVoRt%^_0ut{&;p@1!*|BmOx)Ne7_1yBkWoRur4#e z_9}z+UAyL#`G!zc?%YG4y!o0}QvRPP)}di}o}&rO#1N*q6)T397~O<5Of7T^>p1KQ zPPb{2rm(%^(lp{Qs6kvBYv8yG2WB+&K4TNZk$Q_d9H0mItN8)+kRHKW2)vK6GI~N!BS6V|&~QW0GkP8YN`JvE z*E1Sx2zn6->Z%8gHv}z4f_myflMO++NKjurXu2V2iC#ifs%wiVN=!9kcI1NC*SaEg zd8B?nB50dxsV~lDL?W3Xnaqzcz;R*d~XQ99*ys77Vpn`fFB6q@qZa=_;=pF(_lS4(?EhT R+VG^d>HWf~--x$Fe*hf-TY>-p literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class b/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class new file mode 100644 index 0000000000000000000000000000000000000000..e33b94711d94b23e1c65e75bf46110cd142a78f9 GIT binary patch literal 1034 zcmbVL%Sr<=6ulYk%ST(Suj10-e|x5(0^Q_Q;o(P@zQ=nv z%pZaBRUnP%@*Cj`oQH~($}l68#Pscq)azq3xiW(uADSH-r-Hx~t`yGPG)_(ivS2|D zZz&Xl+bk{%<`9~Pd;%4|pdvyG!_eY4s02$NRXGd7ssvs}=D7U|tVT3zP{uutde#Bn E0k9@BGXMYp literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class b/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class new file mode 100644 index 0000000000000000000000000000000000000000..1a7c8e56aaf18a0a1401dbd3db5b58b1b7e39f08 GIT binary patch literal 2290 zcma)7=~5d<5dKCI2+$@53>YWDUNB&ZYwg$}#NY!Ph~pOeO)&lJdj_c?<0`YWaD~S$)aoa0fdq)M&whF4`94cS#l++Dt)uW~L zBv5{&bs>p(7g8{i_{hM=I43aDB6MkUJqjc#&{kABTZj^78KlQRFV2%asM-_hY-Wpr z`wa}>fi+tP}qI>1Ow8f-wW*oFGLBa6F-c#(>4nyn~uCh3f`BuOn~BAo$7i3+#N;z!!DoV|$9rpM=4s>S3*)wTr9` zu{O-w7;9c>=dRmnKecddseM^pU_?x)s8SshZEUaym1$lp@I^ zyreyW(N;kxk!jx*3J_??qd7(Qs?xh&VMF>fds_Ka2cxmE=n%Bt)mgNbJ3CFXvvDvf zm#pYrMfJ0#ruJNY$0)yJxVPyDDxObnXwy-lQ9Y=Qq`=VQ3Za+PmJ>MK@uLH^=(?Vk z+VNc4EFZOf>1$~n%92xv%oY_O(7tqB9aw9gzE9WCKDVQ+fr>=a(g2af9_U(+oZKKIpvjS`l)buAewvsdR^qH_*zJ zAfhR?SyFTnn6sw6OD(sn9p|e5ZxJ@6CQp~(+kI73KOazGU#9Qgo|$;IIK3^WU%$vi ztLKHx%rCQ3zm5vbolZ_A)l^Wk!N7ABabZ|fx&@P$Zgf)VZa&?!#%!KyTvy(!__kVc z_*i%INYzgN3=af`@qk_^{7HbO1?}`)rjLRvMr6MXF~?-S3UQ0&e24{>w?o`vc{jv8mWv_oH<2Bpq?d^7Wuj)%cbLeI z5ZNn4cC-cAJW;HZT|Fk7kH~J~3AKkSdykyBva!VP{5;W_4#nBO%BvcG%HoLxBt`z$-Qsu}h%~ YF*4P$8bHLlj&mC141$0|7%}Yq2jYn+R{#J2 literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/templates/error.html b/Sprint 1/deliverable3/deliverable3/target/classes/templates/error.html new file mode 100644 index 000000000..130701ba9 --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/target/classes/templates/error.html @@ -0,0 +1,10 @@ + + + + + Error + + +Error + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/templates/index.html b/Sprint 1/deliverable3/deliverable3/target/classes/templates/index.html new file mode 100644 index 000000000..fae1fc07c --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/target/classes/templates/index.html @@ -0,0 +1,28 @@ + + + + + Thymeleaf Example + + + +

Welcome to Thymeleaf!

+ +

+ +
+

Current Date and Time:

+
+ + +
+ +
+ + +
+ +
+ + + diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/templates/login.html b/Sprint 1/deliverable3/deliverable3/target/classes/templates/login.html new file mode 100644 index 000000000..795d5cb8c --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/target/classes/templates/login.html @@ -0,0 +1,23 @@ + + + + + Login + + +

Login

+
+
+ + +
+
+ + +
+
+ +
+
+ + diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/templates/loginSuccess.html b/Sprint 1/deliverable3/deliverable3/target/classes/templates/loginSuccess.html new file mode 100644 index 000000000..7a517bfcb --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/target/classes/templates/loginSuccess.html @@ -0,0 +1,10 @@ + + + + + Title + + +Login Success + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/templates/register.html b/Sprint 1/deliverable3/deliverable3/target/classes/templates/register.html new file mode 100644 index 000000000..abf6b9f58 --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3/target/classes/templates/register.html @@ -0,0 +1,7 @@ +
+ + + + + +
\ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/templates/styles.css b/Sprint 1/deliverable3/deliverable3/target/classes/templates/styles.css new file mode 100644 index 000000000..e69de29bb From b642fc2757c57850d725c9a09562bea49dfa053e Mon Sep 17 00:00:00 2001 From: bihiy Date: Wed, 26 Mar 2025 09:54:47 -0400 Subject: [PATCH 023/100] Registration System --- Sprint 1/deliverable3/pom.xml | 14 ++++ .../Controller/indexController.java | 51 +++++++++++-- .../com/jydoc/deliverable3/DTO/UserDTO.java | 4 +- .../deliverable3/GlobalExceptionHandler.java | 76 +++++++++++++++---- .../jydoc/deliverable3/Model/UserModel.java | 29 +++++-- .../Repository/UserRepository.java | 2 +- .../deliverable3/Service/UserService.java | 13 +++- .../src/main/resources/application.properties | 6 +- .../src/main/resources/static/index.html | 28 +++++++ .../main/resources/templates/register.html | 67 ++++++++++------ .../src/main/resources/templates/styles.css | 14 ++++ 11 files changed, 246 insertions(+), 58 deletions(-) create mode 100644 Sprint 1/deliverable3/src/main/resources/static/index.html diff --git a/Sprint 1/deliverable3/pom.xml b/Sprint 1/deliverable3/pom.xml index 2a9077de2..53c096c12 100644 --- a/Sprint 1/deliverable3/pom.xml +++ b/Sprint 1/deliverable3/pom.xml @@ -65,6 +65,20 @@ 3.2.0 + + com.googlecode.owasp-java-html-sanitizer + owasp-java-html-sanitizer + 20240325.1 + + + + + org.apache.commons + commons-text + 1.12.0 + + + org.springframework.boot spring-boot-starter-data-jpa diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java index 82c5d6ff9..b0d2b5ab5 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java @@ -2,12 +2,19 @@ //TODO: We need to figure out how to set the user input into a DTO, then convert to Model and add into database package com.jydoc.deliverable3.Controller; +import com.jydoc.deliverable3.DTO.UserDTO; +import com.jydoc.deliverable3.Model.UserModel; +import com.jydoc.deliverable3.Repository.UserRepository; +import com.jydoc.deliverable3.Service.UserService; +import jakarta.validation.Valid; + import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; + import java.time.LocalDate; @@ -17,11 +24,17 @@ @Controller public class indexController { + private final UserRepository userRepository; + private final UserService userService; + + public indexController(UserRepository userRepository) { + this.userRepository = userRepository; + this.userService = new UserService(); + } + // This method maps to the root URL ("/") @GetMapping("/") public String index(Model model) { - // Add the user's name to the model (this can be dynamic) - model.addAttribute("userName", "Guest"); // Add the current date to the model model.addAttribute("currentDate", LocalDate.now()); @@ -30,15 +43,17 @@ public String index(Model model) { return "index"; } -@GetMapping("/login") + @GetMapping("/login") public String login(Model model) { - model.addAttribute("userDTO", new UserDTO()); return "login"; } @PostMapping("/login") public String handleLogin(@Valid @ModelAttribute("userDTO") UserDTO userDTO, Model model) { - boolean isAuthenticated = userService.authenticate(userDTO.getEmail(), userDTO.getPassword()); + + //TODO: Needs to be fixed + UserService UserService = new UserService(); + boolean isAuthenticated = UserService.authenticate(userDTO.getEmail(), userDTO.getPassword()); if (isAuthenticated) { model.addAttribute("username", userDTO.getEmail()); @@ -50,10 +65,30 @@ public String handleLogin(@Valid @ModelAttribute("userDTO") UserDTO userDTO, Mod } @GetMapping("/register") - public String register(Model model) { + public String showRegistrationForm(Model model) { + model.addAttribute("user", new UserDTO()); + return "register"; + } + + @PostMapping("/register") + public String registerUser(@ModelAttribute("user") UserDTO userDTO, BindingResult result, Model model) { //TODO: Implement registration system + if (result.hasErrors()) { + return "register"; // TODO: Implement register error to bring popup then refresh + } + else { + UserModel user = new UserModel(); + user.setEmail(userDTO.getEmail()); + user.setPassword(userDTO.getPassword()); + user.setFirstName(userDTO.getFirstName()); //TODO: Transfer to Service package + user.setLastName(userDTO.getLastName()); + userRepository.save(user); + return "redirect:/"; + } + + + - return "register"; } } diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java index 2ff515b46..b8f4d232c 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java @@ -9,7 +9,7 @@ import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Size; import lombok.Data; - +//TODO: Authentication needs to be fixed here @Data public class UserDTO { //@Data applies Getters, Setters, NoArgsConstructor, and AllArgsConstructor @@ -27,10 +27,12 @@ public class UserDTO { //@Data applies Getters, Setters, NoArgsConstructor, and private String password; @NotBlank(message = "First name cannot be empty") + @Pattern(regexp = "^[\\p{L}'-]+$", message = "First name can only contain letters, hyphens, and apostrophes") @Size(min = 2, max = 30, message = "First name must be between 2 and 30 characters") private String firstName; @NotBlank(message = "Last name cannot be empty") + @Pattern(regexp = "^[\\p{L}'-]+$", message = "Last name can only contain letters, hyphens, and apostrophes") @Size(min = 2, max = 30, message = "Last name must be between 2 and 30 characters") private String lastName; } diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java index 0f7a69e4f..0a9fa7da7 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java @@ -1,4 +1,4 @@ -package com.jydoc.deliverable3.Exception; +package com.jydoc.deliverable3; import jakarta.validation.ConstraintViolationException; import org.springframework.http.HttpStatus; @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.validation.FieldError; +import org.hibernate.validator.internal.engine.path.PathImpl; import java.util.HashMap; import java.util.Map; @@ -14,35 +15,82 @@ @RestControllerAdvice public class GlobalExceptionHandler { - // Handle validation errors (MethodArgumentNotValidException) @ExceptionHandler(MethodArgumentNotValidException.class) public ResponseEntity> handleValidationErrors(MethodArgumentNotValidException ex) { Map errors = new HashMap<>(); - - ex.getBindingResult().getAllErrors().forEach((error) -> { + + ex.getBindingResult().getAllErrors().forEach(error -> { String fieldName = ((FieldError) error).getField(); - String errorMessage = error.getDefaultMessage(); + String errorMessage = getCustomErrorMessage(error); errors.put(fieldName, errorMessage); }); - - return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); // Return errors with 400 status + + return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); } - // Handle ConstraintViolationException (if needed for specific validation annotations) @ExceptionHandler(ConstraintViolationException.class) public ResponseEntity> handleConstraintViolation(ConstraintViolationException ex) { Map errors = new HashMap<>(); - + ex.getConstraintViolations().forEach(violation -> { - errors.put(violation.getPropertyPath().toString(), violation.getMessage()); + String fieldName = ((PathImpl) violation.getPropertyPath()).getLeafNode().getName(); + String errorMessage = getCustomConstraintMessage(violation); + errors.put(fieldName, errorMessage); }); - + return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); } - // Global exception handler for all other exceptions + private String getCustomErrorMessage(org.springframework.validation.ObjectError error) { + String errorCode = error.getCode(); + String defaultMessage = error.getDefaultMessage(); + String fieldName = error.getObjectName(); + + if (error instanceof FieldError) { + fieldName = ((FieldError) error).getField(); + } + + return switch (errorCode) { + case "NotBlank", "NotEmpty" -> fieldName + " is required"; + case "Pattern" -> { + if (fieldName.equals("password")) { + yield "Password must contain at least one digit, one lowercase, one uppercase letter, and one special character"; + } + yield fieldName + " has invalid format"; + } + case "Size" -> { + Object[] args = error.getArguments(); + if (args != null && args.length >= 3) { + yield fieldName + " length must be between " + args[2] + " and " + args[1]; + } + yield defaultMessage; + } + default -> defaultMessage; + }; + } + + private String getCustomConstraintMessage(jakarta.validation.ConstraintViolation violation) { + String fieldName = ((PathImpl) violation.getPropertyPath()).getLeafNode().getName(); + String message = violation.getMessage(); + + if (message.contains("jakarta.validation.constraints.NotBlank") || + message.contains("jakarta.validation.constraints.NotEmpty")) { + return fieldName + " is required"; + } else if (message.contains("jakarta.validation.constraints.Pattern")) { + if (fieldName.equals("password")) { + return "Password must meet complexity requirements"; + } + return fieldName + " has invalid format"; + } else if (message.contains("jakarta.validation.constraints.Size")) { + return fieldName + " length is invalid"; + } + + return message; + } + @ExceptionHandler(Exception.class) public ResponseEntity handleGlobalException(Exception ex) { - return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); // 500 status for internal errors + return new ResponseEntity<>("An error occurred: " + ex.getMessage(), + HttpStatus.INTERNAL_SERVER_ERROR); } -} +} \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java index 7bfb69bea..f8ddd88bc 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java @@ -6,6 +6,9 @@ import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.*; + import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -19,22 +22,36 @@ public class UserModel { //Each row in the database is a unique user containing all of these columns @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name="user-id") + @Column(name="userid") private int id; - @Column(name="user-isadmin") + + @Column(name="userisadmin") private boolean admin; - @Column(name="user-firstname") + @NotBlank + @Size(min = 2, max = 50, message = "First name must be 2-50 characters") + @Pattern(regexp = "^[\\p{L}'-]+$", message = "First name can only contain letters, hyphens, and apostrophes") + @Column(name="userfirstname") private String firstName; - @Column(name="user-lastname") + @NotBlank + @Size(min = 2, max = 50, message = "Last name must be 2-50 characters") + @Pattern(regexp = "^[\\p{L}'-]+$", message = "Last name can only contain letters, hyphens, and apostrophes") + @Column(name="userlastname") private String lastName; - @Column(name="user-email") + @NotBlank + @NotBlank(message = "Email cannot be blank") + @Email(message = "Email must be valid") + @Column(name="useremail", unique=true) private String email; - @Column(name="user-password") + @Size(min = 6, message = "Password must be at least 6 characters") + @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", + message = "Password must contain at least one letter and one number") + @NotBlank(message = "Password cannot be blank") + @Column(name="userpassword") private String password; } diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java index 412dfcfb7..ec8913523 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java @@ -13,7 +13,7 @@ public interface UserRepository extends CrudRepository { //Custom Queries List findById(int id); //TODO: Switch this to Long type - List findByEmail(String email); + //static List findByEmail(String email); List findByFirstName(String firstName); List findByLastName(String lastName); List findByFirstNameAndLastName(String firstName, String lastName); diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java index 267b34c01..c2994f634 100644 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java @@ -1,13 +1,17 @@ //This is where user data is processed. - - package com.jydoc.deliverable3.Service; import com.jydoc.deliverable3.DTO.UserDTO; import com.jydoc.deliverable3.Model.UserModel; +import com.jydoc.deliverable3.Repository.UserRepository; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; public class UserService { + public UserModel convertToEntity(UserDTO UserDto) { UserModel user = new UserModel(); @@ -31,4 +35,9 @@ public UserDTO convertToDTO(UserModel UserModel) { user.setPassword(UserModel.getPassword()); return user; } + + + public boolean authenticate(@NotBlank(message = "Email cannot be empty") @Email(message = "Invalid email format") String email, @NotBlank(message = "Password cannot be empty") @Size(min = 6, message = "Password must be at least 6 characters") @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", + message = "Password must contain at least one letter and one number") String password) { return true; + } } diff --git a/Sprint 1/deliverable3/src/main/resources/application.properties b/Sprint 1/deliverable3/src/main/resources/application.properties index 731b3ff73..7f1b435c3 100644 --- a/Sprint 1/deliverable3/src/main/resources/application.properties +++ b/Sprint 1/deliverable3/src/main/resources/application.properties @@ -1,9 +1,9 @@ #Server Configuration - +# TODO: CHANGE DDL-AUTO TO UPDATE!!!! spring.application.name=deliverable3 spring.jpa.hibernate.ddl-auto=create-drop -spring.datasource.url=jdbc:mysql://localhost:3306/user_database +spring.datasource.url=jdbc:mysql://localhost:3306/userdatabase spring.datasource.username=root -spring.datasource.password= +spring.datasource.password=JYDOC spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/src/main/resources/static/index.html b/Sprint 1/deliverable3/src/main/resources/static/index.html new file mode 100644 index 000000000..ab81ba2bf --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/static/index.html @@ -0,0 +1,28 @@ + + + + + Thymeleaf Example + + + +

Welcome to Thymeleaf!

+ +

+ +
+

Current Date and Time:

+
+ + +
+ +
+ + +
+ +
+ + + diff --git a/Sprint 1/deliverable3/src/main/resources/templates/register.html b/Sprint 1/deliverable3/src/main/resources/templates/register.html index b448e8307..fbaa3c493 100644 --- a/Sprint 1/deliverable3/src/main/resources/templates/register.html +++ b/Sprint 1/deliverable3/src/main/resources/templates/register.html @@ -1,34 +1,55 @@ - - Registration - + User Registration + -
-

Registration Form

+

Register

+
+ - - - - - - - + +
+ + + +
- - - + +
+ + + +
- - - + +
+ + + +
- - -
-
+ +
+ + + +
+ + + - + \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/styles.css b/Sprint 1/deliverable3/src/main/resources/templates/styles.css index e69de29bb..3aaa3cb2d 100644 --- a/Sprint 1/deliverable3/src/main/resources/templates/styles.css +++ b/Sprint 1/deliverable3/src/main/resources/templates/styles.css @@ -0,0 +1,14 @@ +.error { + color: #dc3545; + font-size: 0.875em; +} +.error-border { + border-color: #dc3545; +} +.error-list { + background-color: #f8d7da; + border: 1px solid #f5c6cb; + border-radius: 4px; + padding: 10px; + margin-bottom: 20px; +} \ No newline at end of file From 1d80dd0854aff9195a53740bebe066eaf92ae51e Mon Sep 17 00:00:00 2001 From: bihiy Date: Wed, 26 Mar 2025 09:58:06 -0400 Subject: [PATCH 024/100] Cleanup --- Sprint 1/deliverable3.zip | Bin 25604 -> 0 bytes Sprint 1/deliverable3/HELP.md | 29 -- Sprint 1/deliverable3/deliverable3.iml | 13 - .../Controller/indexController.class | Bin 2663 -> 0 bytes .../com/jydoc/deliverable3/DTO/UserDTO.class | Bin 4814 -> 0 bytes .../Deliverable3Application.class | Bin 769 -> 0 bytes .../deliverable3/GlobalExceptionHandler.class | Bin 4467 -> 0 bytes .../jydoc/deliverable3/Model/UserModel.class | Bin 2244 -> 0 bytes .../Repository/UserRepository.class | Bin 1034 -> 0 bytes .../deliverable3/Service/UserService.class | Bin 2290 -> 0 bytes .../target/classes/templates/error.html | 10 - .../target/classes/templates/index.html | 28 -- .../target/classes/templates/login.html | 23 -- .../classes/templates/loginSuccess.html | 10 - .../target/classes/templates/register.html | 7 - .../target/classes/templates/styles.css | 0 Sprint 1/deliverable3/mvnw | 259 ------------------ Sprint 1/deliverable3/mvnw.cmd | 149 ---------- Sprint 1/deliverable3/pom.xml | 122 --------- .../Controller/indexController.java | 94 ------- .../com/jydoc/deliverable3/DTO/UserDTO.java | 39 --- .../deliverable3/Deliverable3Application.java | 13 - .../deliverable3/GlobalExceptionHandler.java | 96 ------- .../jydoc/deliverable3/Model/UserModel.java | 57 ---- .../Repository/UserRepository.java | 24 -- .../deliverable3/Service/UserService.java | 43 --- .../src/main/resources/application.properties | 9 - .../src/main/resources/static/index.html | 28 -- .../src/main/resources/templates/error.html | 10 - .../src/main/resources/templates/index.html | 28 -- .../src/main/resources/templates/login.html | 23 -- .../resources/templates/loginSuccess.html | 10 - .../main/resources/templates/register.html | 55 ---- .../src/main/resources/templates/styles.css | 14 - .../Deliverable3ApplicationTests.java | 13 - 35 files changed, 1206 deletions(-) delete mode 100644 Sprint 1/deliverable3.zip delete mode 100644 Sprint 1/deliverable3/HELP.md delete mode 100644 Sprint 1/deliverable3/deliverable3.iml delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/GlobalExceptionHandler.class delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/templates/error.html delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/templates/index.html delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/templates/login.html delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/templates/loginSuccess.html delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/templates/register.html delete mode 100644 Sprint 1/deliverable3/deliverable3/target/classes/templates/styles.css delete mode 100644 Sprint 1/deliverable3/mvnw delete mode 100644 Sprint 1/deliverable3/mvnw.cmd delete mode 100644 Sprint 1/deliverable3/pom.xml delete mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java delete mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java delete mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java delete mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java delete mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java delete mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java delete mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java delete mode 100644 Sprint 1/deliverable3/src/main/resources/application.properties delete mode 100644 Sprint 1/deliverable3/src/main/resources/static/index.html delete mode 100644 Sprint 1/deliverable3/src/main/resources/templates/error.html delete mode 100644 Sprint 1/deliverable3/src/main/resources/templates/index.html delete mode 100644 Sprint 1/deliverable3/src/main/resources/templates/login.html delete mode 100644 Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html delete mode 100644 Sprint 1/deliverable3/src/main/resources/templates/register.html delete mode 100644 Sprint 1/deliverable3/src/main/resources/templates/styles.css delete mode 100644 Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java diff --git a/Sprint 1/deliverable3.zip b/Sprint 1/deliverable3.zip deleted file mode 100644 index 271fa57c4875ea58c73f8bd38e676d0a6633b4d4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 25604 zcmbtc1zgoh*S@rLcS?7+v~;I*cXvrB9a7TW-JOC;BOLE^-x@vHQv=1%%fP7dY<&Q8XT4Aw3-u0&48ZcaqTwpP4WCNR|W zhSo-Z{>IP&_`93xZzOpDxT!uP}W{8BYSmxreKlrFT)q?I$`<$K!83u^mmx;+tsaIs{;;fpC(UhXaduxf=zyhEd@ z(27FLBm-EpW#be?b(T0WeeWV8ML)5-E@QJ?Z>nfdsho_e98trEyoL-Df3p=^58@#E zMlA33+auxEc@nH?Bh_QrNnUu>nZlq1NGoG@ZI*P?B=MI)y;#1_iV);3E>_m?eJyJF zH}fL&i$X%b!MkhMQp@adJR-rU0cU}ox;|Y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2J3#^|V4*$J9HzQB{ zZ?XRBsQ7Ievap{1QidC?xqE*2whTqUh~u4Jy#3+kH1TaXdi7r`&HZD!x8dHR`~dgA zL%O$77Df$!*{J)69dDzI0@F`#x8wVbbhjarTU34tanq2yDXq65WPu;*?kA6UqDls=H@2b7yg=xqpeJ^NoYzp(dX?Z0c`&BUAiPhsznaa#r{56fEQU+C!l`21}dj{cPlx1#m8#o7Ec z-~Uf+z`HU1-^IC^yJdj;mUmivzw3XpYbpFU5&qlq{gd%_KeGP2d^cTY%KC5Q`)#-D zwj?CeA29xYa(Mu_AC3QAk{hO4|AQpoH^^=V?ro9QN`5600B}E8{kupvh4_yB)%MDvA|4EkHTL$-d`lW1u?-6F85P!Ug?##~#!1R`%E7qUU z>f3BEN~4tg%6q#X)4t8d`+tD=^WfEOIW$L6e<8=uLe9U-aibw^!2R`Kwfuhp=-a@6 zp^R+$za2dHfvN9M4hBq@_!aPf5b;i{1zS_e` and `` from the parent. -To prevent this, the project POM contains empty overrides for these elements. -If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. - diff --git a/Sprint 1/deliverable3/deliverable3.iml b/Sprint 1/deliverable3/deliverable3.iml deleted file mode 100644 index 2cf3f920f..000000000 --- a/Sprint 1/deliverable3/deliverable3.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class b/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class deleted file mode 100644 index 2bbe8f2a4402d96228d63e231577ab1ef3b89523..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2663 zcmbVOZC4XV6n=&cWC=lNf+#8!QEMQ;mKPC>wM7tW4KF1K75j2F$utZkyPVk#)bITh z{TH?$)YfzQ1NxuZ(>t?E5_%F2m2)<;^K$QV?{l9!%U}Qe@h5;q{18JMj3^>;w4;Ne z_rN~3t+MTutd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5j z;Y>$nXd;IYB}Zd0k*4e?a2=CK5$kD8VGh$e;@JSK7V!eU!ZV%Gf{wk7tf!F08im!5 zTUf^iBG@FqonU_>9mPOEVP_jz;tY*nlb?XbRcr+o{WRq0*`_DaMr5kVb9K(s=5%G& z*nUPpitS`NG4&pUM8-^*<7}P%pvv>~-_Alq1(LOVk{7AKE(P!nUJ#zDfJ#3?qmh`a z;{;V+)EHyIb`8U*ab{o-F9V5aTtlm?TO9yxwW4QN^U-S%aLC0pomE2qR{wsdm8nAb G9{3l4T$3RH diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class b/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class deleted file mode 100644 index f40fe2906c3b14eb901f827428740a632b9b39ef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4814 zcmbVQSyLR>75;i=dZrl~36PL9LPBF1VfL|>Nb(?LYr~oZkSt`BAX`y0(?E-vZam#+ zbDZ5 zzyFNS%VqOq?()rRxz}B@%C~};RZ^f7#C4aB-RM@J8l{S5Q@SM5 zULAX|mr}E0SY-vhvs+OtcvZ_@of5NsI`)g1wqdyL1E*RNVMfP65q7LtRo9z0DyB#e z={W40mW@D|rtpZ4ES{r((Xg+)wQ2B6eZzI13KE_gSrX&tbqwMdV_G%60^?`$1(Cm? zV;Ca}QkHum$blN)V@$_5CJ0ZDD?uWAhezu0!&GF&b2?s>P?Dy^;R^5x9Vf-TlkV5U z1V#QG9j8UEQ$7>rD2lT>UWy!MYiY(XrQ@7LuB{pF+9juC_OjCFb-avM6zs1U>*giL zE*jn~%cI(MJ;U}~1$TxEORd5Ff08y?E6Ci~v^}e0E?Ta|Cb?kSj%RolBTyg?>qgZx za`%n0Rr1BTq6AkpEQXhxcf5=2%JnI(e8qHKW7TB!{AJFvoP^3Qn_086;XP6?v>lr7 zN2t98+y5RN*?8F%r&=-C@rN5Dz4>UPG1>!BeOf<#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deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class deleted file mode 100644 index efcd494a354085320bc8fee605438a97b7adbd6f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 769 zcmb7CO;6iE5PcgG970+ke3h0SxP=^8BqT1WkkX)@3{*{(9(r0ki`iiBM(Z^nKZ{eV z9{2(MQB`MMBzy>mTJnr$X6Mb!oB93c*CT)d-nUT0LV$W34JR_=shp}Rj0&}2A>O~$A96BF}^Ox2CFB1+{EKdl&p*(_DDaLVWwT38OyZsQeR zGxUs2cs{dACzn=a^48dE9vS2KsB~5`sirM7L(~nQ`x>Sq&->pio{{rl{rzwra%{Ad zca9H@zEnw3wpuAcZXfP5)Q4sw8CF82<#~}s(th=0F?2!`i*zik^7fOn?ygkMa2Wm{ z7rss=6wS2Noj1am;=(3`ygnyP`#F>D%1k~B&zzH%9=1lNu(AB4e6PDN?BKxj$FTFI z&`xD?ta3%O474_`+!5iN%%!hfj3}HT9!vh@)0#fg#wtAav4?8Z>RwJ1kJ&+m}<&EU?}eDto4-jp(JBQN5Ueg8Bqn zpekrp(S~+`LC2leN=4VSr>9(f-nihnbJ_)CQkyjGf;MV+GfrX1oi5KCwm0T@Io&b~ zsf&4|=$Vd9B-4g>gpyRx7^SjBBzN}qrQ?h)NL5{`X;m7@7Ockx1vjbKh)n{!Z$w!@ zC4wQ#O1ZA%mIOA?dnNF+S@Mz_n8QvLH=~Pb((@9#z~0`77;}@1s!f&cybpBPu}ciy zCB`kdRl#j4ZpR%0ZPhLWlqtte>G>Iftx>~k4awqc6WA3O4ra2Q5d2j-Jn?PCb&!P6+IXt%mQbqLfTvEBYk8`UMV$ zAw&q4ti{N%Q!tW!xde7&kAl4_G~6km&FXWy>*-pA05Y$htDCl$Gabt(MTAtHENP4c zBU@ip-K-&tE6~}3{jxfD3$#`W!>0+{gM$hVskj&S3EbpA^rMP+OVHb>Q7Y-vhQP*U z2fkF+llvkmi!i9-ep!J{C&ngHnX#et`D`kaOJ&ZdGMST^7Ce9l6%463f?^T8+iR)ks9!6ThsERS1 ztV$7i&xTPfb3Yu4t9d0~L7Q3LBvE20I3>^*$ID2)kC}#5@V96JivK!YSN3z9Z%W2`(sX}A+ofej_?NL zuzALJ=(o{;_F>;Ldt-N4t(};aiA!2cM?2am6s~cet4-Cu4j|!@|))tvAk$K=FYxFx4 zPm;0w>MDv1Xi840F?JZ)^((V4JO%Km>Dyg7D9B~{^9+`?kCoFZ~bsk2d+*uycx%MW!nZRRsOT{yI zwgc~QP{lXMtE8e&ns`r|cwfZ@To`g@OUT$wBreWR|5f@$CJDh&@qVyU-=TR z^<3-y70Q__ST{QGGZIVa;1>G@n}H?VQior$^~~;{u>A^pf1qr=Z@7R7SiH7TXr3SYEJR?$K`{jV zObEI=0(yXW_es2WT@&widhS6dkyY?^ui)(_jHi5bTh`!}E3tUp7`)O*30{bIm{(c3 zc9}>f_`pv{hPjN^YOjxJb0E5cshyb0G`A*C3o(An9SOOuDK43Disg`gyZQ%~z<(et z;V5_e5>Cjk57pyzg)Q>m5Wo(;O7D!I=<>6`2k62go`#@#HlEP@9L+cIS?9p-82=d= z$(={W`giYHZG1x@#?;@8R+`$3TYM+|;ku-T{OQDVc%H_aN!u52iI7^6z>EAQ9lb<} pI=t*hExG>+?_cFdChQ|hyoNXMcKGdGe1I?bEJ3+1@io3h*Wc{uB%uHR diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class b/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class deleted file mode 100644 index 920da29aae991d869023d1bfb396604eda652cdb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2244 zcma)-+foxj5Qcj~LI_zPAm@XEAO=uY#Unu!Ihm?}l!R2t-I9zju-T<{Cs@3b7g{A{ zl@~sM4`un!?jo37E4g8&r+dHY>Ha(X`u*c45v@=@MKNkgQe2}1wKAG6+g1JeykeL2 z3OB_WcZ>s*FX&q~OnuMgj<;hJ6BS0x`@Bt~6ty!-7?rB9aJsLcnnoSe$td+vIIi3_ zs+>_z;n+Acbknd7^oBK6Ga7ZP&^FWXBh}#zje6B#f>#Y;s*`?=2E4FS!*xH| zPNkiOXgEnD8jaEzqs$fj-N7+0OGd3r!V+?sQA>8F#AxV!&61+ZOTra+){14>(vZTo zTtP?b-68#kzUhqAmn`(c{0RWW@trA)7kj6Bz6 z0a4vUF7x1_K6%`-iZ(OqDhP{j*Qy8HDXR9X#@S`VEE$eac5oP%M*@Y*7MjxxUNI8X zKX08ybfBkT+SLR5ME_e^e3BIIiZ3gqxR3mi@Wz#*db2ZOO`$x9DgZ-75R>x zKt6cA>%Tsp%`16iwzxd9D?5gRVoRt%^_0ut{&;p@1!*|BmOx)Ne7_1yBkWoRur4#e z_9}z+UAyL#`G!zc?%YG4y!o0}QvRPP)}di}o}&rO#1N*q6)T397~O<5Of7T^>p1KQ zPPb{2rm(%^(lp{Qs6kvBYv8yG2WB+&K4TNZk$Q_d9H0mItN8)+kRHKW2)vK6GI~N!BS6V|&~QW0GkP8YN`JvE z*E1Sx2zn6->Z%8gHv}z4f_myflMO++NKjurXu2V2iC#ifs%wiVN=!9kcI1NC*SaEg zd8B?nB50dxsV~lDL?W3Xnaqzcz;R*d~XQ99*ys77Vpn`fFB6q@qZa=_;=pF(_lS4(?EhT R+VG^d>HWf~--x$Fe*hf-TY>-p diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class b/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class deleted file mode 100644 index e33b94711d94b23e1c65e75bf46110cd142a78f9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1034 zcmbVL%Sr<=6ulYk%ST(Suj10-e|x5(0^Q_Q;o(P@zQ=nv z%pZaBRUnP%@*Cj`oQH~($}l68#Pscq)azq3xiW(uADSH-r-Hx~t`yGPG)_(ivS2|D zZz&Xl+bk{%<`9~Pd;%4|pdvyG!_eY4s02$NRXGd7ssvs}=D7U|tVT3zP{uutde#Bn E0k9@BGXMYp diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class b/Sprint 1/deliverable3/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class deleted file mode 100644 index 1a7c8e56aaf18a0a1401dbd3db5b58b1b7e39f08..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2290 zcma)7=~5d<5dKCI2+$@53>YWDUNB&ZYwg$}#NY!Ph~pOeO)&lJdj_c?<0`YWaD~S$)aoa0fdq)M&whF4`94cS#l++Dt)uW~L zBv5{&bs>p(7g8{i_{hM=I43aDB6MkUJqjc#&{kABTZj^78KlQRFV2%asM-_hY-Wpr z`wa}>fi+tP}qI>1Ow8f-wW*oFGLBa6F-c#(>4nyn~uCh3f`BuOn~BAo$7i3+#N;z!!DoV|$9rpM=4s>S3*)wTr9` zu{O-w7;9c>=dRmnKecddseM^pU_?x)s8SshZEUaym1$lp@I^ zyreyW(N;kxk!jx*3J_??qd7(Qs?xh&VMF>fds_Ka2cxmE=n%Bt)mgNbJ3CFXvvDvf zm#pYrMfJ0#ruJNY$0)yJxVPyDDxObnXwy-lQ9Y=Qq`=VQ3Za+PmJ>MK@uLH^=(?Vk z+VNc4EFZOf>1$~n%92xv%oY_O(7tqB9aw9gzE9WCKDVQ+fr>=a(g2af9_U(+oZKKIpvjS`l)buAewvsdR^qH_*zJ zAfhR?SyFTnn6sw6OD(sn9p|e5ZxJ@6CQp~(+kI73KOazGU#9Qgo|$;IIK3^WU%$vi ztLKHx%rCQ3zm5vbolZ_A)l^Wk!N7ABabZ|fx&@P$Zgf)VZa&?!#%!KyTvy(!__kVc z_*i%INYzgN3=af`@qk_^{7HbO1?}`)rjLRvMr6MXF~?-S3UQ0&e24{>w?o`vc{jv8mWv_oH<2Bpq?d^7Wuj)%cbLeI z5ZNn4cC-cAJW;HZT|Fk7kH~J~3AKkSdykyBva!VP{5;W_4#nBO%BvcG%HoLxBt`z$-Qsu}h%~ YF*4P$8bHLlj&mC141$0|7%}Yq2jYn+R{#J2 diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/templates/error.html b/Sprint 1/deliverable3/deliverable3/target/classes/templates/error.html deleted file mode 100644 index 130701ba9..000000000 --- a/Sprint 1/deliverable3/deliverable3/target/classes/templates/error.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Error - - -Error - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/templates/index.html b/Sprint 1/deliverable3/deliverable3/target/classes/templates/index.html deleted file mode 100644 index fae1fc07c..000000000 --- a/Sprint 1/deliverable3/deliverable3/target/classes/templates/index.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Thymeleaf Example - - - -

Welcome to Thymeleaf!

- -

- -
-

Current Date and Time:

-
- - -
- -
- - -
- -
- - - diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/templates/login.html b/Sprint 1/deliverable3/deliverable3/target/classes/templates/login.html deleted file mode 100644 index 795d5cb8c..000000000 --- a/Sprint 1/deliverable3/deliverable3/target/classes/templates/login.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - Login - - -

Login

-
-
- - -
-
- - -
-
- -
-
- - diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/templates/loginSuccess.html b/Sprint 1/deliverable3/deliverable3/target/classes/templates/loginSuccess.html deleted file mode 100644 index 7a517bfcb..000000000 --- a/Sprint 1/deliverable3/deliverable3/target/classes/templates/loginSuccess.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - -Login Success - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/templates/register.html b/Sprint 1/deliverable3/deliverable3/target/classes/templates/register.html deleted file mode 100644 index abf6b9f58..000000000 --- a/Sprint 1/deliverable3/deliverable3/target/classes/templates/register.html +++ /dev/null @@ -1,7 +0,0 @@ -
- - - - - -
\ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/target/classes/templates/styles.css b/Sprint 1/deliverable3/deliverable3/target/classes/templates/styles.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/Sprint 1/deliverable3/mvnw b/Sprint 1/deliverable3/mvnw deleted file mode 100644 index 19529ddf8..000000000 --- a/Sprint 1/deliverable3/mvnw +++ /dev/null @@ -1,259 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Apache Maven Wrapper startup batch script, version 3.3.2 -# -# Optional ENV vars -# ----------------- -# JAVA_HOME - location of a JDK home dir, required when download maven via java source -# MVNW_REPOURL - repo url base for downloading maven distribution -# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output -# ---------------------------------------------------------------------------- - -set -euf -[ "${MVNW_VERBOSE-}" != debug ] || set -x - -# OS specific support. -native_path() { printf %s\\n "$1"; } -case "$(uname)" in -CYGWIN* | MINGW*) - [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" - native_path() { cygpath --path --windows "$1"; } - ;; -esac - -# set JAVACMD and JAVACCMD -set_java_home() { - # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched - if [ -n "${JAVA_HOME-}" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - JAVACCMD="$JAVA_HOME/jre/sh/javac" - else - JAVACMD="$JAVA_HOME/bin/java" - JAVACCMD="$JAVA_HOME/bin/javac" - - if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then - echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 - echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 - return 1 - fi - fi - else - JAVACMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v java - )" || : - JAVACCMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v javac - )" || : - - if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then - echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 - return 1 - fi - fi -} - -# hash string like Java String::hashCode -hash_string() { - str="${1:-}" h=0 - while [ -n "$str" ]; do - char="${str%"${str#?}"}" - h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) - str="${str#?}" - done - printf %x\\n $h -} - -verbose() { :; } -[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } - -die() { - printf %s\\n "$1" >&2 - exit 1 -} - -trim() { - # MWRAPPER-139: - # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. - # Needed for removing poorly interpreted newline sequences when running in more - # exotic environments such as mingw bash on Windows. - printf "%s" "${1}" | tr -d '[:space:]' -} - -# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties -while IFS="=" read -r key value; do - case "${key-}" in - distributionUrl) distributionUrl=$(trim "${value-}") ;; - distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; - esac -done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" -[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" - -case "${distributionUrl##*/}" in -maven-mvnd-*bin.*) - MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ - case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in - *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; - :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; - :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; - :Linux*x86_64*) distributionPlatform=linux-amd64 ;; - *) - echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 - distributionPlatform=linux-amd64 - ;; - esac - distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" - ;; -maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; -*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; -esac - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" -distributionUrlName="${distributionUrl##*/}" -distributionUrlNameMain="${distributionUrlName%.*}" -distributionUrlNameMain="${distributionUrlNameMain%-bin}" -MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" -MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" - -exec_maven() { - unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : - exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" -} - -if [ -d "$MAVEN_HOME" ]; then - verbose "found existing MAVEN_HOME at $MAVEN_HOME" - exec_maven "$@" -fi - -case "${distributionUrl-}" in -*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; -*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; -esac - -# prepare tmp dir -if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then - clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } - trap clean HUP INT TERM EXIT -else - die "cannot create temp dir" -fi - -mkdir -p -- "${MAVEN_HOME%/*}" - -# Download and Install Apache Maven -verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -verbose "Downloading from: $distributionUrl" -verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -# select .zip or .tar.gz -if ! command -v unzip >/dev/null; then - distributionUrl="${distributionUrl%.zip}.tar.gz" - distributionUrlName="${distributionUrl##*/}" -fi - -# verbose opt -__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' -[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v - -# normalize http auth -case "${MVNW_PASSWORD:+has-password}" in -'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; -has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; -esac - -if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then - verbose "Found wget ... using wget" - wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" -elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then - verbose "Found curl ... using curl" - curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" -elif set_java_home; then - verbose "Falling back to use Java to download" - javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" - targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" - cat >"$javaSource" <<-END - public class Downloader extends java.net.Authenticator - { - protected java.net.PasswordAuthentication getPasswordAuthentication() - { - return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); - } - public static void main( String[] args ) throws Exception - { - setDefault( new Downloader() ); - java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); - } - } - END - # For Cygwin/MinGW, switch paths to Windows format before running javac and java - verbose " - Compiling Downloader.java ..." - "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" - verbose " - Running Downloader.java ..." - "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" -fi - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -if [ -n "${distributionSha256Sum-}" ]; then - distributionSha256Result=false - if [ "$MVN_CMD" = mvnd.sh ]; then - echo "Checksum validation is not supported for maven-mvnd." >&2 - echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - elif command -v sha256sum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - elif command -v shasum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - else - echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 - echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - fi - if [ $distributionSha256Result = false ]; then - echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 - echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 - exit 1 - fi -fi - -# unzip and move -if command -v unzip >/dev/null; then - unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" -else - tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" -fi -printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" -mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" - -clean || : -exec_maven "$@" diff --git a/Sprint 1/deliverable3/mvnw.cmd b/Sprint 1/deliverable3/mvnw.cmd deleted file mode 100644 index 249bdf382..000000000 --- a/Sprint 1/deliverable3/mvnw.cmd +++ /dev/null @@ -1,149 +0,0 @@ -<# : batch portion -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.3.2 -@REM -@REM Optional ENV vars -@REM MVNW_REPOURL - repo url base for downloading maven distribution -@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output -@REM ---------------------------------------------------------------------------- - -@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) -@SET __MVNW_CMD__= -@SET __MVNW_ERROR__= -@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% -@SET PSModulePath= -@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( - IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) -) -@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% -@SET __MVNW_PSMODULEP_SAVE= -@SET __MVNW_ARG0_NAME__= -@SET MVNW_USERNAME= -@SET MVNW_PASSWORD= -@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) -@echo Cannot start maven from wrapper >&2 && exit /b 1 -@GOTO :EOF -: end batch / begin powershell #> - -$ErrorActionPreference = "Stop" -if ($env:MVNW_VERBOSE -eq "true") { - $VerbosePreference = "Continue" -} - -# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties -$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl -if (!$distributionUrl) { - Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" -} - -switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { - "maven-mvnd-*" { - $USE_MVND = $true - $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" - $MVN_CMD = "mvnd.cmd" - break - } - default { - $USE_MVND = $false - $MVN_CMD = $script -replace '^mvnw','mvn' - break - } -} - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -if ($env:MVNW_REPOURL) { - $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } - $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" -} -$distributionUrlName = $distributionUrl -replace '^.*/','' -$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' -$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" -if ($env:MAVEN_USER_HOME) { - $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" -} -$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' -$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" - -if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { - Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" - Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" - exit $? -} - -if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { - Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" -} - -# prepare tmp dir -$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile -$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" -$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null -trap { - if ($TMP_DOWNLOAD_DIR.Exists) { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } - } -} - -New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null - -# Download and Install Apache Maven -Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -Write-Verbose "Downloading from: $distributionUrl" -Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -$webclient = New-Object System.Net.WebClient -if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { - $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) -} -[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum -if ($distributionSha256Sum) { - if ($USE_MVND) { - Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." - } - Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash - if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { - Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." - } -} - -# unzip and move -Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null -Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null -try { - Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null -} catch { - if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { - Write-Error "fail to move MAVEN_HOME" - } -} finally { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } -} - -Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/Sprint 1/deliverable3/pom.xml b/Sprint 1/deliverable3/pom.xml deleted file mode 100644 index 53c096c12..000000000 --- a/Sprint 1/deliverable3/pom.xml +++ /dev/null @@ -1,122 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.4.4 - - - com.jydoc - deliverable3 - 0.0.1-SNAPSHOT - deliverable3 - Demo project for Spring Boot - - - - - - - - - - - - - - - 21 - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-web - - - io.github.wimdeblauwe - htmx-spring-boot-thymeleaf - 4.0.1 - - - - com.mysql - mysql-connector-j - runtime - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.modelmapper - modelmapper - 3.2.0 - - - - com.googlecode.owasp-java-html-sanitizer - owasp-java-html-sanitizer - 20240325.1 - - - - - org.apache.commons - commons-text - 1.12.0 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-validation - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.projectlombok - lombok - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - - - diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java deleted file mode 100644 index b0d2b5ab5..000000000 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java +++ /dev/null @@ -1,94 +0,0 @@ -//This controller "listens" for user responses. -//TODO: We need to figure out how to set the user input into a DTO, then convert to Model and add into database - -package com.jydoc.deliverable3.Controller; -import com.jydoc.deliverable3.DTO.UserDTO; -import com.jydoc.deliverable3.Model.UserModel; -import com.jydoc.deliverable3.Repository.UserRepository; -import com.jydoc.deliverable3.Service.UserService; -import jakarta.validation.Valid; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; - - -import java.time.LocalDate; - - - - -@Controller -public class indexController { - - private final UserRepository userRepository; - private final UserService userService; - - public indexController(UserRepository userRepository) { - this.userRepository = userRepository; - this.userService = new UserService(); - } - - // This method maps to the root URL ("/") - @GetMapping("/") - public String index(Model model) { - - // Add the current date to the model - model.addAttribute("currentDate", LocalDate.now()); - - // Return the name of the Thymeleaf template ("index") - return "index"; - } - - @GetMapping("/login") - public String login(Model model) { - return "login"; - } - - @PostMapping("/login") - public String handleLogin(@Valid @ModelAttribute("userDTO") UserDTO userDTO, Model model) { - - //TODO: Needs to be fixed - UserService UserService = new UserService(); - boolean isAuthenticated = UserService.authenticate(userDTO.getEmail(), userDTO.getPassword()); - - if (isAuthenticated) { - model.addAttribute("username", userDTO.getEmail()); - return "loginSuccess"; - } else { - model.addAttribute("error", "Invalid email or password"); - return "login"; // Return back to login page with error message - } - } - - @GetMapping("/register") - public String showRegistrationForm(Model model) { - model.addAttribute("user", new UserDTO()); - return "register"; - } - - @PostMapping("/register") - public String registerUser(@ModelAttribute("user") UserDTO userDTO, BindingResult result, Model model) { - //TODO: Implement registration system - - if (result.hasErrors()) { - return "register"; // TODO: Implement register error to bring popup then refresh - } - else { - UserModel user = new UserModel(); - user.setEmail(userDTO.getEmail()); - user.setPassword(userDTO.getPassword()); - user.setFirstName(userDTO.getFirstName()); //TODO: Transfer to Service package - user.setLastName(userDTO.getLastName()); - userRepository.save(user); - return "redirect:/"; - } - - - - - } -} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java deleted file mode 100644 index b8f4d232c..000000000 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java +++ /dev/null @@ -1,39 +0,0 @@ -// This DTO accepts user input to fill variables, then is converted by -// UserService into a UserModel. -// Also used for business logic. -//test -package com.jydoc.deliverable3.DTO; - -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Pattern; -import jakarta.validation.constraints.Size; -import lombok.Data; -//TODO: Authentication needs to be fixed here -@Data -public class UserDTO { //@Data applies Getters, Setters, NoArgsConstructor, and AllArgsConstructor - - private int id; - private boolean admin; - - @NotBlank(message = "Email cannot be empty") - @Email(message = "Invalid email format") - private String email; - - @NotBlank(message = "Password cannot be empty") - @Size(min = 6, message = "Password must be at least 6 characters") - @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", - message = "Password must contain at least one letter and one number") - private String password; - - @NotBlank(message = "First name cannot be empty") - @Pattern(regexp = "^[\\p{L}'-]+$", message = "First name can only contain letters, hyphens, and apostrophes") - @Size(min = 2, max = 30, message = "First name must be between 2 and 30 characters") - private String firstName; - - @NotBlank(message = "Last name cannot be empty") - @Pattern(regexp = "^[\\p{L}'-]+$", message = "Last name can only contain letters, hyphens, and apostrophes") - @Size(min = 2, max = 30, message = "Last name must be between 2 and 30 characters") - private String lastName; -} - diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java deleted file mode 100644 index 64bf1de75..000000000 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.jydoc.deliverable3; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Deliverable3Application { - - public static void main(String[] args) { - SpringApplication.run(Deliverable3Application.class, args); - } - -} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java deleted file mode 100644 index 0a9fa7da7..000000000 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.jydoc.deliverable3; - -import jakarta.validation.ConstraintViolationException; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestControllerAdvice; -import org.springframework.validation.FieldError; -import org.hibernate.validator.internal.engine.path.PathImpl; - -import java.util.HashMap; -import java.util.Map; - -@RestControllerAdvice -public class GlobalExceptionHandler { - - @ExceptionHandler(MethodArgumentNotValidException.class) - public ResponseEntity> handleValidationErrors(MethodArgumentNotValidException ex) { - Map errors = new HashMap<>(); - - ex.getBindingResult().getAllErrors().forEach(error -> { - String fieldName = ((FieldError) error).getField(); - String errorMessage = getCustomErrorMessage(error); - errors.put(fieldName, errorMessage); - }); - - return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); - } - - @ExceptionHandler(ConstraintViolationException.class) - public ResponseEntity> handleConstraintViolation(ConstraintViolationException ex) { - Map errors = new HashMap<>(); - - ex.getConstraintViolations().forEach(violation -> { - String fieldName = ((PathImpl) violation.getPropertyPath()).getLeafNode().getName(); - String errorMessage = getCustomConstraintMessage(violation); - errors.put(fieldName, errorMessage); - }); - - return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); - } - - private String getCustomErrorMessage(org.springframework.validation.ObjectError error) { - String errorCode = error.getCode(); - String defaultMessage = error.getDefaultMessage(); - String fieldName = error.getObjectName(); - - if (error instanceof FieldError) { - fieldName = ((FieldError) error).getField(); - } - - return switch (errorCode) { - case "NotBlank", "NotEmpty" -> fieldName + " is required"; - case "Pattern" -> { - if (fieldName.equals("password")) { - yield "Password must contain at least one digit, one lowercase, one uppercase letter, and one special character"; - } - yield fieldName + " has invalid format"; - } - case "Size" -> { - Object[] args = error.getArguments(); - if (args != null && args.length >= 3) { - yield fieldName + " length must be between " + args[2] + " and " + args[1]; - } - yield defaultMessage; - } - default -> defaultMessage; - }; - } - - private String getCustomConstraintMessage(jakarta.validation.ConstraintViolation violation) { - String fieldName = ((PathImpl) violation.getPropertyPath()).getLeafNode().getName(); - String message = violation.getMessage(); - - if (message.contains("jakarta.validation.constraints.NotBlank") || - message.contains("jakarta.validation.constraints.NotEmpty")) { - return fieldName + " is required"; - } else if (message.contains("jakarta.validation.constraints.Pattern")) { - if (fieldName.equals("password")) { - return "Password must meet complexity requirements"; - } - return fieldName + " has invalid format"; - } else if (message.contains("jakarta.validation.constraints.Size")) { - return fieldName + " length is invalid"; - } - - return message; - } - - @ExceptionHandler(Exception.class) - public ResponseEntity handleGlobalException(Exception ex) { - return new ResponseEntity<>("An error occurred: " + ex.getMessage(), - HttpStatus.INTERNAL_SERVER_ERROR); - } -} \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java deleted file mode 100644 index f8ddd88bc..000000000 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java +++ /dev/null @@ -1,57 +0,0 @@ -//The User Model is used to interact and create the database - - -package com.jydoc.deliverable3.Model; -import jakarta.persistence.*; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.*; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Entity -@Getter -@Setter -@NoArgsConstructor - -public class UserModel { -//Each row in the database is a unique user containing all of these columns - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name="userid") - private int id; - - - @Column(name="userisadmin") - private boolean admin; - - @NotBlank - @Size(min = 2, max = 50, message = "First name must be 2-50 characters") - @Pattern(regexp = "^[\\p{L}'-]+$", message = "First name can only contain letters, hyphens, and apostrophes") - @Column(name="userfirstname") - private String firstName; - - @NotBlank - @Size(min = 2, max = 50, message = "Last name must be 2-50 characters") - @Pattern(regexp = "^[\\p{L}'-]+$", message = "Last name can only contain letters, hyphens, and apostrophes") - @Column(name="userlastname") - private String lastName; - - @NotBlank - @NotBlank(message = "Email cannot be blank") - @Email(message = "Email must be valid") - @Column(name="useremail", unique=true) - private String email; - - @Size(min = 6, message = "Password must be at least 6 characters") - @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", - message = "Password must contain at least one letter and one number") - @NotBlank(message = "Password cannot be blank") - @Column(name="userpassword") - private String password; - -} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java deleted file mode 100644 index ec8913523..000000000 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -//This is where the backend interacts with the database to retrieve or add data - -package com.jydoc.deliverable3.Repository; -import com.jydoc.deliverable3.Model.UserModel; -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface UserRepository extends CrudRepository { - - - //Custom Queries - List findById(int id); //TODO: Switch this to Long type - //static List findByEmail(String email); - List findByFirstName(String firstName); - List findByLastName(String lastName); - List findByFirstNameAndLastName(String firstName, String lastName); - - - - -} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java deleted file mode 100644 index c2994f634..000000000 --- a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java +++ /dev/null @@ -1,43 +0,0 @@ -//This is where user data is processed. - -package com.jydoc.deliverable3.Service; -import com.jydoc.deliverable3.DTO.UserDTO; -import com.jydoc.deliverable3.Model.UserModel; -import com.jydoc.deliverable3.Repository.UserRepository; -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Pattern; -import jakarta.validation.constraints.Size; - -public class UserService { - - - public UserModel convertToEntity(UserDTO UserDto) { - - UserModel user = new UserModel(); - user.setId(UserDto.getId()); - user.setAdmin(UserDto.isAdmin()); - user.setFirstName(UserDto.getFirstName()); - user.setLastName(UserDto.getLastName()); - user.setEmail(UserDto.getEmail()); - user.setPassword(UserDto.getPassword()); - return user; - } - - public UserDTO convertToDTO(UserModel UserModel) { - - UserDTO user = new UserDTO(); - user.setId(UserModel.getId()); - user.setAdmin(UserModel.isAdmin()); - user.setFirstName(UserModel.getFirstName()); - user.setLastName(UserModel.getLastName()); - user.setEmail(UserModel.getEmail()); - user.setPassword(UserModel.getPassword()); - return user; - } - - - public boolean authenticate(@NotBlank(message = "Email cannot be empty") @Email(message = "Invalid email format") String email, @NotBlank(message = "Password cannot be empty") @Size(min = 6, message = "Password must be at least 6 characters") @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", - message = "Password must contain at least one letter and one number") String password) { return true; - } -} diff --git a/Sprint 1/deliverable3/src/main/resources/application.properties b/Sprint 1/deliverable3/src/main/resources/application.properties deleted file mode 100644 index 7f1b435c3..000000000 --- a/Sprint 1/deliverable3/src/main/resources/application.properties +++ /dev/null @@ -1,9 +0,0 @@ - -#Server Configuration -# TODO: CHANGE DDL-AUTO TO UPDATE!!!! -spring.application.name=deliverable3 -spring.jpa.hibernate.ddl-auto=create-drop -spring.datasource.url=jdbc:mysql://localhost:3306/userdatabase -spring.datasource.username=root -spring.datasource.password=JYDOC -spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/src/main/resources/static/index.html b/Sprint 1/deliverable3/src/main/resources/static/index.html deleted file mode 100644 index ab81ba2bf..000000000 --- a/Sprint 1/deliverable3/src/main/resources/static/index.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Thymeleaf Example - - - -

Welcome to Thymeleaf!

- -

- -
-

Current Date and Time:

-
- - -
- -
- - -
- -
- - - diff --git a/Sprint 1/deliverable3/src/main/resources/templates/error.html b/Sprint 1/deliverable3/src/main/resources/templates/error.html deleted file mode 100644 index 130701ba9..000000000 --- a/Sprint 1/deliverable3/src/main/resources/templates/error.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Error - - -Error - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/index.html b/Sprint 1/deliverable3/src/main/resources/templates/index.html deleted file mode 100644 index fae1fc07c..000000000 --- a/Sprint 1/deliverable3/src/main/resources/templates/index.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Thymeleaf Example - - - -

Welcome to Thymeleaf!

- -

- -
-

Current Date and Time:

-
- - -
- -
- - -
- -
- - - diff --git a/Sprint 1/deliverable3/src/main/resources/templates/login.html b/Sprint 1/deliverable3/src/main/resources/templates/login.html deleted file mode 100644 index 795d5cb8c..000000000 --- a/Sprint 1/deliverable3/src/main/resources/templates/login.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - Login - - -

Login

-
-
- - -
-
- - -
-
- -
-
- - diff --git a/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html b/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html deleted file mode 100644 index 7a517bfcb..000000000 --- a/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - -Login Success - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/register.html b/Sprint 1/deliverable3/src/main/resources/templates/register.html deleted file mode 100644 index fbaa3c493..000000000 --- a/Sprint 1/deliverable3/src/main/resources/templates/register.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - User Registration - - - -

Register

-
- - - - -
- - - -
- - -
- - - -
- - -
- - - -
- - -
- - - -
- - -
- - \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/styles.css b/Sprint 1/deliverable3/src/main/resources/templates/styles.css deleted file mode 100644 index 3aaa3cb2d..000000000 --- a/Sprint 1/deliverable3/src/main/resources/templates/styles.css +++ /dev/null @@ -1,14 +0,0 @@ -.error { - color: #dc3545; - font-size: 0.875em; -} -.error-border { - border-color: #dc3545; -} -.error-list { - background-color: #f8d7da; - border: 1px solid #f5c6cb; - border-radius: 4px; - padding: 10px; - margin-bottom: 20px; -} \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java deleted file mode 100644 index b233ee828..000000000 --- a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.jydoc.deliverable3; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class Deliverable3ApplicationTests { - - @Test - void contextLoads() { - } - -} From bafa5257cc7bf2249d7b009bd2b9a73d4a99ca73 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Wed, 26 Mar 2025 10:10:22 -0400 Subject: [PATCH 025/100] Update UserModel.java additional validation --- .../jydoc/deliverable3/Model/UserModel.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java index e5bc23680..f8ddd88bc 100644 --- a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java +++ b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java @@ -6,6 +6,9 @@ import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.*; + import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -22,18 +25,32 @@ public class UserModel { @Column(name="userid") private int id; + @Column(name="userisadmin") private boolean admin; + @NotBlank + @Size(min = 2, max = 50, message = "First name must be 2-50 characters") + @Pattern(regexp = "^[\\p{L}'-]+$", message = "First name can only contain letters, hyphens, and apostrophes") @Column(name="userfirstname") private String firstName; + @NotBlank + @Size(min = 2, max = 50, message = "Last name must be 2-50 characters") + @Pattern(regexp = "^[\\p{L}'-]+$", message = "Last name can only contain letters, hyphens, and apostrophes") @Column(name="userlastname") private String lastName; - @Column(name="useremail") + @NotBlank + @NotBlank(message = "Email cannot be blank") + @Email(message = "Email must be valid") + @Column(name="useremail", unique=true) private String email; + @Size(min = 6, message = "Password must be at least 6 characters") + @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", + message = "Password must contain at least one letter and one number") + @NotBlank(message = "Password cannot be blank") @Column(name="userpassword") private String password; From d89e81c6d8106a8ccafa5025ff757d06bbc05165 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Wed, 26 Mar 2025 10:10:58 -0400 Subject: [PATCH 026/100] Update UserDTO.java --- .../src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java index 2ff515b46..dfbdda002 100644 --- a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java +++ b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java @@ -9,7 +9,7 @@ import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Size; import lombok.Data; - +//TODO: Authentication needs to be fixed here @Data public class UserDTO { //@Data applies Getters, Setters, NoArgsConstructor, and AllArgsConstructor @@ -27,11 +27,12 @@ public class UserDTO { //@Data applies Getters, Setters, NoArgsConstructor, and private String password; @NotBlank(message = "First name cannot be empty") + @Pattern(regexp = "^[\\p{L}'-]+$", message = "First name can only contain letters, hyphens, and apostrophes") @Size(min = 2, max = 30, message = "First name must be between 2 and 30 characters") private String firstName; @NotBlank(message = "Last name cannot be empty") + @Pattern(regexp = "^[\\p{L}'-]+$", message = "Last name can only contain letters, hyphens, and apostrophes") @Size(min = 2, max = 30, message = "Last name must be between 2 and 30 characters") private String lastName; } - From 7bc3745c6e6ba9d8a7978ffa9efad4c0ebddd5c8 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Wed, 26 Mar 2025 10:12:08 -0400 Subject: [PATCH 027/100] Update indexController.java --- .../Controller/indexController.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java index 0b8789684..b0d2b5ab5 100644 --- a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java +++ b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java @@ -7,14 +7,14 @@ import com.jydoc.deliverable3.Repository.UserRepository; import com.jydoc.deliverable3.Service.UserService; import jakarta.validation.Valid; -import org.antlr.v4.runtime.misc.LogManager; + import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; + import java.time.LocalDate; @@ -50,6 +50,8 @@ public String login(Model model) { @PostMapping("/login") public String handleLogin(@Valid @ModelAttribute("userDTO") UserDTO userDTO, Model model) { + + //TODO: Needs to be fixed UserService UserService = new UserService(); boolean isAuthenticated = UserService.authenticate(userDTO.getEmail(), userDTO.getPassword()); @@ -71,17 +73,22 @@ public String showRegistrationForm(Model model) { @PostMapping("/register") public String registerUser(@ModelAttribute("user") UserDTO userDTO, BindingResult result, Model model) { //TODO: Implement registration system + if (result.hasErrors()) { return "register"; // TODO: Implement register error to bring popup then refresh } + else { + UserModel user = new UserModel(); + user.setEmail(userDTO.getEmail()); + user.setPassword(userDTO.getPassword()); + user.setFirstName(userDTO.getFirstName()); //TODO: Transfer to Service package + user.setLastName(userDTO.getLastName()); + userRepository.save(user); + return "redirect:/"; + } + + - UserModel user = new UserModel(); - user.setEmail(userDTO.getEmail()); - user.setPassword(userDTO.getPassword()); - user.setFirstName(userDTO.getFirstName()); //TODO: Transfer to Service package - user.setLastName(userDTO.getLastName()); - userRepository.save(user); - return "redirect:/index"; } } From 8cce7ea9921d3d66c9d49d03576c0aad1c7800b4 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Wed, 26 Mar 2025 10:13:22 -0400 Subject: [PATCH 028/100] Update register.html --- .../main/resources/templates/register.html | 58 +++++++++++++++++-- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/register.html b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/register.html index abf6b9f58..89904066b 100644 --- a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/register.html +++ b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/register.html @@ -1,7 +1,55 @@ + + + + User Registration + + + +

Register

- - - - + + + + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ -
\ No newline at end of file + + + From 5bc422e1f481f265d85e119a3c8db27ded580ad1 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Wed, 26 Mar 2025 10:13:54 -0400 Subject: [PATCH 029/100] Update styles.css --- .../src/main/resources/templates/styles.css | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/styles.css b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/styles.css index e69de29bb..046e065ca 100644 --- a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/styles.css +++ b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/styles.css @@ -0,0 +1,14 @@ +.error { + color: #dc3545; + font-size: 0.875em; +} +.error-border { + border-color: #dc3545; +} +.error-list { + background-color: #f8d7da; + border: 1px solid #f5c6cb; + border-radius: 4px; + padding: 10px; + margin-bottom: 20px; +} From 1a22c2f8dfb50b90b7f47cca794ec3e6df1cc1fd Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Wed, 26 Mar 2025 11:33:00 -0400 Subject: [PATCH 030/100] Update indexController.java --- .../java/com/jydoc/deliverable3/Controller/indexController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java index b0d2b5ab5..0aed0b456 100644 --- a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java +++ b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java @@ -56,7 +56,7 @@ public String handleLogin(@Valid @ModelAttribute("userDTO") UserDTO userDTO, Mod boolean isAuthenticated = UserService.authenticate(userDTO.getEmail(), userDTO.getPassword()); if (isAuthenticated) { - model.addAttribute("username", userDTO.getEmail()); + model.addAttribute("email", userDTO.getEmail()); return "loginSuccess"; } else { model.addAttribute("error", "Invalid email or password"); From e0721a01691e44b4635bf4fa94bcd74b80cf227a Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Wed, 26 Mar 2025 11:44:37 -0400 Subject: [PATCH 031/100] Update application.properties --- .../deliverable3/src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/application.properties b/Sprint 1/deliverable3/deliverable3/src/main/resources/application.properties index 0cc001234..5877bfc77 100644 --- a/Sprint 1/deliverable3/deliverable3/src/main/resources/application.properties +++ b/Sprint 1/deliverable3/deliverable3/src/main/resources/application.properties @@ -1,6 +1,6 @@ #Server Configuration - +#have to include update as well spring.application.name=deliverable3 spring.jpa.hibernate.ddl-auto=create-drop spring.datasource.url=jdbc:mysql://localhost:3306/userdatabase From 4c03c249b0171ee735272e0c947b6a9445b1e0cb Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Wed, 26 Mar 2025 11:50:51 -0400 Subject: [PATCH 032/100] Update login.html --- .../src/main/resources/templates/login.html | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/login.html b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/login.html index 795d5cb8c..fa30490ea 100644 --- a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/login.html +++ b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/login.html @@ -3,21 +3,36 @@ Login +

Login

-
+ + +

+ +
- - + + +
+
- + +
+
+ From c832e5e4f6bdde77d1c1fcc2a5b098c6602fbe15 Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Wed, 26 Mar 2025 11:59:14 -0400 Subject: [PATCH 033/100] Update indexController.java --- .../Controller/indexController.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java index 0aed0b456..1afd2bddd 100644 --- a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java +++ b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java @@ -51,17 +51,12 @@ public String login(Model model) { @PostMapping("/login") public String handleLogin(@Valid @ModelAttribute("userDTO") UserDTO userDTO, Model model) { - //TODO: Needs to be fixed - UserService UserService = new UserService(); - boolean isAuthenticated = UserService.authenticate(userDTO.getEmail(), userDTO.getPassword()); - - if (isAuthenticated) { - model.addAttribute("email", userDTO.getEmail()); - return "loginSuccess"; - } else { - model.addAttribute("error", "Invalid email or password"); - return "login"; // Return back to login page with error message - } + if (!isAuthenticated) { + model.addAttribute("error", "Invalid email or password"); + return "login"; // Return to the login page and show an error message + } + + return "redirect:/dashboard"; } @GetMapping("/register") From 6721e9573b740fcd3778a16d2b9d3041566d8757 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Wed, 26 Mar 2025 13:04:37 -0400 Subject: [PATCH 034/100] Cleanup --- Sprint 1/deliverable3/deliverable3/HELP.md | 29 -- .../deliverable3/deliverable3.iml | 13 - Sprint 1/deliverable3/deliverable3/mvnw | 259 ------------------ Sprint 1/deliverable3/deliverable3/mvnw.cmd | 149 ---------- Sprint 1/deliverable3/deliverable3/pom.xml | 108 -------- .../Controller/indexController.java | 89 ------ .../com/jydoc/deliverable3/DTO/UserDTO.java | 38 --- .../deliverable3/Deliverable3Application.java | 13 - .../deliverable3/GlobalExceptionHandler.java | 48 ---- .../jydoc/deliverable3/Model/UserModel.java | 57 ---- .../Repository/UserRepository.java | 24 -- .../deliverable3/Service/UserService.java | 47 ---- .../src/main/resources/application.properties | 9 - .../src/main/resources/templates/error.html | 10 - .../src/main/resources/templates/index.html | 28 -- .../src/main/resources/templates/login.html | 38 --- .../resources/templates/loginSuccess.html | 10 - .../main/resources/templates/register.html | 55 ---- .../src/main/resources/templates/styles.css | 14 - .../Deliverable3ApplicationTests.java | 13 - 20 files changed, 1051 deletions(-) delete mode 100644 Sprint 1/deliverable3/deliverable3/HELP.md delete mode 100644 Sprint 1/deliverable3/deliverable3/deliverable3.iml delete mode 100644 Sprint 1/deliverable3/deliverable3/mvnw delete mode 100644 Sprint 1/deliverable3/deliverable3/mvnw.cmd delete mode 100644 Sprint 1/deliverable3/deliverable3/pom.xml delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/application.properties delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/templates/error.html delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/templates/index.html delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/templates/login.html delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/templates/loginSuccess.html delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/templates/register.html delete mode 100644 Sprint 1/deliverable3/deliverable3/src/main/resources/templates/styles.css delete mode 100644 Sprint 1/deliverable3/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java diff --git a/Sprint 1/deliverable3/deliverable3/HELP.md b/Sprint 1/deliverable3/deliverable3/HELP.md deleted file mode 100644 index 6bed04940..000000000 --- a/Sprint 1/deliverable3/deliverable3/HELP.md +++ /dev/null @@ -1,29 +0,0 @@ -# Getting Started - -### Reference Documentation -For further reference, please consider the following sections: - -* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) -* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.4/maven-plugin) -* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.4/maven-plugin/build-image.html) -* [Spring Web](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html) -* [Thymeleaf](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html#web.servlet.spring-mvc.template-engines) -* [htmx](https://github.com/wimdeblauwe/htmx-spring-boot) - -### Guides -The following guides illustrate how to use some features concretely: - -* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) -* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) -* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) -* [Handling Form Submission](https://spring.io/guides/gs/handling-form-submission/) -* [htmx](https://www.youtube.com/watch?v=j-rfPoXe5aE) -* [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/) - -### Maven Parent overrides - -Due to Maven's design, elements are inherited from the parent POM to the project POM. -While most of the inheritance is fine, it also inherits unwanted elements like `` and `` from the parent. -To prevent this, the project POM contains empty overrides for these elements. -If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. - diff --git a/Sprint 1/deliverable3/deliverable3/deliverable3.iml b/Sprint 1/deliverable3/deliverable3/deliverable3.iml deleted file mode 100644 index 2cf3f920f..000000000 --- a/Sprint 1/deliverable3/deliverable3/deliverable3.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/mvnw b/Sprint 1/deliverable3/deliverable3/mvnw deleted file mode 100644 index b9a45d76e..000000000 --- a/Sprint 1/deliverable3/deliverable3/mvnw +++ /dev/null @@ -1,259 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Apache Maven Wrapper startup batch script, version 3.3.2 -# -# Optional ENV vars -# ----------------- -# JAVA_HOME - location of a JDK home dir, required when download maven via java source -# MVNW_REPOURL - repo url base for downloading maven distribution -# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output -# ---------------------------------------------------------------------------- - -set -euf -[ "${MVNW_VERBOSE-}" != debug ] || set -x - -# OS specific support. -native_path() { printf %s\\n "$1"; } -case "$(uname)" in -CYGWIN* | MINGW*) - [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" - native_path() { cygpath --path --windows "$1"; } - ;; -esac - -# set JAVACMD and JAVACCMD -set_java_home() { - # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched - if [ -n "${JAVA_HOME-}" ]; then - if [ -x "$JAVA_HOME/jre/sh/java" ]; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - JAVACCMD="$JAVA_HOME/jre/sh/javac" - else - JAVACMD="$JAVA_HOME/bin/java" - JAVACCMD="$JAVA_HOME/bin/javac" - - if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then - echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 - echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 - return 1 - fi - fi - else - JAVACMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v java - )" || : - JAVACCMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v javac - )" || : - - if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then - echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 - return 1 - fi - fi -} - -# hash string like Java String::hashCode -hash_string() { - str="${1:-}" h=0 - while [ -n "$str" ]; do - char="${str%"${str#?}"}" - h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) - str="${str#?}" - done - printf %x\\n $h -} - -verbose() { :; } -[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } - -die() { - printf %s\\n "$1" >&2 - exit 1 -} - -trim() { - # MWRAPPER-139: - # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. - # Needed for removing poorly interpreted newline sequences when running in more - # exotic environments such as mingw bash on Windows. - printf "%s" "${1}" | tr -d '[:space:]' -} - -# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties -while IFS="=" read -r key value; do - case "${key-}" in - distributionUrl) distributionUrl=$(trim "${value-}") ;; - distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; - esac -done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" -[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" - -case "${distributionUrl##*/}" in -maven-mvnd-*bin.*) - MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ - case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in - *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; - :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; - :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; - :Linux*x86_64*) distributionPlatform=linux-amd64 ;; - *) - echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 - distributionPlatform=linux-amd64 - ;; - esac - distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" - ;; -maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; -*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; -esac - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" -distributionUrlName="${distributionUrl##*/}" -distributionUrlNameMain="${distributionUrlName%.*}" -distributionUrlNameMain="${distributionUrlNameMain%-bin}" -MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" -MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" - -exec_maven() { - unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : - exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" -} - -if [ -d "$MAVEN_HOME" ]; then - verbose "found existing MAVEN_HOME at $MAVEN_HOME" - exec_maven "$@" -fi - -case "${distributionUrl-}" in -*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; -*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; -esac - -# prepare tmp dir -if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then - clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } - trap clean HUP INT TERM EXIT -else - die "cannot create temp dir" -fi - -mkdir -p -- "${MAVEN_HOME%/*}" - -# Download and Install Apache Maven -verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -verbose "Downloading from: $distributionUrl" -verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -# select .zip or .tar.gz -if ! command -v unzip >/dev/null; then - distributionUrl="${distributionUrl%.zip}.tar.gz" - distributionUrlName="${distributionUrl##*/}" -fi - -# verbose opt -__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' -[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v - -# normalize http auth -case "${MVNW_PASSWORD:+has-password}" in -'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; -has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; -esac - -if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then - verbose "Found wget ... using wget" - wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" -elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then - verbose "Found curl ... using curl" - curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" -elif set_java_home; then - verbose "Falling back to use Java to download" - javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" - targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" - cat >"$javaSource" <<-END - public class Downloader extends java.net.Authenticator - { - protected java.net.PasswordAuthentication getPasswordAuthentication() - { - return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); - } - public static void main( String[] args ) throws Exception - { - setDefault( new Downloader() ); - java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); - } - } - END - # For Cygwin/MinGW, switch paths to Windows format before running javac and java - verbose " - Compiling Downloader.java ..." - "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" - verbose " - Running Downloader.java ..." - "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" -fi - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -if [ -n "${distributionSha256Sum-}" ]; then - distributionSha256Result=false - if [ "$MVN_CMD" = mvnd.sh ]; then - echo "Checksum validation is not supported for maven-mvnd." >&2 - echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - elif command -v sha256sum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - elif command -v shasum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - else - echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 - echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - fi - if [ $distributionSha256Result = false ]; then - echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 - echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 - exit 1 - fi -fi - -# unzip and move -if command -v unzip >/dev/null; then - unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" -else - tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" -fi -printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" -mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" - -clean || : -exec_maven "$@" diff --git a/Sprint 1/deliverable3/deliverable3/mvnw.cmd b/Sprint 1/deliverable3/deliverable3/mvnw.cmd deleted file mode 100644 index b150b91ed..000000000 --- a/Sprint 1/deliverable3/deliverable3/mvnw.cmd +++ /dev/null @@ -1,149 +0,0 @@ -<# : batch portion -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.3.2 -@REM -@REM Optional ENV vars -@REM MVNW_REPOURL - repo url base for downloading maven distribution -@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output -@REM ---------------------------------------------------------------------------- - -@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) -@SET __MVNW_CMD__= -@SET __MVNW_ERROR__= -@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% -@SET PSModulePath= -@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( - IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) -) -@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% -@SET __MVNW_PSMODULEP_SAVE= -@SET __MVNW_ARG0_NAME__= -@SET MVNW_USERNAME= -@SET MVNW_PASSWORD= -@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) -@echo Cannot start maven from wrapper >&2 && exit /b 1 -@GOTO :EOF -: end batch / begin powershell #> - -$ErrorActionPreference = "Stop" -if ($env:MVNW_VERBOSE -eq "true") { - $VerbosePreference = "Continue" -} - -# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties -$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl -if (!$distributionUrl) { - Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" -} - -switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { - "maven-mvnd-*" { - $USE_MVND = $true - $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" - $MVN_CMD = "mvnd.cmd" - break - } - default { - $USE_MVND = $false - $MVN_CMD = $script -replace '^mvnw','mvn' - break - } -} - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -if ($env:MVNW_REPOURL) { - $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } - $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" -} -$distributionUrlName = $distributionUrl -replace '^.*/','' -$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' -$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" -if ($env:MAVEN_USER_HOME) { - $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" -} -$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' -$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" - -if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { - Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" - Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" - exit $? -} - -if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { - Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" -} - -# prepare tmp dir -$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile -$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" -$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null -trap { - if ($TMP_DOWNLOAD_DIR.Exists) { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } - } -} - -New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null - -# Download and Install Apache Maven -Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -Write-Verbose "Downloading from: $distributionUrl" -Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -$webclient = New-Object System.Net.WebClient -if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { - $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) -} -[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum -if ($distributionSha256Sum) { - if ($USE_MVND) { - Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." - } - Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash - if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { - Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." - } -} - -# unzip and move -Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null -Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null -try { - Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null -} catch { - if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { - Write-Error "fail to move MAVEN_HOME" - } -} finally { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } -} - -Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/Sprint 1/deliverable3/deliverable3/pom.xml b/Sprint 1/deliverable3/deliverable3/pom.xml deleted file mode 100644 index d8a68814f..000000000 --- a/Sprint 1/deliverable3/deliverable3/pom.xml +++ /dev/null @@ -1,108 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.4.4 - - - com.jydoc - deliverable3 - 0.0.1-SNAPSHOT - deliverable3 - Demo project for Spring Boot - - - - - - - - - - - - - - - 21 - - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-web - - - io.github.wimdeblauwe - htmx-spring-boot-thymeleaf - 4.0.1 - - - - com.mysql - mysql-connector-j - runtime - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.modelmapper - modelmapper - 3.2.0 - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-validation - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.projectlombok - lombok - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - - - diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java deleted file mode 100644 index 1afd2bddd..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java +++ /dev/null @@ -1,89 +0,0 @@ -//This controller "listens" for user responses. -//TODO: We need to figure out how to set the user input into a DTO, then convert to Model and add into database - -package com.jydoc.deliverable3.Controller; -import com.jydoc.deliverable3.DTO.UserDTO; -import com.jydoc.deliverable3.Model.UserModel; -import com.jydoc.deliverable3.Repository.UserRepository; -import com.jydoc.deliverable3.Service.UserService; -import jakarta.validation.Valid; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; - - -import java.time.LocalDate; - - - - -@Controller -public class indexController { - - private final UserRepository userRepository; - private final UserService userService; - - public indexController(UserRepository userRepository) { - this.userRepository = userRepository; - this.userService = new UserService(); - } - - // This method maps to the root URL ("/") - @GetMapping("/") - public String index(Model model) { - - // Add the current date to the model - model.addAttribute("currentDate", LocalDate.now()); - - // Return the name of the Thymeleaf template ("index") - return "index"; - } - - @GetMapping("/login") - public String login(Model model) { - return "login"; - } - - @PostMapping("/login") - public String handleLogin(@Valid @ModelAttribute("userDTO") UserDTO userDTO, Model model) { - - if (!isAuthenticated) { - model.addAttribute("error", "Invalid email or password"); - return "login"; // Return to the login page and show an error message - } - - return "redirect:/dashboard"; - } - - @GetMapping("/register") - public String showRegistrationForm(Model model) { - model.addAttribute("user", new UserDTO()); - return "register"; - } - - @PostMapping("/register") - public String registerUser(@ModelAttribute("user") UserDTO userDTO, BindingResult result, Model model) { - //TODO: Implement registration system - - if (result.hasErrors()) { - return "register"; // TODO: Implement register error to bring popup then refresh - } - else { - UserModel user = new UserModel(); - user.setEmail(userDTO.getEmail()); - user.setPassword(userDTO.getPassword()); - user.setFirstName(userDTO.getFirstName()); //TODO: Transfer to Service package - user.setLastName(userDTO.getLastName()); - userRepository.save(user); - return "redirect:/"; - } - - - - - } -} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java deleted file mode 100644 index dfbdda002..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java +++ /dev/null @@ -1,38 +0,0 @@ -// This DTO accepts user input to fill variables, then is converted by -// UserService into a UserModel. -// Also used for business logic. -//test -package com.jydoc.deliverable3.DTO; - -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Pattern; -import jakarta.validation.constraints.Size; -import lombok.Data; -//TODO: Authentication needs to be fixed here -@Data -public class UserDTO { //@Data applies Getters, Setters, NoArgsConstructor, and AllArgsConstructor - - private int id; - private boolean admin; - - @NotBlank(message = "Email cannot be empty") - @Email(message = "Invalid email format") - private String email; - - @NotBlank(message = "Password cannot be empty") - @Size(min = 6, message = "Password must be at least 6 characters") - @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", - message = "Password must contain at least one letter and one number") - private String password; - - @NotBlank(message = "First name cannot be empty") - @Pattern(regexp = "^[\\p{L}'-]+$", message = "First name can only contain letters, hyphens, and apostrophes") - @Size(min = 2, max = 30, message = "First name must be between 2 and 30 characters") - private String firstName; - - @NotBlank(message = "Last name cannot be empty") - @Pattern(regexp = "^[\\p{L}'-]+$", message = "Last name can only contain letters, hyphens, and apostrophes") - @Size(min = 2, max = 30, message = "Last name must be between 2 and 30 characters") - private String lastName; -} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java deleted file mode 100644 index 64ce3b1c7..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.jydoc.deliverable3; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Deliverable3Application { - - public static void main(String[] args) { - SpringApplication.run(Deliverable3Application.class, args); - } - -} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java deleted file mode 100644 index cc52e6d56..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.jydoc.deliverable3; - -import jakarta.validation.ConstraintViolationException; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestControllerAdvice; -import org.springframework.validation.FieldError; - -import java.util.HashMap; -import java.util.Map; - -@RestControllerAdvice -public class GlobalExceptionHandler { - - // Handle validation errors (MethodArgumentNotValidException) - @ExceptionHandler(MethodArgumentNotValidException.class) - public ResponseEntity> handleValidationErrors(MethodArgumentNotValidException ex) { - Map errors = new HashMap<>(); - - ex.getBindingResult().getAllErrors().forEach((error) -> { - String fieldName = ((FieldError) error).getField(); - String errorMessage = error.getDefaultMessage(); - errors.put(fieldName, errorMessage); - }); - - return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); // Return errors with 400 status - } - - // Handle ConstraintViolationException (if needed for specific validation annotations) - @ExceptionHandler(ConstraintViolationException.class) - public ResponseEntity> handleConstraintViolation(ConstraintViolationException ex) { - Map errors = new HashMap<>(); - - ex.getConstraintViolations().forEach(violation -> { - errors.put(violation.getPropertyPath().toString(), violation.getMessage()); - }); - - return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); - } - - // Global exception handler for all other exceptions - @ExceptionHandler(Exception.class) - public ResponseEntity handleGlobalException(Exception ex) { - return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); // 500 status for internal errors - } -} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java deleted file mode 100644 index f8ddd88bc..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java +++ /dev/null @@ -1,57 +0,0 @@ -//The User Model is used to interact and create the database - - -package com.jydoc.deliverable3.Model; -import jakarta.persistence.*; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.*; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Entity -@Getter -@Setter -@NoArgsConstructor - -public class UserModel { -//Each row in the database is a unique user containing all of these columns - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name="userid") - private int id; - - - @Column(name="userisadmin") - private boolean admin; - - @NotBlank - @Size(min = 2, max = 50, message = "First name must be 2-50 characters") - @Pattern(regexp = "^[\\p{L}'-]+$", message = "First name can only contain letters, hyphens, and apostrophes") - @Column(name="userfirstname") - private String firstName; - - @NotBlank - @Size(min = 2, max = 50, message = "Last name must be 2-50 characters") - @Pattern(regexp = "^[\\p{L}'-]+$", message = "Last name can only contain letters, hyphens, and apostrophes") - @Column(name="userlastname") - private String lastName; - - @NotBlank - @NotBlank(message = "Email cannot be blank") - @Email(message = "Email must be valid") - @Column(name="useremail", unique=true) - private String email; - - @Size(min = 6, message = "Password must be at least 6 characters") - @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", - message = "Password must contain at least one letter and one number") - @NotBlank(message = "Password cannot be blank") - @Column(name="userpassword") - private String password; - -} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java deleted file mode 100644 index ec8913523..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -//This is where the backend interacts with the database to retrieve or add data - -package com.jydoc.deliverable3.Repository; -import com.jydoc.deliverable3.Model.UserModel; -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface UserRepository extends CrudRepository { - - - //Custom Queries - List findById(int id); //TODO: Switch this to Long type - //static List findByEmail(String email); - List findByFirstName(String firstName); - List findByLastName(String lastName); - List findByFirstNameAndLastName(String firstName, String lastName); - - - - -} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java b/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java deleted file mode 100644 index c70d4bfbf..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java +++ /dev/null @@ -1,47 +0,0 @@ -//This is where user data is processed. - -package com.jydoc.deliverable3.Service; -import com.jydoc.deliverable3.DTO.UserDTO; -import com.jydoc.deliverable3.Model.UserModel; -import com.jydoc.deliverable3.Repository.UserRepository; -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Pattern; -import jakarta.validation.constraints.Size; - -public class UserService { - - - public UserModel convertToEntity(UserDTO UserDto) { - - UserModel user = new UserModel(); - user.setId(UserDto.getId()); - user.setAdmin(UserDto.isAdmin()); - user.setFirstName(UserDto.getFirstName()); - user.setLastName(UserDto.getLastName()); - user.setEmail(UserDto.getEmail()); - user.setPassword(UserDto.getPassword()); - return user; - } - - public UserDTO convertToDTO(UserModel UserModel) { - - UserDTO user = new UserDTO(); - user.setId(UserModel.getId()); - user.setAdmin(UserModel.isAdmin()); - user.setFirstName(UserModel.getFirstName()); - user.setLastName(UserModel.getLastName()); - user.setEmail(UserModel.getEmail()); - user.setPassword(UserModel.getPassword()); - return user; - } - - - - - - public boolean authenticate(@NotBlank(message = "Email cannot be empty") @Email(message = "Invalid email format") String email, @NotBlank(message = "Password cannot be empty") @Size(min = 6, message = "Password must be at least 6 characters") @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", - message = "Password must contain at least one letter and one number") String password) { - return true; - } -} diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/application.properties b/Sprint 1/deliverable3/deliverable3/src/main/resources/application.properties deleted file mode 100644 index 5877bfc77..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/resources/application.properties +++ /dev/null @@ -1,9 +0,0 @@ - -#Server Configuration -#have to include update as well -spring.application.name=deliverable3 -spring.jpa.hibernate.ddl-auto=create-drop -spring.datasource.url=jdbc:mysql://localhost:3306/userdatabase -spring.datasource.username=root -spring.datasource.password=JYDOC -spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/error.html b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/error.html deleted file mode 100644 index 130701ba9..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/error.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Error - - -Error - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/index.html b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/index.html deleted file mode 100644 index fae1fc07c..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/index.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Thymeleaf Example - - - -

Welcome to Thymeleaf!

- -

- -
-

Current Date and Time:

-
- - -
- -
- - -
- -
- - - diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/login.html b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/login.html deleted file mode 100644 index fa30490ea..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/login.html +++ /dev/null @@ -1,38 +0,0 @@ - - - - - Login - - - -

Login

- - -

- -
-
- - - -
- -
- - - -
- -
- -
-
- - - diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/loginSuccess.html b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/loginSuccess.html deleted file mode 100644 index 7a517bfcb..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/loginSuccess.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - -Login Success - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/register.html b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/register.html deleted file mode 100644 index 89904066b..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/register.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - User Registration - - - -

Register

-
- - - - -
- - - -
- - -
- - - -
- - -
- - - -
- - -
- - - -
- - -
- - diff --git a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/styles.css b/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/styles.css deleted file mode 100644 index 046e065ca..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/main/resources/templates/styles.css +++ /dev/null @@ -1,14 +0,0 @@ -.error { - color: #dc3545; - font-size: 0.875em; -} -.error-border { - border-color: #dc3545; -} -.error-list { - background-color: #f8d7da; - border: 1px solid #f5c6cb; - border-radius: 4px; - padding: 10px; - margin-bottom: 20px; -} diff --git a/Sprint 1/deliverable3/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java b/Sprint 1/deliverable3/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java deleted file mode 100644 index 496abea0b..000000000 --- a/Sprint 1/deliverable3/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.jydoc.deliverable3; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class Deliverable3ApplicationTests { - - @Test - void contextLoads() { - } - -} From 05940817c4328207cc2b8e9a68f94a20c422a5c8 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Wed, 26 Mar 2025 13:05:30 -0400 Subject: [PATCH 035/100] Working Version --- Sprint 1/deliverable3/HELP.md | 29 ++ Sprint 1/deliverable3/deliverable3.iml | 13 + Sprint 1/deliverable3/mvnw | 259 ++++++++++++++++++ Sprint 1/deliverable3/mvnw.cmd | 149 ++++++++++ Sprint 1/deliverable3/pom.xml | 108 ++++++++ .../Controller/indexController.java | 101 +++++++ .../com/jydoc/deliverable3/DTO/UserDTO.java | 38 +++ .../deliverable3/Deliverable3Application.java | 13 + .../deliverable3/GlobalExceptionHandler.java | 48 ++++ .../jydoc/deliverable3/Model/UserModel.java | 57 ++++ .../Repository/UserRepository.java | 26 ++ .../deliverable3/Service/UserService.java | 53 ++++ .../src/main/resources/application.properties | 9 + .../src/main/resources/templates/error.html | 10 + .../src/main/resources/templates/index.html | 28 ++ .../src/main/resources/templates/login.html | 33 +++ .../resources/templates/loginSuccess.html | 10 + .../main/resources/templates/register.html | 55 ++++ .../src/main/resources/templates/styles.css | 14 + .../Deliverable3ApplicationTests.java | 13 + .../target/classes/application.properties | 9 + .../Controller/indexController.class | Bin 0 -> 3432 bytes .../com/jydoc/deliverable3/DTO/UserDTO.class | Bin 0 -> 5016 bytes .../Deliverable3Application.class | Bin 0 -> 769 bytes .../deliverable3/GlobalExceptionHandler.class | Bin 0 -> 4467 bytes .../jydoc/deliverable3/Model/UserModel.class | Bin 0 -> 3461 bytes .../Repository/UserRepository.class | Bin 0 -> 1083 bytes .../deliverable3/Service/UserService.class | Bin 0 -> 2368 bytes .../target/classes/templates/error.html | 10 + .../target/classes/templates/index.html | 28 ++ .../target/classes/templates/login.html | 33 +++ .../classes/templates/loginSuccess.html | 10 + .../target/classes/templates/register.html | 55 ++++ .../target/classes/templates/styles.css | 14 + 34 files changed, 1225 insertions(+) create mode 100644 Sprint 1/deliverable3/HELP.md create mode 100644 Sprint 1/deliverable3/deliverable3.iml create mode 100644 Sprint 1/deliverable3/mvnw create mode 100644 Sprint 1/deliverable3/mvnw.cmd create mode 100644 Sprint 1/deliverable3/pom.xml create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java create mode 100644 Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java create mode 100644 Sprint 1/deliverable3/src/main/resources/application.properties create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/error.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/index.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/login.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/register.html create mode 100644 Sprint 1/deliverable3/src/main/resources/templates/styles.css create mode 100644 Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java create mode 100644 Sprint 1/deliverable3/target/classes/application.properties create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/GlobalExceptionHandler.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class create mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class create mode 100644 Sprint 1/deliverable3/target/classes/templates/error.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/index.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/login.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/loginSuccess.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/register.html create mode 100644 Sprint 1/deliverable3/target/classes/templates/styles.css diff --git a/Sprint 1/deliverable3/HELP.md b/Sprint 1/deliverable3/HELP.md new file mode 100644 index 000000000..6bed04940 --- /dev/null +++ b/Sprint 1/deliverable3/HELP.md @@ -0,0 +1,29 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.4/maven-plugin) +* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.4/maven-plugin/build-image.html) +* [Spring Web](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html) +* [Thymeleaf](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html#web.servlet.spring-mvc.template-engines) +* [htmx](https://github.com/wimdeblauwe/htmx-spring-boot) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) +* [Handling Form Submission](https://spring.io/guides/gs/handling-form-submission/) +* [htmx](https://www.youtube.com/watch?v=j-rfPoXe5aE) +* [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/) + +### Maven Parent overrides + +Due to Maven's design, elements are inherited from the parent POM to the project POM. +While most of the inheritance is fine, it also inherits unwanted elements like `` and `` from the parent. +To prevent this, the project POM contains empty overrides for these elements. +If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. + diff --git a/Sprint 1/deliverable3/deliverable3.iml b/Sprint 1/deliverable3/deliverable3.iml new file mode 100644 index 000000000..2cf3f920f --- /dev/null +++ b/Sprint 1/deliverable3/deliverable3.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/mvnw b/Sprint 1/deliverable3/mvnw new file mode 100644 index 000000000..b9a45d76e --- /dev/null +++ b/Sprint 1/deliverable3/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/Sprint 1/deliverable3/mvnw.cmd b/Sprint 1/deliverable3/mvnw.cmd new file mode 100644 index 000000000..b150b91ed --- /dev/null +++ b/Sprint 1/deliverable3/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/Sprint 1/deliverable3/pom.xml b/Sprint 1/deliverable3/pom.xml new file mode 100644 index 000000000..d8a68814f --- /dev/null +++ b/Sprint 1/deliverable3/pom.xml @@ -0,0 +1,108 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.4 + + + com.jydoc + deliverable3 + 0.0.1-SNAPSHOT + deliverable3 + Demo project for Spring Boot + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-web + + + io.github.wimdeblauwe + htmx-spring-boot-thymeleaf + 4.0.1 + + + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.modelmapper + modelmapper + 3.2.0 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-validation + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java new file mode 100644 index 000000000..e3bfd2dae --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Controller/indexController.java @@ -0,0 +1,101 @@ +//This controller "listens" for user responses. +//TODO: We need to figure out how to set the user input into a DTO, then convert to Model and add into database + +package com.jydoc.deliverable3.Controller; +import com.jydoc.deliverable3.DTO.UserDTO; +import com.jydoc.deliverable3.Model.UserModel; +import com.jydoc.deliverable3.Repository.UserRepository; +import com.jydoc.deliverable3.Service.UserService; +import jakarta.validation.Valid; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; + + +import java.time.LocalDate; + + + + +@Controller +public class indexController { + + private final UserRepository userRepository; + private final UserService userService; + + public indexController(UserRepository userRepository) { + this.userRepository = userRepository; + this.userService = new UserService(); + } + + // This method maps to the root URL ("/") + @GetMapping("/") + public String index(Model model) { + + // Add the current date to the model + model.addAttribute("currentDate", LocalDate.now()); + + // Return the name of the Thymeleaf template ("index") + return "index"; + } + + @GetMapping("/login") + public String login(Model model) { + if (!model.containsAttribute("userDTO")) { + model.addAttribute("userDTO", new UserDTO()); + } + return "login"; // Make sure the login page is returned + } + + @PostMapping("/login") + public String handleLogin(@Valid @ModelAttribute("userDTO") UserDTO userDTO, BindingResult result, Model model) { + + if (result.hasErrors()) { + return "login"; + } + + boolean isAuthenticated = userService.authenticate(userDTO.getEmail(), userDTO.getPassword()); + + if(!isAuthenticated) { + model.addAttribute("error", "Invalid email or password"); + return "login"; // Return to the login page and show an error message + } + return "redirect:/"; + + + + } + + @GetMapping("/register") + public String showRegistrationForm(Model model) { + model.addAttribute("user", new UserDTO()); + return "register"; + } + + @PostMapping("/register") + public String registerUser(@Valid @ModelAttribute("user") UserDTO userDTO, BindingResult result, Model model) { + //TODO: Implement registration system + + if (result.hasErrors()) { + + return "register"; // TODO: Implement register error to bring popup then refresh + } + else { + UserModel user = new UserModel(); + user.setEmail(userDTO.getEmail()); + user.setPassword(userDTO.getPassword()); + user.setFirstName(userDTO.getFirstName()); //TODO: Transfer to Service package + user.setLastName(userDTO.getLastName()); + userRepository.save(user); + return "redirect:/"; + } + + + + + } +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java new file mode 100644 index 000000000..dfbdda002 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/DTO/UserDTO.java @@ -0,0 +1,38 @@ +// This DTO accepts user input to fill variables, then is converted by +// UserService into a UserModel. +// Also used for business logic. +//test +package com.jydoc.deliverable3.DTO; + +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; +import lombok.Data; +//TODO: Authentication needs to be fixed here +@Data +public class UserDTO { //@Data applies Getters, Setters, NoArgsConstructor, and AllArgsConstructor + + private int id; + private boolean admin; + + @NotBlank(message = "Email cannot be empty") + @Email(message = "Invalid email format") + private String email; + + @NotBlank(message = "Password cannot be empty") + @Size(min = 6, message = "Password must be at least 6 characters") + @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", + message = "Password must contain at least one letter and one number") + private String password; + + @NotBlank(message = "First name cannot be empty") + @Pattern(regexp = "^[\\p{L}'-]+$", message = "First name can only contain letters, hyphens, and apostrophes") + @Size(min = 2, max = 30, message = "First name must be between 2 and 30 characters") + private String firstName; + + @NotBlank(message = "Last name cannot be empty") + @Pattern(regexp = "^[\\p{L}'-]+$", message = "Last name can only contain letters, hyphens, and apostrophes") + @Size(min = 2, max = 30, message = "Last name must be between 2 and 30 characters") + private String lastName; +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java new file mode 100644 index 000000000..64ce3b1c7 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Deliverable3Application.java @@ -0,0 +1,13 @@ +package com.jydoc.deliverable3; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Deliverable3Application { + + public static void main(String[] args) { + SpringApplication.run(Deliverable3Application.class, args); + } + +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java new file mode 100644 index 000000000..cc52e6d56 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/GlobalExceptionHandler.java @@ -0,0 +1,48 @@ +package com.jydoc.deliverable3; + +import jakarta.validation.ConstraintViolationException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.validation.FieldError; + +import java.util.HashMap; +import java.util.Map; + +@RestControllerAdvice +public class GlobalExceptionHandler { + + // Handle validation errors (MethodArgumentNotValidException) + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity> handleValidationErrors(MethodArgumentNotValidException ex) { + Map errors = new HashMap<>(); + + ex.getBindingResult().getAllErrors().forEach((error) -> { + String fieldName = ((FieldError) error).getField(); + String errorMessage = error.getDefaultMessage(); + errors.put(fieldName, errorMessage); + }); + + return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); // Return errors with 400 status + } + + // Handle ConstraintViolationException (if needed for specific validation annotations) + @ExceptionHandler(ConstraintViolationException.class) + public ResponseEntity> handleConstraintViolation(ConstraintViolationException ex) { + Map errors = new HashMap<>(); + + ex.getConstraintViolations().forEach(violation -> { + errors.put(violation.getPropertyPath().toString(), violation.getMessage()); + }); + + return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); + } + + // Global exception handler for all other exceptions + @ExceptionHandler(Exception.class) + public ResponseEntity handleGlobalException(Exception ex) { + return new ResponseEntity<>(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); // 500 status for internal errors + } +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java new file mode 100644 index 000000000..f8ddd88bc --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Model/UserModel.java @@ -0,0 +1,57 @@ +//The User Model is used to interact and create the database + + +package com.jydoc.deliverable3.Model; +import jakarta.persistence.*; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.*; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Getter +@Setter +@NoArgsConstructor + +public class UserModel { +//Each row in the database is a unique user containing all of these columns + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name="userid") + private int id; + + + @Column(name="userisadmin") + private boolean admin; + + @NotBlank + @Size(min = 2, max = 50, message = "First name must be 2-50 characters") + @Pattern(regexp = "^[\\p{L}'-]+$", message = "First name can only contain letters, hyphens, and apostrophes") + @Column(name="userfirstname") + private String firstName; + + @NotBlank + @Size(min = 2, max = 50, message = "Last name must be 2-50 characters") + @Pattern(regexp = "^[\\p{L}'-]+$", message = "Last name can only contain letters, hyphens, and apostrophes") + @Column(name="userlastname") + private String lastName; + + @NotBlank + @NotBlank(message = "Email cannot be blank") + @Email(message = "Email must be valid") + @Column(name="useremail", unique=true) + private String email; + + @Size(min = 6, message = "Password must be at least 6 characters") + @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", + message = "Password must contain at least one letter and one number") + @NotBlank(message = "Password cannot be blank") + @Column(name="userpassword") + private String password; + +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java new file mode 100644 index 000000000..d483174a7 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Repository/UserRepository.java @@ -0,0 +1,26 @@ +//This is where the backend interacts with the database to retrieve or add data + +package com.jydoc.deliverable3.Repository; +import com.jydoc.deliverable3.Model.UserModel; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface UserRepository extends CrudRepository { + + + + //Custom Queries + List findById(int id); //TODO: Switch this to Long type + List findByEmail(String email); + List findByFirstName(String firstName); + List findByLastName(String lastName); + List findByFirstNameAndLastName(String firstName, String lastName); + + + + + +} diff --git a/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java new file mode 100644 index 000000000..5209d3c7b --- /dev/null +++ b/Sprint 1/deliverable3/src/main/java/com/jydoc/deliverable3/Service/UserService.java @@ -0,0 +1,53 @@ +//This is where user data is processed. + +package com.jydoc.deliverable3.Service; +import com.jydoc.deliverable3.DTO.UserDTO; +import com.jydoc.deliverable3.Model.UserModel; +import com.jydoc.deliverable3.Repository.UserRepository; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; + +public class UserService { + + UserRepository userRepository; + + + public UserModel convertToEntity(UserDTO UserDto) { + + UserModel user = new UserModel(); + user.setId(UserDto.getId()); + user.setAdmin(UserDto.isAdmin()); + user.setFirstName(UserDto.getFirstName()); + user.setLastName(UserDto.getLastName()); + user.setEmail(UserDto.getEmail()); + user.setPassword(UserDto.getPassword()); + return user; + } + + public UserDTO convertToDTO(UserModel UserModel) { + + UserDTO user = new UserDTO(); + user.setId(UserModel.getId()); + user.setAdmin(UserModel.isAdmin()); + user.setFirstName(UserModel.getFirstName()); + user.setLastName(UserModel.getLastName()); + user.setEmail(UserModel.getEmail()); + user.setPassword(UserModel.getPassword()); + return user; + } + + + + + + public boolean authenticate(@NotBlank(message = "Email cannot be empty") @Email(message = "Invalid email format") String email, @NotBlank(message = "Password cannot be empty") @Size(min = 6, message = "Password must be at least 6 characters") @Pattern(regexp = "^(?=.*[A-Za-z])(?=.*\\d).{6,}$", + message = "Password must contain at least one letter and one number") String password) { + return true; + + + } + + +} diff --git a/Sprint 1/deliverable3/src/main/resources/application.properties b/Sprint 1/deliverable3/src/main/resources/application.properties new file mode 100644 index 000000000..e1fff99c8 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/application.properties @@ -0,0 +1,9 @@ + +#Server Configuration + +spring.application.name=deliverable3 +spring.jpa.hibernate.ddl-auto=create-drop +spring.datasource.url=jdbc:mysql://localhost:3306/user_database +spring.datasource.username=root +spring.datasource.password= +spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/src/main/resources/templates/error.html b/Sprint 1/deliverable3/src/main/resources/templates/error.html new file mode 100644 index 000000000..130701ba9 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/error.html @@ -0,0 +1,10 @@ + + + + + Error + + +Error + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/index.html b/Sprint 1/deliverable3/src/main/resources/templates/index.html new file mode 100644 index 000000000..fae1fc07c --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/index.html @@ -0,0 +1,28 @@ + + + + + Thymeleaf Example + + + +

Welcome to Thymeleaf!

+ +

+ +
+

Current Date and Time:

+
+ + +
+ +
+ + +
+ +
+ + + diff --git a/Sprint 1/deliverable3/src/main/resources/templates/login.html b/Sprint 1/deliverable3/src/main/resources/templates/login.html new file mode 100644 index 000000000..fe9554099 --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/login.html @@ -0,0 +1,33 @@ + + + + + Login + + +

Login

+ + +
+

+
+ + +
+
+ + +
+ +
+ + +
+ +
+ +
+
+ + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html b/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html new file mode 100644 index 000000000..7a517bfcb --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/loginSuccess.html @@ -0,0 +1,10 @@ + + + + + Title + + +Login Success + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/src/main/resources/templates/register.html b/Sprint 1/deliverable3/src/main/resources/templates/register.html new file mode 100644 index 000000000..89904066b --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/register.html @@ -0,0 +1,55 @@ + + + + User Registration + + + +

Register

+
+ + + + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + diff --git a/Sprint 1/deliverable3/src/main/resources/templates/styles.css b/Sprint 1/deliverable3/src/main/resources/templates/styles.css new file mode 100644 index 000000000..046e065ca --- /dev/null +++ b/Sprint 1/deliverable3/src/main/resources/templates/styles.css @@ -0,0 +1,14 @@ +.error { + color: #dc3545; + font-size: 0.875em; +} +.error-border { + border-color: #dc3545; +} +.error-list { + background-color: #f8d7da; + border: 1px solid #f5c6cb; + border-radius: 4px; + padding: 10px; + margin-bottom: 20px; +} diff --git a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java new file mode 100644 index 000000000..496abea0b --- /dev/null +++ b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java @@ -0,0 +1,13 @@ +package com.jydoc.deliverable3; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Deliverable3ApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/Sprint 1/deliverable3/target/classes/application.properties b/Sprint 1/deliverable3/target/classes/application.properties new file mode 100644 index 000000000..e3cb0d6f4 --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/application.properties @@ -0,0 +1,9 @@ + +#Server Configuration + +spring.application.name=deliverable3 +spring.jpa.hibernate.ddl-auto=create-drop +spring.datasource.url=jdbc:mysql://localhost:3306/user_database +spring.datasource.username=root +spring.datasource.password=radmin +spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class new file mode 100644 index 0000000000000000000000000000000000000000..55a2bba25b90f09a5d6baa30f045e905ff32df20 GIT binary patch literal 3432 zcmb7GTUQfT7~O{i5|ZI!xLCX(q9O!gRMaZbDsokWQb1I^v_mq6fnGnWGjnFLPS9nioltal~b42(^g7N>sez} zx3z_=KA;X;rfXZ-tZu7@nbw~b-v#RPj&4uuE0$xpmc1@;Hd(<+QAoYJO(zjTy+FKz z+Kg_m8Y$h=DXb%?LqNv9PeBY#0#O-6;itf!v%Rxq1Zq@m>gR z3J&0)K$8cdYvgn_X{EHR6d`z~wI;B?yC+%ZcOr_zXb<6tf({%NIAqxw)mgC(GxOBe za{8KOFROV&owSIufTE?-L#}HZ3wddJq;XRVB3 zMsXTvLO82n0O!a{xsX@2tdZ7S!!p(DjF;I?>rOt)O08YgoKf4hY{x6sd1?KEg7Ls`r znCO`gV~F|bGO#d)1=?>DTEUDIj#9V?MI3h(%t?q8 zLNsRBj(eNsDHZN3cpw!NDwO<)LXh<5SemkFA(Ct|{`2=EK&(CSL zA>RuhgYKfinjEO)t2iEaj!TBvIH|jfR(eX4lYr#Y(AnbUMsYAY*p7|}NiK2LOnDo{7$ zYN=)ZD}Ym@dach|Thz>SR!_=7An>9hGbQsQQ8t`P6QaEI)?DR;EEY(ic?FJF;;b|Z zZjyFk2KE2Hh*&~~GgLBG(gbOqby?O-Ih>~~rv&K3+qs)vU)j#z0p_@@*{-IRfHWs3 zDp~5>uIyLbwhFko=g7SA<8KwT-|Q?}Yt!Bgv%P{Ev+Nwlwz@UfI6k(Pa>Ey>SOYtT z9F0e2th}Al#|+tp%{xvV{gPRM-m=S$%|>W`(d;f!f-t;ad7u|@{DH{YeZdQ@C)r%^Ep7@94J4d zCf4^V{u>&5H*lWUr43xZ5Nrv)#J;}Rwb*q(!q`YL$aaKi;u5(SBvw~=%(;qATtgpE z#iuds1$}PQjUV&?PT(0sp=+$;QxB8@FOdNCTk#n_CsZ<}5UP}amPd0(kPMWmhS<&t`bQmYK&%JR~WPNY`VG;)zdA3yB!Vcf^6w_$f{J lG)?$4O%!M<)SI$5VxI4Xm~lFn-S@qB|G{e~IU;@p{sX*eW7z-z literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class new file mode 100644 index 0000000000000000000000000000000000000000..eeee3de03145441a2e32048690d44aeee6eef28e GIT binary patch literal 5016 zcmbVQ*>@A?75|N-k;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sb>^61NE&7#D`-Spx$<%{&j))&g=rz|EIQy2G#}Qi?a*R zKs(Ujx!sK!fc-`_~0pM3EgV<R5; za<~ueUKXwJOIYrJAO9Hr8-VO%XtNVz&#}*6l6Yx?pWlm&i(xK?qs7=9S7Z6aDF&1;#IC~2WmDx)3BY!=@F%LsMM25M@k8qHt~-6R}J=A@BhzHMukZlz$dUd6Jt1qCveD%^G16QRZ29K16KQg1Mq`!Fh$@%duCbYV9*NnEJt~SL?f0xmVeBci`Wysk(N;-(eZrJ7bWW=b_%WbbT973AkuJ~aeROW z{%}+AKGsOZ_$Q4!c*w2C`FfefBT@;r$YFe!l*&@=#A8xPzi9tJ`b)eZe>Bn*-mA)& zOjx*x$!Z%CzK9j{rSYbetRi zf5`J!rqq+4VW}QJhxj?l&+$(&4Yc1!&98`kVWMxdJ)#REj_-37!w>L7errtGPx$!} Qe!*3m)Cc$#evQn30Y!-7@&Et; literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class new file mode 100644 index 0000000000000000000000000000000000000000..efcd494a354085320bc8fee605438a97b7adbd6f GIT binary patch literal 769 zcmb7CO;6iE5PcgG970+ke3h0SxP=^8BqT1WkkX)@3{*{(9(r0ki`iiBM(Z^nKZ{eV z9{2(MQB`MMBzy>mTJnr$X6Mb!oB93c*CT)d-nUT0LV$W34JR_=shp}Rj0&}2A>O~$A96BF}^Ox2CFB1+{EKdl&p*(_DDaLVWwT38OyZsQeR zGxUs2cs{dACzn=a^48dE9vS2KsB~5`sirM7L(~nQ`x>Sq&->pio{{rl{rzwra%{Ad zca9H@zEnw3wpuAcZXfP5)Q4sw8CF82<#~}s(th=0F?2!`i*zik^7fOn?ygkMa2Wm{ z7rss=6wS2Noj1am;=(3`ygnyP`#F>D%1k~B&zzH%9=1lNu(AB4e6PDN?BKxj$FTFI z&`xD?ta3%O474_`+!5iN%%!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SOOuDK43Disg`gyZQ%~z<(et z;V5_e5>Cjk57pyzg)Q>m5Wo(;O7D!I=<>6`2k62go`#@#HlEP@9L+cIS?9p-82=d= z$(={W`giYHZG1x@#?;@8R+`$3TYM+|;ku-T{OQDVc%H_aN!u52iI7^6z>EAQ9lb<} pI=t*hExG>+?_cFdChQ|hyoNXMcKGdGe1I?bEJ3+1@io3h*Wc{uB%uHR literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class new file mode 100644 index 0000000000000000000000000000000000000000..99879815698b2cc5ae3396d4630212942b0574a5 GIT binary patch literal 3461 zcmbVP>r)d~6hAis!ebHSp(0{~MF`JDtY8JTh+xwOr1EIx)!ro6u#oJg*$ovP|D%3r zXXGAZUppm*)FO-SsI4Zp>vqc5AR@-4Z za~>c8ecR`GS0es=bz?ie{aVnix;j>@Y%ym7yUBC|*iu9WIPx9t#`YsVUKT!+StISb zq^IB(3^Gi|);BEY8KQm)q`N`9TgE%KEsR`-Q6nMV%D23o6BNlQ+m;#R^3EFPHOh8H zb4BcuDmpj)U^bdMmIaw|5JW+-AZ44<0VjLdQcxN7HZMp!+CRv@Pkb1gKAap8^!SpV zlr*E3nLUrfHwT_Yvx>#-sp#=}{#cpVNHZOkc?+IfIDrYB94WU3y$}vn)&OUsq7H@= zD8c}@mM(byk4YMv#I^2OG!qo0Quam?C`*K@8CfnO1^uhs8c~>lI_CH%Imc+?AV60R zK)oJ7DSdA7pkvuQx9gCVqG|kGRGfXm3y+9Rzx~Q-mktuaQJb$w{?JkE>EoG+{pIOB zIsNW%+@%iE<1_E)r#>LF4=aI6IW41Ert%Z)W|c{^m`kbxnzbxi)GRldg zVK4yVXrmR(F+p7k!&DnC);7;Ko=jFsW_M-5VA?-ya*hqRh#MP<2DS7Z$W{ zS;az1tr;BUD?6wx_W_w<%uh|dRSaq89I?^jCT8pkTE$j&gx(06Dh=s?LFcwggpLJ` zH7J4N;P#?nyfgz`>GS#;r^q23Vp>k^CH-(MOyMUkD)BYL3=_^_i)cH zB20k&gdlFpq9K0$eO(;QaqJPvW!CVla~76O63ryo#^oV7;?N{ACN zG5C?h?^QwSagnZh9Ddq3rC#5^26r=ND0Nrma*y`w!ABZ}_r`?}-&O;EK!-K(lOL(0 zQFtCYf_(VS8u+97@Li3<^N1_)*4N zsYBCqlhO~=Wrk55cRSXB8+Rj+ zsSD{Ib;ZaBU#>QC{Ztj(P$-^{U&JW4+wAblt{(-E6fp?!0XqETx- zj;A8jVP9az`wojgD$CN1^Y;4i97yQxzY2$v{G1>XIm&j1chkTl6Vn`pe>e2NcvS_u z#!rQZA3Wb{`mNBF1PWJyG@`|CgfDPQ%2F!Bj8GCix!ISmkA~&SblNLD|n9~)m4BGI%zr) literal 0 HcmV?d00001 diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class new file mode 100644 index 0000000000000000000000000000000000000000..1014544f130ee9ec40e0501bcb74434cc90a66b5 GIT binary patch literal 2368 zcmah~=~5d<5dKC81ZZQh4H%LTFBq`IwZ1}#!3Q=FD-lPy65}HoR%5Xs?NYlV5}e9g z&~#6$`|EFdx@Z6S_s_opETGtl7+MmD8)!wFK=*+> zmR3Q!d24O&K-pTLZQgMm{ZODKmEK99U0}@iiq^qN&a=mDuJFb65aiVI`RTXd;W>Qootivx>JNu z-_8ldpHd$QbY&e^t(J;=%HQJt61bA}Y+2ZmzQg;9F|PNWKwz?2rVEHtjxO7Csc-d` zx8!O^6V=sJGlWyUIhStcbguU)MS=%mQF{U-&4NxN)492N0!?`|rs!T#df&^fOP@Me zE1&9M)D9MnQu9-tM{9brvm`re<4w6_N$)GFpDi_A&&>-4;(`&`r9oEQ<$R$H14j*i zRB3F1!Hp837uAjvIDF$LM{2=!JuS84xpY__*hA@SX&uXglZ(t26(G>QbX*-+tDb&B zkJ%w#M^OcV%oESvXq-%2GL*TeOjSJM4jB6oS`d}Mg@fQnIyK?I7t8}z`nM+UqGBf$>h`{XGuzqT%9u`bLtqF`>9Yg~`YmCZ);Q_(fui** z+F2y|zt-{h5bsEd;Tf&`H(($Wt&s!1#y7MR$YO=OIQTdI;*q@n7ZT6kqhn=qB1C71 zZk9bE`dNM&!eluT;wH=S5K}B~g}6KU2St}N4x^p)tF-o@8@=eK?~#dXNRf661DK_+ z5VJAM87pikH&(GmtlH^0U&ptEwn1L4^a_y>*u+*N*(8yjiO7BtVwTB#8R9<6xe)U# zAB1?w@==J#EEhsNX&`%@lA1(zh$s$|c7w={5ZO^8JJy8kHc_mSU8|Gbj>zudJGvgO z>|=7`%Escq^Lpw|tW&_TS`}jW9?vO;eRoMKSD}N=AOrA%e$UX_N8%; + + + + Error + + +Error + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/index.html b/Sprint 1/deliverable3/target/classes/templates/index.html new file mode 100644 index 000000000..fae1fc07c --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/templates/index.html @@ -0,0 +1,28 @@ + + + + + Thymeleaf Example + + + +

Welcome to Thymeleaf!

+ +

+ +
+

Current Date and Time:

+
+ + +
+ +
+ + +
+ +
+ + + diff --git a/Sprint 1/deliverable3/target/classes/templates/login.html b/Sprint 1/deliverable3/target/classes/templates/login.html new file mode 100644 index 000000000..fe9554099 --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/templates/login.html @@ -0,0 +1,33 @@ + + + + + Login + + +

Login

+ + +
+

+
+ + +
+
+ + +
+ +
+ + +
+ +
+ +
+
+ + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html b/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html new file mode 100644 index 000000000..7a517bfcb --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html @@ -0,0 +1,10 @@ + + + + + Title + + +Login Success + + \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/register.html b/Sprint 1/deliverable3/target/classes/templates/register.html new file mode 100644 index 000000000..89904066b --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/templates/register.html @@ -0,0 +1,55 @@ + + + + User Registration + + + +

Register

+
+ + + + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + + +
+ + +
+ + diff --git a/Sprint 1/deliverable3/target/classes/templates/styles.css b/Sprint 1/deliverable3/target/classes/templates/styles.css new file mode 100644 index 000000000..046e065ca --- /dev/null +++ b/Sprint 1/deliverable3/target/classes/templates/styles.css @@ -0,0 +1,14 @@ +.error { + color: #dc3545; + font-size: 0.875em; +} +.error-border { + border-color: #dc3545; +} +.error-list { + background-color: #f8d7da; + border: 1px solid #f5c6cb; + border-radius: 4px; + padding: 10px; + margin-bottom: 20px; +} From 3ba659c213965f83d3ae0182955308cc46e11644 Mon Sep 17 00:00:00 2001 From: ChrisJackson0313 Date: Wed, 26 Mar 2025 15:10:07 -0400 Subject: [PATCH 036/100] Update Deliverable3ApplicationTests.java Test cases for login. --- .../Deliverable3ApplicationTests.java | 158 +++++++++++++++++- 1 file changed, 157 insertions(+), 1 deletion(-) diff --git a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java index 496abea0b..7b345b8ad 100644 --- a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java +++ b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java @@ -1,11 +1,167 @@ package com.jydoc.deliverable3; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; +import jakarta.validation.Validation; +import jakarta.validation.Validator; +import jakarta.validation.ValidatorFactory; +import jakarta.validation.ConstraintViolation; +import java.util.Set; +import static org.junit.jupiter.api.Assertions.*; @SpringBootTest class Deliverable3ApplicationTests { + @BeforeEach + void setUp() { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + validator = factory.getValidator(); + } + + @Test + void testValidUserModel() { + UserModel validUser = new UserModel(); + validUser.setFirstName("John"); + validUser.setLastName("Doe"); + validUser.setEmail("john.doe@example.com"); + validUser.setPassword("password123"); + validUser.setAdmin(false); + + Set> violations = validator.validate(validUser); + assertTrue(violations.isEmpty(), "Valid user should have no violations"); + } + + @Test + void testFirstNameValidations() { + UserModel user = new UserModel(); + + // Test first name too short + user.setFirstName("A"); + Set> violations = validator.validate(user); + assertFalse(violations.isEmpty(), "First name less than 2 characters should fail"); + + // Test first name too long + user.setFirstName("ThisIsAVeryLongFirstNameThatExceedsFiftyCharactersLimit"); + violations = validator.validate(user); + assertFalse(violations.isEmpty(), "First name over 50 characters should fail"); + + // Test first name with invalid characters + user.setFirstName("John123"); + violations = validator.validate(user); + assertFalse(violations.isEmpty(), "First name with numbers should fail"); + + // Test first name with allowed special characters + user.setFirstName("Mary-Jane"); + violations = validator.validate(user); + assertTrue(violations.isEmpty(), "First name with hyphen should be valid"); + + user.setFirstName("O'Brien"); + violations = validator.validate(user); + assertTrue(violations.isEmpty(), "First name with apostrophe should be valid"); + } + + @Test + void testLastNameValidations() { + UserModel user = new UserModel(); + + // Test last name too short + user.setLastName("A"); + Set> violations = validator.validate(user); + assertFalse(violations.isEmpty(), "Last name less than 2 characters should fail"); + + // Test last name too long + user.setLastName("ThisIsAVeryLongLastNameThatExceedsFiftyCharactersLimit"); + violations = validator.validate(user); + assertFalse(violations.isEmpty(), "Last name over 50 characters should fail"); + + // Test last name with invalid characters + user.setLastName("Smith123"); + violations = validator.validate(user); + assertFalse(violations.isEmpty(), "Last name with numbers should fail"); + + // Test last name with allowed special characters + user.setLastName("Van-Helsing"); + violations = validator.validate(user); + assertTrue(violations.isEmpty(), "Last name with hyphen should be valid"); + } + + @Test + void testEmailValidations() { + UserModel user = new UserModel(); + + // Test blank email + user.setEmail(""); + Set> violations = validator.validate(user); + assertFalse(violations.isEmpty(), "Blank email should fail"); + + // Test invalid email formats + String[] invalidEmails = { + "invalid-email", + "invalid@email", + "invalid@email.", + "@email.com", + "email@.com" + }; + + for (String email : invalidEmails) { + user.setEmail(email); + violations = validator.validate(user); + assertFalse(violations.isEmpty(), "Invalid email format should fail: " + email); + } + + // Test valid email + user.setEmail("valid.email123@example.com"); + violations = validator.validate(user); + assertTrue(violations.isEmpty(), "Valid email should pass"); + } + + @Test + void testPasswordValidations() { + UserModel user = new UserModel(); + + // Test password too short + user.setPassword("12"); + Set> violations = validator.validate(user); + assertFalse(violations.isEmpty(), "Password less than 6 characters should fail"); + + // Test password without letters + user.setPassword("123456"); + violations = validator.validate(user); + assertFalse(violations.isEmpty(), "Password without letters should fail"); + + // Test password without numbers + user.setPassword("password"); + violations = validator.validate(user); + assertFalse(violations.isEmpty(), "Password without numbers should fail"); + + // Test valid password + user.setPassword("password123"); + violations = validator.validate(user); + assertTrue(violations.isEmpty(), "Valid password should pass"); + } + + @Test + void testAdminFlag() { + UserModel adminUser = new UserModel(); + adminUser.setFirstName("Admin"); + adminUser.setLastName("User"); + adminUser.setEmail("admin@example.com"); + adminUser.setPassword("admin123"); + adminUser.setAdmin(true); + + UserModel regularUser = new UserModel(); + regularUser.setFirstName("Regular"); + regularUser.setLastName("User"); + regularUser.setEmail("regular@example.com"); + regularUser.setPassword("regular123"); + regularUser.setAdmin(false); + + // Verify admin flag can be set correctly + assertTrue(adminUser.isAdmin(), "Admin flag should be settable to true"); + assertFalse(regularUser.isAdmin(), "Admin flag should be settable to false"); + } +} + @Test void contextLoads() { } From 33fee839e2bd87a4f0bc6a5433021c5d08d9b2aa Mon Sep 17 00:00:00 2001 From: ChrisJackson0313 Date: Wed, 26 Mar 2025 15:38:46 -0400 Subject: [PATCH 037/100] Update Deliverable3ApplicationTests.java --- .../Deliverable3ApplicationTests.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java index 7b345b8ad..59aff832f 100644 --- a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java +++ b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java @@ -38,26 +38,26 @@ void testFirstNameValidations() { // Test first name too short user.setFirstName("A"); Set> violations = validator.validate(user); - assertFalse(violations.isEmpty(), "First name less than 2 characters should fail"); + assertFalse(violations.isEmpty(), "First name less than 2 characters are invalid."); // Test first name too long user.setFirstName("ThisIsAVeryLongFirstNameThatExceedsFiftyCharactersLimit"); violations = validator.validate(user); - assertFalse(violations.isEmpty(), "First name over 50 characters should fail"); + assertFalse(violations.isEmpty(), "First name over 50 characters are invalid."); // Test first name with invalid characters user.setFirstName("John123"); violations = validator.validate(user); - assertFalse(violations.isEmpty(), "First name with numbers should fail"); + assertFalse(violations.isEmpty(), "First name with numbers are invalid."); // Test first name with allowed special characters user.setFirstName("Mary-Jane"); violations = validator.validate(user); - assertTrue(violations.isEmpty(), "First name with hyphen should be valid"); + assertTrue(violations.isEmpty(), "First names with a hyphen are valid."); user.setFirstName("O'Brien"); violations = validator.validate(user); - assertTrue(violations.isEmpty(), "First name with apostrophe should be valid"); + assertTrue(violations.isEmpty(), "First name with apostrophe should be valid."); } @Test @@ -67,22 +67,22 @@ void testLastNameValidations() { // Test last name too short user.setLastName("A"); Set> violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Last name less than 2 characters should fail"); + assertFalse(violations.isEmpty(), "Last name less than 2 characters are invalid."); // Test last name too long user.setLastName("ThisIsAVeryLongLastNameThatExceedsFiftyCharactersLimit"); violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Last name over 50 characters should fail"); + assertFalse(violations.isEmpty(), "Last name over 50 characters are invalid."); // Test last name with invalid characters user.setLastName("Smith123"); violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Last name with numbers should fail"); + assertFalse(violations.isEmpty(), "Last name with numbers are invalid."); // Test last name with allowed special characters user.setLastName("Van-Helsing"); violations = validator.validate(user); - assertTrue(violations.isEmpty(), "Last name with hyphen should be valid"); + assertTrue(violations.isEmpty(), "Last name with a hyphen should be valid."); } @Test @@ -92,7 +92,7 @@ void testEmailValidations() { // Test blank email user.setEmail(""); Set> violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Blank email should fail"); + assertFalse(violations.isEmpty(), "A blank email is invalid."); // Test invalid email formats String[] invalidEmails = { @@ -106,13 +106,13 @@ void testEmailValidations() { for (String email : invalidEmails) { user.setEmail(email); violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Invalid email format should fail: " + email); + assertFalse(violations.isEmpty(), "Invalid email format: " + email); } // Test valid email user.setEmail("valid.email123@example.com"); violations = validator.validate(user); - assertTrue(violations.isEmpty(), "Valid email should pass"); + assertTrue(violations.isEmpty(), "Valid email should pass."); } @Test @@ -122,22 +122,22 @@ void testPasswordValidations() { // Test password too short user.setPassword("12"); Set> violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Password less than 6 characters should fail"); + assertFalse(violations.isEmpty(), "Passwords less than 6 characters are invalid."); // Test password without letters user.setPassword("123456"); violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Password without letters should fail"); + assertFalse(violations.isEmpty(), "Passwords without letters are invalid."); // Test password without numbers user.setPassword("password"); violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Password without numbers should fail"); + assertFalse(violations.isEmpty(), "Passwords without numbers are invalid.l"); // Test valid password user.setPassword("password123"); violations = validator.validate(user); - assertTrue(violations.isEmpty(), "Valid password should pass"); + assertTrue(violations.isEmpty(), "Valid passwords will pass."); } @Test @@ -157,8 +157,8 @@ void testAdminFlag() { regularUser.setAdmin(false); // Verify admin flag can be set correctly - assertTrue(adminUser.isAdmin(), "Admin flag should be settable to true"); - assertFalse(regularUser.isAdmin(), "Admin flag should be settable to false"); + assertTrue(adminUser.isAdmin(), "Admin flag should be settable to true."); + assertFalse(regularUser.isAdmin(), "Admin flag should be settable to false."); } } From 751394b4571350d92e43a4ba859aabb1a7a17e97 Mon Sep 17 00:00:00 2001 From: bihiy Date: Wed, 26 Mar 2025 18:15:00 -0400 Subject: [PATCH 038/100] Updated test cases --- .../Deliverable3ApplicationTests.java | 155 ++++++++---------- 1 file changed, 71 insertions(+), 84 deletions(-) diff --git a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java index 59aff832f..bd3bea53d 100644 --- a/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java +++ b/Sprint 1/deliverable3/src/test/java/com/jydoc/deliverable3/Deliverable3ApplicationTests.java @@ -1,30 +1,41 @@ package com.jydoc.deliverable3; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import com.jydoc.deliverable3.Model.UserModel; +import jakarta.validation.ConstraintViolation; import jakarta.validation.Validation; import jakarta.validation.Validator; import jakarta.validation.ValidatorFactory; -import jakarta.validation.ConstraintViolation; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + import java.util.Set; + import static org.junit.jupiter.api.Assertions.*; @SpringBootTest class Deliverable3ApplicationTests { - @BeforeEach + private Validator validator; + + @BeforeEach void setUp() { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); validator = factory.getValidator(); } + @Test + void contextLoads() { + assertDoesNotThrow(() -> {}, "Context should load successfully"); + } + @Test void testValidUserModel() { UserModel validUser = new UserModel(); validUser.setFirstName("John"); validUser.setLastName("Doe"); validUser.setEmail("john.doe@example.com"); - validUser.setPassword("password123"); + validUser.setPassword("Password123"); validUser.setAdmin(false); Set> violations = validator.validate(validUser); @@ -34,136 +45,112 @@ void testValidUserModel() { @Test void testFirstNameValidations() { UserModel user = new UserModel(); - + user.setLastName("Doe"); + user.setEmail("test@example.com"); + user.setPassword("Password123"); + // Test first name too short user.setFirstName("A"); Set> violations = validator.validate(user); - assertFalse(violations.isEmpty(), "First name less than 2 characters are invalid."); + assertFalse(violations.isEmpty(), "First name less than 2 characters should be invalid"); // Test first name too long user.setFirstName("ThisIsAVeryLongFirstNameThatExceedsFiftyCharactersLimit"); violations = validator.validate(user); - assertFalse(violations.isEmpty(), "First name over 50 characters are invalid."); - - // Test first name with invalid characters - user.setFirstName("John123"); - violations = validator.validate(user); - assertFalse(violations.isEmpty(), "First name with numbers are invalid."); - - // Test first name with allowed special characters - user.setFirstName("Mary-Jane"); - violations = validator.validate(user); - assertTrue(violations.isEmpty(), "First names with a hyphen are valid."); + assertFalse(violations.isEmpty(), "First name over 50 characters should be invalid"); - user.setFirstName("O'Brien"); + // Test valid first name + user.setFirstName("John"); violations = validator.validate(user); - assertTrue(violations.isEmpty(), "First name with apostrophe should be valid."); + assertTrue(violations.isEmpty(), "Valid first name should pass"); } @Test void testLastNameValidations() { UserModel user = new UserModel(); - + user.setFirstName("John"); + user.setEmail("test@example.com"); + user.setPassword("Password123"); + // Test last name too short user.setLastName("A"); Set> violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Last name less than 2 characters are invalid."); + assertFalse(violations.isEmpty(), "Last name less than 2 characters should be invalid"); // Test last name too long user.setLastName("ThisIsAVeryLongLastNameThatExceedsFiftyCharactersLimit"); violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Last name over 50 characters are invalid."); - - // Test last name with invalid characters - user.setLastName("Smith123"); - violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Last name with numbers are invalid."); + assertFalse(violations.isEmpty(), "Last name over 50 characters should be invalid"); - // Test last name with allowed special characters - user.setLastName("Van-Helsing"); + // Test valid last name + user.setLastName("Doe"); violations = validator.validate(user); - assertTrue(violations.isEmpty(), "Last name with a hyphen should be valid."); + assertTrue(violations.isEmpty(), "Valid last name should pass"); } @Test void testEmailValidations() { UserModel user = new UserModel(); - + user.setFirstName("John"); + user.setLastName("Doe"); + user.setPassword("Password123"); + // Test blank email user.setEmail(""); Set> violations = validator.validate(user); - assertFalse(violations.isEmpty(), "A blank email is invalid."); - - // Test invalid email formats - String[] invalidEmails = { - "invalid-email", - "invalid@email", - "invalid@email.", - "@email.com", - "email@.com" - }; - - for (String email : invalidEmails) { - user.setEmail(email); - violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Invalid email format: " + email); - } + assertFalse(violations.isEmpty(), "Blank email should be invalid"); + + // Test invalid email format + user.setEmail("invalid-email"); + violations = validator.validate(user); + assertFalse(violations.isEmpty(), "Invalid email format should be rejected"); // Test valid email - user.setEmail("valid.email123@example.com"); + user.setEmail("valid.email@example.com"); violations = validator.validate(user); - assertTrue(violations.isEmpty(), "Valid email should pass."); + assertTrue(violations.isEmpty(), "Valid email should pass"); } @Test void testPasswordValidations() { UserModel user = new UserModel(); - + user.setFirstName("John"); + user.setLastName("Doe"); + user.setEmail("test@example.com"); + // Test password too short - user.setPassword("12"); + user.setPassword("Pwd1"); Set> violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Passwords less than 6 characters are invalid."); + assertFalse(violations.isEmpty(), "Password less than 6 characters should be invalid"); - // Test password without letters - user.setPassword("123456"); + // Test password without numbers + user.setPassword("Password"); violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Passwords without letters are invalid."); + assertFalse(violations.isEmpty(), "Password without numbers should be invalid"); - // Test password without numbers - user.setPassword("password"); + // Test password without letters + user.setPassword("123456"); violations = validator.validate(user); - assertFalse(violations.isEmpty(), "Passwords without numbers are invalid.l"); + assertFalse(violations.isEmpty(), "Password without letters should be invalid"); // Test valid password - user.setPassword("password123"); + user.setPassword("Password123"); violations = validator.validate(user); - assertTrue(violations.isEmpty(), "Valid passwords will pass."); + assertTrue(violations.isEmpty(), "Valid password should pass"); } @Test void testAdminFlag() { - UserModel adminUser = new UserModel(); - adminUser.setFirstName("Admin"); - adminUser.setLastName("User"); - adminUser.setEmail("admin@example.com"); - adminUser.setPassword("admin123"); - adminUser.setAdmin(true); - - UserModel regularUser = new UserModel(); - regularUser.setFirstName("Regular"); - regularUser.setLastName("User"); - regularUser.setEmail("regular@example.com"); - regularUser.setPassword("regular123"); - regularUser.setAdmin(false); - - // Verify admin flag can be set correctly - assertTrue(adminUser.isAdmin(), "Admin flag should be settable to true."); - assertFalse(regularUser.isAdmin(), "Admin flag should be settable to false."); - } -} + UserModel user = new UserModel(); + user.setFirstName("Admin"); + user.setLastName("User"); + user.setEmail("admin@example.com"); + user.setPassword("Admin123"); - @Test - void contextLoads() { - } + user.setAdmin(true); + assertTrue(user.isAdmin(), "Admin flag should be settable to true"); -} + user.setAdmin(false); + assertFalse(user.isAdmin(), "Admin flag should be settable to false"); + } +} \ No newline at end of file From 40e69b287e5cdb12d10425fc39da37925f67dbaf Mon Sep 17 00:00:00 2001 From: Diego Rivera <159937690+DiegoRiveraa@users.noreply.github.com> Date: Wed, 26 Mar 2025 19:57:13 -0400 Subject: [PATCH 039/100] Update codePlaceHolder.txt --- Sprint 1/codePlaceHolder.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint 1/codePlaceHolder.txt b/Sprint 1/codePlaceHolder.txt index e69de29bb..86624400d 100644 --- a/Sprint 1/codePlaceHolder.txt +++ b/Sprint 1/codePlaceHolder.txt @@ -0,0 +1,13 @@ +// Account creation +public class AccountService { + public void createPatient(String name, String email, String history, String meds) { + // Store patient data (simplified) + System.out.println("Storing patient: " + name); + // Insert into MySQL logic here + } + + public void createProvider(String name, String contact, String pastRecords) { + System.out.println("Storing provider: " + name); + // Insert into MySQL logic here + } +} From 79c1d1d903b034876a4decb254aedcc649b184d6 Mon Sep 17 00:00:00 2001 From: Diego Rivera <159937690+DiegoRiveraa@users.noreply.github.com> Date: Wed, 26 Mar 2025 20:00:25 -0400 Subject: [PATCH 040/100] Update codePlaceHolder.txt --- Sprint 2/codePlaceHolder.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint 2/codePlaceHolder.txt b/Sprint 2/codePlaceHolder.txt index e69de29bb..1fc29b494 100644 --- a/Sprint 2/codePlaceHolder.txt +++ b/Sprint 2/codePlaceHolder.txt @@ -0,0 +1,12 @@ +// tracking and notifications +public class ReminderService { + public void sendReminder(String method, boolean urgent) { + if (urgent) { + System.out.println("Sending urgent reminder via " + method); + // Notify provider + call patient + } else { + System.out.println("Sending non-urgent reminder via " + method); + // Push notification + } + } +} From 7a978c8ceb037628727f0a469ea3a10c6e53d5d9 Mon Sep 17 00:00:00 2001 From: Diego Rivera <159937690+DiegoRiveraa@users.noreply.github.com> Date: Wed, 26 Mar 2025 20:01:11 -0400 Subject: [PATCH 041/100] Update codePlaceHolder.txt --- Sprint 3/codePlaceHolder.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint 3/codePlaceHolder.txt b/Sprint 3/codePlaceHolder.txt index e69de29bb..101a42c77 100644 --- a/Sprint 3/codePlaceHolder.txt +++ b/Sprint 3/codePlaceHolder.txt @@ -0,0 +1,12 @@ +// Update patient records & generate reports +public class RecordUpdater { + public void updateIntake(String patientName, String med, String status) { + System.out.println("Updating " + patientName + "'s record: " + med + " - " + status); + // Save to DB + } + + public String generateMonthlyReport(String patientName) { + // Simulated report content + return "Monthly Report for " + patientName + ":\nMissed: MedA\nTaken: MedB"; + } +} From e529982a70d9bb8f26cb1b5c1d50affee394271c Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Wed, 26 Mar 2025 21:16:11 -0400 Subject: [PATCH 042/100] Add files via upload --- Sprint 1/Jydoc - Sheet1.pdf | Bin 0 -> 38006 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Sprint 1/Jydoc - Sheet1.pdf diff --git a/Sprint 1/Jydoc - Sheet1.pdf b/Sprint 1/Jydoc - Sheet1.pdf new file mode 100644 index 0000000000000000000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aUF*jq}qYJ42IbR1h!v)K|7 zHo37GSZhhem#H~hN=9-~D3PtY1hrAZ`@u;lCftQ$5+s`f0a*g@1UteyRZ6HKTO0xk zHQ8j6fdvIo)?|88Ujp-qfL?@>&6NPg3dVwBldwK0IoMFp3#21L&CLaCB-B!l)nYBB zNN5B1SwTt-S`-LR1XPQSve#qy7W)Z%3jC6k+e#_HYEUH91)?yMl&iIr-F+!!$Hl=y zn$V!wv?dg#|Nc^*MT3Ih)YBj+Sm2lg1y6|zj4OEG`ETh!acs|I2a5B=*bG>|YdkA1 zWi|$MmP+<(bb?=#L-8kCvbYb|QYnQJPgKROC`;k>_G$dUMe!Tbpt|f{E@v|fP0j$| zieM$R@vd2^?{4Hv#O$Lz@h254 zl-k9lQn_7Brk2>oNTt#~rckQw+9}lbF(qNQW>QTOwteLiyLkyE90zvoq%zVbMu41V zmz!KEwVhX{kg9C+AXGBDzB1)g)}m5N?8bvBY}W#NBza0qYP%oMj+_)rPmKYsES1Cf tR>W_87fuU);PT|;bp9AZ7RXV3lR&AM)O7BNkts Date: Wed, 26 Mar 2025 21:16:58 -0400 Subject: [PATCH 043/100] Rename Jydoc - Sheet1.pdf to JydocTestCases.pdf --- Sprint 1/{Jydoc - Sheet1.pdf => JydocTestCases.pdf} | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename Sprint 1/{Jydoc - Sheet1.pdf => JydocTestCases.pdf} (100%) diff --git a/Sprint 1/Jydoc - Sheet1.pdf b/Sprint 1/JydocTestCases.pdf similarity index 100% rename from Sprint 1/Jydoc - Sheet1.pdf rename to Sprint 1/JydocTestCases.pdf From edfe3bcbdf265dba2bdcb9afe384d1522d8b10b4 Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Wed, 26 Mar 2025 21:22:23 -0400 Subject: [PATCH 044/100] Update codePlaceHolder.txt --- Sprint 1/codePlaceHolder.txt | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/Sprint 1/codePlaceHolder.txt b/Sprint 1/codePlaceHolder.txt index 86624400d..8fc10861b 100644 --- a/Sprint 1/codePlaceHolder.txt +++ b/Sprint 1/codePlaceHolder.txt @@ -1,13 +1 @@ -// Account creation -public class AccountService { - public void createPatient(String name, String email, String history, String meds) { - // Store patient data (simplified) - System.out.println("Storing patient: " + name); - // Insert into MySQL logic here - } - - public void createProvider(String name, String contact, String pastRecords) { - System.out.println("Storing provider: " + name); - // Insert into MySQL logic here - } -} +//Check deliverable3 folder From 8ac08e3c53f59f5e016aed24bcb70a7cd08aba69 Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Wed, 26 Mar 2025 21:22:50 -0400 Subject: [PATCH 045/100] Update TestCasesPlaceholder.txt --- Sprint 1/TestCasesPlaceholder.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint 1/TestCasesPlaceholder.txt b/Sprint 1/TestCasesPlaceholder.txt index e69de29bb..927bb8564 100644 --- a/Sprint 1/TestCasesPlaceholder.txt +++ b/Sprint 1/TestCasesPlaceholder.txt @@ -0,0 +1 @@ +//check JydocTestCases.pdf From 295208a3b1f982b4b078e8798ff11c399ea4c27b Mon Sep 17 00:00:00 2001 From: Ozi <40478846+AsmaJawad@users.noreply.github.com> Date: Wed, 26 Mar 2025 21:44:18 -0400 Subject: [PATCH 046/100] Update codePlaceHolder.txt --- Sprint 2/codePlaceHolder.txt | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Sprint 2/codePlaceHolder.txt b/Sprint 2/codePlaceHolder.txt index 1fc29b494..d3f5a12fa 100644 --- a/Sprint 2/codePlaceHolder.txt +++ b/Sprint 2/codePlaceHolder.txt @@ -1,12 +1 @@ -// tracking and notifications -public class ReminderService { - public void sendReminder(String method, boolean urgent) { - if (urgent) { - System.out.println("Sending urgent reminder via " + method); - // Notify provider + call patient - } else { - System.out.println("Sending non-urgent reminder via " + method); - // Push notification - } - } -} + From afc01b468dd2752fd4d96079819d38b6ad635c92 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Thu, 27 Mar 2025 20:32:45 -0400 Subject: [PATCH 047/100] Second working version --- Sprint 2/prototype2/HELP.md | 39 +++ Sprint 2/prototype2/mvnw | 259 ++++++++++++++++++ Sprint 2/prototype2/mvnw.cmd | 149 ++++++++++ Sprint 2/prototype2/pom.xml | 136 +++++++++ .../com/jydoc/deliverable4/DTO/LoginDTO.java | 21 ++ .../com/jydoc/deliverable4/DTO/UserDTO.java | 42 +++ .../Initializers/AuthorityInitializer.java | 33 +++ .../deliverable4/Prototype2Application.java | 13 + .../deliverable4/Service/UserService.java | 161 +++++++++++ .../Service/UserValidationHelper.java | 42 +++ .../deliverable4/config/SecurityConfig.java | 134 +++++++++ .../deliverable4/config/SessionConfig.java | 4 + .../controllers/AuthController.java | 114 ++++++++ .../controllers/CustomErrorController.java | 48 ++++ .../controllers/DashboardController.java | 25 ++ .../deliverable4/model/AuthorityModel.java | 36 +++ .../deliverable4/model/UserAuthority.java | 23 ++ .../deliverable4/model/UserAuthorityId.java | 31 +++ .../jydoc/deliverable4/model/UserModel.java | 59 ++++ .../repositories/AuthorityRepository.java | 19 ++ .../repositories/UserAuthorityRepository.java | 21 ++ .../repositories/UserRepository.java | 33 +++ .../Exceptions/EmailExistsException.java | 7 + .../Exceptions/UsernameExistsException.java | 7 + .../security/auth/CustomUserDetails.java | 76 +++++ .../auth/CustomUserDetailsService.java | 45 +++ .../src/main/resources/application.properties | 27 ++ .../src/main/resources/static/css/styles.css | 107 ++++++++ .../src/main/resources/static/js/script.js | 0 .../main/resources/templates/dashboard.html | 163 +++++++++++ .../src/main/resources/templates/error.html | 41 +++ .../resources/templates/fragments/footer.html | 39 +++ .../resources/templates/fragments/header.html | 101 +++++++ .../src/main/resources/templates/index.html | 89 ++++++ .../src/main/resources/templates/login.html | 45 +++ .../src/main/resources/templates/logout.html | 26 ++ .../main/resources/templates/register.html | 34 +++ .../Prototype2ApplicationTests.java | 13 + .../target/classes/application.properties | 27 ++ .../com/jydoc/deliverable4/DTO/LoginDTO.class | Bin 0 -> 2503 bytes .../com/jydoc/deliverable4/DTO/UserDTO.class | Bin 0 -> 5163 bytes .../Initializers/AuthorityInitializer.class | Bin 0 -> 2229 bytes .../deliverable4/Prototype2Application.class | Bin 0 -> 763 bytes .../UserService$AuthenticationException.class | Bin 0 -> 794 bytes .../UserService$EmailExistsException.class | Bin 0 -> 974 bytes .../UserService$UsernameExistsException.class | Bin 0 -> 985 bytes .../deliverable4/Service/UserService.class | Bin 0 -> 8897 bytes .../Service/UserValidationHelper.class | Bin 0 -> 1953 bytes .../deliverable4/config/SecurityConfig.class | Bin 0 -> 13081 bytes .../deliverable4/config/SessionConfig.class | Bin 0 -> 324 bytes .../controllers/AuthController.class | Bin 0 -> 5685 bytes .../controllers/CustomErrorController.class | Bin 0 -> 2583 bytes .../controllers/DashboardController.class | Bin 0 -> 2622 bytes ...AuthorityModel$AuthorityModelBuilder.class | Bin 0 -> 2775 bytes .../deliverable4/model/AuthorityModel.class | Bin 0 -> 3194 bytes .../deliverable4/model/UserAuthority.class | Bin 0 -> 1167 bytes .../deliverable4/model/UserAuthorityId.class | Bin 0 -> 1134 bytes .../model/UserModel$UserModelBuilder.class | Bin 0 -> 3323 bytes .../jydoc/deliverable4/model/UserModel.class | Bin 0 -> 4957 bytes .../repositories/AuthorityRepository.class | Bin 0 -> 1046 bytes .../UserAuthorityRepository.class | Bin 0 -> 1045 bytes .../repositories/UserRepository.class | Bin 0 -> 1467 bytes .../Exceptions/EmailExistsException.class | Bin 0 -> 475 bytes .../Exceptions/UsernameExistsException.class | Bin 0 -> 484 bytes .../security/auth/CustomUserDetails.class | Bin 0 -> 2408 bytes .../auth/CustomUserDetailsService.class | Bin 0 -> 4660 bytes .../target/classes/static/css/styles.css | 107 ++++++++ .../target/classes/static/js/script.js | 0 .../target/classes/templates/dashboard.html | 163 +++++++++++ .../target/classes/templates/error.html | 41 +++ .../classes/templates/fragments/footer.html | 39 +++ .../classes/templates/fragments/header.html | 101 +++++++ .../target/classes/templates/index.html | 89 ++++++ .../target/classes/templates/login.html | 45 +++ .../target/classes/templates/logout.html | 26 ++ .../target/classes/templates/register.html | 34 +++ 76 files changed, 2934 insertions(+) create mode 100644 Sprint 2/prototype2/HELP.md create mode 100644 Sprint 2/prototype2/mvnw create mode 100644 Sprint 2/prototype2/mvnw.cmd create mode 100644 Sprint 2/prototype2/pom.xml create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Prototype2Application.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserValidationHelper.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SessionConfig.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/CustomErrorController.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/DashboardController.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/AuthorityModel.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthority.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthorityId.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/AuthorityRepository.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserAuthorityRepository.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserRepository.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java create mode 100644 Sprint 2/prototype2/src/main/resources/application.properties create mode 100644 Sprint 2/prototype2/src/main/resources/static/css/styles.css create mode 100644 Sprint 2/prototype2/src/main/resources/static/js/script.js create mode 100644 Sprint 2/prototype2/src/main/resources/templates/dashboard.html create mode 100644 Sprint 2/prototype2/src/main/resources/templates/error.html create mode 100644 Sprint 2/prototype2/src/main/resources/templates/fragments/footer.html create mode 100644 Sprint 2/prototype2/src/main/resources/templates/fragments/header.html create mode 100644 Sprint 2/prototype2/src/main/resources/templates/index.html create mode 100644 Sprint 2/prototype2/src/main/resources/templates/login.html create mode 100644 Sprint 2/prototype2/src/main/resources/templates/logout.html create mode 100644 Sprint 2/prototype2/src/main/resources/templates/register.html create mode 100644 Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/Prototype2ApplicationTests.java create mode 100644 Sprint 2/prototype2/target/classes/application.properties create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/DTO/LoginDTO.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/DTO/UserDTO.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Initializers/AuthorityInitializer.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Prototype2Application.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$AuthenticationException.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$EmailExistsException.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$UsernameExistsException.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserValidationHelper.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/config/SecurityConfig.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/config/SessionConfig.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/controllers/AuthController.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/controllers/CustomErrorController.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/controllers/DashboardController.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/AuthorityModel$AuthorityModelBuilder.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/AuthorityModel.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/UserAuthority.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/UserAuthorityId.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/UserModel$UserModelBuilder.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/UserModel.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/AuthorityRepository.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/UserAuthorityRepository.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/UserRepository.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/auth/CustomUserDetails.class create mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.class create mode 100644 Sprint 2/prototype2/target/classes/static/css/styles.css create mode 100644 Sprint 2/prototype2/target/classes/static/js/script.js create mode 100644 Sprint 2/prototype2/target/classes/templates/dashboard.html create mode 100644 Sprint 2/prototype2/target/classes/templates/error.html create mode 100644 Sprint 2/prototype2/target/classes/templates/fragments/footer.html create mode 100644 Sprint 2/prototype2/target/classes/templates/fragments/header.html create mode 100644 Sprint 2/prototype2/target/classes/templates/index.html create mode 100644 Sprint 2/prototype2/target/classes/templates/login.html create mode 100644 Sprint 2/prototype2/target/classes/templates/logout.html create mode 100644 Sprint 2/prototype2/target/classes/templates/register.html diff --git a/Sprint 2/prototype2/HELP.md b/Sprint 2/prototype2/HELP.md new file mode 100644 index 000000000..21906b98c --- /dev/null +++ b/Sprint 2/prototype2/HELP.md @@ -0,0 +1,39 @@ +# Getting Started + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/3.4.4/maven-plugin) +* [Create an OCI image](https://docs.spring.io/spring-boot/3.4.4/maven-plugin/build-image.html) +* [Spring Web](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html) +* [Spring Security](https://docs.spring.io/spring-boot/3.4.4/reference/web/spring-security.html) +* [Spring Session](https://docs.spring.io/spring-session/reference/) +* [htmx](https://github.com/wimdeblauwe/htmx-spring-boot) +* [Thymeleaf](https://docs.spring.io/spring-boot/3.4.4/reference/web/servlet.html#web.servlet.spring-mvc.template-engines) +* [JDBC API](https://docs.spring.io/spring-boot/3.4.4/reference/data/sql.html) +* [Validation](https://docs.spring.io/spring-boot/3.4.4/reference/io/validation.html) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) +* [Securing a Web Application](https://spring.io/guides/gs/securing-web/) +* [Spring Boot and OAuth2](https://spring.io/guides/tutorials/spring-boot-oauth2/) +* [Authenticating a User with LDAP](https://spring.io/guides/gs/authenticating-ldap/) +* [htmx](https://www.youtube.com/watch?v=j-rfPoXe5aE) +* [Handling Form Submission](https://spring.io/guides/gs/handling-form-submission/) +* [Accessing Relational Data using JDBC with Spring](https://spring.io/guides/gs/relational-data-access/) +* [Managing Transactions](https://spring.io/guides/gs/managing-transactions/) +* [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/) +* [Validation](https://spring.io/guides/gs/validating-form-input/) + +### Maven Parent overrides + +Due to Maven's design, elements are inherited from the parent POM to the project POM. +While most of the inheritance is fine, it also inherits unwanted elements like `` and `` from the parent. +To prevent this, the project POM contains empty overrides for these elements. +If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. + diff --git a/Sprint 2/prototype2/mvnw b/Sprint 2/prototype2/mvnw new file mode 100644 index 000000000..19529ddf8 --- /dev/null +++ b/Sprint 2/prototype2/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/Sprint 2/prototype2/mvnw.cmd b/Sprint 2/prototype2/mvnw.cmd new file mode 100644 index 000000000..249bdf382 --- /dev/null +++ b/Sprint 2/prototype2/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/Sprint 2/prototype2/pom.xml b/Sprint 2/prototype2/pom.xml new file mode 100644 index 000000000..314b1f27f --- /dev/null +++ b/Sprint 2/prototype2/pom.xml @@ -0,0 +1,136 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.4 + + + com.jydoc + deliverable4 + 0.0.1-SNAPSHOT + prototype2 + Demo project for Spring Boot + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-web + + + io.github.wimdeblauwe + htmx-spring-boot-thymeleaf + 4.0.1 + + + org.springframework.session + spring-session-jdbc + + + org.thymeleaf.extras + thymeleaf-extras-springsecurity6 + + + + + javax.validation + validation-api + 2.0.1.Final + + + + + org.hibernate.validator + hibernate-validator + 6.2.5.Final + + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java new file mode 100644 index 000000000..6b2f13cd0 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java @@ -0,0 +1,21 @@ +package com.jydoc.deliverable4.DTO; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; + +public record LoginDTO( + @NotBlank(message = "Username or email is required") + String username, + + @NotBlank(message = "Password is required") + @Size(min = 8, message = "Password must be at least 8 characters") + String password +) { + public static LoginDTO empty() { + return new LoginDTO("", ""); + } + + public String getNormalizedUsername() { + return username.trim().toLowerCase(); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java new file mode 100644 index 000000000..fb5616c83 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java @@ -0,0 +1,42 @@ +package com.jydoc.deliverable4.DTO; + +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.Pattern; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Size; + + +@Data +@Getter +@Setter +public class UserDTO { + + // Getters and Setters + @NotEmpty(message = "Username is required") + @Size(min = 3, max = 20, message = "Username must be 3-20 characters") + private String username; + + @NotEmpty(message = "Password is required") + @Size(min = 6, message = "Password must be at least 6 characters") + @Pattern(regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).{8,}$", + message = "Password must contain uppercase, lowercase, and number") + private String password; + + @Email(message = "Invalid email format") + @NotEmpty(message = "Email is required") + private String email; + + @NotEmpty(message= "Invalid first name") + private String firstName; + + @NotEmpty(message= "Invalid last name") + private String lastName; + + private String authority = "ROLE_USER"; + + +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java new file mode 100644 index 000000000..8a944ec08 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java @@ -0,0 +1,33 @@ +package com.jydoc.deliverable4.Initializers; + +import com.jydoc.deliverable4.model.AuthorityModel; +import com.jydoc.deliverable4.repositories.AuthorityRepository; +import jakarta.annotation.PostConstruct; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class AuthorityInitializer { + private final AuthorityRepository authorityRepository; + + @PostConstruct + @Transactional + public void init() { + // Correct way to check if authority doesn't exist + if (!authorityRepository.findByAuthority("ROLE_USER").isPresent()) { + AuthorityModel role = new AuthorityModel(); + role.setAuthority("ROLE_USER"); + authorityRepository.save(role); + } + + // Alternative cleaner version: + authorityRepository.findByAuthority("ROLE_USER") + .orElseGet(() -> { + AuthorityModel role = new AuthorityModel(); + role.setAuthority("ROLE_USER"); + return authorityRepository.save(role); + }); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Prototype2Application.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Prototype2Application.java new file mode 100644 index 000000000..8736e4c1c --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Prototype2Application.java @@ -0,0 +1,13 @@ +package com.jydoc.deliverable4; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Prototype2Application { + + public static void main(String[] args) { + SpringApplication.run(Prototype2Application.class, args); + } + +} diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java new file mode 100644 index 000000000..880a06cfb --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java @@ -0,0 +1,161 @@ +package com.jydoc.deliverable4.Service; + +import com.jydoc.deliverable4.DTO.LoginDTO; +import com.jydoc.deliverable4.DTO.UserDTO; +import com.jydoc.deliverable4.model.AuthorityModel; +import com.jydoc.deliverable4.model.UserModel; +import com.jydoc.deliverable4.repositories.AuthorityRepository; +import com.jydoc.deliverable4.repositories.UserRepository; +import lombok.RequiredArgsConstructor; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class UserService { + private static final Logger logger = LogManager.getLogger(UserService.class); + private static final String DEFAULT_ROLE = "ROLE_USER"; + + + private final UserValidationHelper validationHelper; + private final UserRepository userRepository; + private final AuthorityRepository authorityRepository; + private final PasswordEncoder passwordEncoder; + + // Add this temporary test method to your service + public void verifyPasswordEncoding() { + String testPassword = "password123"; + String encoded = passwordEncoder.encode(testPassword); + System.out.println("Encoded password: " + encoded); + System.out.println("Matches verification: " + + passwordEncoder.matches(testPassword, encoded)); + } + + // ---------------------- Public API ---------------------- + + @Transactional + public void registerNewUser(UserDTO userDto) { + validateRegistration(userDto); + UserModel user = buildUserFromDto(userDto); + assignDefaultRole(user); + userRepository.save(user); + } + + @Transactional(readOnly = true) + public UserModel authenticate(LoginDTO loginDto) { + if (loginDto == null) { + throw new IllegalArgumentException("Login credentials cannot be null"); + } + return authenticateUser(loginDto.username(), loginDto.password()); + } + + @Transactional(readOnly = true) + public UserModel validateLogin(LoginDTO loginDto) { + String credential = loginDto.username().trim().toLowerCase(); + String rawPassword = loginDto.password(); + + logger.debug("Login attempt for: {}", credential); + + UserModel user = userRepository.findByUsernameOrEmail(credential) + .orElseThrow(() -> { + logger.warn("Login failed - user not found: {}", credential); + return new AuthenticationException("Invalid credentials"); + }); + + if (!passwordEncoder.matches(rawPassword, user.getPassword())) { + logger.warn("Login failed - password mismatch for user: {}", user.getUsername()); + throw new AuthenticationException("Invalid credentials"); + } + + logger.info("Login successful for user: {}", user.getUsername()); + return user; + } + + // ---------------------- Core Business Logic ---------------------- + + private UserModel buildUserFromDto(UserDTO userDto) { + return UserModel.builder() + .username(userDto.getUsername().trim()) + .password(passwordEncoder.encode(userDto.getPassword())) + .email(userDto.getEmail().toLowerCase().trim()) + .enabled(true) + .build(); + } + + @Transactional + protected void assignDefaultRole(UserModel user) { + authorityRepository.findByAuthority("ROLE_USER") + .ifPresentOrElse( + user::addAuthority, + () -> { + AuthorityModel newRole = new AuthorityModel("ROLE_USER"); + user.addAuthority(authorityRepository.save(newRole)); + } + ); + } + + @Transactional(readOnly = true) + protected UserModel authenticateUser(String usernameOrEmail, String password) { + UserModel user = findActiveUser(usernameOrEmail) + .orElseThrow(() -> new AuthenticationException("Invalid credentials")); + + if (!passwordEncoder.matches(password, user.getPassword())) { + throw new AuthenticationException("Invalid credentials"); + } + return user; + } + + // ---------------------- Validation Methods ---------------------- + + private void validateRegistration(UserDTO userDto) { + + validationHelper.validateUserRegistration(userDto); + } + + // ---------------------- Utility Methods ---------------------- + + @Transactional(readOnly = true) + public Optional findActiveUser(String usernameOrEmail) { + return userRepository.findByUsernameOrEmail(usernameOrEmail.trim().toLowerCase()) + .filter(UserModel::isEnabled); + } + + @Transactional(readOnly = true) + public boolean usernameExists(String username) { + return userRepository.existsByUsername(username.trim()); + } + + @Transactional(readOnly = true) + public boolean emailExists(String email) { + return userRepository.existsByEmail(email.trim().toLowerCase()); + } + + // ---------------------- Custom Exceptions ---------------------- + + public static class AuthenticationException extends RuntimeException { + public AuthenticationException(String message) { + super(message); + logger.error("Authentication failed: {}", message); + } + } + + public static class UsernameExistsException extends RuntimeException { + public UsernameExistsException(String username) { + super(String.format("Username '%s' already exists", username)); + logger.warn("Registration attempt with existing username: {}", username); + } + } + + public static class EmailExistsException extends RuntimeException { + public EmailExistsException(String email) { + super(String.format("Email '%s' is already registered", email)); + logger.warn("Registration attempt with existing email: {}", email); + } + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserValidationHelper.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserValidationHelper.java new file mode 100644 index 000000000..c43b009de --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserValidationHelper.java @@ -0,0 +1,42 @@ +package com.jydoc.deliverable4.Service; + +import com.jydoc.deliverable4.DTO.UserDTO; +import com.jydoc.deliverable4.security.Exceptions.EmailExistsException; +import com.jydoc.deliverable4.security.Exceptions.UsernameExistsException; +import com.jydoc.deliverable4.repositories.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +class UserValidationHelper { + private final UserRepository userRepository; + + @Transactional(readOnly = true) + public void validateUserRegistration(UserDTO userDto) { + if (userDto == null) { + throw new IllegalArgumentException("User data cannot be null"); + } + + String username = userDto.getUsername().trim(); + if (existsByUsername(username)) { + throw new UsernameExistsException(username); + } + + String email = userDto.getEmail().trim().toLowerCase(); + if (existsByEmail(email)) { + throw new EmailExistsException(email); + } + } + + @Transactional(readOnly = true) + public boolean existsByUsername(String username) { + return userRepository.existsByUsername(username); + } + + @Transactional(readOnly = true) + public boolean existsByEmail(String email) { + return userRepository.existsByEmail(email); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java new file mode 100644 index 000000000..b18395422 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java @@ -0,0 +1,134 @@ +package com.jydoc.deliverable4.config; + +import com.jydoc.deliverable4.security.auth.CustomUserDetailsService; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.csrf.CookieCsrfTokenRepository; +import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession; + +@Configuration +@EnableWebSecurity +@EnableJdbcHttpSession +public class SecurityConfig { + + private final CustomUserDetailsService userDetailsService; + + public SecurityConfig(CustomUserDetailsService userDetailsService) { + this.userDetailsService = userDetailsService; + } + + // Public endpoints configuration + private static final String[] PUBLIC_ENDPOINTS = { + "/", + "/home", + "/login", + "/register", + "/css/**", + "/js/**", + "/images/**", + "/error", + "/webjars/**", + "/api/public/**" + }; + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http + // CSRF configuration (enabled for forms, disabled for APIs) + .csrf(csrf -> csrf + .ignoringRequestMatchers("/api/**") + .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) + ) + + // Security headers + .headers(headers -> headers + .frameOptions(frame -> frame.sameOrigin()) + .httpStrictTransportSecurity(hsts -> hsts + .includeSubDomains(true) + .maxAgeInSeconds(31536000) // 1 year + ) + ) + + // Authorization configuration + .authorizeHttpRequests(auth -> auth + .requestMatchers(PUBLIC_ENDPOINTS).permitAll() + .requestMatchers("/dashboard").authenticated() + .requestMatchers("/user/**").hasAuthority("ROLE_USER") + .requestMatchers("/admin/**").hasAuthority("ROLE_ADMIN") + .requestMatchers("/api/user/**").hasAuthority("ROLE_USER") + .requestMatchers("/api/admin/**").hasAuthority("ROLE_ADMIN") + .anyRequest().authenticated() + ) + + // Form login configuration + .formLogin(form -> form + .loginPage("/login") + .loginProcessingUrl("/perform_login") + .defaultSuccessUrl("/dashboard", true) + .failureUrl("/login?error=true") + .usernameParameter("username") + .passwordParameter("password") + .permitAll() + ) + + // Logout configuration + .logout(logout -> logout + .logoutUrl("/perform_logout") + .logoutSuccessUrl("/login?logout") + .deleteCookies("JSESSIONID", "XSRF-TOKEN") + .invalidateHttpSession(true) + .clearAuthentication(true) + .permitAll() + ) + + // Session management (stateful) + .sessionManagement(session -> session + .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) + .invalidSessionUrl("/login?invalid-session") + .maximumSessions(1) + .maxSessionsPreventsLogin(false) + .expiredUrl("/login?session-expired") + ) + + // Exception handling + .exceptionHandling(exceptions -> exceptions + .accessDeniedPage("/access-denied") + ) + + // Set the custom UserDetailsService + .userDetailsService(userDetailsService); + + return http.build(); + } + + @Bean + public AuthenticationManager authenticationManager( + AuthenticationConfiguration authenticationConfiguration) throws Exception { + return authenticationConfiguration.getAuthenticationManager(); + } + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + private void configureFormLogin(HttpSecurity http) throws Exception { + http.formLogin(form -> form + .loginPage("/login") + .loginProcessingUrl("/perform_login") + .usernameParameter("usernameOrEmail") // Update parameter name + .passwordParameter("password") + .defaultSuccessUrl("/dashboard", true) + .failureUrl("/login?error=true") + .permitAll() + ); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SessionConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SessionConfig.java new file mode 100644 index 000000000..84f130e1b --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SessionConfig.java @@ -0,0 +1,4 @@ +package com.jydoc.deliverable4.config; + +public class SessionConfig { +} diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java new file mode 100644 index 000000000..0a2d2ddcf --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java @@ -0,0 +1,114 @@ +package com.jydoc.deliverable4.controllers; + +import com.jydoc.deliverable4.DTO.UserDTO; +import com.jydoc.deliverable4.DTO.LoginDTO; +import com.jydoc.deliverable4.model.UserModel; // Changed from org.apache.catalina.User +import com.jydoc.deliverable4.Service.UserService; // Added service dependency +import jakarta.servlet.http.HttpSession; +import jakarta.validation.Valid; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; + +@Controller +public class AuthController { + + private final UserService userService; + private final Logger logger = LoggerFactory.getLogger(AuthController.class); + // Constructor injection for UserService + public AuthController(UserService userService) { + this.userService = userService; + } + + /* ---------------------- Registration ---------------------- */ + + @GetMapping("/register") + public String showRegistrationForm(Model model) { + model.addAttribute("user", new UserDTO()); + return "register"; + } + + @PostMapping("/register") + public String registerUser(@Valid @ModelAttribute("user") UserDTO userDto, + BindingResult result) { + if (result.hasErrors()) { + return "register"; + } + + // Register the user + userService.registerNewUser(userDto); + return "redirect:/login?registered"; + } + + /* ---------------------- Login ---------------------- */ + + @GetMapping("/login") + public String showLoginForm(Model model, + @RequestParam(required = false) String error, + @RequestParam(required = false) String registered, + @RequestParam(required = false) String logout) { + + + model.addAttribute("loginData", LoginDTO.empty()); + + // Add the parameters as model attributes for Thymeleaf + model.addAttribute("error", error != null); + model.addAttribute("registered", registered != null); + model.addAttribute("logout", logout != null); + + return "login"; + } + + @PostMapping("/login") + public String loginUser(@Valid @ModelAttribute("loginData") LoginDTO loginDto, + BindingResult result, + HttpSession session, + RedirectAttributes redirectAttributes) { + + logger.debug("Login attempt with data: {}", loginDto); + + if (result.hasErrors()) { + logger.debug("Validation errors: {}", result.getAllErrors()); + return "login"; + } + + try { + UserModel user = userService.validateLogin(loginDto); + session.setAttribute("user", user); + logger.info("Login successful for: {}", user.getUsername()); + return "redirect:/home"; + } catch (UserService.AuthenticationException e) { + logger.error("Login failed: {}", e.getMessage()); + redirectAttributes.addFlashAttribute("error", "Invalid credentials"); + return "redirect:/login?error"; + } + } + + /* ---------------------- Home Page ---------------------- */ + + @GetMapping("/home") + public String showHomePage(Model model, HttpSession session) { + UserModel user = (UserModel) session.getAttribute("user"); + if (user != null) { + model.addAttribute("username", user.getUsername()); + } + return "index"; + } + + /* ---------------------- Logout ---------------------- */ + + @GetMapping("/confirm-logout") + public String showLogoutConfirmation() { + return "logout"; // Shows the confirmation page + } + + @PostMapping("/logout") + public String performLogout(HttpSession session) { + session.invalidate(); + return "redirect:/login?logout"; + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/CustomErrorController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/CustomErrorController.java new file mode 100644 index 000000000..deb78980e --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/CustomErrorController.java @@ -0,0 +1,48 @@ +package com.jydoc.deliverable4.controllers; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.http.HttpServletRequest; +import org.springframework.boot.web.servlet.error.ErrorController; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.Date; + +@Controller +public class CustomErrorController implements ErrorController { + + @RequestMapping("/error") + public String handleError(HttpServletRequest request, Model model) { + // Get error status + Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); + Object exception = request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); + + HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; + if (status != null) { + httpStatus = HttpStatus.valueOf(Integer.parseInt(status.toString())); + } + + // Add error information to model + model.addAttribute("status", httpStatus.value()); + model.addAttribute("error", httpStatus.getReasonPhrase()); + model.addAttribute("message", getErrorMessage(exception)); + model.addAttribute("path", request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI)); + model.addAttribute("timestamp", new Date()); + + return "error"; + } + + private String getErrorMessage(Object exception) { + if (exception != null) { + Throwable ex = (Throwable) exception; + // Customize message for specific errors + if (ex.getMessage().contains("Field 'authority' doesn't have a default value")) { + return "Database error: Required role configuration is missing. Please contact support."; + } + return ex.getMessage(); + } + return "Unknown error occurred"; + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/DashboardController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/DashboardController.java new file mode 100644 index 000000000..6a8d02b9e --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/DashboardController.java @@ -0,0 +1,25 @@ +package com.jydoc.deliverable4.controllers; + +import org.springframework.security.core.Authentication; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class DashboardController { + + @GetMapping("/dashboard") + public String showDashboard(Authentication authentication, Model model) { + // Get user details from Spring Security + UserDetails userDetails = (UserDetails) authentication.getPrincipal(); + + // Add user info to model + model.addAttribute("username", userDetails.getUsername()); + model.addAttribute("authorities", userDetails.getAuthorities()); + model.addAttribute("isAdmin", userDetails.getAuthorities().stream() + .anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN"))); + + return "dashboard"; + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/AuthorityModel.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/AuthorityModel.java new file mode 100644 index 000000000..f4cf5dd54 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/AuthorityModel.java @@ -0,0 +1,36 @@ +package com.jydoc.deliverable4.model; + +import jakarta.persistence.*; +import lombok.*; +import java.util.HashSet; +import java.util.Set; + +@Entity +@Table(name = "authorities") +@Getter @Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder(toBuilder = true) +public class AuthorityModel { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false, unique = true, length = 50) + private String authority; + + @ManyToMany(mappedBy = "authorities") + @Builder.Default + private Set users = new HashSet<>(); + + // Added constructor + public AuthorityModel(String authority) { + this.authority = authority; + } + + // Custom builder + public static class AuthorityModelBuilder { + private Set users = new HashSet<>(); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthority.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthority.java new file mode 100644 index 000000000..3d42c138b --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthority.java @@ -0,0 +1,23 @@ +package com.jydoc.deliverable4.model; + +import jakarta.persistence.*; + +@Entity +@Table(name = "user_authorities") +@IdClass(UserAuthorityId.class) +public class UserAuthority { + + @Id + @Column(name = "user_id") + private Long userId; + + @Id + @Column(name = "authority_id") + private Long authorityId; + + // Getters and setters + public Long getUserId() { return userId; } + public void setUserId(Long userId) { this.userId = userId; } + public Long getAuthorityId() { return authorityId; } + public void setAuthorityId(Long authorityId) { this.authorityId = authorityId; } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthorityId.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthorityId.java new file mode 100644 index 000000000..97d3c1661 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthorityId.java @@ -0,0 +1,31 @@ +package com.jydoc.deliverable4.model; + +import java.io.Serializable; +import java.util.Objects; + +public class UserAuthorityId implements Serializable { + private Long userId; + private Long authorityId; + + public UserAuthorityId() {} + + public UserAuthorityId(Long userId, Long authorityId) { + this.userId = userId; + this.authorityId = authorityId; + } + + // equals() and hashCode() + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + UserAuthorityId that = (UserAuthorityId) o; + return Objects.equals(userId, that.userId) && + Objects.equals(authorityId, that.authorityId); + } + + @Override + public int hashCode() { + return Objects.hash(userId, authorityId); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java new file mode 100644 index 000000000..92ce65c68 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java @@ -0,0 +1,59 @@ +package com.jydoc.deliverable4.model; + +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; + +import java.util.HashSet; +import java.util.Set; + +@Entity +@Table(name = "users") +@Getter @Setter +@NoArgsConstructor +@AllArgsConstructor +@Builder(toBuilder = true) +public class UserModel { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(unique = true, nullable = false, length = 50) + private String username; + + @Column(nullable = false, length = 100) + private String password; + + @Column(unique = true, length = 100) + private String email; + + private boolean enabled; + + @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE}) + @JoinTable( + name = "user_authorities", + joinColumns = @JoinColumn(name = "user_id"), + inverseJoinColumns = @JoinColumn(name = "authority_id") + ) + @Fetch(FetchMode.JOIN) // Improves eager loading performance + @Builder.Default + private Set authorities = new HashSet<>(); + + // Improved authority management + public void addAuthority(AuthorityModel authority) { + this.authorities.add(authority); + authority.getUsers().add(this); + } + + public void removeAuthority(AuthorityModel authority) { + this.authorities.remove(authority); + authority.getUsers().remove(this); + } + + // Custom builder to handle collections + public static class UserModelBuilder { + private Set authorities = new HashSet<>(); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/AuthorityRepository.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/AuthorityRepository.java new file mode 100644 index 000000000..2ea69f03b --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/AuthorityRepository.java @@ -0,0 +1,19 @@ +package com.jydoc.deliverable4.repositories; + +import com.jydoc.deliverable4.model.AuthorityModel; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; +import java.util.Optional; + +public interface AuthorityRepository extends JpaRepository { + + // Return full AuthorityModel objects instead of just authority strings + @Query("SELECT a FROM AuthorityModel a JOIN a.users u WHERE u.id = :userId") + List findAuthoritiesByUserId(@Param("userId") Long userId); + + // Keep this as is since it returns full entities + Optional findByAuthority(String authority); +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserAuthorityRepository.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserAuthorityRepository.java new file mode 100644 index 000000000..4cb874e8b --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserAuthorityRepository.java @@ -0,0 +1,21 @@ +package com.jydoc.deliverable4.repositories; + +import com.jydoc.deliverable4.model.UserAuthority; +import com.jydoc.deliverable4.model.UserAuthorityId; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import java.util.List; + +public interface UserAuthorityRepository extends JpaRepository { + + // Fixed parameter name consistency + @Query("SELECT ua FROM UserAuthority ua WHERE ua.userId = :userId") + List findByUserId(@Param("userId") Long userId); + + // Fixed native query with consistent parameter naming + @Query(value = "SELECT * FROM user_authorities WHERE user_id = :userId", nativeQuery = true) + List findUserAuthoritiesByUserId(@Param("userId") Long userId); + + +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserRepository.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserRepository.java new file mode 100644 index 000000000..c7958be34 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserRepository.java @@ -0,0 +1,33 @@ +package com.jydoc.deliverable4.repositories; + +import com.jydoc.deliverable4.model.UserModel; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import java.util.Optional; + +public interface UserRepository extends JpaRepository { + + // Standard username lookup + Optional findByUsername(String username); + + // Username lookup with authorities eager loading + @Query("SELECT DISTINCT u FROM UserModel u LEFT JOIN FETCH u.authorities WHERE u.username = :username") + Optional findByUsernameWithAuthorities(@Param("username") String username); + + // Existence checks + boolean existsByUsername(String username); + boolean existsByEmail(String email); + + // Combined username/email lookup (basic) + @Query("SELECT u FROM UserModel u WHERE LOWER(u.username) = LOWER(:credential) OR LOWER(u.email) = LOWER(:credential)") + Optional findByUsernameOrEmail(@Param("credential") String credential); + + + + + // Combined username/email lookup with authorities eager loading + @Query("SELECT DISTINCT u FROM UserModel u LEFT JOIN FETCH u.authorities " + + "WHERE u.username = :credential OR u.email = :credential") + Optional findByUsernameOrEmailWithAuthorities(@Param("credential") String credential); +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.java new file mode 100644 index 000000000..b3abc3583 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.java @@ -0,0 +1,7 @@ +package com.jydoc.deliverable4.security.Exceptions; + +public class EmailExistsException extends RuntimeException { + public EmailExistsException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.java new file mode 100644 index 000000000..8eda3f5dc --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.java @@ -0,0 +1,7 @@ +package com.jydoc.deliverable4.security.Exceptions; + +public class UsernameExistsException extends RuntimeException { + public UsernameExistsException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java new file mode 100644 index 000000000..ccdcc5525 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java @@ -0,0 +1,76 @@ +package com.jydoc.deliverable4.security.auth; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Collection; +import java.util.Objects; + +public class CustomUserDetails implements UserDetails { + private final Long userId; + private final String username; + private final String password; + private final boolean enabled; + private final Collection authorities; + + public CustomUserDetails(Long userId, String username, String password, + boolean enabled, Collection authorities) { + this.userId = userId; + this.username = username; + this.password = password; + this.enabled = enabled; + this.authorities = authorities; + } + + public Long getUserId() { + return userId; + } + + @Override + public Collection getAuthorities() { + return authorities; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public String getUsername() { + return username; + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CustomUserDetails that = (CustomUserDetails) o; + return Objects.equals(username, that.username); + } + + @Override + public int hashCode() { + return Objects.hash(username); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java new file mode 100644 index 000000000..c477abf15 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java @@ -0,0 +1,45 @@ +package com.jydoc.deliverable4.security.auth; + +import com.jydoc.deliverable4.model.UserModel; +import com.jydoc.deliverable4.repositories.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Set; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class CustomUserDetailsService implements UserDetailsService { + + private final UserRepository userRepository; + + @Override + @Transactional(readOnly = true) + public UserDetails loadUserByUsername(String usernameOrEmail) { + return userRepository.findByUsernameOrEmailWithAuthorities(usernameOrEmail) + .map(this::mapToUserDetails) + .orElseThrow(() -> new UsernameNotFoundException( + "User not found with username or email: " + usernameOrEmail)); + } + + private UserDetails mapToUserDetails(UserModel user) { + Set authorities = user.getAuthorities().stream() + .map(auth -> new SimpleGrantedAuthority(auth.getAuthority())) + .collect(Collectors.toSet()); + + return new CustomUserDetails( + user.getId(), + user.getUsername(), + user.getPassword(), + user.isEnabled(), + authorities + ); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/application.properties b/Sprint 2/prototype2/src/main/resources/application.properties new file mode 100644 index 000000000..9831fc116 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/application.properties @@ -0,0 +1,27 @@ +spring.application.name=prototype2 +spring.jpa.hibernate.ddl-auto=create-drop +spring.datasource.url=jdbc:mysql://localhost:3306/userdatabase +spring.datasource.username=root +spring.datasource.password= +spring.datasource.driverClassName=com.mysql.jdbc.Driver +# Enable JDBC Session Storage +spring.session.store-type=jdbc +# Auto-create session tables (for development only) +#Disable in production +spring.session.jdbc.initialize-schema=never + +# Optional: Show SQL queries (for debugging) +spring.jpa.show-sql=true +logging.level.org.springframework.jdbc.core=DEBUG + +# Sessions +# 30 minute timeout +server.servlet.session.timeout=30m + +logging.level.org.hibernate.SQL=DEBUG +logging.level.org.hibernate.type=TRACE +spring.jpa.properties.hibernate.format_sql=true + +logging.level.com.jydoc=DEBUG +logging.level.org.springframework.security=DEBUG + diff --git a/Sprint 2/prototype2/src/main/resources/static/css/styles.css b/Sprint 2/prototype2/src/main/resources/static/css/styles.css new file mode 100644 index 000000000..ff30abe6f --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/static/css/styles.css @@ -0,0 +1,107 @@ +body { + font-family: Arial, sans-serif; + line-height: 1.6; + margin: 0; + padding: 20px; +} + +.error { + color: red; +} + +.success { + color: green; +} + +form { + max-width: 400px; + margin: 20px 0; +} + +form div { + margin-bottom: 10px; +} + +label { + display: inline-block; + width: 100px; +} + +/* Logout Page Styles */ +.logout-container { + max-width: 500px; + margin: 2rem auto; + padding: 2rem; + text-align: center; + border: 1px solid #ddd; + border-radius: 8px; +} + +.btn-logout { + background-color: #dc3545; + color: white; + padding: 0.5rem 1rem; + border: none; + border-radius: 4px; + cursor: pointer; + margin-right: 1rem; +} + +.btn-cancel { + padding: 0.5rem 1rem; + border: 1px solid #ddd; + border-radius: 4px; + text-decoration: none; + color: #333; +} + +.btn-logout:hover { + background-color: #c82333; +} + +.btn-cancel:hover { + background-color: #f8f9fa; +} + +/* Custom styles */ +body { + min-height: 100vh; + display: flex; + flex-direction: column; +} + +main { + flex: 1; +} + +.btn-lg { + min-width: 180px; +} + +.shadow-sm { + box-shadow: 0 .125rem .25rem rgba(0,0,0,.075) !important; +} + +/* Animation for buttons */ +.btn { + transition: all 0.3s ease; +} + +.btn:hover { + transform: translateY(-2px); + box-shadow: 0 4px 8px rgba(0,0,0,0.1); +} + +/* Footer styling */ +footer { + box-shadow: 0 -2px 5px rgba(0,0,0,0.05); +} + +footer a { + transition: color 0.2s ease; +} + +footer a:hover { + color: #0d6efd !important; + text-decoration: underline; +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/static/js/script.js b/Sprint 2/prototype2/src/main/resources/static/js/script.js new file mode 100644 index 000000000..e69de29bb diff --git a/Sprint 2/prototype2/src/main/resources/templates/dashboard.html b/Sprint 2/prototype2/src/main/resources/templates/dashboard.html new file mode 100644 index 000000000..dd5e20291 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/dashboard.html @@ -0,0 +1,163 @@ + + + + + + User Dashboard + + + + + + + + +
+
+ +
+
+
+ User Profile +
+
+

Username:

+

Roles: + +

+
+
+ + +
+
+ Quick Actions +
+ +
+
+ + +
+
+
+
+
+ Dashboard Overview +
+
+
Welcome to your dashboard
+

Here you can manage your account and access all system features.

+
+
+
+
+ + +
+
+
+
+
Documents
+

24

+ View all +
+
+
+
+
+
+
Tasks
+

5

+ View tasks +
+
+
+
+
+
+
Notifications
+

3

+ View alerts +
+
+
+
+ + +
+
+
+
+ Admin Tools +
+
+
+
+
+
+
User Management
+

Manage all system users and permissions

+ Go to Users +
+
+
+
+
+
+
System Reports
+

View system analytics and reports

+ View Reports +
+
+
+
+
+
+
Audit Logs
+

Review system activity logs

+ View Logs +
+
+
+
+
+
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/error.html b/Sprint 2/prototype2/src/main/resources/templates/error.html new file mode 100644 index 000000000..38d4e6ba1 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/error.html @@ -0,0 +1,41 @@ + + + + + Error Page + + + + +
+
+

⚠️ Oops! Something went wrong

+

We're sorry, but an error occurred while processing your request.

+ +
+

Error Type

+

Error message

+

Request path:

+

Status code:

+

Timestamp:

+
+ +
+ Go to Home Page + +
+
+
+ + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/fragments/footer.html b/Sprint 2/prototype2/src/main/resources/templates/fragments/footer.html new file mode 100644 index 000000000..f42441320 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/fragments/footer.html @@ -0,0 +1,39 @@ + + + +
+
+
+ +
+ © 2023 Application Name. All rights reserved. +
+ + +
+ +
+
+ + +
+
+ v1.0.0 +
+
+
+
+ + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/fragments/header.html b/Sprint 2/prototype2/src/main/resources/templates/fragments/header.html new file mode 100644 index 000000000..0b9dbc379 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/fragments/header.html @@ -0,0 +1,101 @@ + + + + + Navigation + + + +
+ +
+ + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/index.html b/Sprint 2/prototype2/src/main/resources/templates/index.html new file mode 100644 index 000000000..c35664607 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/index.html @@ -0,0 +1,89 @@ + + + + + + Welcome to Our App + + + + +
+ +
+
+
+

Welcome to Our Platform

+

Manage your account and access premium features

+ +
+ + + Dashboard + + + + + Register + + + + + Login + + + +
+ + +
+
+
+
+ +
+
+
+

Features

+
    +
  • Secure authentication
  • +
  • User dashboard
  • +
  • Responsive design
  • +
+
+
+
+
+

Get Started

+

Join our platform today to access all features.

+ + Create Account + + + Go to Dashboard + +
+
+
+
+ +
+ + + + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/login.html b/Sprint 2/prototype2/src/main/resources/templates/login.html new file mode 100644 index 000000000..972c137c7 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/login.html @@ -0,0 +1,45 @@ + + + + + Login + + + +
+ +
+

Login

+ + +
+ Invalid username/email or password +
+
+ You have been logged out +
+
+ Your session has expired. Please login again. +
+ + +
+
+ + + +
+
+ + +
+ +
+ +

Don't have an account? Register here

+
+ + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/logout.html b/Sprint 2/prototype2/src/main/resources/templates/logout.html new file mode 100644 index 000000000..f68ec77a1 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/logout.html @@ -0,0 +1,26 @@ + + + + + Logout + + + +
+ +
+

Are you sure you want to log out?

+ + +
+ + +
+ + + Cancel +
+ +
+ + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/register.html b/Sprint 2/prototype2/src/main/resources/templates/register.html new file mode 100644 index 000000000..f4e1ee768 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/register.html @@ -0,0 +1,34 @@ + + + + + Register + + + +
+ +
+

Register

+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +

Already have an account? Login here

+
+ + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/Prototype2ApplicationTests.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/Prototype2ApplicationTests.java new file mode 100644 index 000000000..dbc67b6da --- /dev/null +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/Prototype2ApplicationTests.java @@ -0,0 +1,13 @@ +package com.jydoc.deliverable4; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Prototype2ApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/Sprint 2/prototype2/target/classes/application.properties b/Sprint 2/prototype2/target/classes/application.properties new file mode 100644 index 000000000..b4b512501 --- /dev/null +++ b/Sprint 2/prototype2/target/classes/application.properties @@ -0,0 +1,27 @@ +spring.application.name=prototype2 +spring.jpa.hibernate.ddl-auto=create-drop +spring.datasource.url=jdbc:mysql://localhost:3306/userdatabase +spring.datasource.username=root +spring.datasource.password=JYDOC +spring.datasource.driverClassName=com.mysql.jdbc.Driver +# Enable JDBC Session Storage +spring.session.store-type=jdbc +# Auto-create session tables (for development only) +#Disable in production +spring.session.jdbc.initialize-schema=never + +# Optional: Show SQL queries (for debugging) +spring.jpa.show-sql=true +logging.level.org.springframework.jdbc.core=DEBUG + +# Sessions +# 30 minute timeout +server.servlet.session.timeout=30m + +logging.level.org.hibernate.SQL=DEBUG +logging.level.org.hibernate.type=TRACE +spring.jpa.properties.hibernate.format_sql=true + +logging.level.com.jydoc=DEBUG +logging.level.org.springframework.security=DEBUG + diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/DTO/LoginDTO.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/DTO/LoginDTO.class new file mode 100644 index 0000000000000000000000000000000000000000..e3c73b707dbe83499c0cef1c11bc92e9da76e172 GIT binary patch literal 2503 zcma)8?NZxD6g_JjB#el`e6*w`Q4>gPlSHLW+9alF12hS#`6v)NZGSEH4hSr*E6HTY zGxbL^(g28^*>W(!%vig7_nv$2**$lM|NcMy7r4H*Li7-Sed z@Hd7zP(@*A5;rqzlE}A?O&=kToz2gW-BrI@aMyO;)X%sN2WF<9l^+ z*IL=xuqtxjc4@+(H+|u`+z|}SxU|H7ad<^uwy|H&FszJH<8^iQg(+zA#?ApFfm-yIqWxxYlx)fLuIO1Nwtz%xdYb~=?rLDl@ zwj21?x(t>`HAiIz%@MxO_leBRi|F1>>6yaecHOjn)1zu_Pmr=^x-;&aG`h1+Y({G6 zhRt16%(neXP$6l@cGGlBI>U{2B&X>I=AJNlVAchv`F*o`z&&0Kghxa(;Wgwcwky_~ z&Ytjgl%kbzWtG==xo4|&WXuEyHi72)5&>y(O#}zBwn^z65$3zreFW{TuG1e7P9r!` zEl}(;)8xJg)}`mrWxW!$_!?R*yvi_{Y^8((nCx!QXp14cEt_6dJh9bDjKqz7N3}Ak zFMcRSm!u4oA{rr2U&m91vAFrmac}2HBlH`|4dSOPDp=F7ZeRnO3|Bj^gBPmN3X6y$ zG7Rm-Nf=%ydD!l;JQ7yu_>8-?y6|T!QXVxM<%HnF&P`e(pifcf z>Y=8wM5|#i%+v3dkK4FIh7quFbWC~m2uHrtG)BG_zNE#%D!x+4uUp6&q&i58rrj<& zWuaFa8Qi5bYXnz~m@B;lE6u-wR=V{DBd^Jn!ae#9lDqnTLtis=#kaUmD+09$sQp}2 z-UFHsrO2#IXq7XM^b}2Fa#Q3U7q8~s#XTg?xfG?0-Or~wgfbS%Q?ZyOHtNs#2l}u1 z(fsH;N{MH5cgv(Y5o*9&cjcIKJ6RR@dN#5 z!JzJGfYCyo(J)a;w}M&`r2%y+A0spnMLbWs6YWdBO(AnV6O8nm;9|XZ(pfa^mQ)5y x#4?3ttkAeZGu3shSCgq03pXz4p&u#IC31aEy3_Fl&#;Q0$(AMC7Iv_U>GyQ>6F~p~ literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/DTO/UserDTO.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/DTO/UserDTO.class new file mode 100644 index 0000000000000000000000000000000000000000..0d388210304043fdbcf6c3391c92d08d2c185785 GIT binary patch literal 5163 zcmb_gTW=f375j}%uZjwyg0p(Mh0C;s4BAPRPL&OT)I%a zZ0QZYX{|NwRkLB(_Z0Naw#Qqv8%BL)GDFH<72D9KAXV1t({DDls)B*x0Mwn@{hDDDRJUxcZd(f83C6>7Z?nVyFHJ}+W$6#A zI3nwwYI<=OObCl~|C`I{_isPb;>k>!NOsY5`n)FRSh@w5I;*?`t^&+Ssx6rKH zMonKbEQ8r}x?VSJ%{CYc1qU4m?-p-sRiol4i)D#XLo*nq;=IXqTet5`DoECJ%hFaP zGyEjU8&)h6!0KH`d}C$4znwaUn$w_X~5yP)7$=Oh?rn?cSu z*Vpw%S+n%drdmogB&EG#fRI^=F&Y9}ElY zh7Wa;C+}|gZN5@+$J52!ebqB-)b)91LYJf@N#!xiT6IZl7}EBXF?-eES`}uuu4A0< zZf{9BY)ESM%~s9Y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hp7FwUo&hvm3FJ;NfC5NE!dbxk;qfQsuzki6Y*9IHN`A0P!e?(@8P_K>kPSWJ)?|> z0K+6LW#X8cz?Hsu+-~lPV8?Vg71LEU?p1jp%{dnK2Fl!BPs{zR`jse%ekMbP`)Otg za#AQ`7_MkuYi#gV3}tG&?Q7W-RT)YGxa|8%bHgMBx=hX5;DP22KNUM$D%54V)>UpxIF0;sI|8O~Zm=ItIS(ADsa`?|Q1a zry92I(;b#;%}H1VJNyP zIB>$2dGz}R^fxMKI3Yn7N*}j`Q&!EE^65DfuH1@Jnh52sD9td3Rfcgw_xFA)jrL(J zOSAQnjR#oDVQI7!@^@5o7keVb*-d-q#D9;J9(3HzEAb(4A3Fsv3vR>`F>-g z2+Jex*F6!=xk@$Ktx^I}Jkb)8*9>dwBh2iQyI5{gl3r`qk->gd0Gva~xi^&HdYdf_E5X0V&kEWW}Okp8>7KXyFdq~BRs^gD)g z7^gu#fs2?#k>ZswjU`;dExMhgm{X+jK0Y8c6dkwmA*~}I(CVn8jDCh_Q177|4D{M76l(5E}~p}DOY2++)2^ES)p^8KAZNR Vk*81b5bOAYBw3PdV+U1C{RNX=YLWl| literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Prototype2Application.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Prototype2Application.class new file mode 100644 index 0000000000000000000000000000000000000000..52aa797dcf7df18fc4154ae82e2279f052e96cdd GIT binary patch literal 763 zcmb7CO;6iE5PcgG970+kw0yNa^cJFul@RJB2q}%k$+U=|aOi36EM`-CH(IZu{H&ge zdgu@6kE%Lrknq8mTJnr$X6Mb!oB8wi*KYtLyz8KWr2x$?T3BXSpNm_;Q=t?7C7R3F zF)SY|t=tL2Qh$FMpv~|hHW{Da&rHl`GF7+IiYS#w{M;I6-2Flxjuwkl#lk70JLq6F zK(~t*c*!s@HsSfgDxF+gk;yw_zwyWz$0wz;l1UY9p&6on_}tYv6?s1VTJcPr2OI8( zb;z;NPJVZMZ1lBCin7s433B`JkfAv?Gs&4W2Cil<$eg|q?WpJDWY(OI4rr7Pb>OF+p2Il#CrsEMgD7m`8y)H zMiwW{NVf(*!G4tCb&@^|O4%UUeSCl(HpyDSE4(HUpZu`|1KPb{@PL)8=X`&%psNb7 dTES>z3)|%1p}$2GlWJhMlzVtX+LwI``~v{s$msw8 literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$AuthenticationException.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$AuthenticationException.class new file mode 100644 index 0000000000000000000000000000000000000000..e74dbe1f496db823ebe020ef8755a4bee0cf01d0 GIT binary patch literal 794 zcmbtS+iuf95IvJiour{{0%>WvG^Ldat%P6tL=aLbAduXG2=skp56(umw_0x^5aJtv zPk|Q%4}1V0g&2oQ1OWmGTiTg3J7=!@en>y3(7NK)B_~F-gR%dbV+HoB<)IBtsm`9Va6PnZ?y@*WcN1W&h zTQx{{&+oIH=#c%VIonfRLMJAU*%CGaV`E>PsBp-BVU*Z~+#C79)TLL$0%3K3?1n4_ zhN`Ho`%LMCqZ{3quja9YmWOr|XK{|O{+DosDqCwL^Y(9=nrZXlV8o%5Ha#p8ZvT68 zTR)dNGtbI_iI}h$=!}oX>45E%Vnl>?U_zA~E2|59YOJ`S&Ixyd|4-c`cq!+(il@nb z*(G7=kloNkkCas@JGPRz(Kllo@;w=}+|O+9dch~ujyQMsP3{QI2U*7UAW?bF!d&^o z1h9dQJip>2`Q-r$S`l=J^3>ki+5G@|53hY@_ahd|cqf-7oR@P!T!7a?dLs*ei&a6( p-$_`*1wlXy7ja1fUlzSe0wAPyIZNnD?n2gZMPx&qI-+l){tZtk)yx0@ literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$EmailExistsException.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$EmailExistsException.class new file mode 100644 index 0000000000000000000000000000000000000000..737a68de3eb455c3f4ece2eed0a56710a56c9f4b GIT binary patch literal 974 zcmbtTZBG+H5Pr5VTw5xX3aAKjC|KU)zVJnBG=$V>Qo&GdLj1J7j_o%0LiV-=V*DxU zZ_qEkB>DsVQO3Da)0#BV#JgnYW_D(tooAo>@$>6<0DIWUAR%B^e5pLUv=)_Y71`3$ zB%9~9rk08fX=++X2^2cACml})E$6V&A=l(E0n0)rk1TS3?AMG|K}%rbRj7Sw1n#a^ zht(Im<(DI&i-zTmkn95@s1%ZWOo1<=Eluwm2mrjfd1BSb=0%aZu%#DHD zsAo~cWec-;%wb+&(+z#6bKVSHr%9gbk(LdQcAXmOo^r`~5s@Bzb89bbwMYxBR72fz z0Qzmhs7KX$<)%#y(Z1ZPOXE%2hVStlzU=znR1W zu3K2lV+l6|mj8kvkUEu`=PivHbA-X)q}DCi0uTRv+||AwD)Bj^5qeYmVUq-=t16&_ zuHPX2JZ4OwSPfn2)umRkKM1BwTSWqU)&ImT3#9u@#W=&;AIO7c_moUKY(A4(`owBw z%v>$(YL_0V_;7`hd)$fZ1u_Q|na5$o!puJj0@C}Qj3VO7*>RI&1lBi_zQqjQVG-|fi@o`a p23W-!d)x}QQDTsF{!R;az(pIpCa{UEzAa*#ZH|+cSVg literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$UsernameExistsException.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$UsernameExistsException.class new file mode 100644 index 0000000000000000000000000000000000000000..d8328686f28c5c3d8fe3a92799f16435272bf07e GIT binary patch literal 985 zcmbtT+iuf95Iviub&`f&0&StR#D$hLDbz20fgmI(MIf1i8mLt9v~>n&BVVHRrWYZ8 z1NaSi;Ud8Y@KK0yld3@~0ts8%*_oZ0vvYj>0;8{D9ZDl`YsEdS z?w>YZ4u$#+8?~X(AghQH&RG~QVFHr^bEj>#dy!EgZ612mH7br6?v9F-xhpVz23&2Y zfHKZoxKP40W(4Y996Ft&R_r+~3e-Mnxfjs7(uxsoCW!im8xytSh7{6`5elvzST(&S@ z!UC=cRQ>`YkUNl?N3NbR=@5x0yzW@A1@8a*#7ie~*gO`%5XrfXxJ3dJu8L@@7w(aM zp7JJ8c4JQlJ5sCE9|UuztrCF;?*BtK1o9`8rD&&07)XUB_=HS5ZatHlg=|POa>nt=A}TD(^b!2BERo?Du*?5L zhV4SVEOOtF-Oa8xKV#$*#y(=IJiGb@m$LZ42^n1FbsSk<-(m{yFpu}R#@-#1OzW|B-5byv1 literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService.class new file mode 100644 index 0000000000000000000000000000000000000000..98dc481179b31a7cf20bd9f3aa17e761d14c5a4c GIT binary patch literal 8897 zcmcIq349#aUH;x`?Uhy&d9{h{NOlt0ksVuyH>e;mDUlOkty?#Zu_oGqzwZ znHk3{%x6X}n$+MeB@SAHdm{r=zDPaTf)v^lNE^5jHz}m5E2mb9zLi&Ka!bC#=3uGq zW=?XQ&()ThA57ECTMTT)%?exd<|S*yEo4pqjO}0KUC}oSeo=#S2=G0F87**lYlLbqtO zOSsI`6*Z1K4D7*Pg`1X4$Ih9)HEGS;Mc*@h+ogDS>=|nSuA`?;XkhU=xOX~9MD`l! zLqDxQTe6*;fbN**=8yWW!o+JM(}-7|Ky@^?ak(25ZW#l2V!uK=;b_knj#_hO$?+#$ z$5QBR$ZjpAz0(p)2Mip3Fn3~h!OHqI@DE=laIeD7D(H_pjx}#OL*9HTZx#H}$FtU= z__G=JD|C&y^LC*t>sdLD*``zM%9@3O>vzpsU4@e4Byj{o28IQ`8;{rp+rKY~qZm!# zn1KiJkizW^R1!>R>by~C7HbxmPl&EPb>VjuZ#3{Gq1aqbFXGy90}~*Dlv(mGii`|K zOYo$DR8=z!!aCq@ZH8#=Mj5xnMQ+O&Z)GN;vd$J}Mh8!?NP zVCS5H89Y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Q$P5M55fhV-kRP9JzAy*M~A^RILxj!%;!7sFpgp3F2 zDsVewG~T|}WfTv2uv4HFy4VAVCR-n%yBC4deSnnAF3@UkAPrADK+7FPdiDh0WOKhG nqf&5QkZ}%2?+VhxQt0C3D2Q8RsABLebns*NEQB)E+il=~ToUCW literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/config/SecurityConfig.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/config/SecurityConfig.class new file mode 100644 index 0000000000000000000000000000000000000000..5066f228daeec30a7a2143f4feef22db4ab93763 GIT binary patch literal 13081 zcmcgyd3+nkb^e}s0EAW&1WLAL*>3F64h36;EK9OwT9PS}3Mo+{O;D04Tb7orB0N1EREk+$iTUcX-Hoi^<^vkPKLKp(r=3(HZDs5;mTOLAtZj*ulbf`s5=kpnbnU|VUi~PD z74w$cXBA94lTTXi89QYO_6%JHN#6fDVHOM1iQZzq;A9V1A?S`#kktm(AS!4}=~?y# z;@#T0X~=P>68Ra|&P`3aX4X3ExTh0yXniI<#QenVjv$8i5Y`!3k81=2OZnW)<(z_9 zu$^4utTmCCDB78{<>nIug~Ci(enE38?@kIH@4Ql$mL|hen4qErtCffw3|z0|3r$<5 z;x$Ge&@XN@aFcqmUTNHMsS_o|sP$;k$`?4T$(wewfm_tHwn@j$4mneHE{10B)vX3@ zQ?FVx&XiLu#OPHT^Ckmv1z(%D@_Fj&pqVqLtgMyelvZ!bW&>S%ighk!%_xNqn7MR@ zwo^QBQ66`v;FU!+=voQoW@*pO5;Z(#8Fi{yyUV~fY!|d>+Y8pw@fLWp4D7I|6;MVfND)N)X5&f{q^N>&(9Q`#6(JsiM_pQ7%}sCMsm78mvZR7 z5$r}&3?ZxzqnDnSpzA5E^_{!4zBx zPTx?+8n)Dubzzb#&qMcEuIsqF3U1L-Jf{q#mHi@&wmQ)a29v^F#b2uNu1p|-a@y5;JGhJDqgXUQ8uigtq`pBY-vMvYfNYStb>+sDC z^rYY#K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EgN;hpqtP^;j>5 z$wF9;=yamm{wKD=%mKUuWfl|Ld{2c~8nSKJ21AFE5kUR!aT?&dDnb kp4a3Z@-B{-IKG?4`5L|=@8R>;IldQb<$dx2`4BezA2}Fm+W-In literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/config/SessionConfig.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/config/SessionConfig.class new file mode 100644 index 0000000000000000000000000000000000000000..a016790a9c7b3e12bf1e1dbdff8a4d9242ea73c6 GIT binary patch literal 324 zcmb7<&q~8U5XQgBpGIS~#W(QgA9OF?6hR7}LVKw6zS)d*L%It|TJW(v2_Ad^AF4PT zym)jMzS-Z*FtgwH{__jKBc?eb#2Jz?Qj7@GTJN-Kv|Fo1S+nU0qkHRY|3HY(FIE{2 z2v^2$RQ*I+Tf1ukMi`7qNH&DSCu)FD>ZK5aArK69Y%mRJo5;JeS4Li~C9Mrj z)3oV*pXq&H>5;Ug4TqC9O|SI$oBAvLX0(^_E|`=bT1lgscYN=A@6Gt%|9$NZ07Lj^ z5>1F{Xx7n!R)O|eYr!&ID?ek7PR-hxP@wgolXt>H0tVPVbvFN4%LC+dpn) zLeIY}keIQj3_ej;6qplSM>7J2WSEdut(5_=W44UdHX#z(5c^x`7Vv|5yF|hp! z+h1@pwm|<#1Aj_0%yZS*={PnEG|TlGwg_x%uypwBs9MH*5?zS3VJq&_aKDZe9uT-! zxl!<){LHj(&Do2df6**D=4p?B3g}igI~0b#GgS;};BYMv6CBRZq-&sw0#(MQflwO$ zpg`QWXPh9k{Wk2tP7S+sbfbq5)U#*7a-FOdI$qv9;^ec`I&KF=my}54tl*gMdw!r; zaUqF5^lKQx_fSCRCxhW zPRm6Sn#JNo;(4xZ5X$Hj|6-d^)bSz@I zR}ABLl&X|_ahw#mM;Vc_!cf|rT6Dr(is7>cQ_noxhEo{Pa9YP1(5v=avxtJS_Ed33 zfnPPWG1mzG;{qEeD-=m7pMyx*4ov7ci*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CM_jpwiWWGX>d0fRc zYNVs3^pH>2aYGSgp3c2iA_!|#&$LFPWHuA}tGvmyxz1~eS2?q*>GKlmq|YWy{8D#)2v1o zoz5r-dLua%cT<&oNGT_qxS~S=6jNEig8LuI>8WyYkOY$+mc6SI>yI?~4NTJ;Y4QNy zB#JR(xLO}u)zGZ6M2|j~ELkb;PyGHS{#-&}h;OpCCdj)_vb}$%Dl{s(9?4lyf}_Ho qsJNI=j#Y|ot?|{+{Dpe{O8HIrn{rKB`ggv+#Vg5YmlgFNNc<0=_7BAX literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/controllers/CustomErrorController.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/controllers/CustomErrorController.class new file mode 100644 index 0000000000000000000000000000000000000000..a1a9814e01bdcfe2b75a3cbb504506957f2be2c6 GIT binary patch literal 2583 zcmbVNZF3V<6n<`+kThKiq<|DEEFd&(O4b)dXs}w_0@d`zq!a!=xqf$YS35-EnWTYQ^K#VudRorX|WNjwOIujU=U z#g$zbGKF;aT0Xj#7gBmM?<=kXf5Y~wVh9EfCNXT_5Dqhpzm8j1s%71xq1-kU*vx&9-CALyXRA%6kV1yxOl0IWuf#)Jw3OqygE)#~NgOxu4o)zf z_hilTTN-jx@}}7JV!<3MqZn+7>;Y;H~cIN;RAe_ z#771$<70-gevt|sYl(Eypp5fswI}2AeTengh!WnP&ps&W;S=&YRHf!|&A_xy!66b? zNpRnDSL>4dB8BS|r>5|IUK44|;Ikw?H>h~NV7O{~O>65>)w3;f)7cS{R~q87WqYoY zUZWwTZ_Ne1@|p`;{Bxb{wwZ8qsg3-aj5`#%k&7gd!aPHqDy^QvjejjO*{;crKsqVh zVi;5oQBb_uO5#g~;Se@ZPQ#k#ifAqBHn7An(zUl%m)@@ClSUCM23B=+(iEM@;}l5Z z`5TUCRLyZ7sJbT|^=RCzdct?dm09OI!sKREZ1SL?%upU_tl@SN>jv)Nn^*eHzU)&v zcHD7&hE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q}Yg_2jQ)eTMVzs*r+dNvvV$UF5mg)eE<3B3xIXp%0Po|!LVUsjA7z{A9B~{ z{eAbr-hpUG3}bh_z89@9=#}br8Y!eLWNeJXW~jG=o_lcA3EFN)_}-xi`JONCxV?Z( z_whi4>%*uUgkE&C*`ZQH@@cCfC zFjc80Dkx_ogK3m3%-ER41%^r0VHkOSJPDlz|{Ozgk%9$(a11L|Ms=5g1q_8m zjrfY@iMpH?Bio92`{@>c76VU7f<~j#s%$c3TEQ@Ei+i3Vq4>u(EK9C%mEK(g!(}=( zxl^>2np^{t2Ki|z=`54wl4K-J=OfrVQZ!12x&|`1M!G!;zycP@lF8R8s!aM0Nu6X~ zCOfqgSWf)}+4C|5>Lv>q$Rdp#eR)-~JW7j8QUQfg;>atM8g7uDme8e3cAdpi-1Sx5 zb=9f8foUAqz9Hv)z(kGy*D&?t+E=8uocFNm^q->m64PX5$;v9rGTy?_kEyJ#hMl8v zfg&tg%UP5#j~U!1ZH1&HV1#z{4DBi^s1l@kx^;*Y4K<3&!nAVi2No@))|eW=WE3gE s*Kw21GU;oIf1qT3hPI1tq5uE@ literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/UserModel$UserModelBuilder.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/UserModel$UserModelBuilder.class new file mode 100644 index 0000000000000000000000000000000000000000..96004719d6d6264edab5369798d8ddac61665730 GIT binary patch literal 3323 zcmbtWZByGu5Pl8}0;7PTlq676peD6Vi2IT@O$|dW>F7c? zL*jrR^Q_6Oz3gV`K$Imz_ncuFGSASNN^fiEVHot3YSJ*XE8N{L3K@rn&R+CE*KkEg zKL!}?mhEcx;G|-gvlU?)$HL(yQ{2f`ZJK7Ey24pkqhx)wSToFua2Wb{P43%{Ar0X& z3>4m&BU3qLW>Civ-eKr4D&(`T;5l8etvyfUT^%F1%Ft6ILl&hT`k#%*@wa+noCj1G4vLVJ&VhlL)6P(jNDw|(tIxj^gr!>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jQsE@dzS4D$MWh`Cgl}BDI4Lx{N$u> zuL8L%WIr2f+=Auothn+^mDmIA6*m>mgsNT_Vc>KuKYJs;#I!3~wW3v`ePf|}=6rFm zD{&{kv|LzTA=5&B=|=u>Ot)OyS&`7trl@}>Q*u4;wHW>yd0u+v<9bb=t#oZ&BC0 z1ugYM3ShxuH=HXo73Bq+YElNdjxl!UYivz%j(o1MY2D!JI9E407P!8p@doDkfp4ln zJj8JUU07VhZQNPIXRuVjGFABG2~<)>CDN3xP|6oihtvRYuSogkA!9^d==^=t%vX&y zi==vs-#)8x7i+k84-t*G@j3bVJnmEag&HiZ--Eh}A}P2mLANd+V1wT`HEe9*1g8&C zCSrvwVt0h&bD6(GP5l#z2;Q37!?BD%{hKkw;cq{Qfb)FpXZdoz0GF#%{#HD~J6sV2 zRn!RYaUN4#$TOh+SgsTMTr%zCdWl>Y$?@`0xq9W9MKi^(v&J-_`vaW1`#w(p)z~7A z#Ay?d3SzvCcY|+V_$i{MkVyAv9<37iu9hqQxTBRupzt$l`?ogE*08!y7$c#dQ$O!G zbpE43I;miHlc}|wlgf3B1NbaK~mhFVrxxNp%JcMwuLK-UlB5bUz=7tz}auO{w>4CF8VwC To{K0Kqxb`7y=E4{AJOwa3?WGo literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/AuthorityRepository.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/AuthorityRepository.class new file mode 100644 index 0000000000000000000000000000000000000000..591f2cb507ab5ad50225b833206830d051a2e317 GIT binary patch literal 1046 zcmb7D%Wl&^6uncLhLl2EUTs;8x+Lv~mbdfUc+U)J$+ZW*$NQ1HOp` zAHYW;?l`rbECTJq^31jGIcLs2^ZU=wUjWdCXLVR1@Oq>sY@CH^#6l6vsnGl~7B86= zsWQ?kErnriXTRXeW`m-d)nS#u)|gK@i+K{U{^eMVY#r7Jyiz)1Ce<>Dt~8&B?@E7V zA-9~3Q(ggQ>@4LKAc37LnS=!u(sr^>M(ER!!2Ur{F$F4#TF++%XJyO+X>1F{^aQF5 zKXA`!g*F7%+%-UBD5Hd1rv-uY|AHL_OH7$4^r&*9=eMml$h|jkiIo%aSsID+;^_N}(n@<4G`?7_u?#}SzIlBtM?jUEeq5cbR7K!m-r1q`0azGRKlPUI z7@Hfsh!lZ~8@AnkEI;OAGYe>I`9c2`&f8JXvF2g*30WU1r$^#M#yHsB(zGi7O`mYQ zJp}IHQ^PB|f;X%VcVQJ8xT_%szV7)CumSh;HGv2C^QM6<*v7(!Z+|$etYh~hc#J<^ ScRwk+pJH)_vje+1-riqoc}Ud& literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/UserAuthorityRepository.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/UserAuthorityRepository.class new file mode 100644 index 0000000000000000000000000000000000000000..ddffae4872ee4d1b86d86715412f4a7cd9927a9f GIT binary patch literal 1045 zcmb7DT~8B16ukqKN-0o9KILJ1;gut(Y=Xp!{llk7(PWQ6&9@Za*nfaBLvbxO=M2wzo6{RW6$gb;O90&r_ z_?7U5Q#dqbcmOjnhr1Gi3jXHZ0aRfjTN7Bs%S#E=;2{R8F8xs+sbKcec$(K+gY~TL#$O>II~@Q3 literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/UserRepository.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/UserRepository.class new file mode 100644 index 0000000000000000000000000000000000000000..43120d649d9214f0703119bf1bcbd8a5f3d316d2 GIT binary patch literal 1467 zcmcIkQFGEj5ZELxa8)Ugtux9{=Xc zFSN}RquoABFo*QC&k{fayBET1zZvR09)=Of=dC0`U1`8lAvT3dxYX_|;d{(2A(I+c zmwx*l(+L%q0fEhM0<={Z9gnF{BB-+>=u2yfC_NuFiqxp-Rp~XRKbWQ76zZ}ZA|WXh zN=G2)gq{*T{!s)1l`VUoub3u}K5DJ1*ZYvmA!bVrm>Xg#pX;V&9yg4))q10PhKtas zICjm@3P#+}V40PMacWo3jEdPfJ~6@~ONbfG6Vox#HkQhGWgLyy1Rl?_o`^d`|LJo2 zlj}32Uo~|aA?R-LD-oz*y4Tr7ZTUoCXMEJ`G2vqEJpN~A6}RQcpJ_?n<|sD9!@ZF} z3v`Jqx9q0r?ToBpF-pJq7=b4XNzL7ctN+rsgs|p2VyYXOI0$^7 zny7eWOUwKBuW?;@Jf;#_J`S)RmrUIcWs6sYi??`RU)SUvDC&{NSA@Vd{8IQzZQx6j zhD}(5E!?Fr9DmpGTZ3(M?VxLYfeUt{V+3v>&RzgF;T9UUHS&IJ$zb$t$l@jeM$?^X n(_PRH-M#4?xg`DHIquKp$YJz@6{8={M`Mj~r3dgRs`&5^0UVu& literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.class new file mode 100644 index 0000000000000000000000000000000000000000..74c60642825912620c8ca1f5c3d7cd93f1411010 GIT binary patch literal 475 zcmbtRO-lnY5Phj_S8KJkqM$c#et@}nt5k~A(<)-6_jGq?BfA?(vZei5o&*p60DqJ? zQK<*LnZV4v;qhK(^7j7n3ZRee1}a#IP;H`yy1@Q}nkkv7Vj}O#!t0y{^MoF~Hiba_ zTo>B+1a=PNAKuVgT}--1qX?@47m3N`!y+|_OexbdvTB^snRJwtR{Moq>Nz>cmCgop z?Yvud1*(@OC4p9~3%V)uG1>bdA<&6UqOy^)I^geS)lan(=*R!`?FvLWIj1I{PQS(z zXkU|`n)Fs#m6IpSu8pB7Z9-Q%Ja6x>aZZB}4iNF0!x4OW(Tvs@^*D!q{rKb=;)$yY l8XUu?fO&zr&eiT03r%b=Vm>y}Vx>0MHNhYVZ*i=k^8tccdxHP~ literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.class new file mode 100644 index 0000000000000000000000000000000000000000..a46212c1a36a8219316e4e6e0eae2026cd968f31 GIT binary patch literal 484 zcmbtRyG{c!5FCdj2O*FU1O=j@;~{YkT~H*R)qxO!^v>NXadc-R+ZU0~qC%qJ1NbP! z8c-+@6}GhAu}3qz>$mrpR{$qiZ=iyO2-PNPs0(aOI@tD$sS4Ioe zkCj%wC$O=b{P6nTDn07%4I(TGoTjFTC$r3?aYnhCl9j`pj$%h?X_cSFb3GT|JF;2^ z3+23tMCvcwp-?}Rh737>8eVYAh zQlNcBer&QEX}NGumW>;IQ`(d+Rj6?LkERZT7IqNvyu%W_dE$(g81?uJ_x1gQXNV`x mDrj&FzXRq4<}zoSUo14S!if1;MT?c%oYw?{AiT!0g3bp4WPg+Z literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/auth/CustomUserDetails.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/auth/CustomUserDetails.class new file mode 100644 index 0000000000000000000000000000000000000000..ddb8f7bb70a52615e6827da8f056801f5414ce3c GIT binary patch literal 2408 zcmb_eT~ixX7=BKYB?(;u1VRC&prXwOW!2V74Mk~6D>b2=L75S+mSly6u#3B!DmUKw zQ|uKNIwRU~M#n2J{861g=j;MYh+~KGBIlev=Y5~|c|Rxry!ic30Ly6fBY|WZDIFU6 z1cr9ar>4<1oo(as)~?kI1o{?j#}1YRlEu=?CXM>w;LSAN(lLv- z1%{PJ3NMVI^w;{PV@k)b7h~$-bM@j)X;Wfe*HJ`CAhl!qJ0x2Cs)yui8Wn*%uD5OY z2Qn^Sdkh#uv3Hh*rt4XTjAbi~zi}=X*>!u{F@uiBFgHRAUBOta)c+g*p=UaQ)mn~X zdstnn3arK5Rr!s%5asdW&1O#))zSuIQFB}5Ias$HYpt`tWqF^=9LoZ6n`V2%^lbSZ zU8aH^n?YZwU#?E+z}R`%!-Es(p@zjGYCSP!xC6_hnIHZ~XD=Ia8KW%ARc2WBSN>eR zstgF^C~%S|)dS-vQeBB>03QF#(`5;={b>D3)UE=fC-`dUL?salNgu-QAF=)AX4CCB z!J6x=e0N}bva30eHtAvfjoI3hPgiZfMj6WqY_?roDQo*HCu5-yPgvB95>mM52Tt_F z>I-&Ej>LiWz-;a{%!8=RGO|I#!X&3vf&O*3<29`Zwyeyt3-fPYP6#%5hBHQ>%+Z^d z^OO@gF9)C6Io8z9Nv3vAF3QgFoWKoA3u?_H34=G!c-O~$ru-X3xpItjdF~hkZtNJa^+v~dWF9qp(T$he<9Og4Ghfj_Z&0QKv>3kRdDxM z%r%S?a0)BR*h~m`TDm3PKVUqkSdb4{&Ix=<42}PMaza(5CMW?)tl|+@nfp7$mKhjK d{ei@nNojxmIo|2^?orIU!P9hnM#Ti`F987#{1X5G literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.class new file mode 100644 index 0000000000000000000000000000000000000000..15a1f7f13035d05a35510e21744e80284368ad75 GIT binary patch literal 4660 zcmcIn`*#%89sk^fFt8buH7XWCSTMvq&;g|oSp*>_NL>hJLu{~GC%ZSvklDH0nc3jB z_Fc6PZM9GPez*3mtwMowdi=Ske^XCCcXsx@8)6^lWHxv1{oe2QbH9(z_s&25b>r^< zPU79I=s~Z6O(y!VS>Vx}Dp;4xd6l#B(skCPZ!fy?kQK;W$#=rCWtYMgYpN84s&Fxo z{^K&V9XH5If6d8Bfq@byFUX<_oKX2?fkT-t8vUw}BLhpTs_#noV+*z#NSNq{De%zy zS0OOG3v$+e$6HR1Ri;Xz z<65)D&{3Z4ribXS0TY8r3iR2Oh}%aS-IbLg({U7I2F6WH zV86g^^*C@@q(k=+>Xxdqs)j7pQrcVzZ)ahdh>~4~)d9@bzejLO@1|HUN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-i3IZZxyF)rlfXV z-BF2}$wU;Gnxp#Y*)LF7Z}}pSOlThASerOZQ(BRE6AKIDSMl^UJg3jyXk>3>L?hO? zU&far9i+Ng$7HNy;3jeljI{)=!D-d9vq8&16iG1dUyW?N5(QG@dzJ5B<1@mwpHuJG k@jAX0jlPZV;`{O35AhTHmeN1PpDCN*=q>yO?_m4C0k(OD%m4rY literal 0 HcmV?d00001 diff --git a/Sprint 2/prototype2/target/classes/static/css/styles.css b/Sprint 2/prototype2/target/classes/static/css/styles.css new file mode 100644 index 000000000..ff30abe6f --- /dev/null +++ b/Sprint 2/prototype2/target/classes/static/css/styles.css @@ -0,0 +1,107 @@ +body { + font-family: Arial, sans-serif; + line-height: 1.6; + margin: 0; + padding: 20px; +} + +.error { + color: red; +} + +.success { + color: green; +} + +form { + max-width: 400px; + margin: 20px 0; +} + +form div { + margin-bottom: 10px; +} + +label { + display: inline-block; + width: 100px; +} + +/* Logout Page Styles */ +.logout-container { + max-width: 500px; + margin: 2rem auto; + padding: 2rem; + text-align: center; + border: 1px solid #ddd; + border-radius: 8px; +} + +.btn-logout { + background-color: #dc3545; + color: white; + padding: 0.5rem 1rem; + border: none; + border-radius: 4px; + cursor: pointer; + margin-right: 1rem; +} + +.btn-cancel { + padding: 0.5rem 1rem; + border: 1px solid #ddd; + border-radius: 4px; + text-decoration: none; + color: #333; +} + +.btn-logout:hover { + background-color: #c82333; +} + +.btn-cancel:hover { + background-color: #f8f9fa; +} + +/* Custom styles */ +body { + min-height: 100vh; + display: flex; + flex-direction: column; +} + +main { + flex: 1; +} + +.btn-lg { + min-width: 180px; +} + +.shadow-sm { + box-shadow: 0 .125rem .25rem rgba(0,0,0,.075) !important; +} + +/* Animation for buttons */ +.btn { + transition: all 0.3s ease; +} + +.btn:hover { + transform: translateY(-2px); + box-shadow: 0 4px 8px rgba(0,0,0,0.1); +} + +/* Footer styling */ +footer { + box-shadow: 0 -2px 5px rgba(0,0,0,0.05); +} + +footer a { + transition: color 0.2s ease; +} + +footer a:hover { + color: #0d6efd !important; + text-decoration: underline; +} \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/static/js/script.js b/Sprint 2/prototype2/target/classes/static/js/script.js new file mode 100644 index 000000000..e69de29bb diff --git a/Sprint 2/prototype2/target/classes/templates/dashboard.html b/Sprint 2/prototype2/target/classes/templates/dashboard.html new file mode 100644 index 000000000..dd5e20291 --- /dev/null +++ b/Sprint 2/prototype2/target/classes/templates/dashboard.html @@ -0,0 +1,163 @@ + + + + + + User Dashboard + + + + + + + + +
+
+ +
+
+
+ User Profile +
+
+

Username:

+

Roles: + +

+
+
+ + +
+
+ Quick Actions +
+ +
+
+ + +
+
+
+
+
+ Dashboard Overview +
+
+
Welcome to your dashboard
+

Here you can manage your account and access all system features.

+
+
+
+
+ + +
+
+
+
+
Documents
+

24

+ View all +
+
+
+
+
+
+
Tasks
+

5

+ View tasks +
+
+
+
+
+
+
Notifications
+

3

+ View alerts +
+
+
+
+ + +
+
+
+
+ Admin Tools +
+
+
+
+
+
+
User Management
+

Manage all system users and permissions

+ Go to Users +
+
+
+
+
+
+
System Reports
+

View system analytics and reports

+ View Reports +
+
+
+
+
+
+
Audit Logs
+

Review system activity logs

+ View Logs +
+
+
+
+
+
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/error.html b/Sprint 2/prototype2/target/classes/templates/error.html new file mode 100644 index 000000000..38d4e6ba1 --- /dev/null +++ b/Sprint 2/prototype2/target/classes/templates/error.html @@ -0,0 +1,41 @@ + + + + + Error Page + + + + +
+
+

⚠️ Oops! Something went wrong

+

We're sorry, but an error occurred while processing your request.

+ +
+

Error Type

+

Error message

+

Request path:

+

Status code:

+

Timestamp:

+
+ +
+ Go to Home Page + +
+
+
+ + \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/fragments/footer.html b/Sprint 2/prototype2/target/classes/templates/fragments/footer.html new file mode 100644 index 000000000..f42441320 --- /dev/null +++ b/Sprint 2/prototype2/target/classes/templates/fragments/footer.html @@ -0,0 +1,39 @@ + + + +
+
+
+ +
+ © 2023 Application Name. All rights reserved. +
+ + +
+ +
+
+ + +
+
+ v1.0.0 +
+
+
+
+ + \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/fragments/header.html b/Sprint 2/prototype2/target/classes/templates/fragments/header.html new file mode 100644 index 000000000..0b9dbc379 --- /dev/null +++ b/Sprint 2/prototype2/target/classes/templates/fragments/header.html @@ -0,0 +1,101 @@ + + + + + Navigation + + + +
+ +
+ + \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/index.html b/Sprint 2/prototype2/target/classes/templates/index.html new file mode 100644 index 000000000..c35664607 --- /dev/null +++ b/Sprint 2/prototype2/target/classes/templates/index.html @@ -0,0 +1,89 @@ + + + + + + Welcome to Our App + + + + +
+ +
+
+
+

Welcome to Our Platform

+

Manage your account and access premium features

+ +
+ + + Dashboard + + + + + Register + + + + + Login + + + +
+ + +
+
+
+
+ +
+
+
+

Features

+
    +
  • Secure authentication
  • +
  • User dashboard
  • +
  • Responsive design
  • +
+
+
+
+
+

Get Started

+

Join our platform today to access all features.

+ + Create Account + + + Go to Dashboard + +
+
+
+
+ +
+ + + + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/login.html b/Sprint 2/prototype2/target/classes/templates/login.html new file mode 100644 index 000000000..972c137c7 --- /dev/null +++ b/Sprint 2/prototype2/target/classes/templates/login.html @@ -0,0 +1,45 @@ + + + + + Login + + + +
+ +
+

Login

+ + +
+ Invalid username/email or password +
+
+ You have been logged out +
+
+ Your session has expired. Please login again. +
+ + +
+
+ + + +
+
+ + +
+ +
+ +

Don't have an account? Register here

+
+ + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/logout.html b/Sprint 2/prototype2/target/classes/templates/logout.html new file mode 100644 index 000000000..f68ec77a1 --- /dev/null +++ b/Sprint 2/prototype2/target/classes/templates/logout.html @@ -0,0 +1,26 @@ + + + + + Logout + + + +
+ +
+

Are you sure you want to log out?

+ + +
+ + +
+ + + Cancel +
+ +
+ + \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/register.html b/Sprint 2/prototype2/target/classes/templates/register.html new file mode 100644 index 000000000..f4e1ee768 --- /dev/null +++ b/Sprint 2/prototype2/target/classes/templates/register.html @@ -0,0 +1,34 @@ + + + + + Register + + + +
+ +
+

Register

+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +

Already have an account? Login here

+
+ + \ No newline at end of file From f9727c7985610d69d68f689970f442e13974c9bc Mon Sep 17 00:00:00 2001 From: bihiy Date: Thu, 27 Mar 2025 21:25:03 -0400 Subject: [PATCH 048/100] Documentation and additional refactoring --- .../target/classes/application.properties | 9 -- .../Controller/indexController.class | Bin 3432 -> 0 bytes .../com/jydoc/deliverable3/DTO/UserDTO.class | Bin 5016 -> 0 bytes .../Deliverable3Application.class | Bin 769 -> 0 bytes .../deliverable3/GlobalExceptionHandler.class | Bin 4467 -> 0 bytes .../jydoc/deliverable3/Model/UserModel.class | Bin 3461 -> 0 bytes .../Repository/UserRepository.class | Bin 1083 -> 0 bytes .../deliverable3/Service/UserService.class | Bin 2368 -> 0 bytes .../target/classes/templates/error.html | 10 -- .../target/classes/templates/index.html | 28 ----- .../target/classes/templates/login.html | 33 ----- .../classes/templates/loginSuccess.html | 10 -- .../target/classes/templates/register.html | 55 -------- .../target/classes/templates/styles.css | 14 --- .../deliverable4/Deliverable4Application.java | 111 +++++++++++++++++ .../Initializers/AuthorityInitializer.java | 39 ++++-- .../deliverable4/Prototype2Application.java | 13 -- .../deliverable4/Service/UserService.java | 117 ++++++++++++------ .../Service/UserValidationHelper.java | 62 ++++++++-- .../repositories/AuthorityRepository.java | 20 ++- .../repositories/UserAuthorityRepository.java | 25 +++- .../repositories/UserRepository.java | 34 +++-- .../Exceptions/EmailExistsException.java | 49 +++++++- .../src/main/resources/application.properties | 75 ++++++++--- 24 files changed, 437 insertions(+), 267 deletions(-) delete mode 100644 Sprint 1/deliverable3/target/classes/application.properties delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/GlobalExceptionHandler.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Repository/UserRepository.class delete mode 100644 Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class delete mode 100644 Sprint 1/deliverable3/target/classes/templates/error.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/index.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/login.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/loginSuccess.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/register.html delete mode 100644 Sprint 1/deliverable3/target/classes/templates/styles.css create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Deliverable4Application.java delete mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Prototype2Application.java diff --git a/Sprint 1/deliverable3/target/classes/application.properties b/Sprint 1/deliverable3/target/classes/application.properties deleted file mode 100644 index e3cb0d6f4..000000000 --- a/Sprint 1/deliverable3/target/classes/application.properties +++ /dev/null @@ -1,9 +0,0 @@ - -#Server Configuration - -spring.application.name=deliverable3 -spring.jpa.hibernate.ddl-auto=create-drop -spring.datasource.url=jdbc:mysql://localhost:3306/user_database -spring.datasource.username=root -spring.datasource.password=radmin -spring.datasource.driverClassName=com.mysql.jdbc.Driver diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Controller/indexController.class deleted file mode 100644 index 55a2bba25b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;)zdA3yB!Vcf^6w_$f{J lG)?$4O%!M<)SI$5VxI4Xm~lFn-S@qB|G{e~IU;@p{sX*eW7z-z diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/DTO/UserDTO.class deleted file mode 100644 index eeee3de03145441a2e32048690d44aeee6eef28e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5016 zcmbVQ*>@A?75|N-k;Y;SHef&)h>{xP6@{fhWK6;u)Y^t%LK3r-u{79&r5Qyt1`MV9 zk~A&tW7?O#m51`soYRnV^3dg>={Y_5lbWW#JB#+jZqGsJes}rZ``vrL`+f4i{`2Wy z0G!5e(ug6RLPCd%q=LS?#yulfHteO`rNz5u(NmB-Y1x){NoW>vdLW# z?p7V!u$^49VpwGbTW1iz#xfYw`v~4?{;aQA8ff%e9 zHP6W1Gs;%UXXlC%T+Of;UT)6u&af+2rkMGP>AJ>}$?ExO&a#|@$}XB&vr_fe6b!G2 z=Gzf!d%^bo(U6Uoz2np>20MOlYou4#s;$xPit5wpdjEQ^=dFh(J;&Mpan^-LZn%zC zS#|ww7+$t)vZC2z+2XQMGm4&BW0Is-zcxvi4Ud{O;gdCU$$U`dR&I^FI(=~L`sv99 zWAfq6QGa!#Gzu}#Jzuvx<{Wo2ovRu;{gg57>MW^Eq1 z&OGS1uHUFWnt6O+^5!_*Ot`)a z>IMTYF;W=4#tUH9^p>5{Wwu?#4Ej!^MmXydBMYJ=oN&aoOwe$`iOMFbM7_n~#Z`TH z1;S`#@e*)aM}9bm8JgoQOQ)qJ2SffDrLE75R=vKc8qP}vn*(VR!&kTy4Nm4g&}iZW z80Bz;)-f84-g(a`uFM+MuqNu|D}~wf{wZ@;%N!WVD4d?5hUfH9laHRE2At+OL87>` zd1tj&G%r|Ee?7c056bPwN}O>VPX=H$D2c1##|qAcN+VWjTH#5NJ4gsWJ3>SO2we|A z7Eu7x%IKCPewxP5@beVjlZ)YfHdy1zwd{M&ikS;y4*;YHrOF&W(apHCo}O!B1hzxjya>NIKjJ_7}3 zU7W-DfVhCyDcObCHq>P#>(ZFKZbJJ5h(|gXQ6TeM1$sFJPJeWd16AeFaL~2(Ad7dC~@p=_+7H~~iZ~4v+H#>Wy0UlWS&O7X4@)+y% z_;!oOcRD>Tbb5Td&Eq@WJT9Q0Dd&5ZKCd(9Ij$6bt7D%)`G`aeH~4?jXZGSIX+2QD zEqsTo+o9CpH;)GPcL4nvsb>^61NE&7#D`-Spx$<%{&j))&g=rz|EIQy2G#}Qi?a*R zKs(Ujx!sK!fc-`_~0pM3EgV<R5; za<~ueUKXwJOIYrJAO9Hr8-VO%XtNVz&#}*6l6Yx?pWlm&i(xK?qs7=9S7Z6aDF&1;#IC~2WmDx)3BY!=@F%LsMM25M@k8qHt~-6R}J=A@BhzHMukZlz$dUd6Jt1qCveD%^G16QRZ29K16KQg1Mq`!Fh$@%duCbYV9*NnEJt~SL?f0xmVeBci`Wysk(N;-(eZrJ7bWW=b_%WbbT973AkuJ~aeROW z{%}+AKGsOZ_$Q4!c*w2C`FfefBT@;r$YFe!l*&@=#A8xPzi9tJ`b)eZe>Bn*-mA)& zOjx*x$!Z%CzK9j{rSYbetRi zf5`J!rqq+4VW}QJhxj?l&+$(&4Yc1!&98`kVWMxdJ)#REj_-37!w>L7errtGPx$!} Qe!*3m)Cc$#evQn30Y!-7@&Et; diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Deliverable3Application.class deleted file mode 100644 index efcd494a354085320bc8fee605438a97b7adbd6f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 769 zcmb7CO;6iE5PcgG970+ke3h0SxP=^8BqT1WkkX)@3{*{(9(r0ki`iiBM(Z^nKZ{eV z9{2(MQB`MMBzy>mTJnr$X6Mb!oB93c*CT)d-nUT0LV$W34JR_=shp}Rj0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FZ~bsk2d+*uycx%MW!nZRRsOT{yI zwgc~QP{lXMtE8e&ns`r|cwfZ@To`g@OUT$wBreWR|5f@$CJDh&@qVyU-=TR z^<3-y70Q__ST{QGGZIVa;1>G@n}H?VQior$^~~;{u>A^pf1qr=Z@7R7SiH7TXr3SYEJR?$K`{jV zObEI=0(yXW_es2WT@&widhS6dkyY?^ui)(_jHi5bTh`!}E3tUp7`)O*30{bIm{(c3 zc9}>f_`pv{hPjN^YOjxJb0E5cshyb0G`A*C3o(An9SOOuDK43Disg`gyZQ%~z<(et z;V5_e5>Cjk57pyzg)Q>m5Wo(;O7D!I=<>6`2k62go`#@#HlEP@9L+cIS?9p-82=d= z$(={W`giYHZG1x@#?;@8R+`$3TYM+|;ku-T{OQDVc%H_aN!u52iI7^6z>EAQ9lb<} pI=t*hExG>+?_cFdChQ|hyoNXMcKGdGe1I?bEJ3+1@io3h*Wc{uB%uHR diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Model/UserModel.class deleted file mode 100644 index 99879815698b2cc5ae3396d4630212942b0574a5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3461 zcmbVP>r)d~6hAis!ebHSp(0{~MF`JDtY8JTh+xwOr1EIx)!ro6u#oJg*$ovP|D%3r zXXGAZUppm*)FO-SsI4Zp>vqc5AR@-4Z za~>c8ecR`GS0es=bz?ie{aVnix;j>@Y%ym7yUBC|*iu9WIPx9t#`YsVUKT!+StISb zq^IB(3^Gi|);BEY8KQm)q`N`9TgE%KEsR`-Q6nMV%D23o6BNlQ+m;#R^3EFPHOh8H zb4BcuDmpj)U^bdMmIaw|5JW+-AZ44<0VjLdQcxN7HZMp!+CRv@Pkb1gKAap8^!SpV zlr*E3nLUrfHwT_Yvx>#-sp#=}{#cpVNHZOkc?+IfIDrYB94WU3y$}vn)&OUsq7H@= zD8c}@mM(byk4YMv#I^2OG!qo0Quam?C`*K@8CfnO1^uhs8c~>lI_CH%Imc+?AV60R zK)oJ7DSdA7pkvuQx9gCVqG|kGRGfXm3y+9Rzx~Q-mktuaQJb$w{?JkE>EoG+{pIOB zIsNW%+@%iE<1_E)r#>LF4=aI6IW41Ert%Z)W|c{^m`kbxnzbxi)GRldg zVK4yVXrmR(F+p7k!&DnC);7;Ko=jFsW_M-5VA?-ya*hqRh#MP<2DS7Z$W{ zS;az1tr;BUD?6wx_W_w<%uh|dRSaq89I?^jCT8pkTE$j&gx(06Dh=s?LFcwggpLJ` zH7J4N;P#?nyfgz`>GS#;r^q23Vp>k^CH-(MOyMUkD)BYL3=_^_i)cH zB20k&gdlFpq9K0$eO(;QaqJPvW!CVla~76O63ryo#^oV7;?N{ACN zG5C?h?^QwSagnZh9Ddq3rC#5^26r=ND0Nrma*y`w!ABZ}_r`?}-&O;EK!-K(lOL(0 zQFtCYf_(VS8u+97@Li3<^N1_)*4N zsYBCqlhO~=Wrk55cRSXB8+Rj+ zsSD{Ib;ZaBU#>QC{Ztj(P$-^{U&JW4+wAblt{(-E6fp?!0XqETx- zj;A8jVP9az`wojgD$CN1^Y;4i97yQxzY2$v{G1>XIm&j1chkTl6Vn`pe>e2NcvS_u z#!rQZA3Wb{`mNBF1PWJyG@`|CgfDPQ%2F!Bj8GCix!ISmkA~&SblNLD|n9~)m4BGI%zr) diff --git a/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class b/Sprint 1/deliverable3/target/classes/com/jydoc/deliverable3/Service/UserService.class deleted file mode 100644 index 1014544f130ee9ec40e0501bcb74434cc90a66b5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2368 zcmah~=~5d<5dKC81ZZQh4H%LTFBq`IwZ1}#!3Q=FD-lPy65}HoR%5Xs?NYlV5}e9g z&~#6$`|EFdx@Z6S_s_opETGtl7+MmD8)!wFK=*+> zmR3Q!d24O&K-pTLZQgMm{ZODKmEK99U0}@iiq^qN&a=mDuJFb65aiVI`RTXd;W>Qootivx>JNu z-_8ldpHd$QbY&e^t(J;=%HQJt61bA}Y+2ZmzQg;9F|PNWKwz?2rVEHtjxO7Csc-d` zx8!O^6V=sJGlWyUIhStcbguU)MS=%mQF{U-&4NxN)492N0!?`|rs!T#df&^fOP@Me zE1&9M)D9MnQu9-tM{9brvm`re<4w6_N$)GFpDi_A&&>-4;(`&`r9oEQ<$R$H14j*i zRB3F1!Hp837uAjvIDF$LM{2=!JuS84xpY__*hA@SX&uXglZ(t26(G>QbX*-+tDb&B zkJ%w#M^OcV%oESvXq-%2GL*TeOjSJM4jB6oS`d}Mg@fQnIyK?I7t8}z`nM+UqGBf$>h`{XGuzqT%9u`bLtqF`>9Yg~`YmCZ);Q_(fui** z+F2y|zt-{h5bsEd;Tf&`H(($Wt&s!1#y7MR$YO=OIQTdI;*q@n7ZT6kqhn=qB1C71 zZk9bE`dNM&!eluT;wH=S5K}B~g}6KU2St}N4x^p)tF-o@8@=eK?~#dXNRf661DK_+ z5VJAM87pikH&(GmtlH^0U&ptEwn1L4^a_y>*u+*N*(8yjiO7BtVwTB#8R9<6xe)U# zAB1?w@==J#EEhsNX&`%@lA1(zh$s$|c7w={5ZO^8JJy8kHc_mSU8|Gbj>zudJGvgO z>|=7`%Escq^Lpw|tW&_TS`}jW9?vO;eRoMKSD}N=AOrA%e$UX_N8%; - - - - Error - - -Error - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/index.html b/Sprint 1/deliverable3/target/classes/templates/index.html deleted file mode 100644 index fae1fc07c..000000000 --- a/Sprint 1/deliverable3/target/classes/templates/index.html +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Thymeleaf Example - - - -

Welcome to Thymeleaf!

- -

- -
-

Current Date and Time:

-
- - -
- -
- - -
- -
- - - diff --git a/Sprint 1/deliverable3/target/classes/templates/login.html b/Sprint 1/deliverable3/target/classes/templates/login.html deleted file mode 100644 index fe9554099..000000000 --- a/Sprint 1/deliverable3/target/classes/templates/login.html +++ /dev/null @@ -1,33 +0,0 @@ - - - - - Login - - -

Login

- - -
-

-
- - -
-
- - -
- -
- - -
- -
- -
-
- - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html b/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html deleted file mode 100644 index 7a517bfcb..000000000 --- a/Sprint 1/deliverable3/target/classes/templates/loginSuccess.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - -Login Success - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/target/classes/templates/register.html b/Sprint 1/deliverable3/target/classes/templates/register.html deleted file mode 100644 index 89904066b..000000000 --- a/Sprint 1/deliverable3/target/classes/templates/register.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - User Registration - - - -

Register

-
- - - - -
- - - -
- - -
- - - -
- - -
- - - -
- - -
- - - -
- - -
- - diff --git a/Sprint 1/deliverable3/target/classes/templates/styles.css b/Sprint 1/deliverable3/target/classes/templates/styles.css deleted file mode 100644 index 046e065ca..000000000 --- a/Sprint 1/deliverable3/target/classes/templates/styles.css +++ /dev/null @@ -1,14 +0,0 @@ -.error { - color: #dc3545; - font-size: 0.875em; -} -.error-border { - border-color: #dc3545; -} -.error-list { - background-color: #f8d7da; - border: 1px solid #f5c6cb; - border-radius: 4px; - padding: 10px; - margin-bottom: 20px; -} diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Deliverable4Application.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Deliverable4Application.java new file mode 100644 index 000000000..bfc32f45c --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Deliverable4Application.java @@ -0,0 +1,111 @@ +package com.jydoc.deliverable4; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.core.env.Environment; +import java.util.Arrays; + +/** + * Main entry point for the Deliverable 4 Spring Boot application. + *

+ * This class serves as the configuration class and application launcher. It enables: + *

    + *
  • Spring Boot auto-configuration
  • + *
  • Component scanning within the base package and sub-packages
  • + *
  • Externalized configuration through application.properties/yml
  • + *
+ * + * @SpringBootApplication is a convenience annotation that combines: + * @Configuration, @EnableAutoConfiguration, and @ComponentScan + */ +@SpringBootApplication +public class Deliverable4Application { + + /** + * Main method that serves as the entry point for the Spring Boot application. + *

+ * Initializes the Spring application context and starts the embedded server. + * + * @param args command line arguments passed to the application + * (can include Spring profile activation, property overrides, etc.) + */ + public static void main(String[] args) { + // Create and configure the Spring application + SpringApplication application = new SpringApplication(Deliverable4Application.class); + + // Apply any additional configuration + configureApplication(application); + + // Run the application and get the environment context + Environment env = application.run(args).getEnvironment(); + + // Log application startup information + logApplicationStartup(env); + } + + /** + * Configures additional Spring application settings. + *

+ * Placeholder for custom application configuration that needs to execute + * before the application context is refreshed. + * + * @param application the SpringApplication instance being configured + */ + private static void configureApplication(SpringApplication application) { + // Example custom configurations: + // application.setBannerMode(Banner.Mode.OFF); + // application.setAdditionalProfiles("dev"); + // application.setLogStartupInfo(false); + } + + /** + * Logs application startup information including: + *

    + *
  • Access URLs
  • + *
  • Active profiles
  • + *
  • Protocol (HTTP/HTTPS)
  • + *
+ * + * @param env the Spring Environment containing configuration properties + */ + private static void logApplicationStartup(Environment env) { + // Determine protocol (HTTP/HTTPS) + String protocol = env.getProperty("server.ssl.key-store") != null ? "https" : "http"; + + // Get server configuration + String serverPort = env.getProperty("server.port", "8080"); // Default to 8080 if not set + String contextPath = env.getProperty("server.servlet.context-path", ""); + String appName = env.getProperty("spring.application.name", "application"); + + // Format and display startup information + System.out.printf("\n----------------------------------------------------------\n" + + "Application '%s' is running!\n\n" + + "Access URLs:\n" + + "Local: \t\t%s://localhost:%s%s\n" + + "External: \t%s://%s:%s%s\n" + + "Profile(s): \t%s\n" + + "----------------------------------------------------------\n", + appName, + protocol, + serverPort, + contextPath, + protocol, + getHostAddress(), + serverPort, + contextPath, + Arrays.toString(env.getActiveProfiles())); + } + + /** + * Gets the host address for external access display. + *

+ * In a real production environment, this would get the actual host IP. + * + * @return the host address string + */ + private static String getHostAddress() { + // In production, you might use: + // return InetAddress.getLocalHost().getHostAddress(); + return "localhost"; + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java index 8a944ec08..466e2effa 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java @@ -7,27 +7,42 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; +import java.util.Set; + +/** + * Component responsible for initializing default authorities in the system. + */ @Component @RequiredArgsConstructor public class AuthorityInitializer { + + private static final Set DEFAULT_AUTHORITIES = Set.of( + "ROLE_USER", + "ROLE_ADMIN", + "ROLE_MODERATOR" + ); + private final AuthorityRepository authorityRepository; + /** + * Initializes default authorities if they don't exist. + */ @PostConstruct @Transactional - public void init() { - // Correct way to check if authority doesn't exist - if (!authorityRepository.findByAuthority("ROLE_USER").isPresent()) { - AuthorityModel role = new AuthorityModel(); - role.setAuthority("ROLE_USER"); - authorityRepository.save(role); - } + public void initializeDefaultAuthorities() { + DEFAULT_AUTHORITIES.forEach(this::createAuthorityIfNotExists); + } - // Alternative cleaner version: - authorityRepository.findByAuthority("ROLE_USER") + /** + * Creates an authority if it doesn't already exist. + * @param authorityName the name of the authority to create + */ + private void createAuthorityIfNotExists(String authorityName) { + authorityRepository.findByAuthority(authorityName) .orElseGet(() -> { - AuthorityModel role = new AuthorityModel(); - role.setAuthority("ROLE_USER"); - return authorityRepository.save(role); + AuthorityModel authority = new AuthorityModel(); + authority.setAuthority(authorityName); + return authorityRepository.save(authority); }); } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Prototype2Application.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Prototype2Application.java deleted file mode 100644 index 8736e4c1c..000000000 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Prototype2Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.jydoc.deliverable4; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Prototype2Application { - - public static void main(String[] args) { - SpringApplication.run(Prototype2Application.class, args); - } - -} diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java index 880a06cfb..cc1e984e7 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java @@ -11,42 +11,58 @@ import org.apache.logging.log4j.Logger; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.util.Optional; +/** + * Service layer for user management operations including: + *

    + *
  • User registration and validation
  • + *
  • Authentication and credential verification
  • + *
  • User role management
  • + *
+ * + *

All database operations are transactional with appropriate propagation settings.

+ */ @Service @RequiredArgsConstructor public class UserService { private static final Logger logger = LogManager.getLogger(UserService.class); private static final String DEFAULT_ROLE = "ROLE_USER"; - private final UserValidationHelper validationHelper; private final UserRepository userRepository; private final AuthorityRepository authorityRepository; private final PasswordEncoder passwordEncoder; - // Add this temporary test method to your service - public void verifyPasswordEncoding() { - String testPassword = "password123"; - String encoded = passwordEncoder.encode(testPassword); - System.out.println("Encoded password: " + encoded); - System.out.println("Matches verification: " + - passwordEncoder.matches(testPassword, encoded)); - } - // ---------------------- Public API ---------------------- + /** + * Registers a new user with the system. + * + * @param userDto the user data transfer object containing registration details + * @throws UsernameExistsException if the username is already taken + * @throws EmailExistsException if the email is already registered + * @throws IllegalArgumentException if user data is invalid + */ @Transactional public void registerNewUser(UserDTO userDto) { validateRegistration(userDto); UserModel user = buildUserFromDto(userDto); assignDefaultRole(user); userRepository.save(user); + logger.info("Successfully registered new user: {}", user.getUsername()); } + /** + * Authenticates a user with provided credentials. + * + * @param loginDto the login data transfer object containing credentials + * @return authenticated UserModel + * @throws AuthenticationException if credentials are invalid + * @throws IllegalArgumentException if login data is null + */ @Transactional(readOnly = true) public UserModel authenticate(LoginDTO loginDto) { if (loginDto == null) { @@ -55,6 +71,13 @@ public UserModel authenticate(LoginDTO loginDto) { return authenticateUser(loginDto.username(), loginDto.password()); } + /** + * Validates login credentials and returns the authenticated user. + * + * @param loginDto the login credentials + * @return authenticated UserModel + * @throws AuthenticationException if authentication fails + */ @Transactional(readOnly = true) public UserModel validateLogin(LoginDTO loginDto) { String credential = loginDto.username().trim().toLowerCase(); @@ -73,71 +96,87 @@ public UserModel validateLogin(LoginDTO loginDto) { throw new AuthenticationException("Invalid credentials"); } + if (!user.isEnabled()) { + logger.warn("Login failed - account disabled: {}", user.getUsername()); + throw new AuthenticationException("Account is disabled"); + } + logger.info("Login successful for user: {}", user.getUsername()); return user; } // ---------------------- Core Business Logic ---------------------- + /** + * Constructs a UserModel from registration DTO with proper encoding and normalization. + * + * @param userDto the user registration data + * @return properly configured UserModel + */ private UserModel buildUserFromDto(UserDTO userDto) { return UserModel.builder() .username(userDto.getUsername().trim()) .password(passwordEncoder.encode(userDto.getPassword())) .email(userDto.getEmail().toLowerCase().trim()) .enabled(true) + .accountNonExpired(true) + .credentialsNonExpired(true) + .accountNonLocked(true) .build(); } - @Transactional + /** + * Assigns the default role to a new user. + * + * @param user the user to receive the default role + */ + @Transactional(propagation = Propagation.MANDATORY) protected void assignDefaultRole(UserModel user) { - authorityRepository.findByAuthority("ROLE_USER") + authorityRepository.findByAuthority(DEFAULT_ROLE) .ifPresentOrElse( user::addAuthority, () -> { - AuthorityModel newRole = new AuthorityModel("ROLE_USER"); + AuthorityModel newRole = new AuthorityModel(DEFAULT_ROLE); user.addAuthority(authorityRepository.save(newRole)); + logger.debug("Created new default role: {}", DEFAULT_ROLE); } ); } - @Transactional(readOnly = true) - protected UserModel authenticateUser(String usernameOrEmail, String password) { - UserModel user = findActiveUser(usernameOrEmail) - .orElseThrow(() -> new AuthenticationException("Invalid credentials")); - - if (!passwordEncoder.matches(password, user.getPassword())) { - throw new AuthenticationException("Invalid credentials"); - } - return user; - } - // ---------------------- Validation Methods ---------------------- + /** + * Validates user registration data. + * + * @param userDto the user registration data + * @throws IllegalArgumentException if user data is invalid + */ private void validateRegistration(UserDTO userDto) { - + if (userDto == null) { + throw new IllegalArgumentException("User data cannot be null"); + } validationHelper.validateUserRegistration(userDto); } // ---------------------- Utility Methods ---------------------- + /** + * Finds an active user by username or email. + * + * @param usernameOrEmail the user identifier + * @return Optional containing the user if found and active + */ @Transactional(readOnly = true) public Optional findActiveUser(String usernameOrEmail) { return userRepository.findByUsernameOrEmail(usernameOrEmail.trim().toLowerCase()) .filter(UserModel::isEnabled); } - @Transactional(readOnly = true) - public boolean usernameExists(String username) { - return userRepository.existsByUsername(username.trim()); - } - - @Transactional(readOnly = true) - public boolean emailExists(String email) { - return userRepository.existsByEmail(email.trim().toLowerCase()); - } - // ---------------------- Custom Exceptions ---------------------- + /** + * Exception thrown when authentication fails. + */ public static class AuthenticationException extends RuntimeException { public AuthenticationException(String message) { super(message); @@ -145,6 +184,9 @@ public AuthenticationException(String message) { } } + /** + * Exception thrown when attempting to register an existing username. + */ public static class UsernameExistsException extends RuntimeException { public UsernameExistsException(String username) { super(String.format("Username '%s' already exists", username)); @@ -152,6 +194,9 @@ public UsernameExistsException(String username) { } } + /** + * Exception thrown when attempting to register an existing email. + */ public static class EmailExistsException extends RuntimeException { public EmailExistsException(String email) { super(String.format("Email '%s' is already registered", email)); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserValidationHelper.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserValidationHelper.java index c43b009de..d6acb274a 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserValidationHelper.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserValidationHelper.java @@ -8,33 +8,81 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +/** + * Service component responsible for validating user registration data. + *

+ * Performs checks for duplicate usernames and email addresses before user registration. + * All validation methods are transactional and read-only to ensure data consistency. + */ @Service @RequiredArgsConstructor -class UserValidationHelper { +public class UserValidationHelper { + private final UserRepository userRepository; + /** + * Validates user registration data for potential conflicts. + * + * @param userDto the user data transfer object containing registration information + * @throws IllegalArgumentException if the provided user data is null + * @throws UsernameExistsException if the username is already registered + * @throws EmailExistsException if the email address is already registered + */ @Transactional(readOnly = true) public void validateUserRegistration(UserDTO userDto) { if (userDto == null) { throw new IllegalArgumentException("User data cannot be null"); } - String username = userDto.getUsername().trim(); - if (existsByUsername(username)) { - throw new UsernameExistsException(username); + validateUsername(userDto.getUsername()); + validateEmail(userDto.getEmail()); + } + + /** + * Checks if a username already exists in the system. + * + * @param username the username to check (will be trimmed before checking) + * @throws UsernameExistsException if the username is already taken + */ + @Transactional(readOnly = true) + public void validateUsername(String username) { + String normalizedUsername = username.trim(); + if (existsByUsername(normalizedUsername)) { + throw new UsernameExistsException(normalizedUsername); } + } - String email = userDto.getEmail().trim().toLowerCase(); - if (existsByEmail(email)) { - throw new EmailExistsException(email); + /** + * Checks if an email address already exists in the system. + * + * @param email the email to check (will be normalized to lowercase and trimmed) + * @throws EmailExistsException if the email is already registered + */ + @Transactional(readOnly = true) + public void validateEmail(String email) { + String normalizedEmail = email.trim().toLowerCase(); + if (existsByEmail(normalizedEmail)) { + throw new EmailExistsException(normalizedEmail); } } + /** + * Checks if a username exists in the repository. + * + * @param username the username to check + * @return true if the username exists, false otherwise + */ @Transactional(readOnly = true) public boolean existsByUsername(String username) { return userRepository.existsByUsername(username); } + /** + * Checks if an email exists in the repository. + * + * @param email the email to check + * @return true if the email exists, false otherwise + */ @Transactional(readOnly = true) public boolean existsByEmail(String email) { return userRepository.existsByEmail(email); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/AuthorityRepository.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/AuthorityRepository.java index 2ea69f03b..06faaedfc 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/AuthorityRepository.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/AuthorityRepository.java @@ -8,12 +8,26 @@ import java.util.List; import java.util.Optional; +/** + * Repository for managing {@link AuthorityModel} entities. + * Provides methods to query authority data from the database. + */ public interface AuthorityRepository extends JpaRepository { - // Return full AuthorityModel objects instead of just authority strings + /** + * Finds all authority models associated with a specific user ID. + * + * @param userId the ID of the user to search for + * @return a list of authority models associated with the user + */ @Query("SELECT a FROM AuthorityModel a JOIN a.users u WHERE u.id = :userId") - List findAuthoritiesByUserId(@Param("userId") Long userId); + List findAllByUserId(@Param("userId") Long userId); - // Keep this as is since it returns full entities + /** + * Finds an authority model by its authority string. + * + * @param authority the authority string to search for + * @return an Optional containing the authority model if found + */ Optional findByAuthority(String authority); } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserAuthorityRepository.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserAuthorityRepository.java index 4cb874e8b..5b5c72040 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserAuthorityRepository.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserAuthorityRepository.java @@ -5,17 +5,30 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; + import java.util.List; +/** + * Repository for managing {@link UserAuthority} entities. + * Provides methods to query user-authority relationships from the database. + */ public interface UserAuthorityRepository extends JpaRepository { - // Fixed parameter name consistency + /** + * Finds all user-authority relationships for a given user ID using JPQL. + * + * @param userId the ID of the user to search for + * @return list of user-authority relationships + */ @Query("SELECT ua FROM UserAuthority ua WHERE ua.userId = :userId") - List findByUserId(@Param("userId") Long userId); + List findAllByUserId(@Param("userId") Long userId); - // Fixed native query with consistent parameter naming + /** + * Finds all user-authority relationships for a given user ID using native SQL. + * + * @param userId the ID of the user to search for + * @return list of user-authority relationships + */ @Query(value = "SELECT * FROM user_authorities WHERE user_id = :userId", nativeQuery = true) - List findUserAuthoritiesByUserId(@Param("userId") Long userId); - - + List findAllByUserIdNative(@Param("userId") Long userId); } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserRepository.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserRepository.java index c7958be34..3dd557156 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserRepository.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserRepository.java @@ -4,29 +4,41 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; + import java.util.Optional; +/** + * Repository for {@link UserModel} entities providing user lookup operations. + * Includes methods for finding users with different loading strategies for authorities. + */ public interface UserRepository extends JpaRepository { - // Standard username lookup + // Basic user lookups Optional findByUsername(String username); + boolean existsByUsername(String username); + boolean existsByEmail(String email); - // Username lookup with authorities eager loading + /** + * Finds a user by username with authorities eagerly loaded. + * @param username the username to search for + * @return user with authorities loaded + */ @Query("SELECT DISTINCT u FROM UserModel u LEFT JOIN FETCH u.authorities WHERE u.username = :username") Optional findByUsernameWithAuthorities(@Param("username") String username); - // Existence checks - boolean existsByUsername(String username); - boolean existsByEmail(String email); - - // Combined username/email lookup (basic) + /** + * Finds a user by username or email (case-insensitive). + * @param credential username or email to search for + * @return matching user if found + */ @Query("SELECT u FROM UserModel u WHERE LOWER(u.username) = LOWER(:credential) OR LOWER(u.email) = LOWER(:credential)") Optional findByUsernameOrEmail(@Param("credential") String credential); - - - - // Combined username/email lookup with authorities eager loading + /** + * Finds a user by username or email with authorities eagerly loaded. + * @param credential username or email to search for + * @return matching user with authorities if found + */ @Query("SELECT DISTINCT u FROM UserModel u LEFT JOIN FETCH u.authorities " + "WHERE u.username = :credential OR u.email = :credential") Optional findByUsernameOrEmailWithAuthorities(@Param("credential") String credential); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.java index b3abc3583..90c1d9935 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.java @@ -1,7 +1,52 @@ package com.jydoc.deliverable4.security.Exceptions; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * Exception thrown when attempting to register with an email address + * that already exists in the system. + * + *

This exception should be thrown during user registration validation + * when a duplicate email address is detected.

+ */ public class EmailExistsException extends RuntimeException { - public EmailExistsException(String message) { - super(message); + private static final Logger logger = LogManager.getLogger(EmailExistsException.class); + + /** + * Constructs a new exception with a standardized message format. + * + * @param email the duplicate email address that caused the exception + */ + public EmailExistsException(String email) { + super(String.format("The email address '%s' is already registered", email)); + logger.warn("Registration attempt with existing email: {}", email); + } + + /** + * Constructs a new exception with custom message and cause. + * + * @param message the detail message + * @param cause the underlying cause + */ + public EmailExistsException(String message, Throwable cause) { + super(message, cause); + logger.warn("Email conflict detected: {}", message, cause); + } + + /** + * Gets the duplicate email that caused this exception. + * + * @return the duplicate email address + */ + public String getEmail() { + return extractEmailFromMessage(getMessage()); + } + + private String extractEmailFromMessage(String message) { + if (message != null && message.contains("'")) { + return message.substring(message.indexOf("'") + 1, message.lastIndexOf("'")); + } + return "unknown"; } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/application.properties b/Sprint 2/prototype2/src/main/resources/application.properties index 9831fc116..8b964f59e 100644 --- a/Sprint 2/prototype2/src/main/resources/application.properties +++ b/Sprint 2/prototype2/src/main/resources/application.properties @@ -1,27 +1,66 @@ +# ====================== +# Application Metadata +# ====================== spring.application.name=prototype2 -spring.jpa.hibernate.ddl-auto=create-drop -spring.datasource.url=jdbc:mysql://localhost:3306/userdatabase -spring.datasource.username=root -spring.datasource.password= -spring.datasource.driverClassName=com.mysql.jdbc.Driver -# Enable JDBC Session Storage -spring.session.store-type=jdbc -# Auto-create session tables (for development only) -#Disable in production -spring.session.jdbc.initialize-schema=never -# Optional: Show SQL queries (for debugging) -spring.jpa.show-sql=true -logging.level.org.springframework.jdbc.core=DEBUG +# ====================== +# Database Configuration +# ====================== +# Production: Use environment variables +spring.datasource.url=${DB_URL} +spring.datasource.username=${DB_USERNAME} +spring.datasource.password=${DB_PASSWORD} +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -# Sessions -# 30 minute timeout -server.servlet.session.timeout=30m +# Connection pool settings +spring.datasource.hikari.maximum-pool-size=10 +spring.datasource.hikari.connection-timeout=30000 -logging.level.org.hibernate.SQL=DEBUG -logging.level.org.hibernate.type=TRACE +# ====================== +# JPA/Hibernate Settings +# ====================== +# spring.jpa.hibernate.ddl-auto=validate # Changed from create-drop for safety TODO: Revert to this for production +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true + +# ====================== +# Session Management +# ====================== +# Production: Consider using redis instead +spring.session.store-type=jdbc +spring.session.jdbc.initialize-schema=always # Always disabled in production +spring.session.jdbc.table-name=SPRING_SESSION # Explicit table name +server.servlet.session.timeout=30m +server.servlet.session.tracking-modes=cookie +# ====================== +# Logging Configuration +# ====================== +# Application logging logging.level.com.jydoc=DEBUG + +# Spring Security logging logging.level.org.springframework.security=DEBUG +# SQL logging +logging.level.org.hibernate.SQL=DEBUG +logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE +logging.level.org.springframework.jdbc.core=DEBUG + +# ====================== +# Profile-specific Notes +# ====================== +# Development profile suggestions: +# ------------------------------ +# spring.jpa.hibernate.ddl-auto=update +# spring.jpa.properties.hibernate.hbm2ddl.import_files=sample-data.sql +# spring.session.jdbc.initialize-schema=always + +# Production profile must include: +# ------------------------------- +# spring.jpa.hibernate.ddl-auto=validate +# spring.session.jdbc.initialize-schema=never +# spring.datasource.tomcat.test-on-borrow=true +# spring.datasource.tomcat.validation-query=SELECT 1 \ No newline at end of file From c71c129a50642070799e8dae3ce5513e8c2769af Mon Sep 17 00:00:00 2001 From: bihiy Date: Thu, 27 Mar 2025 22:53:40 -0400 Subject: [PATCH 049/100] Bug patching --- .../deliverable4/Service/UserService.java | 65 +++++++++++++--- .../jydoc/deliverable4/model/UserModel.java | 23 +++++- .../target/classes/application.properties | 75 ++++++++++++++----- 3 files changed, 131 insertions(+), 32 deletions(-) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java index cc1e984e7..a92ef596d 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java @@ -9,21 +9,30 @@ import lombok.RequiredArgsConstructor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.DisabledException; +import org.springframework.security.authentication.LockedException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.util.Optional; /** - * Service layer for user management operations including: + * Service layer for comprehensive user management including: *
    *
  • User registration and validation
  • *
  • Authentication and credential verification
  • - *
  • User role management
  • + *
  • User role and authority management
  • + *
  • Account status handling
  • *
* - *

All database operations are transactional with appropriate propagation settings.

+ *

All database operations are transactional with appropriate propagation settings. + * Integrates with Spring Security for authentication and authorization.

*/ @Service @RequiredArgsConstructor @@ -35,11 +44,12 @@ public class UserService { private final UserRepository userRepository; private final AuthorityRepository authorityRepository; private final PasswordEncoder passwordEncoder; + private final AuthenticationManager authenticationManager; // ---------------------- Public API ---------------------- /** - * Registers a new user with the system. + * Registers a new user with the system after validating all requirements. * * @param userDto the user data transfer object containing registration details * @throws UsernameExistsException if the username is already taken @@ -56,11 +66,11 @@ public void registerNewUser(UserDTO userDto) { } /** - * Authenticates a user with provided credentials. + * Authenticates a user using Spring Security's authentication manager. * * @param loginDto the login data transfer object containing credentials - * @return authenticated UserModel - * @throws AuthenticationException if credentials are invalid + * @return authenticated UserModel entity + * @throws AuthenticationException if credentials are invalid or account is locked/disabled * @throws IllegalArgumentException if login data is null */ @Transactional(readOnly = true) @@ -72,7 +82,7 @@ public UserModel authenticate(LoginDTO loginDto) { } /** - * Validates login credentials and returns the authenticated user. + * Validates login credentials against stored user data. * * @param loginDto the login credentials * @return authenticated UserModel @@ -105,6 +115,41 @@ public UserModel validateLogin(LoginDTO loginDto) { return user; } + // ---------------------- Authentication Methods ---------------------- + + /** + * Core authentication method using Spring Security's authentication manager. + * + * @param username the username to authenticate + * @param password the raw password to verify + * @return authenticated UserModel + * @throws AuthenticationException wrapping various authentication failure scenarios + */ + @Transactional(readOnly = true) + public UserModel authenticateUser(String username, String password) { + try { + Authentication authentication = authenticationManager.authenticate( + new UsernamePasswordAuthenticationToken(username, password) + ); + + return userRepository.findByUsername(authentication.getName()) + .orElseThrow(() -> { + logger.error("Authentication succeeded but user not found: {}", username); + return new AuthenticationException("User account error"); + }); + + } catch (BadCredentialsException e) { + logger.warn("Authentication failed - bad credentials for user: {}", username); + throw new AuthenticationException("Invalid username or password"); + } catch (DisabledException e) { + logger.warn("Authentication failed - disabled account: {}", username); + throw new AuthenticationException("Account is disabled"); + } catch (LockedException e) { + logger.warn("Authentication failed - locked account: {}", username); + throw new AuthenticationException("Account is locked"); + } + } + // ---------------------- Core Business Logic ---------------------- /** @@ -126,7 +171,7 @@ private UserModel buildUserFromDto(UserDTO userDto) { } /** - * Assigns the default role to a new user. + * Assigns the default role to a new user, creating the role if it doesn't exist. * * @param user the user to receive the default role */ @@ -163,7 +208,7 @@ private void validateRegistration(UserDTO userDto) { /** * Finds an active user by username or email. * - * @param usernameOrEmail the user identifier + * @param usernameOrEmail the user identifier (username or email) * @return Optional containing the user if found and active */ @Transactional(readOnly = true) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java index 92ce65c68..2283a9b5b 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java @@ -4,6 +4,7 @@ import lombok.*; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import org.springframework.security.core.userdetails.UserDetails; import java.util.HashSet; import java.util.Set; @@ -29,7 +30,17 @@ public class UserModel { @Column(unique = true, length = 100) private String email; - private boolean enabled; + @Builder.Default + private boolean enabled = true; + + @Builder.Default + private boolean accountNonExpired = true; + + @Builder.Default + private boolean credentialsNonExpired = true; + + @Builder.Default + private boolean accountNonLocked = true; @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @JoinTable( @@ -37,11 +48,11 @@ public class UserModel { joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "authority_id") ) - @Fetch(FetchMode.JOIN) // Improves eager loading performance + @Fetch(FetchMode.JOIN) @Builder.Default private Set authorities = new HashSet<>(); - // Improved authority management + // Authority management methods public void addAuthority(AuthorityModel authority) { this.authorities.add(authority); authority.getUsers().add(this); @@ -52,8 +63,12 @@ public void removeAuthority(AuthorityModel authority) { authority.getUsers().remove(this); } - // Custom builder to handle collections + // Custom builder to handle default values public static class UserModelBuilder { + private boolean enabled = true; + private boolean accountNonExpired = true; + private boolean credentialsNonExpired = true; + private boolean accountNonLocked = true; private Set authorities = new HashSet<>(); } } \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/application.properties b/Sprint 2/prototype2/target/classes/application.properties index b4b512501..8b964f59e 100644 --- a/Sprint 2/prototype2/target/classes/application.properties +++ b/Sprint 2/prototype2/target/classes/application.properties @@ -1,27 +1,66 @@ +# ====================== +# Application Metadata +# ====================== spring.application.name=prototype2 -spring.jpa.hibernate.ddl-auto=create-drop -spring.datasource.url=jdbc:mysql://localhost:3306/userdatabase -spring.datasource.username=root -spring.datasource.password=JYDOC -spring.datasource.driverClassName=com.mysql.jdbc.Driver -# Enable JDBC Session Storage -spring.session.store-type=jdbc -# Auto-create session tables (for development only) -#Disable in production -spring.session.jdbc.initialize-schema=never -# Optional: Show SQL queries (for debugging) -spring.jpa.show-sql=true -logging.level.org.springframework.jdbc.core=DEBUG +# ====================== +# Database Configuration +# ====================== +# Production: Use environment variables +spring.datasource.url=${DB_URL} +spring.datasource.username=${DB_USERNAME} +spring.datasource.password=${DB_PASSWORD} +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -# Sessions -# 30 minute timeout -server.servlet.session.timeout=30m +# Connection pool settings +spring.datasource.hikari.maximum-pool-size=10 +spring.datasource.hikari.connection-timeout=30000 -logging.level.org.hibernate.SQL=DEBUG -logging.level.org.hibernate.type=TRACE +# ====================== +# JPA/Hibernate Settings +# ====================== +# spring.jpa.hibernate.ddl-auto=validate # Changed from create-drop for safety TODO: Revert to this for production +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true + +# ====================== +# Session Management +# ====================== +# Production: Consider using redis instead +spring.session.store-type=jdbc +spring.session.jdbc.initialize-schema=always # Always disabled in production +spring.session.jdbc.table-name=SPRING_SESSION # Explicit table name +server.servlet.session.timeout=30m +server.servlet.session.tracking-modes=cookie +# ====================== +# Logging Configuration +# ====================== +# Application logging logging.level.com.jydoc=DEBUG + +# Spring Security logging logging.level.org.springframework.security=DEBUG +# SQL logging +logging.level.org.hibernate.SQL=DEBUG +logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE +logging.level.org.springframework.jdbc.core=DEBUG + +# ====================== +# Profile-specific Notes +# ====================== +# Development profile suggestions: +# ------------------------------ +# spring.jpa.hibernate.ddl-auto=update +# spring.jpa.properties.hibernate.hbm2ddl.import_files=sample-data.sql +# spring.session.jdbc.initialize-schema=always + +# Production profile must include: +# ------------------------------- +# spring.jpa.hibernate.ddl-auto=validate +# spring.session.jdbc.initialize-schema=never +# spring.datasource.tomcat.test-on-borrow=true +# spring.datasource.tomcat.validation-query=SELECT 1 \ No newline at end of file From eedf8cf4d11ed4e05fdda60b647b5b5be5254615 Mon Sep 17 00:00:00 2001 From: bihiy Date: Thu, 27 Mar 2025 22:59:35 -0400 Subject: [PATCH 050/100] Cleanup --- Sprint 2/prototype2/.idea/.gitignore | 105 +++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Sprint 2/prototype2/.idea/.gitignore diff --git a/Sprint 2/prototype2/.idea/.gitignore b/Sprint 2/prototype2/.idea/.gitignore new file mode 100644 index 000000000..759b648e2 --- /dev/null +++ b/Sprint 2/prototype2/.idea/.gitignore @@ -0,0 +1,105 @@ +### Java ### +*.class +*.jar +*.war +*.ear +*.nar +hs_err_pid* + +# Build output +target/ +build/ +out/ +bin/ + +# IDE specific files +.idea/ +*.iml +*.ipr +*.iws +.settings/ +.vscode/ +.classpath +.project +.factorypath + +# Eclipse +.metadata/ + +# NetBeans +nbproject/private/ + +nbbuild/ + +nbdist/ +.nb-gradle/ + +### IntelliJ ### +# User-specific +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/shelf/ +.idea/httpRequests/ + +# Datasource storage +.idea/dataSources/ +.idea/dataSources.local.xml +.idea/dataSources.ids + +# Gradle +.gradle/ +gradle-app.setting + +# Maven +log/ +dependency-reduced-pom.xml + +### Spring Boot ### +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ + +### Database ### +*.db +*.sql +*.h2.db + +### OS generated files ### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +### Logs ### +*.log +logs/ + +### Environment files ### +.env +*.env +.env.local +.env.development +.env.test +.env.production + +### System Files ### +*.swp +*.swo +*~ +~$* + +### Test files ### +/temp/ +/test-output/ + +### Frontend (if applicable) ### +node_modules/ +dist/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +.class \ No newline at end of file From 0cda418d818d020560910b299262858b3535314e Mon Sep 17 00:00:00 2001 From: bihiy Date: Thu, 27 Mar 2025 23:00:15 -0400 Subject: [PATCH 051/100] Cleanup --- .../target/classes/application.properties | 66 ------- .../com/jydoc/deliverable4/DTO/LoginDTO.class | Bin 2503 -> 0 bytes .../com/jydoc/deliverable4/DTO/UserDTO.class | Bin 5163 -> 0 bytes .../Initializers/AuthorityInitializer.class | Bin 2229 -> 0 bytes .../deliverable4/Prototype2Application.class | Bin 763 -> 0 bytes .../UserService$AuthenticationException.class | Bin 794 -> 0 bytes .../UserService$EmailExistsException.class | Bin 974 -> 0 bytes .../UserService$UsernameExistsException.class | Bin 985 -> 0 bytes .../deliverable4/Service/UserService.class | Bin 8897 -> 0 bytes .../Service/UserValidationHelper.class | Bin 1953 -> 0 bytes .../deliverable4/config/SecurityConfig.class | Bin 13081 -> 0 bytes .../deliverable4/config/SessionConfig.class | Bin 324 -> 0 bytes .../controllers/AuthController.class | Bin 5685 -> 0 bytes .../controllers/CustomErrorController.class | Bin 2583 -> 0 bytes .../controllers/DashboardController.class | Bin 2622 -> 0 bytes ...AuthorityModel$AuthorityModelBuilder.class | Bin 2775 -> 0 bytes .../deliverable4/model/AuthorityModel.class | Bin 3194 -> 0 bytes .../deliverable4/model/UserAuthority.class | Bin 1167 -> 0 bytes .../deliverable4/model/UserAuthorityId.class | Bin 1134 -> 0 bytes .../model/UserModel$UserModelBuilder.class | Bin 3323 -> 0 bytes .../jydoc/deliverable4/model/UserModel.class | Bin 4957 -> 0 bytes .../repositories/AuthorityRepository.class | Bin 1046 -> 0 bytes .../UserAuthorityRepository.class | Bin 1045 -> 0 bytes .../repositories/UserRepository.class | Bin 1467 -> 0 bytes .../Exceptions/EmailExistsException.class | Bin 475 -> 0 bytes .../Exceptions/UsernameExistsException.class | Bin 484 -> 0 bytes .../security/auth/CustomUserDetails.class | Bin 2408 -> 0 bytes .../auth/CustomUserDetailsService.class | Bin 4660 -> 0 bytes .../target/classes/static/css/styles.css | 107 ------------ .../target/classes/static/js/script.js | 0 .../target/classes/templates/dashboard.html | 163 ------------------ .../target/classes/templates/error.html | 41 ----- .../classes/templates/fragments/footer.html | 39 ----- .../classes/templates/fragments/header.html | 101 ----------- .../target/classes/templates/index.html | 89 ---------- .../target/classes/templates/login.html | 45 ----- .../target/classes/templates/logout.html | 26 --- .../target/classes/templates/register.html | 34 ---- 38 files changed, 711 deletions(-) delete mode 100644 Sprint 2/prototype2/target/classes/application.properties delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/DTO/LoginDTO.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/DTO/UserDTO.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Initializers/AuthorityInitializer.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Prototype2Application.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$AuthenticationException.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$EmailExistsException.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$UsernameExistsException.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserValidationHelper.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/config/SecurityConfig.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/config/SessionConfig.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/controllers/AuthController.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/controllers/CustomErrorController.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/controllers/DashboardController.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/AuthorityModel$AuthorityModelBuilder.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/AuthorityModel.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/UserAuthority.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/UserAuthorityId.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/UserModel$UserModelBuilder.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/UserModel.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/AuthorityRepository.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/UserAuthorityRepository.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/UserRepository.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/auth/CustomUserDetails.class delete mode 100644 Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.class delete mode 100644 Sprint 2/prototype2/target/classes/static/css/styles.css delete mode 100644 Sprint 2/prototype2/target/classes/static/js/script.js delete mode 100644 Sprint 2/prototype2/target/classes/templates/dashboard.html delete mode 100644 Sprint 2/prototype2/target/classes/templates/error.html delete mode 100644 Sprint 2/prototype2/target/classes/templates/fragments/footer.html delete mode 100644 Sprint 2/prototype2/target/classes/templates/fragments/header.html delete mode 100644 Sprint 2/prototype2/target/classes/templates/index.html delete mode 100644 Sprint 2/prototype2/target/classes/templates/login.html delete mode 100644 Sprint 2/prototype2/target/classes/templates/logout.html delete mode 100644 Sprint 2/prototype2/target/classes/templates/register.html diff --git a/Sprint 2/prototype2/target/classes/application.properties b/Sprint 2/prototype2/target/classes/application.properties deleted file mode 100644 index 8b964f59e..000000000 --- a/Sprint 2/prototype2/target/classes/application.properties +++ /dev/null @@ -1,66 +0,0 @@ -# ====================== -# Application Metadata -# ====================== -spring.application.name=prototype2 - -# ====================== -# Database Configuration -# ====================== -# Production: Use environment variables -spring.datasource.url=${DB_URL} -spring.datasource.username=${DB_USERNAME} -spring.datasource.password=${DB_PASSWORD} -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver - -# Connection pool settings -spring.datasource.hikari.maximum-pool-size=10 -spring.datasource.hikari.connection-timeout=30000 - -# ====================== -# JPA/Hibernate Settings -# ====================== -# spring.jpa.hibernate.ddl-auto=validate # Changed from create-drop for safety TODO: Revert to this for production -spring.jpa.hibernate.ddl-auto=update -spring.jpa.show-sql=true -spring.jpa.properties.hibernate.format_sql=true -spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true - -# ====================== -# Session Management -# ====================== -# Production: Consider using redis instead -spring.session.store-type=jdbc -spring.session.jdbc.initialize-schema=always # Always disabled in production -spring.session.jdbc.table-name=SPRING_SESSION # Explicit table name -server.servlet.session.timeout=30m -server.servlet.session.tracking-modes=cookie - -# ====================== -# Logging Configuration -# ====================== -# Application logging -logging.level.com.jydoc=DEBUG - -# Spring Security logging -logging.level.org.springframework.security=DEBUG - -# SQL logging -logging.level.org.hibernate.SQL=DEBUG -logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE -logging.level.org.springframework.jdbc.core=DEBUG - -# ====================== -# Profile-specific Notes -# ====================== -# Development profile suggestions: -# ------------------------------ -# spring.jpa.hibernate.ddl-auto=update -# spring.jpa.properties.hibernate.hbm2ddl.import_files=sample-data.sql -# spring.session.jdbc.initialize-schema=always - -# Production profile must include: -# ------------------------------- -# spring.jpa.hibernate.ddl-auto=validate -# spring.session.jdbc.initialize-schema=never -# spring.datasource.tomcat.test-on-borrow=true -# spring.datasource.tomcat.validation-query=SELECT 1 \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/DTO/LoginDTO.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/DTO/LoginDTO.class deleted file mode 100644 index e3c73b707dbe83499c0cef1c11bc92e9da76e172..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2503 zcma)8?NZxD6g_JjB#el`e6*w`Q4>gPlSHLW+9alF12hS#`6v)NZGSEH4hSr*E6HTY zGxbL^(g28^*>W(!%vig7_nv$2**$lM|NcMy7r4H*Li7-Sed z@Hd7zP(@*A5;rqzlE}A?O&=kToz2gW-BrI@aMyO;)X%sN2WF<9l^+ z*IL=xuqtxjc4@+(H+|u`+z|}SxU|H7ad<^uwy|H&FszJH<8^iQg(+zA#?ApFfm-yIqWxxYlx)fLuIO1Nwtz%xdYb~=?rLDl@ zwj21?x(t>`HAiIz%@MxO_leBRi|F1>>6yaecHOjn)1zu_Pmr=^x-;&aG`h1+Y({G6 zhRt16%(neXP$6l@cGGlBI>U{2B&X>I=AJNlVAchv`F*o`z&&0Kghxa(;Wgwcwky_~ z&Ytjgl%kbzWtG==xo4|&WXuEyHi72)5&>y(O#}zBwn^z65$3zreFW{TuG1e7P9r!` zEl}(;)8xJg)}`mrWxW!$_!?R*yvi_{Y^8((nCx!QXp14cEt_6dJh9bDjKqz7N3}Ak zFMcRSm!u4oA{rr2U&m91vAFrmac}2HBlH`|4dSOPDp=F7ZeRnO3|Bj^gBPmN3X6y$ zG7Rm-Nf=%ydD!l;JQ7yu_>8-?y6|T!QXVxM<%HnF&P`e(pifcf z>Y=8wM5|#i%+v3dkK4FIh7quFbWC~m2uHrtG)BG_zNE#%D!x+4uUp6&q&i58rrj<& zWuaFa8Qi5bYXnz~m@B;lE6u-wR=V{DBd^Jn!ae#9lDqnTLtis=#kaUmD+09$sQp}2 z-UFHsrO2#IXq7XM^b}2Fa#Q3U7q8~s#XTg?xfG?0-Or~wgfbS%Q?ZyOHtNs#2l}u1 z(fsH;N{MH5cgv(Y5o*9&cjcIKJ6RR@dN#5 z!JzJGfYCyo(J)a;w}M&`r2%y+A0spnMLbWs6YWdBO(AnV6O8nm;9|XZ(pfa^mQ)5y x#4?3ttkAeZGu3shSCgq03pXz4p&u#IC31aEy3_Fl&#;Q0$(AMC7Iv_U>GyQ>6F~p~ diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/DTO/UserDTO.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/DTO/UserDTO.class deleted file mode 100644 index 0d388210304043fdbcf6c3391c92d08d2c185785..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5163 zcmb_gTW=f375j}%uZjwyg0p(Mh0C;s4BAPRPL&OT)I%a zZ0QZYX{|NwRkLB(_Z0Naw#Qqv8%BL)GDFH<72D9KAXV1t({DDls)B*x0Mwn@{hDDDRJUxcZd(f83C6>7Z?nVyFHJ}+W$6#A zI3nwwYI<=OObCl~|C`I{_isPb;>k>!NOsY5`n)FRSh@w5I;*?`t^&+Ssx6rKH zMonKbEQ8r}x?VSJ%{CYc1qU4m?-p-sRiol4i)D#XLo*nq;=IXqTet5`DoECJ%hFaP zGyEjU8&)h6!0KH`d}C$4znwaUn$w_X~5yP)7$=Oh?rn?cSu z*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(`SGG^VP2ama#jC40^jN+SM2$5Yi@%-DDvvkZ19bRvU^vofd} z$}ZV>2bURoLw+O}t|b*W_YOr(pQPH!J{IMvIp%C!#Wf0jASjimg|tE@njlfgg!Cjp zhp7FwUo&hvm3FJ;NfC5NE!dbxk;qfQsuzki6Y*9IHN`A0P!e?(@8P_K>kPSWJ)?|> z0K+6LW#X8cz?Hsu+-~lPV8?Vg71LEU?p1jp%{dnK2Fl!BPs{zR`jse%ekMbP`)Otg za#AQ`7_MkuYi#gV3}tG&?Q7W-RT)YGxa|8%bHgMBx=hX5;DP22KNUM$D%54V)>UpxIF0;sI|8O~Zm=ItIS(ADsa`?|Q1a zry92I(;b#;%}H1VJNyP zIB>$2dGz}R^fxMKI3Yn7N*}j`Q&!EE^65DfuH1@Jnh52sD9td3Rfcgw_xFA)jrL(J zOSAQnjR#oDVQI7!@^@5o7keVb*-d-q#D9;J9(3HzEAb(4A3Fsv3vR>`F>-g z2+Jex*F6!=xk@$Ktx^I}Jkb)8*9>dwBh2iQyI5{gl3r`qk->gd0Gva~xi^&HdYdf_E5X0V&kEWW}Okp8>7KXyFdq~BRs^gD)g z7^gu#fs2?#k>ZswjU`;dExMhgm{X+jK0Y8c6dkwmA*~}I(CVn8jDCh_Q177|4D{M76l(5E}~p}DOY2++)2^ES)p^8KAZNR Vk*81b5bOAYBw3PdV+U1C{RNX=YLWl| diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Prototype2Application.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Prototype2Application.class deleted file mode 100644 index 52aa797dcf7df18fc4154ae82e2279f052e96cdd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 763 zcmb7CO;6iE5PcgG970+kw0yNa^cJFul@RJB2q}%k$+U=|aOi36EM`-CH(IZu{H&ge zdgu@6kE%Lrknq8mTJnr$X6Mb!oB8wi*KYtLyz8KWr2x$?T3BXSpNm_;Q=t?7C7R3F zF)SY|t=tL2Qh$FMpv~|hHW{Da&rHl`GF7+IiYS#w{M;I6-2Flxjuwkl#lk70JLq6F zK(~t*c*!s@HsSfgDxF+gk;yw_zwyWz$0wz;l1UY9p&6on_}tYv6?s1VTJcPr2OI8( zb;z;NPJVZMZ1lBCin7s433B`JkfAv?Gs&4W2Cil<$eg|q?WpJDWY(OI4rr7Pb>OF+p2Il#CrsEMgD7m`8y)H zMiwW{NVf(*!G4tCb&@^|O4%UUeSCl(HpyDSE4(HUpZu`|1KPb{@PL)8=X`&%psNb7 dTES>z3)|%1p}$2GlWJhMlzVtX+LwI``~v{s$msw8 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$AuthenticationException.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$AuthenticationException.class deleted file mode 100644 index e74dbe1f496db823ebe020ef8755a4bee0cf01d0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 794 zcmbtS+iuf95IvJiour{{0%>WvG^Ldat%P6tL=aLbAduXG2=skp56(umw_0x^5aJtv zPk|Q%4}1V0g&2oQ1OWmGTiTg3J7=!@en>y3(7NK)B_~F-gR%dbV+HoB<)IBtsm`9Va6PnZ?y@*WcN1W&h zTQx{{&+oIH=#c%VIonfRLMJAU*%CGaV`E>PsBp-BVU*Z~+#C79)TLL$0%3K3?1n4_ zhN`Ho`%LMCqZ{3quja9YmWOr|XK{|O{+DosDqCwL^Y(9=nrZXlV8o%5Ha#p8ZvT68 zTR)dNGtbI_iI}h$=!}oX>45E%Vnl>?U_zA~E2|59YOJ`S&Ixyd|4-c`cq!+(il@nb z*(G7=kloNkkCas@JGPRz(Kllo@;w=}+|O+9dch~ujyQMsP3{QI2U*7UAW?bF!d&^o z1h9dQJip>2`Q-r$S`l=J^3>ki+5G@|53hY@_ahd|cqf-7oR@P!T!7a?dLs*ei&a6( p-$_`*1wlXy7ja1fUlzSe0wAPyIZNnD?n2gZMPx&qI-+l){tZtk)yx0@ diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$EmailExistsException.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$EmailExistsException.class deleted file mode 100644 index 737a68de3eb455c3f4ece2eed0a56710a56c9f4b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 974 zcmbtTZBG+H5Pr5VTw5xX3aAKjC|KU)zVJnBG=$V>Qo&GdLj1J7j_o%0LiV-=V*DxU zZ_qEkB>DsVQO3Da)0#BV#JgnYW_D(tooAo>@$>6<0DIWUAR%B^e5pLUv=)_Y71`3$ zB%9~9rk08fX=++X2^2cACml})E$6V&A=l(E0n0)rk1TS3?AMG|K}%rbRj7Sw1n#a^ zht(Im<(DI&i-zTmkn95@s1%ZWOo1<=Eluwm2mrjfd1BSb=0%aZu%#DHD zsAo~cWec-;%wb+&(+z#6bKVSHr%9gbk(LdQcAXmOo^r`~5s@Bzb89bbwMYxBR72fz z0Qzmhs7KX$<)%#y(Z1ZPOXE%2hVStlzU=znR1W zu3K2lV+l6|mj8kvkUEu`=PivHbA-X)q}DCi0uTRv+||AwD)Bj^5qeYmVUq-=t16&_ zuHPX2JZ4OwSPfn2)umRkKM1BwTSWqU)&ImT3#9u@#W=&;AIO7c_moUKY(A4(`owBw z%v>$(YL_0V_;7`hd)$fZ1u_Q|na5$o!puJj0@C}Qj3VO7*>RI&1lBi_zQqjQVG-|fi@o`a p23W-!d)x}QQDTsF{!R;az(pIpCa{UEzAa*#ZH|+cSVg diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$UsernameExistsException.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService$UsernameExistsException.class deleted file mode 100644 index d8328686f28c5c3d8fe3a92799f16435272bf07e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 985 zcmbtT+iuf95Iviub&`f&0&StR#D$hLDbz20fgmI(MIf1i8mLt9v~>n&BVVHRrWYZ8 z1NaSi;Ud8Y@KK0yld3@~0ts8%*_oZ0vvYj>0;8{D9ZDl`YsEdS z?w>YZ4u$#+8?~X(AghQH&RG~QVFHr^bEj>#dy!EgZ612mH7br6?v9F-xhpVz23&2Y zfHKZoxKP40W(4Y996Ft&R_r+~3e-Mnxfjs7(uxsoCW!im8xytSh7{6`5elvzST(&S@ z!UC=cRQ>`YkUNl?N3NbR=@5x0yzW@A1@8a*#7ie~*gO`%5XrfXxJ3dJu8L@@7w(aM zp7JJ8c4JQlJ5sCE9|UuztrCF;?*BtK1o9`8rD&&07)XUB_=HS5ZatHlg=|POa>nt=A}TD(^b!2BERo?Du*?5L zhV4SVEOOtF-Oa8xKV#$*#y(=IJiGb@m$LZ42^n1FbsSk<-(m{yFpu}R#@-#1OzW|B-5byv1 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/Service/UserService.class deleted file mode 100644 index 98dc481179b31a7cf20bd9f3aa17e761d14c5a4c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8897 zcmcIq349#aUH;x`?Uhy&d9{h{NOlt0ksVuyH>e;mDUlOkty?#Zu_oGqzwZ znHk3{%x6X}n$+MeB@SAHdm{r=zDPaTf)v^lNE^5jHz}m5E2mb9zLi&Ka!bC#=3uGq zW=?XQ&()ThA57ECTMTT)%?exd<|S*yEo4pqjO}0KUC}oSeo=#S2=G0F87**lYlLbqtO zOSsI`6*Z1K4D7*Pg`1X4$Ih9)HEGS;Mc*@h+ogDS>=|nSuA`?;XkhU=xOX~9MD`l! zLqDxQTe6*;fbN**=8yWW!o+JM(}-7|Ky@^?ak(25ZW#l2V!uK=;b_knj#_hO$?+#$ z$5QBR$ZjpAz0(p)2Mip3Fn3~h!OHqI@DE=laIeD7D(H_pjx}#OL*9HTZx#H}$FtU= z__G=JD|C&y^LC*t>sdLD*``zM%9@3O>vzpsU4@e4Byj{o28IQ`8;{rp+rKY~qZm!# z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d<(b3vzf#B6Qtk$N`9jFo}M!pre~5o)9k}I zeXimr4Y*lM5u58+!VRp`;8>zt*)~4%ct|^9f*-I<9LK49R`3WBvPjY&!z1#&M(1OQ zj=sl)hQxbJ(UTkj1B|ScEf6Q$P5M55fhV-kRP9JzAy*M~A^RILxj!%;!7sFpgp3F2 zDsVewG~T|}WfTv2uv4HFy4VAVCR-n%yBC4deSnnAF3@UkAPrADK+7FPdiDh0WOKhG nqf&5QkZ}%2?+VhxQt0C3D2Q8RsABLebns*NEQB)E+il=~ToUCW diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/config/SecurityConfig.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/config/SecurityConfig.class deleted file mode 100644 index 5066f228daeec30a7a2143f4feef22db4ab93763..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13081 zcmcgyd3+nkb^e}s0EAW&1WLAL*>3F64h36;EK9OwT9PS}3Mo+{O;D04Tb7orB0N1EREk+$iTUcX-Hoi^<^vkPKLKp(r=3(HZDs5;mTOLAtZj*ulbf`s5=kpnbnU|VUi~PD z74w$cXBA94lTTXi89QYO_6%JHN#6fDVHOM1iQZzq;A9V1A?S`#kktm(AS!4}=~?y# z;@#T0X~=P>68Ra|&P`3aX4X3ExTh0yXniI<#QenVjv$8i5Y`!3k81=2OZnW)<(z_9 zu$^4utTmCCDB78{<>nIug~Ci(enE38?@kIH@4Ql$mL|hen4qErtCffw3|z0|3r$<5 z;x$Ge&@XN@aFcqmUTNHMsS_o|sP$;k$`?4T$(wewfm_tHwn@j$4mneHE{10B)vX3@ zQ?FVx&XiLu#OPHT^Ckmv1z(%D@_Fj&pqVqLtgMyelvZ!bW&>S%ighk!%_xNqn7MR@ zwo^QBQ66`v;FU!+=voQoW@*pO5;Z(#8Fi{yyUV~fY!|d>+Y8pw@fLWp4D7I|6;MVfND)N)X5&f{q^N>&(9Q`#6(JsiM_pQ7%}sCMsm78mvZR7 z5$r}&3?Zxz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Y`b5hWvSq! z?WK~HpR9`05&m)={;q_-uR^$kwC|=R?qQ7V2q0V~2j!4P$YR7txP|Bx!q#{R{~W;N zC9~~;uUq8-8P#92p7Osw;M;6{+_%7gP_zH_IYCKU1IRo%yO>`RjEgN;hpqtP^;j>5 z$wF9;=yamm{wKD=%mKUuWfl|Ld{2c~8nSKJ21AFE5kUR!aT?&dDnb kp4a3Z@-B{-IKG?4`5L|=@8R>;IldQb<$dx2`4BezA2}Fm+W-In diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/config/SessionConfig.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/config/SessionConfig.class deleted file mode 100644 index a016790a9c7b3e12bf1e1dbdff8a4d9242ea73c6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 324 zcmb7<&q~8U5XQgBpGIS~#W(QgA9OF?6hR7}LVKw6zS)d*L%It|TJW(v2_Ad^AF4PT zym)jMzS-Z*FtgwH{__jKBc?eb#2Jz?Qj7@GTJN-Kv|Fo1S+nU0qkHRY|3HY(FIE{2 z2v^2$RQ*I+Tf1ukMi`7qNH&DSCu)FD>ZK5aArK69Y%mRJo5;JeS4Li~C9Mrj z)3oV*pXq&H>5;Ug4TqC9O|SI$oBAvLX0(^_E|`=bT1lgscYN=A@6Gt%|9$NZ07Lj^ z5>1F{Xx7n!R)O|eYr!&ID?ek7PR-hxP@wgolXt>H0tVPVbvFN4%LC+dpn) zLeIY}keIQj3_ej;6qplSM>7J2WSEdut(5_=W44UdHX#z(5c^x`7Vv|5yF|hp! z+h1@pwm|<#1Aj_0%yZS*={PnEG|TlGwg_x%uypwBs9MH*5?zS3VJq&_aKDZe9uT-! zxl!<){LHj(&Do2df6**D=4p?B3g}igI~0b#GgS;};BYMv6CBRZq-&sw0#(MQflwO$ zpg`QWXPh9k{Wk2tP7S+sbfbq5)U#*7a-FOdI$qv9;^ec`I&KF=my}54tl*gMdw!r; zaUqF5^lKQx_fSCRCxhW zPRm6Sn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sN_ct46L0yKxSf2ra%ilcmzAdli0pPCgSFQfG)A!^Z}Y1pdaSJ8hoMQ=AbeZ@Ea z6-mw%H_4_IA6K`q>Tu!JCnu4ZG4kG&hbDxi9F6LGMr#t*~`B|ZN~5D)HoCM_jpwiWWGX>d0fRc zYNVs3^pH>2aYGSgp3c2iA_!|#&$LFPWHuA}tGvmyxz1~eS2?q*>GKlmq|YWy{8D#)2v1o zoz5r-dLua%cT<&oNGT_qxS~S=6jNEig8LuI>8WyYkOY$+mc6SI>yI?~4NTJ;Y4QNy zB#JR(xLO}u)zGZ6M2|j~ELkb;PyGHS{#-&}h;OpCCdj)_vb}$%Dl{s(9?4lyf}_Ho qsJNI=j#Y|ot?|{+{Dpe{O8HIrn{rKB`ggv+#Vg5YmlgFNNc<0=_7BAX diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/controllers/CustomErrorController.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/controllers/CustomErrorController.class deleted file mode 100644 index a1a9814e01bdcfe2b75a3cbb504506957f2be2c6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2583 zcmbVNZF3V<6n<`+kThKiq<|DEEFd&(O4b)dXs}w_0@d`zq!a!=xqf$YS35-EnWTYQ^K#VudRorX|WNjwOIujU=U z#g$zbGKF;aT0Xj#7gBmM?<=kXf5Y~wVh9EfCNXT_5Dqhpzm8j1s%71xq1-kU*vx&9-CALyXRA%6kV1yxOl0IWuf#)Jw3OqygE)#~NgOxu4o)zf z_hilTTN-jx@}}7JV!<3MqZn+7>;Y;H~cIN;RAe_ z#771$<70-gevt|sYl(Eypp5fswI}2AeTengh!WnP&ps&W;S=&YRHf!|&A_xy!66b? zNpRnDSL>4dB8BS|r>5|IUK44|;Ikw?H>h~NV7O{~O>65>)w3;f)7cS{R~q87WqYoY zUZWwTZ_Ne1@|p`;{Bxb{wwZ8qsg3-aj5`#%k&7gd!aPHqDy^QvjejjO*{;crKsqVh zVi;5oQBb_u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>E!%a+`1g?^eR; z8J$u9(|%^c&>eU@ijY#Ab1w$D$NxbfwoC`OnjEe;hX>b4Xb!6m>nd~ub~B=Fn7FHK z=MIh@{iy`mLXHj1po_il#J=DqN7o>Yo6xKcX(}OrcIi4a*q}Yg_2jQ)eTMVzs*r+dNvvV$UF5mg)eE<3B3xIXp%0Po|!LVUsjA7z{A9B~{ z{eAbr-hpUG3}bh_z89@9=#}br8Y!eLWNeJXW~jG=o_lcA3EFN)_}-xi`JONCxV?Z( z_whi4>%*uUgkE&C*`ZQH@@cCfC zFjc80Dkx_ogK3m3%-ER41%^r0VHkOSJPDlz|{Ozgk%9$(a11L|Ms=5g1q_8m zjrfY@iMpH?Bio92`{@>c76VU7f<~j#s%$c3TEQ@Ei+i3Vq4>u(EK9C%mEK(g!(}=( zxl^>2np^{t2Ki|z=`54wl4K-J=OfrVQZ!12x&|`1M!G!;zycP@lF8R8s!aM0Nu6X~ zCOfqgSWf)}+4C|5>Lv>q$Rdp#eR)-~JW7j8QUQfg;>atM8g7uDme8e3cAdpi-1Sx5 zb=9f8foUAqz9Hv)z(kGy*D&?t+E=8uocFNm^q->m64PX5$;v9rGTy?_kEyJ#hMl8v zfg&tg%UP5#j~U!1ZH1&HV1#z{4DBi^s1l@kx^;*Y4K<3&!nAVi2No@))|eW=WE3gE s*Kw21GU;oIf1qT3hPI1tq5uE@ diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/UserModel$UserModelBuilder.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/model/UserModel$UserModelBuilder.class deleted file mode 100644 index 96004719d6d6264edab5369798d8ddac61665730..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3323 zcmbtWZByGu5Pl8}0;7PTlq676peD6Vi2IT@O$|dW>F7c? zL*jrR^Q_6Oz3gV`K$Imz_ncuFGSASNN^fiEVHot3YSJ*XE8N{L3K@rn&R+CE*KkEg zKL!}?mhEcx;G|-gvlU?)$HL(yQ{2f`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vKI*#jEp6xo!@Y6iGhgQ|IvX7YYcFogH zQD+OKoWgjh=!SN9pFLe#waRr(weFfH>y4d5c93sn=aJb_cs;+kQdqgGFdE7+=a%ag zhuHDDW4}|^T`V(-OisOAmNSzzC@pJe!`qbAjQsE@dzS4D$MWh`Cgl}BDI4Lx{N$u> zuL8L%WIr2f+=Auothn+^mDmIA6*m>mgsNT_Vc>KuKYJs;#I!3~wW3v`ePf|}=6rFm zD{&{kv|LzTA=5&B=|=u>Ot)OyS&`7trl@}>Q*u4;wHW>yd0u+v<9bb=t#oZ&BC0 z1ugYM3ShxuH=HXo73Bq+YElNdjxl!UYivz%j(o1MY2D!JI9E407P!8p@doDkfp4ln zJj8JUU07VhZQNPIXRuVjGFABG2~<)>CDN3xP|6oihtvRYuSogkA!9^d==^=t%vX&y zi==vs-#)8x7i+k84-t*G@j3bVJnmEag&HiZ--Eh}A}P2mLANd+V1wT`HEe9*1g8&C zCSrvwVt0h&bD6(GP5l#z2;Q37!?BD%{hKkw;cq{Qfb)FpXZdoz0GF#%{#HD~J6sV2 zRn!RYaUN4#$TOh+SgsTMTr%zCdWl>Y$?@`0xq9W9MKi^(v&J-_`vaW1`#w(p)z~7A z#Ay?d3SzvCcY|+V_$i{MkVyAv9<37iu9hqQxTBRupzt$l`?ogE*08!y7$c#dQ$O!G zbpE43I;miHlc}|wlgf3B1NbaK~mhFVrxxNp%JcMwuLK-UlB5bUz=7tz}auO{w>4CF8VwC To{K0Kqxb`7y=E4{AJOwa3?WGo diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/AuthorityRepository.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/AuthorityRepository.class deleted file mode 100644 index 591f2cb507ab5ad50225b833206830d051a2e317..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1046 zcmb7D%Wl&^6uncLhLl2EUTs;8x+Lv~mbdfUc+U)J$+ZW*$NQ1HOp` zAHYW;?l`rbECTJq^31jGIcLs2^ZU=wUjWdCXLVR1@Oq>sY@CH^#6l6vsnGl~7B86= zsWQ?kErnriXTRXeW`m-d)nS#u)|gK@i+K{U{^eMVY#r7Jyiz)1Ce<>Dt~8&B?@E7V zA-9~3Q(ggQ>@4LKAc37LnS=!u(sr^>M(ER!!2Ur{F$F4#TF++%XJyO+X>1F{^aQF5 zKXA`!g*F7%+%-UBD5Hd1rv-uY|AHL_OH7$4^r&*9=eMml$h|jkiIo%aSsID+;^_N}(n@<4G`?7_u?#}SzIlBtM?jUEeq5cbR7K!m-r1q`0azGRKlPUI z7@Hfsh!lZ~8@AnkEI;OAGYe>I`9c2`&f8JXvF2g*30WU1r$^#M#yHsB(zGi7O`mYQ zJp}IHQ^PB|f;X%VcVQJ8xT_%szV7)CumSh;HGv2C^QM6<*v7(!Z+|$etYh~hc#J<^ ScRwk+pJH)_vje+1-riqoc}Ud& diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/UserAuthorityRepository.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/UserAuthorityRepository.class deleted file mode 100644 index ddffae4872ee4d1b86d86715412f4a7cd9927a9f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1045 zcmb7DT~8B16ukqKN-0o9KILJ1;gut(Y=Xp!{llk7(PWQ6&9@Za*nfaBLvbxO=M2wzo6{RW6$gb;O90&r_ z_?7U5Q#dqbcmOjnhr1Gi3jXHZ0aRfjTN7Bs%S#E=;2{R8F8xs+sbKcec$(K+gY~TL#$O>II~@Q3 diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/UserRepository.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/repositories/UserRepository.class deleted file mode 100644 index 43120d649d9214f0703119bf1bcbd8a5f3d316d2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1467 zcmcIkQFGEj5ZELxa8)Ugtux9{=Xc zFSN}RquoABFo*QC&k{fayBET1zZvR09)=Of=dC0`U1`8lAvT3dxYX_|;d{(2A(I+c zmwx*l(+L%q0fEhM0<={Z9gnF{BB-+>=u2yfC_NuFiqxp-Rp~XRKbWQ76zZ}ZA|WXh zN=G2)gq{*T{!s)1l`VUoub3u}K5DJ1*ZYvmA!bVrm>Xg#pX;V&9yg4))q10PhKtas zICjm@3P#+}V40PMacWo3jEdPfJ~6@~ONbfG6Vox#HkQhGWgLyy1Rl?_o`^d`|LJo2 zlj}32Uo~|aA?R-LD-oz*y4Tr7ZTUoCXMEJ`G2vqEJpN~A6}RQcpJ_?n<|sD9!@ZF} z3v`Jqx9q0r?ToBpF-pJq7=b4XNzL7ctN+rsgs|p2VyYXOI0$^7 zny7eWOUwKBuW?;@Jf;#_J`S)RmrUIcWs6sYi??`RU)SUvDC&{NSA@Vd{8IQzZQx6j zhD}(5E!?Fr9DmpGTZ3(M?VxLYfeUt{V+3v>&RzgF;T9UUHS&IJ$zb$t$l@jeM$?^X n(_PRH-M#4?xg`DHIquKp$YJz@6{8={M`Mj~r3dgRs`&5^0UVu& diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/Exceptions/EmailExistsException.class deleted file mode 100644 index 74c60642825912620c8ca1f5c3d7cd93f1411010..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 475 zcmbtRO-lnY5Phj_S8KJkqM$c#et@}nt5k~A(<)-6_jGq?BfA?(vZei5o&*p60DqJ? zQK<*LnZV4v;qhK(^7j7n3ZRee1}a#IP;H`yy1@Q}nkkv7Vj}O#!t0y{^MoF~Hiba_ zTo>B+1a=PNAKuVgT}--1qX?@47m3N`!y+|_OexbdvTB^snRJwtR{Moq>Nz>cmCgop z?Yvud1*(@OC4p9~3%V)uG1>bdA<&6UqOy^)I^geS)lan(=*R!`?FvLWIj1I{PQS(z zXkU|`n)Fs#m6IpSu8pB7Z9-Q%Ja6x>aZZB}4iNF0!x4OW(Tvs@^*D!q{rKb=;)$yY l8XUu?fO&zr&eiT03r%b=Vm>y}Vx>0MHNhYVZ*i=k^8tccdxHP~ diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.class deleted file mode 100644 index a46212c1a36a8219316e4e6e0eae2026cd968f31..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 484 zcmbtRyG{c!5FCdj2O*FU1O=j@;~{YkT~H*R)qxO!^v>NXadc-R+ZU0~qC%qJ1NbP! z8c-+@6}GhAu}3qz>$mrpR{$qiZ=iyO2-PNPs0(aOI@tD$sS4Ioe zkCj%wC$O=b{P6nTDn07%4I(TGoTjFTC$r3?aYnhCl9j`pj$%h?X_cSFb3GT|JF;2^ z3+23tMCvcwp-?}Rh737>8eVYAh zQlNcBer&QEX}NGumW>;IQ`(d+Rj6?LkERZT7IqNvyu%W_dE$(g81?uJ_x1gQXNV`x mDrj&FzXRq4<}zoSUo14S!if1;MT?c%oYw?{AiT!0g3bp4WPg+Z diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/auth/CustomUserDetails.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/auth/CustomUserDetails.class deleted file mode 100644 index ddb8f7bb70a52615e6827da8f056801f5414ce3c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2408 zcmb_eT~ixX7=BKYB?(;u1VRC&prXwOW!2V74Mk~6D>b2=L75S+mSly6u#3B!DmUKw zQ|uKNIwRU~M#n2J{861g=j;MYh+~KGBIlev=Y5~|c|Rxry!ic30Ly6fBY|WZDIFU6 z1cr9ar>4<1oo(as)~?kI1o{?j#}1YRlEu=?CXM>w;LSAN(lLv- z1%{PJ3NMVI^w;{PV@k)b7h~$-bM@j)X;Wfe*HJ`CAhl!qJ0x2Cs)yui8Wn*%uD5OY z2Qn^Sdkh#uv3Hh*rt4XTjAbi~zi}=X*>!u{F@uiBFgHRAUBOta)c+g*p=UaQ)mn~X zdstnn3arK5Rr!s%5asdW&1O#))zSuIQFB}5Ias$HYpt`tWqF^=9LoZ6n`V2%^lbSZ zU8aH^n?YZwU#?E+z}R`%!-Es(p@zjGYCSP!xC6_hnIHZ~XD=Ia8KW%ARc2WBSN>eR zstgF^C~%S|)dS-vQeBB>03QF#(`5;={b>D3)UE=fC-`dUL?salNgu-QAF=)AX4CCB z!J6x=e0N}bva30eHtAvfjoI3hPgiZfMj6WqY_?roDQo*HCu5-yPgvB95>mM52Tt_F z>I-&Ej>LiWz-;a{%!8=RGO|I#!X&3vf&O*3<29`Zwyeyt3-fPYP6#%5hBHQ>%+Z^d z^OO@gF9)C6Io8z9Nv3vAF3QgFoWKoA3u?_H34=G!c-O~$ru-X3xpItjdF~hkZtNJa^+v~dWF9qp(T$he<9Og4Ghfj_Z&0QKv>3kRdDxM z%r%S?a0)BR*h~m`TDm3PKVUqkSdb4{&Ix=<42}PMaza(5CMW?)tl|+@nfp7$mKhjK d{ei@nNojxmIo|2^?orIU!P9hnM#Ti`F987#{1X5G diff --git a/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.class b/Sprint 2/prototype2/target/classes/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.class deleted file mode 100644 index 15a1f7f13035d05a35510e21744e80284368ad75..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4660 zcmcIn`*#%89sk^fFt8buH7XWCSTMvq&;g|oSp*>_NL>hJLu{~GC%ZSvklDH0nc3jB z_Fc6PZM9GPez*3mtwMowdi=Ske^XCCcXsx@8)6^lWHxv1{oe2QbH9(z_s&25b>r^< zPU79I=s~Z6O(y!VS>Vx}Dp;4xd6l#B(skCPZ!fy?kQK;W$#=rCWtYMgYpN84s&Fxo z{^K&V9XH5If6d8Bfq@byFUX<_oKX2?fkT-t8vUw}BLhp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2*GF@Hc$$I?_FO52I&q;=}?)PV$-N zbB0f5|23S~2zw)hBiPFE9t`j{eFyF%!hIOV2tT>*$A11Ez!;8jPNPm$Y}Qau;stz) z@OJZTpT=j1?X#3JYcrqYOnjmjxFC4v{5)0Y103g)c4cDx8s^3)-i3IZZxyF)rlfXV z-BF2}$wU;Gnxp#Y*)LF7Z}}pSOlThASerOZQ(BRE6AKIDSMl^UJg3jyXk>3>L?hO? zU&far9i+Ng$7HNy;3jeljI{)=!D-d9vq8&16iG1dUyW?N5(QG@dzJ5B<1@mwpHuJG k@jAX0jlPZV;`{O35AhTHmeN1PpDCN*=q>yO?_m4C0k(OD%m4rY diff --git a/Sprint 2/prototype2/target/classes/static/css/styles.css b/Sprint 2/prototype2/target/classes/static/css/styles.css deleted file mode 100644 index ff30abe6f..000000000 --- a/Sprint 2/prototype2/target/classes/static/css/styles.css +++ /dev/null @@ -1,107 +0,0 @@ -body { - font-family: Arial, sans-serif; - line-height: 1.6; - margin: 0; - padding: 20px; -} - -.error { - color: red; -} - -.success { - color: green; -} - -form { - max-width: 400px; - margin: 20px 0; -} - -form div { - margin-bottom: 10px; -} - -label { - display: inline-block; - width: 100px; -} - -/* Logout Page Styles */ -.logout-container { - max-width: 500px; - margin: 2rem auto; - padding: 2rem; - text-align: center; - border: 1px solid #ddd; - border-radius: 8px; -} - -.btn-logout { - background-color: #dc3545; - color: white; - padding: 0.5rem 1rem; - border: none; - border-radius: 4px; - cursor: pointer; - margin-right: 1rem; -} - -.btn-cancel { - padding: 0.5rem 1rem; - border: 1px solid #ddd; - border-radius: 4px; - text-decoration: none; - color: #333; -} - -.btn-logout:hover { - background-color: #c82333; -} - -.btn-cancel:hover { - background-color: #f8f9fa; -} - -/* Custom styles */ -body { - min-height: 100vh; - display: flex; - flex-direction: column; -} - -main { - flex: 1; -} - -.btn-lg { - min-width: 180px; -} - -.shadow-sm { - box-shadow: 0 .125rem .25rem rgba(0,0,0,.075) !important; -} - -/* Animation for buttons */ -.btn { - transition: all 0.3s ease; -} - -.btn:hover { - transform: translateY(-2px); - box-shadow: 0 4px 8px rgba(0,0,0,0.1); -} - -/* Footer styling */ -footer { - box-shadow: 0 -2px 5px rgba(0,0,0,0.05); -} - -footer a { - transition: color 0.2s ease; -} - -footer a:hover { - color: #0d6efd !important; - text-decoration: underline; -} \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/static/js/script.js b/Sprint 2/prototype2/target/classes/static/js/script.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/Sprint 2/prototype2/target/classes/templates/dashboard.html b/Sprint 2/prototype2/target/classes/templates/dashboard.html deleted file mode 100644 index dd5e20291..000000000 --- a/Sprint 2/prototype2/target/classes/templates/dashboard.html +++ /dev/null @@ -1,163 +0,0 @@ - - - - - - User Dashboard - - - - - - - - -
-
- -
-
-
- User Profile -
-
-

Username:

-

Roles: - -

-
-
- - -
-
- Quick Actions -
- -
-
- - -
-
-
-
-
- Dashboard Overview -
-
-
Welcome to your dashboard
-

Here you can manage your account and access all system features.

-
-
-
-
- - -
-
-
-
-
Documents
-

24

- View all -
-
-
-
-
-
-
Tasks
-

5

- View tasks -
-
-
-
-
-
-
Notifications
-

3

- View alerts -
-
-
-
- - -
-
-
-
- Admin Tools -
-
-
-
-
-
-
User Management
-

Manage all system users and permissions

- Go to Users -
-
-
-
-
-
-
System Reports
-

View system analytics and reports

- View Reports -
-
-
-
-
-
-
Audit Logs
-

Review system activity logs

- View Logs -
-
-
-
-
-
-
-
-
-
-
- - - - \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/error.html b/Sprint 2/prototype2/target/classes/templates/error.html deleted file mode 100644 index 38d4e6ba1..000000000 --- a/Sprint 2/prototype2/target/classes/templates/error.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - - Error Page - - - - -
-
-

⚠️ Oops! Something went wrong

-

We're sorry, but an error occurred while processing your request.

- -
-

Error Type

-

Error message

-

Request path:

-

Status code:

-

Timestamp:

-
- -
- Go to Home Page - -
-
-
- - \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/fragments/footer.html b/Sprint 2/prototype2/target/classes/templates/fragments/footer.html deleted file mode 100644 index f42441320..000000000 --- a/Sprint 2/prototype2/target/classes/templates/fragments/footer.html +++ /dev/null @@ -1,39 +0,0 @@ - - - -
-
-
- -
- © 2023 Application Name. All rights reserved. -
- - -
- -
-
- - -
-
- v1.0.0 -
-
-
-
- - \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/fragments/header.html b/Sprint 2/prototype2/target/classes/templates/fragments/header.html deleted file mode 100644 index 0b9dbc379..000000000 --- a/Sprint 2/prototype2/target/classes/templates/fragments/header.html +++ /dev/null @@ -1,101 +0,0 @@ - - - - - Navigation - - - -
- -
- - \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/index.html b/Sprint 2/prototype2/target/classes/templates/index.html deleted file mode 100644 index c35664607..000000000 --- a/Sprint 2/prototype2/target/classes/templates/index.html +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - Welcome to Our App - - - - -
- -
-
-
-

Welcome to Our Platform

-

Manage your account and access premium features

- -
- - - Dashboard - - - - - Register - - - - - Login - - - -
- - -
-
-
-
- -
-
-
-

Features

-
    -
  • Secure authentication
  • -
  • User dashboard
  • -
  • Responsive design
  • -
-
-
-
-
-

Get Started

-

Join our platform today to access all features.

- - Create Account - - - Go to Dashboard - -
-
-
-
- -
- - - - - - - \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/login.html b/Sprint 2/prototype2/target/classes/templates/login.html deleted file mode 100644 index 972c137c7..000000000 --- a/Sprint 2/prototype2/target/classes/templates/login.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - Login - - - -
- -
-

Login

- - -
- Invalid username/email or password -
-
- You have been logged out -
-
- Your session has expired. Please login again. -
- - -
-
- - - -
-
- - -
- -
- -

Don't have an account? Register here

-
- - - - \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/logout.html b/Sprint 2/prototype2/target/classes/templates/logout.html deleted file mode 100644 index f68ec77a1..000000000 --- a/Sprint 2/prototype2/target/classes/templates/logout.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - Logout - - - -
- -
-

Are you sure you want to log out?

- - -
- - -
- - - Cancel -
- -
- - \ No newline at end of file diff --git a/Sprint 2/prototype2/target/classes/templates/register.html b/Sprint 2/prototype2/target/classes/templates/register.html deleted file mode 100644 index f4e1ee768..000000000 --- a/Sprint 2/prototype2/target/classes/templates/register.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - Register - - - -
- -
-

Register

- - -
-
- - -
-
- - -
-
- - -
- -
- -

Already have an account? Login here

-
- - \ No newline at end of file From a7d27db2fe77098b25c6f496035487a8ebef57f4 Mon Sep 17 00:00:00 2001 From: bihiy Date: Thu, 27 Mar 2025 23:42:54 -0400 Subject: [PATCH 052/100] Additional documentation and refactoring --- .../com/jydoc/deliverable4/DTO/LoginDTO.java | 31 ++- .../com/jydoc/deliverable4/DTO/UserDTO.java | 57 +++-- .../deliverable4/config/SecurityConfig.java | 208 +++++++++++------- .../deliverable4/config/SessionConfig.java | 52 ++++- .../controllers/AuthController.java | 82 +++++-- .../controllers/CustomErrorController.java | 81 +++++-- .../controllers/DashboardController.java | 49 ++++- .../deliverable4/model/AuthorityModel.java | 31 ++- .../deliverable4/model/UserAuthority.java | 33 ++- .../deliverable4/model/UserAuthorityId.java | 41 +++- .../jydoc/deliverable4/model/UserModel.java | 60 ++++- .../Exceptions/UsernameExistsException.java | 24 ++ .../security/auth/CustomUserDetails.java | 48 ++++ .../auth/CustomUserDetailsService.java | 58 ++++- 14 files changed, 691 insertions(+), 164 deletions(-) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java index 6b2f13cd0..568449d2b 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java @@ -3,19 +3,44 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; +/** + * Data Transfer Object (DTO) for user login requests. + *

+ * Validates credentials format and provides utility methods for credential processing. + * + * @param username The username or email for authentication (case-insensitive) + * @param password The password for authentication + */ public record LoginDTO( - @NotBlank(message = "Username or email is required") + @NotBlank(message = "Username or email cannot be blank") String username, - @NotBlank(message = "Password is required") - @Size(min = 8, message = "Password must be at least 8 characters") + @NotBlank(message = "Password cannot be blank") + @Size(min = 8, message = "Password must be at least 8 characters long") String password ) { + + /** + * Creates an empty LoginDTO instance. + * @return A LoginDTO with empty strings for both fields + */ public static LoginDTO empty() { return new LoginDTO("", ""); } + /** + * Returns a normalized version of the username (trimmed and lowercase). + * @return The processed username ready for comparison + */ public String getNormalizedUsername() { return username.trim().toLowerCase(); } + + /** + * Checks if this LoginDTO represents an empty credential set. + * @return true if both username and password are blank + */ + public boolean isEmpty() { + return username.isBlank() && password.isBlank(); + } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java index fb5616c83..40763327e 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java @@ -2,41 +2,68 @@ import jakarta.validation.constraints.Email; import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; +import jakarta.validation.constraints.NotEmpty; import lombok.Data; -import lombok.Getter; -import lombok.Setter; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.Size; - +/** + * Data Transfer Object (DTO) for user registration and updates. + *

+ * Contains validation rules for user input with appropriate error messages. + * Represents the minimum required data for user operations. + */ @Data -@Getter -@Setter public class UserDTO { - // Getters and Setters + /** + * Unique username for the user. + * Must be 3-20 characters long. + */ @NotEmpty(message = "Username is required") @Size(min = 3, max = 20, message = "Username must be 3-20 characters") private String username; + /** + * Secure password for the user account. + * Must contain at least: + * - 6 characters + * - One uppercase letter + * - One lowercase letter + * - One number + */ @NotEmpty(message = "Password is required") @Size(min = 6, message = "Password must be at least 6 characters") - @Pattern(regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).{8,}$", - message = "Password must contain uppercase, lowercase, and number") + @Pattern( + regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).+$", + message = "Password must contain at least one uppercase, lowercase letter and number" + ) private String password; + /** + * User's email address. + * Must be in valid email format. + */ @Email(message = "Invalid email format") @NotEmpty(message = "Email is required") private String email; - @NotEmpty(message= "Invalid first name") + /** + * User's first name. + * Cannot be empty. + */ + @NotEmpty(message = "First name is required") private String firstName; - @NotEmpty(message= "Invalid last name") + /** + * User's last name. + * Cannot be empty. + */ + @NotEmpty(message = "Last name is required") private String lastName; + /** + * Default authority/role assigned to the user. + * Defaults to 'ROLE_USER' if not specified. + */ private String authority = "ROLE_USER"; - - } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java index b18395422..8a3c280ce 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java @@ -14,6 +14,19 @@ import org.springframework.security.web.csrf.CookieCsrfTokenRepository; import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession; +/** + * Central security configuration class that defines authentication and authorization rules, + * CSRF protection, session management, and security headers for the application. + *

+ * This configuration enables: + *

    + *
  • Form-based authentication with custom login/logout pages
  • + *
  • Role-based authorization (USER and ADMIN)
  • + *
  • CSRF protection with cookie-based token storage
  • + *
  • JDBC-based session management
  • + *
  • BCrypt password hashing
  • + *
+ */ @Configuration @EnableWebSecurity @EnableJdbcHttpSession @@ -21,11 +34,9 @@ public class SecurityConfig { private final CustomUserDetailsService userDetailsService; - public SecurityConfig(CustomUserDetailsService userDetailsService) { - this.userDetailsService = userDetailsService; - } - - // Public endpoints configuration + /** + * Endpoints that are accessible without authentication. + */ private static final String[] PUBLIC_ENDPOINTS = { "/", "/home", @@ -39,96 +50,145 @@ public SecurityConfig(CustomUserDetailsService userDetailsService) { "/api/public/**" }; + /** + * Constructs a new SecurityConfig with required dependencies. + * + * @param userDetailsService custom implementation of UserDetailsService + */ + public SecurityConfig(CustomUserDetailsService userDetailsService) { + this.userDetailsService = userDetailsService; + } + + /** + * Configures the security filter chain with all security policies. + * + * @param http the HttpSecurity to configure + * @return the configured SecurityFilterChain + * @throws Exception if configuration fails + */ @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { - http - // CSRF configuration (enabled for forms, disabled for APIs) - .csrf(csrf -> csrf - .ignoringRequestMatchers("/api/**") - .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) - ) + configureCsrfProtection(http); + configureSecurityHeaders(http); + configureAuthorization(http); + configureFormBasedAuthentication(http); + configureLogout(http); + configureSessionManagement(http); + configureExceptionHandling(http); - // Security headers - .headers(headers -> headers - .frameOptions(frame -> frame.sameOrigin()) - .httpStrictTransportSecurity(hsts -> hsts - .includeSubDomains(true) - .maxAgeInSeconds(31536000) // 1 year - ) - ) + return http.build(); + } - // Authorization configuration - .authorizeHttpRequests(auth -> auth - .requestMatchers(PUBLIC_ENDPOINTS).permitAll() - .requestMatchers("/dashboard").authenticated() - .requestMatchers("/user/**").hasAuthority("ROLE_USER") - .requestMatchers("/admin/**").hasAuthority("ROLE_ADMIN") - .requestMatchers("/api/user/**").hasAuthority("ROLE_USER") - .requestMatchers("/api/admin/**").hasAuthority("ROLE_ADMIN") - .anyRequest().authenticated() - ) + /** + * Configures CSRF protection with exceptions for API endpoints. + */ + private void configureCsrfProtection(HttpSecurity http) throws Exception { + http.csrf(csrf -> csrf + .ignoringRequestMatchers("/api/**") + .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) + ); + } - // Form login configuration - .formLogin(form -> form - .loginPage("/login") - .loginProcessingUrl("/perform_login") - .defaultSuccessUrl("/dashboard", true) - .failureUrl("/login?error=true") - .usernameParameter("username") - .passwordParameter("password") - .permitAll() + /** + * Configures security-related HTTP headers. + */ + /** + * Configures security-related HTTP headers. + */ + private void configureSecurityHeaders(HttpSecurity http) throws Exception { + http.headers(headers -> headers + .frameOptions(frame -> frame.sameOrigin()) + .httpStrictTransportSecurity(hsts -> hsts + .includeSubDomains(true) + .maxAgeInSeconds(31536000) ) + ); + } - // Logout configuration - .logout(logout -> logout - .logoutUrl("/perform_logout") - .logoutSuccessUrl("/login?logout") - .deleteCookies("JSESSIONID", "XSRF-TOKEN") - .invalidateHttpSession(true) - .clearAuthentication(true) - .permitAll() - ) + /** + * Configures authorization rules for different endpoints. + */ + private void configureAuthorization(HttpSecurity http) throws Exception { + http.authorizeHttpRequests(auth -> auth + .requestMatchers(PUBLIC_ENDPOINTS).permitAll() + .requestMatchers("/dashboard").authenticated() + .requestMatchers("/user/**", "/api/user/**").hasAuthority("ROLE_USER") + .requestMatchers("/admin/**", "/api/admin/**").hasAuthority("ROLE_ADMIN") + .anyRequest().authenticated() + ); + } - // Session management (stateful) - .sessionManagement(session -> session - .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) - .invalidSessionUrl("/login?invalid-session") - .maximumSessions(1) - .maxSessionsPreventsLogin(false) - .expiredUrl("/login?session-expired") - ) + /** + * Configures form-based authentication with custom login page. + */ + private void configureFormBasedAuthentication(HttpSecurity http) throws Exception { + http.formLogin(form -> form + .loginPage("/login") + .loginProcessingUrl("/perform_login") + .defaultSuccessUrl("/dashboard", true) + .failureUrl("/login?error=true") + .usernameParameter("username") + .passwordParameter("password") + .permitAll() + ); + } - // Exception handling - .exceptionHandling(exceptions -> exceptions - .accessDeniedPage("/access-denied") - ) + /** + * Configures logout behavior with session invalidation and cookie cleanup. + */ + private void configureLogout(HttpSecurity http) throws Exception { + http.logout(logout -> logout + .logoutUrl("/perform_logout") + .logoutSuccessUrl("/login?logout") + .deleteCookies("JSESSIONID", "XSRF-TOKEN") + .invalidateHttpSession(true) + .clearAuthentication(true) + .permitAll() + ); + } - // Set the custom UserDetailsService - .userDetailsService(userDetailsService); + /** + * Configures session management with concurrency control. + */ + private void configureSessionManagement(HttpSecurity http) throws Exception { + http.sessionManagement(session -> session + .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) + .invalidSessionUrl("/login?invalid-session") + .maximumSessions(1) + .maxSessionsPreventsLogin(false) + .expiredUrl("/login?session-expired") + ); + } - return http.build(); + /** + * Configures exception handling for access denied scenarios. + */ + private void configureExceptionHandling(HttpSecurity http) throws Exception { + http.exceptionHandling(exceptions -> exceptions + .accessDeniedPage("/access-denied") + ); } + /** + * Provides the AuthenticationManager bean. + * + * @param authenticationConfiguration the authentication configuration + * @return configured AuthenticationManager + * @throws Exception if configuration fails + */ @Bean public AuthenticationManager authenticationManager( AuthenticationConfiguration authenticationConfiguration) throws Exception { return authenticationConfiguration.getAuthenticationManager(); } + /** + * Provides the password encoder bean (BCrypt implementation). + * + * @return BCryptPasswordEncoder instance + */ @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } - - private void configureFormLogin(HttpSecurity http) throws Exception { - http.formLogin(form -> form - .loginPage("/login") - .loginProcessingUrl("/perform_login") - .usernameParameter("usernameOrEmail") // Update parameter name - .passwordParameter("password") - .defaultSuccessUrl("/dashboard", true) - .failureUrl("/login?error=true") - .permitAll() - ); - } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SessionConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SessionConfig.java index 84f130e1b..5df75e101 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SessionConfig.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SessionConfig.java @@ -1,4 +1,54 @@ package com.jydoc.deliverable4.config; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession; +import org.springframework.session.web.http.CookieSerializer; +import org.springframework.session.web.http.DefaultCookieSerializer; +import org.springframework.session.web.http.HttpSessionIdResolver; +import org.springframework.session.web.http.HeaderHttpSessionIdResolver; + +/** + * Configures HTTP session management for the application using in-memory storage. + *

+ * Features include: + *

    + *
  • In-memory session storage (default)
  • + *
  • Configurable session timeout
  • + *
  • Secure cookie settings
  • + *
  • Optional header-based session ID resolution
  • + *
+ */ +@Configuration +@EnableSpringHttpSession public class SessionConfig { -} + + /** + * Default session timeout in seconds (30 minutes). + */ + private static final int DEFAULT_SESSION_TIMEOUT = 1800; + + /** + * Configures session cookie settings with security best practices. + * @return Customized cookie serializer + */ + @Bean + public CookieSerializer cookieSerializer() { + DefaultCookieSerializer serializer = new DefaultCookieSerializer(); + serializer.setCookieName("JSESSIONID"); + serializer.setCookiePath("/"); + serializer.setUseHttpOnlyCookie(true); + serializer.setUseSecureCookie(true); // Requires HTTPS + serializer.setSameSite("Lax"); // CSRF protection + return serializer; + } + + /** + * Optional: Configures header-based session ID resolution (for API clients). + * Uncomment if you need to support session tokens in headers. + */ + // @Bean + // public HttpSessionIdResolver httpSessionIdResolver() { + // return HeaderHttpSessionIdResolver.xAuthToken(); + // } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java index 0a2d2ddcf..c08c28b85 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java @@ -2,8 +2,8 @@ import com.jydoc.deliverable4.DTO.UserDTO; import com.jydoc.deliverable4.DTO.LoginDTO; -import com.jydoc.deliverable4.model.UserModel; // Changed from org.apache.catalina.User -import com.jydoc.deliverable4.Service.UserService; // Added service dependency +import com.jydoc.deliverable4.model.UserModel; +import com.jydoc.deliverable4.Service.UserService; import jakarta.servlet.http.HttpSession; import jakarta.validation.Valid; import org.slf4j.Logger; @@ -14,48 +14,76 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +/** + * Controller handling authentication-related operations including: + * - User registration + * - Login/logout functionality + * - Session management + * + * All endpoints return Thymeleaf template names for view resolution. + */ @Controller public class AuthController { + private static final Logger logger = LoggerFactory.getLogger(AuthController.class); private final UserService userService; - private final Logger logger = LoggerFactory.getLogger(AuthController.class); - // Constructor injection for UserService + + /** + * Constructs an AuthController with required UserService dependency + * @param userService Service handling user operations + */ public AuthController(UserService userService) { this.userService = userService; } - /* ---------------------- Registration ---------------------- */ + // ========== REGISTRATION ENDPOINTS ========== + /** + * Displays user registration form + * @param model Model to add attributes for view + * @return "register" template name + */ @GetMapping("/register") public String showRegistrationForm(Model model) { model.addAttribute("user", new UserDTO()); return "register"; } + /** + * Processes user registration form submission + * @param userDto User data transfer object + * @param result Validation result + * @return Redirect to log in on success, re-show form on error + */ @PostMapping("/register") public String registerUser(@Valid @ModelAttribute("user") UserDTO userDto, BindingResult result) { if (result.hasErrors()) { + logger.debug("Registration validation errors present"); return "register"; } - // Register the user userService.registerNewUser(userDto); return "redirect:/login?registered"; } - /* ---------------------- Login ---------------------- */ + // ========== LOGIN ENDPOINTS ========== + /** + * Displays login form with optional status indicators + * @param model Model to add attributes for view + * @param error Optional error flag from redirect + * @param registered Optional registration success flag + * @param logout Optional logout success flag + * @return "login" template name + */ @GetMapping("/login") public String showLoginForm(Model model, @RequestParam(required = false) String error, @RequestParam(required = false) String registered, @RequestParam(required = false) String logout) { - model.addAttribute("loginData", LoginDTO.empty()); - - // Add the parameters as model attributes for Thymeleaf model.addAttribute("error", error != null); model.addAttribute("registered", registered != null); model.addAttribute("logout", logout != null); @@ -63,23 +91,30 @@ public String showLoginForm(Model model, return "login"; } + /** + * Processes login form submission + * @param loginDto Login credentials + * @param result Validation result + * @param session HTTP session to store user + * @param redirectAttributes For flash attributes + * @return Redirect to home on success, re-show form on error + */ @PostMapping("/login") public String loginUser(@Valid @ModelAttribute("loginData") LoginDTO loginDto, BindingResult result, HttpSession session, RedirectAttributes redirectAttributes) { - logger.debug("Login attempt with data: {}", loginDto); + logger.debug("Processing login for: {}", loginDto.username()); if (result.hasErrors()) { - logger.debug("Validation errors: {}", result.getAllErrors()); + logger.debug("Login validation errors"); return "login"; } try { UserModel user = userService.validateLogin(loginDto); session.setAttribute("user", user); - logger.info("Login successful for: {}", user.getUsername()); return "redirect:/home"; } catch (UserService.AuthenticationException e) { logger.error("Login failed: {}", e.getMessage()); @@ -88,8 +123,14 @@ public String loginUser(@Valid @ModelAttribute("loginData") LoginDTO loginDto, } } - /* ---------------------- Home Page ---------------------- */ + // ========== HOME ENDPOINT ========== + /** + * Displays home page for authenticated users + * @param model Model to add attributes for view + * @param session HTTP session containing user + * @return "index" template name + */ @GetMapping("/home") public String showHomePage(Model model, HttpSession session) { UserModel user = (UserModel) session.getAttribute("user"); @@ -99,13 +140,22 @@ public String showHomePage(Model model, HttpSession session) { return "index"; } - /* ---------------------- Logout ---------------------- */ + // ========== LOGOUT ENDPOINTS ========== + /** + * Displays logout confirmation page + * @return "logout" template name + */ @GetMapping("/confirm-logout") public String showLogoutConfirmation() { - return "logout"; // Shows the confirmation page + return "logout"; } + /** + * Processes logout request + * @param session HTTP session to invalidate + * @return Redirect to login with logout flag + */ @PostMapping("/logout") public String performLogout(HttpSession session) { session.invalidate(); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/CustomErrorController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/CustomErrorController.java index deb78980e..fa40f2972 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/CustomErrorController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/CustomErrorController.java @@ -8,41 +8,82 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; +import java.time.Instant; import java.util.Date; +import java.util.Optional; +/** + * Custom error controller to handle application errors and display user-friendly error pages. + * Implements Spring Boot's {@link ErrorController} interface to override default error handling. + */ @Controller public class CustomErrorController implements ErrorController { + private static final String DEFAULT_ERROR_MESSAGE = "An unexpected error occurred"; + private static final String DB_VALIDATION_ERROR = "Database error: Required role configuration is missing. Please contact support."; + + /** + * Handles all error requests and prepares error information for display. + * + * @param request The HTTP request containing error attributes + * @param model The model to populate with error details + * @return The error view template name + */ @RequestMapping("/error") public String handleError(HttpServletRequest request, Model model) { - // Get error status - Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); - Object exception = request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); - - HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; - if (status != null) { - httpStatus = HttpStatus.valueOf(Integer.parseInt(status.toString())); - } + HttpStatus httpStatus = resolveHttpStatus(request); + Throwable exception = resolveException(request); - // Add error information to model model.addAttribute("status", httpStatus.value()); model.addAttribute("error", httpStatus.getReasonPhrase()); - model.addAttribute("message", getErrorMessage(exception)); + model.addAttribute("message", getSafeErrorMessage(exception)); model.addAttribute("path", request.getAttribute(RequestDispatcher.ERROR_REQUEST_URI)); - model.addAttribute("timestamp", new Date()); + model.addAttribute("timestamp", Instant.now()); return "error"; } - private String getErrorMessage(Object exception) { - if (exception != null) { - Throwable ex = (Throwable) exception; - // Customize message for specific errors - if (ex.getMessage().contains("Field 'authority' doesn't have a default value")) { - return "Database error: Required role configuration is missing. Please contact support."; - } - return ex.getMessage(); + /** + * Resolves the HTTP status from the request attributes. + */ + private HttpStatus resolveHttpStatus(HttpServletRequest request) { + return Optional.ofNullable(request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE)) + .map(status -> HttpStatus.valueOf(Integer.parseInt(status.toString()))) + .orElse(HttpStatus.INTERNAL_SERVER_ERROR); + } + + /** + * Resolves the exception from the request attributes. + */ + private Throwable resolveException(HttpServletRequest request) { + return Optional.ofNullable(request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)) + .map(Throwable.class::cast) + .orElse(null); + } + + /** + * Provides a safe error message for display, handling nulls and sensitive information. + */ + private String getSafeErrorMessage(Throwable exception) { + if (exception == null) { + return DEFAULT_ERROR_MESSAGE; + } + + String message = exception.getMessage(); + if (message == null) { + return DEFAULT_ERROR_MESSAGE; } - return "Unknown error occurred"; + + return message.contains("Field 'authority' doesn't have a default value") + ? DB_VALIDATION_ERROR + : sanitizeMessage(message); + } + + /** + * Sanitizes error messages to prevent exposing sensitive information. + */ + private String sanitizeMessage(String message) { + // Basic sanitization - extend this for your specific security requirements + return message.replaceAll("(?i)password|secret|key|token", "[REDACTED]"); } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/DashboardController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/DashboardController.java index 6a8d02b9e..7042f76c8 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/DashboardController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/DashboardController.java @@ -5,21 +5,58 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.security.access.prepost.PreAuthorize; +/** + * Controller for handling dashboard-related requests. + *

+ * Provides authenticated users access to the application dashboard with + * role-specific information and functionality. + */ @Controller public class DashboardController { + /** + * Displays the application dashboard for authenticated users. + * + * @param authentication The Spring Security authentication object + * @param model The model to populate with user data + * @return The dashboard view template name + * @throws ClassCastException if the principal is not a UserDetails instance + */ @GetMapping("/dashboard") + @PreAuthorize("isAuthenticated()") public String showDashboard(Authentication authentication, Model model) { - // Get user details from Spring Security - UserDetails userDetails = (UserDetails) authentication.getPrincipal(); + try { + UserDetails userDetails = getUserDetails(authentication); + populateModelWithUserDetails(model, userDetails); + return "dashboard"; + } catch (ClassCastException e) { + throw new SecurityException("Invalid authentication principal type", e); + } + } + + /** + * Extracts UserDetails from the Authentication object. + */ + private UserDetails getUserDetails(Authentication authentication) { + return (UserDetails) authentication.getPrincipal(); + } - // Add user info to model + /** + * Populates the model with user-specific information. + */ + private void populateModelWithUserDetails(Model model, UserDetails userDetails) { model.addAttribute("username", userDetails.getUsername()); model.addAttribute("authorities", userDetails.getAuthorities()); - model.addAttribute("isAdmin", userDetails.getAuthorities().stream() - .anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN"))); + model.addAttribute("isAdmin", hasAdminAuthority(userDetails)); + } - return "dashboard"; + /** + * Checks if the user has ADMIN authority. + */ + private boolean hasAdminAuthority(UserDetails userDetails) { + return userDetails.getAuthorities().stream() + .anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN")); } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/AuthorityModel.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/AuthorityModel.java index f4cf5dd54..c299fc4c7 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/AuthorityModel.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/AuthorityModel.java @@ -5,32 +5,57 @@ import java.util.HashSet; import java.util.Set; +/** + * Represents an authority/role in the system that can be assigned to users. + * Authorities define permissions or access levels for users. + */ @Entity @Table(name = "authorities") -@Getter @Setter +@Getter +@Setter @NoArgsConstructor @AllArgsConstructor @Builder(toBuilder = true) public class AuthorityModel { + /** + * Unique identifier for the authority. + */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + /** + * Name of the authority (e.g., "ROLE_ADMIN", "ROLE_USER"). + * Must be unique and cannot be null. + */ @Column(nullable = false, unique = true, length = 50) private String authority; + /** + * Set of users who have been granted this authority. + * Represents the many-to-many relationship with UserModel. + */ @ManyToMany(mappedBy = "authorities") @Builder.Default private Set users = new HashSet<>(); - // Added constructor + /** + * Constructs an AuthorityModel with the given authority name. + * + * @param authority the name of the authority + */ public AuthorityModel(String authority) { this.authority = authority; } - // Custom builder + /** + * Custom builder class for AuthorityModel that initializes the users set. + */ public static class AuthorityModelBuilder { + /** + * The set of users for this authority, initialized as empty HashSet. + */ private Set users = new HashSet<>(); } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthority.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthority.java index 3d42c138b..6793f48b4 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthority.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthority.java @@ -1,23 +1,40 @@ package com.jydoc.deliverable4.model; import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; +/** + * Represents the many-to-many relationship between users and authorities. + * This entity serves as a join table that maps users to their assigned authorities/roles. + *

+ * Uses a composite primary key represented by {@link UserAuthorityId} consisting of + * {@code userId} and {@code authorityId}. + * + * @see UserAuthorityId + */ @Entity +@Getter +@Setter @Table(name = "user_authorities") @IdClass(UserAuthorityId.class) public class UserAuthority { + /** + * The ID of the user associated with this authority mapping. + * Part of the composite primary key. + * Cannot be null. + */ @Id - @Column(name = "user_id") + @Column(name = "user_id", nullable = false) private Long userId; + /** + * The ID of the authority associated with this user mapping. + * Part of the composite primary key. + * Cannot be null. + */ @Id - @Column(name = "authority_id") + @Column(name = "authority_id", nullable = false) private Long authorityId; - - // Getters and setters - public Long getUserId() { return userId; } - public void setUserId(Long userId) { this.userId = userId; } - public Long getAuthorityId() { return authorityId; } - public void setAuthorityId(Long authorityId) { this.authorityId = authorityId; } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthorityId.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthorityId.java index 97d3c1661..18ca1e49c 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthorityId.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthorityId.java @@ -1,20 +1,41 @@ package com.jydoc.deliverable4.model; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; import java.io.Serializable; import java.util.Objects; +/** + * Composite primary key class for {@link UserAuthority} entity. + *

+ * Represents the compound key consisting of user ID and authority ID + * used in the user-authority many-to-many relationship mapping. + * + * @see UserAuthority + */ +@NoArgsConstructor +@AllArgsConstructor public class UserAuthorityId implements Serializable { - private Long userId; - private Long authorityId; - public UserAuthorityId() {} + private static final long serialVersionUID = 1L; - public UserAuthorityId(Long userId, Long authorityId) { - this.userId = userId; - this.authorityId = authorityId; - } + /** + * The ID of the user in the relationship. + * Part of the composite primary key. + */ + private Long userId; + + /** + * The ID of the authority in the relationship. + * Part of the composite primary key. + */ + private Long authorityId; - // equals() and hashCode() + /** + * Compares this composite key with another object for equality. + * @param o the object to compare with + * @return true if the objects are equal + */ @Override public boolean equals(Object o) { if (this == o) return true; @@ -24,6 +45,10 @@ public boolean equals(Object o) { Objects.equals(authorityId, that.authorityId); } + /** + * Generates a hash code for this composite key. + * @return the hash code + */ @Override public int hashCode() { return Objects.hash(userId, authorityId); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java index 2283a9b5b..3ed7babf5 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java @@ -9,39 +9,84 @@ import java.util.HashSet; import java.util.Set; +/** + * Represents a user entity in the system, implementing Spring Security's {@link UserDetails}. + *

+ * This entity stores user authentication details and their associated authorities/roles. + * It includes security-related flags and manages a many-to-many relationship with {@link AuthorityModel}. + * + * @see UserDetails + * @see AuthorityModel + */ @Entity @Table(name = "users") -@Getter @Setter +@Getter +@Setter @NoArgsConstructor @AllArgsConstructor @Builder(toBuilder = true) public class UserModel { + /** + * Unique identifier for the user. + */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + /** + * Unique username for authentication. + * Must be non-null and maximum 50 characters. + */ @Column(unique = true, nullable = false, length = 50) private String username; + /** + * Encrypted password for authentication. + * Must be non-null and maximum 100 characters. + */ @Column(nullable = false, length = 100) private String password; + /** + * Unique email address for the user. + * Maximum 100 characters. + */ @Column(unique = true, length = 100) private String email; + /** + * Indicates whether the user is enabled. + * Defaults to true. + */ @Builder.Default private boolean enabled = true; + /** + * Indicates whether the user's account is expired. + * Defaults to true. + */ @Builder.Default private boolean accountNonExpired = true; + /** + * Indicates whether the user's credentials are expired. + * Defaults to true. + */ @Builder.Default private boolean credentialsNonExpired = true; + /** + * Indicates whether the user's account is locked. + * Defaults to true. + */ @Builder.Default private boolean accountNonLocked = true; + /** + * Set of authorities/roles assigned to the user. + * Uses eager fetching with JOIN strategy for performance. + */ @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @JoinTable( name = "user_authorities", @@ -52,18 +97,27 @@ public class UserModel { @Builder.Default private Set authorities = new HashSet<>(); - // Authority management methods + /** + * Adds an authority to the user and maintains the bidirectional relationship. + * @param authority the authority to add + */ public void addAuthority(AuthorityModel authority) { this.authorities.add(authority); authority.getUsers().add(this); } + /** + * Removes an authority from the user and maintains the bidirectional relationship. + * @param authority the authority to remove + */ public void removeAuthority(AuthorityModel authority) { this.authorities.remove(authority); authority.getUsers().remove(this); } - // Custom builder to handle default values + /** + * Custom builder implementation to handle default values properly. + */ public static class UserModelBuilder { private boolean enabled = true; private boolean accountNonExpired = true; diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.java index 8eda3f5dc..7db42464b 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UsernameExistsException.java @@ -1,7 +1,31 @@ package com.jydoc.deliverable4.security.Exceptions; +/** + * Custom exception thrown when attempting to create or update a user with a username + * that already exists in the system. + * + *

This exception should be used during user registration or profile updates + * to enforce unique username constraints. + */ public class UsernameExistsException extends RuntimeException { + + /** + * Constructs a new UsernameExistsException with the specified detail message. + * + * @param message the detail message that explains which username already exists. + * The message is saved for later retrieval by the {@link #getMessage()} method. + */ public UsernameExistsException(String message) { super(message); } + + /** + * Constructs a new UsernameExistsException with the specified detail message and cause. + * + * @param message the detail message that explains which username already exists + * @param cause the underlying cause of this exception + */ + public UsernameExistsException(String message, Throwable cause) { + super(message, cause); + } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java index ccdcc5525..0cf0f59c8 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java @@ -6,6 +6,14 @@ import java.util.Collection; import java.util.Objects; +/** + * Custom implementation of Spring Security's UserDetails interface. + * Extends the standard user details with additional user ID field while implementing + * all required UserDetails contract methods. + * + *

This class serves as an adapter between the application's user model + * and Spring Security's authentication framework. + */ public class CustomUserDetails implements UserDetails { private final Long userId; private final String username; @@ -13,6 +21,15 @@ public class CustomUserDetails implements UserDetails { private final boolean enabled; private final Collection authorities; + /** + * Constructs a new CustomUserDetails instance. + * + * @param userId the unique user identifier from the application's domain model + * @param username the username used to authenticate + * @param password the encrypted password + * @param enabled flag indicating if the user is enabled + * @param authorities the user's granted authorities (roles/permissions) + */ public CustomUserDetails(Long userId, String username, String password, boolean enabled, Collection authorities) { this.userId = userId; @@ -22,6 +39,9 @@ public CustomUserDetails(Long userId, String username, String password, this.authorities = authorities; } + /** + * @return the application-specific user ID + */ public Long getUserId() { return userId; } @@ -41,16 +61,25 @@ public String getUsername() { return username; } + /** + * @return true if the account is not expired (always true in this implementation) + */ @Override public boolean isAccountNonExpired() { return true; } + /** + * @return true if the account is not locked (always true in this implementation) + */ @Override public boolean isAccountNonLocked() { return true; } + /** + * @return true if credentials are not expired (always true in this implementation) + */ @Override public boolean isCredentialsNonExpired() { return true; @@ -61,6 +90,9 @@ public boolean isEnabled() { return enabled; } + /** + * Compares users based on username only. + */ @Override public boolean equals(Object o) { if (this == o) return true; @@ -69,8 +101,24 @@ public boolean equals(Object o) { return Objects.equals(username, that.username); } + /** + * Generates hash code based on username only. + */ @Override public int hashCode() { return Objects.hash(username); } + + /** + * Returns a string representation of the user details (excluding password). + */ + @Override + public String toString() { + return "CustomUserDetails{" + + "userId=" + userId + + ", username='" + username + '\'' + + ", enabled=" + enabled + + ", authorities=" + authorities + + '}'; + } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java index c477abf15..14923e7e0 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java @@ -14,26 +14,58 @@ import java.util.Set; import java.util.stream.Collectors; +/** + * Custom implementation of Spring Security's UserDetailsService that loads user-specific data. + * This service connects the application's user model with Spring Security's authentication framework. + * + *

Key responsibilities: + *

    + *
  • Loading user details by username or email
  • + *
  • Mapping application user model to Spring Security's UserDetails
  • + *
  • Handling user authority/role conversion
  • + *
+ */ @Service @RequiredArgsConstructor public class CustomUserDetailsService implements UserDetailsService { private final UserRepository userRepository; + /** + * Loads user details by username or email. + * + * @param usernameOrEmail the username or email to search for + * @return UserDetails containing user information + * @throws UsernameNotFoundException if user is not found + */ @Override @Transactional(readOnly = true) - public UserDetails loadUserByUsername(String usernameOrEmail) { + public UserDetails loadUserByUsername(String usernameOrEmail) throws UsernameNotFoundException { + UserModel user = findUserByUsernameOrEmail(usernameOrEmail); + return createUserDetails(user); + } + + /** + * Finds a user by their username or email. + * + * @param usernameOrEmail the username or email to search for + * @return found UserModel + * @throws UsernameNotFoundException if user is not found + */ + private UserModel findUserByUsernameOrEmail(String usernameOrEmail) throws UsernameNotFoundException { return userRepository.findByUsernameOrEmailWithAuthorities(usernameOrEmail) - .map(this::mapToUserDetails) .orElseThrow(() -> new UsernameNotFoundException( "User not found with username or email: " + usernameOrEmail)); } - private UserDetails mapToUserDetails(UserModel user) { - Set authorities = user.getAuthorities().stream() - .map(auth -> new SimpleGrantedAuthority(auth.getAuthority())) - .collect(Collectors.toSet()); - + /** + * Creates UserDetails from UserModel. + * + * @param user the user model to convert + * @return UserDetails implementation + */ + private UserDetails createUserDetails(UserModel user) { + Set authorities = mapAuthorities(user); return new CustomUserDetails( user.getId(), user.getUsername(), @@ -42,4 +74,16 @@ private UserDetails mapToUserDetails(UserModel user) { authorities ); } + + /** + * Maps user authorities to Spring Security GrantedAuthority objects. + * + * @param user the user model containing authorities + * @return set of GrantedAuthority objects + */ + private Set mapAuthorities(UserModel user) { + return user.getAuthorities().stream() + .map(auth -> new SimpleGrantedAuthority(auth.getAuthority())) + .collect(Collectors.toSet()); + } } \ No newline at end of file From b7d02e06c502e3e326b0aa1b8a26ce71ee232236 Mon Sep 17 00:00:00 2001 From: bihiy Date: Thu, 27 Mar 2025 23:52:13 -0400 Subject: [PATCH 053/100] Added @Serial to serialVersionUID --- .../java/com/jydoc/deliverable4/model/UserAuthorityId.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthorityId.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthorityId.java index 18ca1e49c..5dbde4b71 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthorityId.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserAuthorityId.java @@ -2,6 +2,8 @@ import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; + +import java.io.Serial; import java.io.Serializable; import java.util.Objects; @@ -17,6 +19,7 @@ @AllArgsConstructor public class UserAuthorityId implements Serializable { + @Serial private static final long serialVersionUID = 1L; /** From b3871be6ef4f75eecff09b2353156dc89492f334 Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 02:37:22 -0400 Subject: [PATCH 054/100] Added test cases and small verification changes --- Sprint 2/prototype2/pom.xml | 49 +++ .../com/jydoc/deliverable4/DTO/UserDTO.java | 71 ++-- .../jydoc/deliverable4/model/UserModel.java | 56 --- .../security/auth/CustomUserDetails.java | 79 +--- .../auth/CustomUserDetailsService.java | 60 +-- .../resources/application-test.properties | 45 +++ .../src/main/resources/application.properties | 3 +- .../Prototype2ApplicationTests.java | 4 +- .../deliverable4/UserDtoValidationTest.java | 221 ++++++++++ .../com/jydoc/deliverable4/UserModelTest.java | 226 +++++++++++ .../deliverable4/UserRepositoryTest.java | 178 ++++++++ .../jydoc/deliverable4/UserServiceTest.java | 381 ++++++++++++++++++ 12 files changed, 1160 insertions(+), 213 deletions(-) create mode 100644 Sprint 2/prototype2/src/main/resources/application-test.properties create mode 100644 Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserDtoValidationTest.java create mode 100644 Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java create mode 100644 Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserRepositoryTest.java create mode 100644 Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java diff --git a/Sprint 2/prototype2/pom.xml b/Sprint 2/prototype2/pom.xml index 314b1f27f..52710c21b 100644 --- a/Sprint 2/prototype2/pom.xml +++ b/Sprint 2/prototype2/pom.xml @@ -46,6 +46,7 @@ org.springframework.boot spring-boot-starter-validation + org.springframework.boot spring-boot-starter-web @@ -102,6 +103,54 @@ spring-boot-starter-data-jpa + + jakarta.validation + jakarta.validation-api + 3.0.2 + + + + + org.hibernate.validator + hibernate-validator + 8.0.2.Final + + + + + org.junit.jupiter + junit-jupiter + 5.11.4 + test + + + org.junit.jupiter + junit-jupiter-api + 5.11.4 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.11.4 + test + + + org.glassfish + jakarta.el + 3.0.4 + + + com.h2database + h2 + test + + + com.h2database + h2 + + + diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java index 40763327e..65658abf8 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java @@ -1,37 +1,21 @@ package com.jydoc.deliverable4.DTO; import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Size; -import jakarta.validation.constraints.NotEmpty; -import lombok.Data; +import lombok.Getter; +import lombok.Setter; -/** - * Data Transfer Object (DTO) for user registration and updates. - *

- * Contains validation rules for user input with appropriate error messages. - * Represents the minimum required data for user operations. - */ -@Data +@Setter +@Getter public class UserDTO { - - /** - * Unique username for the user. - * Must be 3-20 characters long. - */ - @NotEmpty(message = "Username is required") + // Getters and Setters + @NotBlank(message = "Username is required") @Size(min = 3, max = 20, message = "Username must be 3-20 characters") private String username; - /** - * Secure password for the user account. - * Must contain at least: - * - 6 characters - * - One uppercase letter - * - One lowercase letter - * - One number - */ - @NotEmpty(message = "Password is required") + @NotBlank(message = "Password is required") @Size(min = 6, message = "Password must be at least 6 characters") @Pattern( regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).+$", @@ -39,31 +23,30 @@ public class UserDTO { ) private String password; - /** - * User's email address. - * Must be in valid email format. - */ - @Email(message = "Invalid email format") - @NotEmpty(message = "Email is required") + @NotBlank(message = "Email is required") + @Pattern(regexp = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@" + + "(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$", + message = "Invalid email format") private String email; - /** - * User's first name. - * Cannot be empty. - */ - @NotEmpty(message = "First name is required") + @NotBlank(message = "First name is required") private String firstName; - /** - * User's last name. - * Cannot be empty. - */ - @NotEmpty(message = "Last name is required") + @NotBlank(message = "Last name is required") private String lastName; - /** - * Default authority/role assigned to the user. - * Defaults to 'ROLE_USER' if not specified. - */ private String authority = "ROLE_USER"; + + // Constructors, getters and setters remain the same + public UserDTO() { + } + + public UserDTO(String username, String password, String email, String firstName, String lastName) { + this.username = username; + this.password = password; + this.email = email; + this.firstName = firstName; + this.lastName = lastName; + } + } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java index 3ed7babf5..e29ead069 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java @@ -4,20 +4,10 @@ import lombok.*; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; -import org.springframework.security.core.userdetails.UserDetails; import java.util.HashSet; import java.util.Set; -/** - * Represents a user entity in the system, implementing Spring Security's {@link UserDetails}. - *

- * This entity stores user authentication details and their associated authorities/roles. - * It includes security-related flags and manages a many-to-many relationship with {@link AuthorityModel}. - * - * @see UserDetails - * @see AuthorityModel - */ @Entity @Table(name = "users") @Getter @@ -27,66 +17,31 @@ @Builder(toBuilder = true) public class UserModel { - /** - * Unique identifier for the user. - */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - /** - * Unique username for authentication. - * Must be non-null and maximum 50 characters. - */ @Column(unique = true, nullable = false, length = 50) private String username; - /** - * Encrypted password for authentication. - * Must be non-null and maximum 100 characters. - */ @Column(nullable = false, length = 100) private String password; - /** - * Unique email address for the user. - * Maximum 100 characters. - */ @Column(unique = true, length = 100) private String email; - /** - * Indicates whether the user is enabled. - * Defaults to true. - */ @Builder.Default private boolean enabled = true; - /** - * Indicates whether the user's account is expired. - * Defaults to true. - */ @Builder.Default private boolean accountNonExpired = true; - /** - * Indicates whether the user's credentials are expired. - * Defaults to true. - */ @Builder.Default private boolean credentialsNonExpired = true; - /** - * Indicates whether the user's account is locked. - * Defaults to true. - */ @Builder.Default private boolean accountNonLocked = true; - /** - * Set of authorities/roles assigned to the user. - * Uses eager fetching with JOIN strategy for performance. - */ @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @JoinTable( name = "user_authorities", @@ -97,27 +52,16 @@ public class UserModel { @Builder.Default private Set authorities = new HashSet<>(); - /** - * Adds an authority to the user and maintains the bidirectional relationship. - * @param authority the authority to add - */ public void addAuthority(AuthorityModel authority) { this.authorities.add(authority); authority.getUsers().add(this); } - /** - * Removes an authority from the user and maintains the bidirectional relationship. - * @param authority the authority to remove - */ public void removeAuthority(AuthorityModel authority) { this.authorities.remove(authority); authority.getUsers().remove(this); } - /** - * Custom builder implementation to handle default values properly. - */ public static class UserModelBuilder { private boolean enabled = true; private boolean accountNonExpired = true; diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java index 0cf0f59c8..49ad2e025 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java @@ -6,42 +6,32 @@ import java.util.Collection; import java.util.Objects; -/** - * Custom implementation of Spring Security's UserDetails interface. - * Extends the standard user details with additional user ID field while implementing - * all required UserDetails contract methods. - * - *

This class serves as an adapter between the application's user model - * and Spring Security's authentication framework. - */ public class CustomUserDetails implements UserDetails { + private static final long serialVersionUID = 1L; + private final Long userId; private final String username; private final String password; private final boolean enabled; + private final boolean accountNonExpired; + private final boolean accountNonLocked; + private final boolean credentialsNonExpired; private final Collection authorities; - /** - * Constructs a new CustomUserDetails instance. - * - * @param userId the unique user identifier from the application's domain model - * @param username the username used to authenticate - * @param password the encrypted password - * @param enabled flag indicating if the user is enabled - * @param authorities the user's granted authorities (roles/permissions) - */ public CustomUserDetails(Long userId, String username, String password, - boolean enabled, Collection authorities) { - this.userId = userId; - this.username = username; - this.password = password; + boolean enabled, boolean accountNonExpired, + boolean accountNonLocked, boolean credentialsNonExpired, + Collection authorities) { + this.userId = Objects.requireNonNull(userId); + this.username = Objects.requireNonNull(username); + this.password = Objects.requireNonNull(password); this.enabled = enabled; - this.authorities = authorities; + this.accountNonExpired = accountNonExpired; + this.accountNonLocked = accountNonLocked; + this.credentialsNonExpired = credentialsNonExpired; + this.authorities = Objects.requireNonNull(authorities); } - /** - * @return the application-specific user ID - */ public Long getUserId() { return userId; } @@ -61,28 +51,19 @@ public String getUsername() { return username; } - /** - * @return true if the account is not expired (always true in this implementation) - */ @Override public boolean isAccountNonExpired() { - return true; + return accountNonExpired; } - /** - * @return true if the account is not locked (always true in this implementation) - */ @Override public boolean isAccountNonLocked() { - return true; + return accountNonLocked; } - /** - * @return true if credentials are not expired (always true in this implementation) - */ @Override public boolean isCredentialsNonExpired() { - return true; + return credentialsNonExpired; } @Override @@ -90,35 +71,17 @@ public boolean isEnabled() { return enabled; } - /** - * Compares users based on username only. - */ @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; CustomUserDetails that = (CustomUserDetails) o; - return Objects.equals(username, that.username); + return Objects.equals(userId, that.userId) && + Objects.equals(username, that.username); } - /** - * Generates hash code based on username only. - */ @Override public int hashCode() { - return Objects.hash(username); - } - - /** - * Returns a string representation of the user details (excluding password). - */ - @Override - public String toString() { - return "CustomUserDetails{" + - "userId=" + userId + - ", username='" + username + '\'' + - ", enabled=" + enabled + - ", authorities=" + authorities + - '}'; + return Objects.hash(userId, username); } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java index 14923e7e0..3b3fd983b 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java @@ -14,76 +14,30 @@ import java.util.Set; import java.util.stream.Collectors; -/** - * Custom implementation of Spring Security's UserDetailsService that loads user-specific data. - * This service connects the application's user model with Spring Security's authentication framework. - * - *

Key responsibilities: - *

    - *
  • Loading user details by username or email
  • - *
  • Mapping application user model to Spring Security's UserDetails
  • - *
  • Handling user authority/role conversion
  • - *
- */ @Service @RequiredArgsConstructor public class CustomUserDetailsService implements UserDetailsService { private final UserRepository userRepository; - /** - * Loads user details by username or email. - * - * @param usernameOrEmail the username or email to search for - * @return UserDetails containing user information - * @throws UsernameNotFoundException if user is not found - */ @Override @Transactional(readOnly = true) public UserDetails loadUserByUsername(String usernameOrEmail) throws UsernameNotFoundException { - UserModel user = findUserByUsernameOrEmail(usernameOrEmail); - return createUserDetails(user); - } - - /** - * Finds a user by their username or email. - * - * @param usernameOrEmail the username or email to search for - * @return found UserModel - * @throws UsernameNotFoundException if user is not found - */ - private UserModel findUserByUsernameOrEmail(String usernameOrEmail) throws UsernameNotFoundException { - return userRepository.findByUsernameOrEmailWithAuthorities(usernameOrEmail) + UserModel user = userRepository.findByUsernameOrEmailWithAuthorities(usernameOrEmail) .orElseThrow(() -> new UsernameNotFoundException( "User not found with username or email: " + usernameOrEmail)); - } - /** - * Creates UserDetails from UserModel. - * - * @param user the user model to convert - * @return UserDetails implementation - */ - private UserDetails createUserDetails(UserModel user) { - Set authorities = mapAuthorities(user); return new CustomUserDetails( user.getId(), user.getUsername(), user.getPassword(), user.isEnabled(), - authorities + user.isAccountNonExpired(), + user.isAccountNonLocked(), + user.isCredentialsNonExpired(), + user.getAuthorities().stream() + .map(auth -> new SimpleGrantedAuthority(auth.getAuthority())) + .collect(Collectors.toSet()) ); } - - /** - * Maps user authorities to Spring Security GrantedAuthority objects. - * - * @param user the user model containing authorities - * @return set of GrantedAuthority objects - */ - private Set mapAuthorities(UserModel user) { - return user.getAuthorities().stream() - .map(auth -> new SimpleGrantedAuthority(auth.getAuthority())) - .collect(Collectors.toSet()); - } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/application-test.properties b/Sprint 2/prototype2/src/main/resources/application-test.properties new file mode 100644 index 000000000..34be3ec30 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/application-test.properties @@ -0,0 +1,45 @@ +# ====================== +# Test Metadata +# ====================== +spring.application.name=prototype2-test + +# ====================== +# Test Database Configuration (H2) +# ====================== +spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;MODE=MYSQL +spring.datasource.username=sa +spring.datasource.password= +spring.datasource.driver-class-name=org.h2.Driver + +# Hikari connection pool for tests +spring.datasource.hikari.maximum-pool-size=5 +spring.datasource.hikari.connection-timeout=20000 + +# ====================== +# Test JPA/Hibernate Settings +# ====================== +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true +spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true +spring.sql.init.enabled=false + +# ====================== +# Test Session Management +# ====================== +spring.session.store-type=jdbc +spring.session.jdbc.initialize-schema=always +spring.session.jdbc.table-name=SPRING_SESSION +server.servlet.session.timeout=1m + +# ====================== +# Test Logging Configuration +# ====================== +logging.level.com.jydoc=DEBUG +logging.level.org.springframework.security=DEBUG +logging.level.org.hibernate.SQL=DEBUG +logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE +logging.level.org.springframework.jdbc.core=DEBUG + +# Disable banner for cleaner test output +spring.main.banner-mode=off \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/application.properties b/Sprint 2/prototype2/src/main/resources/application.properties index 8b964f59e..edf6c4f7a 100644 --- a/Sprint 2/prototype2/src/main/resources/application.properties +++ b/Sprint 2/prototype2/src/main/resources/application.properties @@ -25,12 +25,13 @@ spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true + # ====================== # Session Management # ====================== # Production: Consider using redis instead spring.session.store-type=jdbc -spring.session.jdbc.initialize-schema=always # Always disabled in production +spring.session.jdbc.initialize-schema=always spring.session.jdbc.table-name=SPRING_SESSION # Explicit table name server.servlet.session.timeout=30m server.servlet.session.tracking-modes=cookie diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/Prototype2ApplicationTests.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/Prototype2ApplicationTests.java index dbc67b6da..fe9b74f0e 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/Prototype2ApplicationTests.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/Prototype2ApplicationTests.java @@ -1,12 +1,14 @@ package com.jydoc.deliverable4; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; - +@Disabled @SpringBootTest class Prototype2ApplicationTests { @Test + void contextLoads() { } diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserDtoValidationTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserDtoValidationTest.java new file mode 100644 index 000000000..a9caca3b3 --- /dev/null +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserDtoValidationTest.java @@ -0,0 +1,221 @@ +package com.jydoc.deliverable4; + +import com.jydoc.deliverable4.DTO.UserDTO; +import jakarta.validation.Validation; +import jakarta.validation.Validator; +import jakarta.validation.ValidatorFactory; +import jakarta.validation.ConstraintViolation; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; + +import java.util.Set; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.*; + +//NOTE: Passes all tests + +@DisplayName("UserDTO Validation Tests") +class UserDtoValidationTest { + + private static Validator validator; + + @BeforeAll + static void setupValidator() { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + validator = factory.getValidator(); + } + + @Nested + @DisplayName("When user is valid") + class ValidUserTests { + @Test + @DisplayName("Should pass all validations") + void validUser_shouldPassValidation() { + UserDTO user = createValidUser(); + assertNoViolations(user); + } + + @Test + @DisplayName("Should have default authority ROLE_USER") + void shouldHaveDefaultAuthority() { + UserDTO user = createValidUser(); + assertEquals("ROLE_USER", user.getAuthority()); + } + } + + @Nested + @DisplayName("Username validation") + class UsernameValidation { + @ParameterizedTest(name = "[{index}] ''{0}'' should fail validation") + @NullAndEmptySource + @ValueSource(strings = {" ", "\t", "\n"}) + @DisplayName("Should reject blank username") + void blankUsername_shouldFail(String username) { + UserDTO user = createValidUser(); + user.setUsername(username); + assertHasViolationWithMessage(user, "Username is required"); + } + + @Test + @DisplayName("Should reject username shorter than 3 chars") + void tooShortUsername_shouldFail() { + UserDTO user = createValidUser(); + user.setUsername("ab"); + assertHasViolationWithMessage(user, "Username must be 3-20 characters"); + } + + @Test + @DisplayName("Should reject username longer than 20 chars") + void tooLongUsername_shouldFail() { + UserDTO user = createValidUser(); + user.setUsername("a".repeat(21)); + assertHasViolationWithMessage(user, "Username must be 3-20 characters"); + } + } + + @Nested + @DisplayName("Password validation") + class PasswordValidation { + @ParameterizedTest(name = "[{index}] ''{0}'' should fail validation") + @NullAndEmptySource + @ValueSource(strings = {" ", "\t", "\n"}) + @DisplayName("Should reject blank password") + void blankPassword_shouldFail(String password) { + UserDTO user = createValidUser(); + user.setPassword(password); + assertHasViolationWithMessage(user, "Password is required"); + } + + @Test + @DisplayName("Should reject password shorter than 6 chars") + void tooShortPassword_shouldFail() { + UserDTO user = createValidUser(); + user.setPassword("Short"); + Set> violations = validator.validate(user); + assertTrue(violations.stream().anyMatch(v -> + v.getMessage().equals("Password must be at least 6 characters"))); + assertTrue(violations.stream().anyMatch(v -> + v.getMessage().equals("Password must contain at least one uppercase, lowercase letter and number"))); + } + + @ParameterizedTest(name = "[{index}] ''{0}'' should fail pattern validation") + @ValueSource(strings = {"nouppercase1", "NOLOWERCASE1", "NoNumbersHere"}) + @DisplayName("Should reject invalid password patterns") + void invalidPatternPassword_shouldFail(String password) { + UserDTO user = createValidUser(); + user.setPassword(password); + assertHasViolationWithMessage(user, + "Password must contain at least one uppercase, lowercase letter and number"); + } + } + + @Nested + @DisplayName("Email validation") + class EmailValidation { + @ParameterizedTest(name = "[{index}] ''{0}'' should fail validation") + @NullAndEmptySource + @ValueSource(strings = {" ", "\t", "\n"}) + @DisplayName("Should reject blank email") + void blankEmail_shouldFail(String email) { + UserDTO user = createValidUser(); + user.setEmail(email); + Set> violations = validator.validate(user); + assertTrue(violations.stream().anyMatch(v -> + v.getMessage().equals("Email is required")), + "Should have 'Email is required' violation"); + } + + @ParameterizedTest(name = "[{index}] ''{0}'' should fail format validation") + @ValueSource(strings = { + "plainstring", + "missing@dot", + "@domain.com", + "user@.com", + "user@domain..com", + "user@domain.c", + "user@domain,com", + "user@domain_com" + }) + @DisplayName("Should reject invalid email formats") + void invalidFormatEmail_shouldFail(String email) { + UserDTO user = createValidUser(); + user.setEmail(email); + Set> violations = validator.validate(user); + + // First check if there's a format violation + boolean hasFormatViolation = violations.stream() + .anyMatch(v -> v.getMessage().equals("Invalid email format")); + + // If no format violation, check if it's being caught by the @NotBlank constraint + if (!hasFormatViolation) { + boolean hasBlankViolation = violations.stream() + .anyMatch(v -> v.getMessage().equals("Email is required")); + assertTrue(hasBlankViolation, + "Expected either format violation or blank violation for: " + email); + } else { + assertTrue(true); // Format violation found as expected + } + } + } + + @Nested + @DisplayName("Name validation") + class NameValidation { + @ParameterizedTest(name = "[{index}] ''{0}'' should fail validation") + @NullAndEmptySource + @ValueSource(strings = {" ", "\t", "\n"}) + @DisplayName("Should reject blank first name") + void blankFirstName_shouldFail(String firstName) { + UserDTO user = createValidUser(); + user.setFirstName(firstName); + assertHasViolationWithMessage(user, "First name is required"); + } + + @ParameterizedTest(name = "[{index}] ''{0}'' should fail validation") + @NullAndEmptySource + @ValueSource(strings = {" ", "\t", "\n"}) + @DisplayName("Should reject blank last name") + void blankLastName_shouldFail(String lastName) { + UserDTO user = createValidUser(); + user.setLastName(lastName); + assertHasViolationWithMessage(user, "Last name is required"); + } + } + + // Helper methods + private UserDTO createValidUser() { + UserDTO user = new UserDTO(); + user.setUsername("validUser123"); + user.setPassword("Valid1Password"); + user.setEmail("valid@example.com"); + user.setFirstName("John"); + user.setLastName("Doe"); + return user; + } + + private void assertNoViolations(UserDTO user) { + Set> violations = validator.validate(user); + assertTrue(violations.isEmpty(), + "Expected no violations but found: " + violations.size() + "\n" + + violations.stream() + .map(v -> v.getPropertyPath() + ": " + v.getMessage()) + .collect(Collectors.joining("\n"))); + } + + private void assertHasViolationWithMessage(UserDTO user, String expectedMessage) { + Set> violations = validator.validate(user); + assertFalse(violations.isEmpty(), "Expected at least one violation but found none"); + assertTrue(violations.stream() + .anyMatch(v -> v.getMessage().equals(expectedMessage)), + "Expected violation with message: '" + expectedMessage + + "' but found:\n" + violations.stream() + .map(v -> v.getPropertyPath() + ": " + v.getMessage()) + .collect(Collectors.joining("\n"))); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java new file mode 100644 index 000000000..babbcefc5 --- /dev/null +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java @@ -0,0 +1,226 @@ +package com.jydoc.deliverable4; + +import com.jydoc.deliverable4.model.UserModel; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import jakarta.validation.ConstraintViolationException; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.TransactionTemplate; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +@ActiveProfiles("test") +class UserModelTest { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private PlatformTransactionManager transactionManager; + + // Helper method for transactional operations + private void executeInTransaction(Runnable operation) { + new TransactionTemplate(transactionManager).execute(status -> { + operation.run(); + return null; + }); + } + + @Test + @Transactional + void testUserEntityPersistence() { + // Given + UserModel user = UserModel.builder() + .username("testuser") + .password("encodedPassword") + .email("test@example.com") + .build(); + + // When + entityManager.persist(user); + entityManager.flush(); + entityManager.clear(); + + // Then + UserModel found = entityManager.find(UserModel.class, user.getId()); + assertNotNull(found); + assertEquals("testuser", found.getUsername()); + assertEquals("encodedPassword", found.getPassword()); + assertEquals("test@example.com", found.getEmail()); + } + + @Test + void testUsernameUniquenessConstraint() { + // First user (should succeed) + executeInTransaction(() -> { + UserModel user1 = UserModel.builder() + .username("uniqueuser") + .password("password1") + .build(); + entityManager.persist(user1); + }); + + // Second user with same username (should fail) + assertThrows(org.hibernate.exception.ConstraintViolationException.class, () -> { + executeInTransaction(() -> { + UserModel user2 = UserModel.builder() + .username("uniqueuser") + .password("password2") + .build(); + entityManager.persist(user2); + entityManager.flush(); // Explicit flush to force immediate constraint check + }); + }); + } + + @Test + void testEmailUniquenessConstraint() { + // First user with email (should succeed) + executeInTransaction(() -> { + UserModel user1 = UserModel.builder() + .username("user1") + .password("password1") + .email("unique@example.com") + .build(); + entityManager.persist(user1); + }); + + // Second user with same email (should fail) + assertThrows(org.hibernate.exception.ConstraintViolationException.class, () -> { + executeInTransaction(() -> { + UserModel user2 = UserModel.builder() + .username("user2") + .password("password2") + .email("unique@example.com") + .build(); + entityManager.persist(user2); + }); + }); + } + + @Test + @Transactional + void testOptionalEmailField() { + // Given + UserModel user = UserModel.builder() + .username("noemail") + .password("password") + .email(null) + .build(); + + // When + entityManager.persist(user); + entityManager.flush(); + entityManager.clear(); + + // Then + UserModel found = entityManager.find(UserModel.class, user.getId()); + assertNull(found.getEmail()); + } + + @Test + @Transactional + void testDefaultSecurityFlags() { + UserModel user = UserModel.builder() + .username("defaultuser") + .password("password") + .build(); + + assertAll( + () -> assertTrue(user.isEnabled()), + () -> assertTrue(user.isAccountNonExpired()), + () -> assertTrue(user.isCredentialsNonExpired()), + () -> assertTrue(user.isAccountNonLocked()) + ); + } + + @Test + @Transactional + void testFieldLengthConstraints() { + // Test username max length (50) + assertThrows(Exception.class, () -> { + UserModel user = UserModel.builder() + .username("a".repeat(51)) + .password("password") + .build(); + entityManager.persist(user); + entityManager.flush(); + }); + + // Test password max length (100) + assertThrows(Exception.class, () -> { + UserModel user = UserModel.builder() + .username("lengthuser") + .password("a".repeat(101)) + .build(); + entityManager.persist(user); + entityManager.flush(); + }); + + // Test email max length (100) + assertThrows(Exception.class, () -> { + UserModel user = UserModel.builder() + .username("emailuser") + .password("password") + .email("a".repeat(90) + "@example.com") // > 100 chars + .build(); + entityManager.persist(user); + entityManager.flush(); + }); + } + + @Test + void testBuilderPattern() { + // Given + UserModel user = UserModel.builder() + .username("builderuser") + .password("password") + .email("builder@example.com") + .enabled(false) + .accountNonExpired(false) + .credentialsNonExpired(false) + .accountNonLocked(false) + .build(); + + // Then + assertAll( + () -> assertEquals("builderuser", user.getUsername()), + () -> assertEquals("password", user.getPassword()), + () -> assertEquals("builder@example.com", user.getEmail()), + () -> assertFalse(user.isEnabled()), + () -> assertFalse(user.isAccountNonExpired()), + () -> assertFalse(user.isCredentialsNonExpired()), + () -> assertFalse(user.isAccountNonLocked()) + ); + } + + @Test + void testToBuilder() { + // Given + UserModel original = UserModel.builder() + .username("original") + .password("password") + .build(); + + // When + UserModel modified = original.toBuilder() + .username("modified") + .enabled(false) + .build(); + + // Then + assertAll( + () -> assertEquals("original", original.getUsername()), + () -> assertTrue(original.isEnabled()), + () -> assertEquals("modified", modified.getUsername()), + () -> assertFalse(modified.isEnabled()) + ); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserRepositoryTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserRepositoryTest.java new file mode 100644 index 000000000..31728cec4 --- /dev/null +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserRepositoryTest.java @@ -0,0 +1,178 @@ +package com.jydoc.deliverable4; + +import com.jydoc.deliverable4.model.AuthorityModel; +import com.jydoc.deliverable4.model.UserModel; +import com.jydoc.deliverable4.repositories.UserRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; +import org.springframework.dao.DataIntegrityViolationException; + +import java.util.Collections; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; + +@DataJpaTest +class UserRepositoryTest { + + @Autowired + private TestEntityManager entityManager; + + @Autowired + private UserRepository userRepository; + + private UserModel testUser; + private AuthorityModel testAuthority; + + @BeforeEach + void setUp() { + testAuthority = new AuthorityModel(); + testAuthority.setAuthority("ROLE_USER"); + entityManager.persist(testAuthority); + + testUser = UserModel.builder() + .username("testuser") + .password("password") + .email("test@example.com") + .accountNonExpired(true) + .accountNonLocked(true) + .credentialsNonExpired(true) + .enabled(true) + .authorities(Collections.singleton(testAuthority)) + .build(); + entityManager.persist(testUser); + entityManager.flush(); + } + + // Basic CRUD operations + @Test + void whenFindById_thenReturnUser() { + Optional foundUser = userRepository.findById(testUser.getId()); + assertTrue(foundUser.isPresent()); + assertEquals(testUser.getUsername(), foundUser.get().getUsername()); + } + + @Test + void whenSaveNewUser_thenUserIsPersisted() { + UserModel newUser = UserModel.builder() + .username("newuser") + .password("newpass") + .email("new@example.com") + .build(); + + UserModel savedUser = userRepository.save(newUser); + assertNotNull(savedUser.getId()); + assertEquals(newUser.getUsername(), savedUser.getUsername()); + } + + // Unique constraint tests + @Test + void whenSaveDuplicateUsername_thenThrowException() { + UserModel duplicateUser = UserModel.builder() + .username("testuser") // duplicate username + .password("password") + .email("different@example.com") + .build(); + + assertThrows(DataIntegrityViolationException.class, () -> { + userRepository.saveAndFlush(duplicateUser); + }); + } + + @Test + void whenSaveDuplicateEmail_thenThrowException() { + UserModel duplicateUser = UserModel.builder() + .username("differentuser") + .password("password") + .email("test@example.com") // duplicate email + .build(); + + assertThrows(DataIntegrityViolationException.class, () -> { + userRepository.saveAndFlush(duplicateUser); + }); + } + + // Query method tests + @Test + void whenFindByUsername_thenReturnUser() { + Optional foundUser = userRepository.findByUsername("testuser"); + assertTrue(foundUser.isPresent()); + assertEquals(testUser.getEmail(), foundUser.get().getEmail()); + } + + @Test + void whenFindByNonExistentUsername_thenReturnEmpty() { + Optional foundUser = userRepository.findByUsername("nonexistent"); + assertFalse(foundUser.isPresent()); + } + + @Test + void whenExistsByUsername_thenReturnCorrectBoolean() { + assertTrue(userRepository.existsByUsername("testuser")); + assertFalse(userRepository.existsByUsername("nonexistent")); + } + + @Test + void whenExistsByEmail_thenReturnCorrectBoolean() { + assertTrue(userRepository.existsByEmail("test@example.com")); + assertFalse(userRepository.existsByEmail("nonexistent@example.com")); + } + + // Custom query tests + @Test + void whenFindByUsernameWithAuthorities_thenReturnUserWithAuthorities() { + Optional foundUser = userRepository.findByUsernameWithAuthorities("testuser"); + assertTrue(foundUser.isPresent()); + assertFalse(foundUser.get().getAuthorities().isEmpty()); + assertEquals("ROLE_USER", foundUser.get().getAuthorities().iterator().next().getAuthority()); + } + + @Test + void whenFindByUsernameOrEmail_thenReturnUser() { + // Test with username + Optional byUsername = userRepository.findByUsernameOrEmail("testuser"); + assertTrue(byUsername.isPresent()); + + // Test with email + Optional byEmail = userRepository.findByUsernameOrEmail("test@example.com"); + assertTrue(byEmail.isPresent()); + + // Test case insensitivity + Optional byUpperCase = userRepository.findByUsernameOrEmail("TESTUSER"); + assertTrue(byUpperCase.isPresent()); + } + + @Test + void whenFindByUsernameOrEmailWithAuthorities_thenReturnUserWithAuthorities() { + Optional foundUser = userRepository.findByUsernameOrEmailWithAuthorities("testuser"); + assertTrue(foundUser.isPresent()); + assertFalse(foundUser.get().getAuthorities().isEmpty()); + } + + @Test + void whenFindByNonExistentUsernameOrEmail_thenReturnEmpty() { + Optional foundUser = userRepository.findByUsernameOrEmail("nonexistent"); + assertFalse(foundUser.isPresent()); + } + + // Additional edge cases + @Test + void whenFindByNullUsername_thenReturnEmpty() { + Optional foundUser = userRepository.findByUsername(null); + assertFalse(foundUser.isPresent()); + } + + @Test + void whenExistsByNullUsername_thenReturnFalse() { + assertFalse(userRepository.existsByUsername(null)); + } + + @Test + void whenFindByEmptyUsername_thenReturnEmpty() { + Optional foundUser = userRepository.findByUsername(""); + assertFalse(foundUser.isPresent()); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java new file mode 100644 index 000000000..49a700474 --- /dev/null +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java @@ -0,0 +1,381 @@ +package com.jydoc.deliverable4; + +import com.jydoc.deliverable4.DTO.LoginDTO; +import com.jydoc.deliverable4.DTO.UserDTO; +import com.jydoc.deliverable4.Service.UserService; +import com.jydoc.deliverable4.Service.UserValidationHelper; +import com.jydoc.deliverable4.model.AuthorityModel; +import com.jydoc.deliverable4.model.UserModel; +import com.jydoc.deliverable4.repositories.AuthorityRepository; +import com.jydoc.deliverable4.repositories.UserRepository; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.DisabledException; +import org.springframework.security.authentication.LockedException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.crypto.password.PasswordEncoder; + +import java.util.HashSet; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +class UserServiceTest { + + @Mock + private UserRepository userRepository; + + @Mock + private AuthorityRepository authorityRepository; + + @Mock + private PasswordEncoder passwordEncoder; + + @Mock + private AuthenticationManager authenticationManager; + + @Mock + private UserValidationHelper validationHelper; + + @InjectMocks + private UserService userService; + + private UserDTO testUserDto; + private LoginDTO testLoginDto; + private UserModel testUser; + private AuthorityModel testAuthority; + + @BeforeEach + void setUp() { + // Initialize UserDTO + testUserDto = new UserDTO(); + testUserDto.setUsername("testuser"); + testUserDto.setEmail("test@example.com"); + testUserDto.setPassword("Password123!"); + + testLoginDto = new LoginDTO("testuser", "Password123!"); + + // Initialize UserModel with proper collections + testUser = new UserModel(); + testUser.setUsername("testuser"); + testUser.setEmail("test@example.com"); + testUser.setPassword("encodedPassword"); + testUser.setEnabled(true); + testUser.setAccountNonExpired(true); + testUser.setCredentialsNonExpired(true); + testUser.setAccountNonLocked(true); + testUser.setAuthorities(new HashSet<>()); // Initialize authorities collection + + // Initialize AuthorityModel with proper collections + testAuthority = new AuthorityModel("ROLE_USER"); + testAuthority.setUsers(new HashSet<>()); // Initialize users collection + } + + // ---------------------- Registration Tests ---------------------- + + @Test + void registerNewUser_ValidUser_Success() { + // Arrange + when(passwordEncoder.encode(anyString())).thenReturn("encodedPassword"); + when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.of(testAuthority)); + + // Act + userService.registerNewUser(testUserDto); + + // Assert + verify(validationHelper).validateUserRegistration(testUserDto); + verify(userRepository).save(any(UserModel.class)); + verify(authorityRepository).findByAuthority("ROLE_USER"); + } + + @Test + void registerNewUser_NullUserDto_ThrowsException() { + // Act & Assert + assertThrows(IllegalArgumentException.class, () -> userService.registerNewUser(null)); + } + + @Test + void registerNewUser_CreatesDefaultRoleIfNotExists() { + // Arrange + when(passwordEncoder.encode(anyString())).thenReturn("encodedPassword"); + when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.empty()); + when(authorityRepository.save(any(AuthorityModel.class))).thenReturn(testAuthority); + + // Act + userService.registerNewUser(testUserDto); + + // Assert + verify(authorityRepository).save(any(AuthorityModel.class)); + } + + // ---------------------- Authentication Tests ---------------------- + + @Test + void authenticate_ValidCredentials_ReturnsUser() { + // Arrange + Authentication auth = mock(Authentication.class); + when(auth.getName()).thenReturn("testuser"); + when(authenticationManager.authenticate(any(UsernamePasswordAuthenticationToken.class))) + .thenReturn(auth); + when(userRepository.findByUsername("testuser")).thenReturn(Optional.of(testUser)); + + // Act + UserModel result = userService.authenticate(testLoginDto); + + // Assert + assertNotNull(result); + assertEquals("testuser", result.getUsername()); + } + + @Test + void authenticate_NullLoginDto_ThrowsException() { + // Act & Assert + assertThrows(IllegalArgumentException.class, () -> userService.authenticate(null)); + } + + @Test + void authenticate_BadCredentials_ThrowsAuthenticationException() { + // Arrange + when(authenticationManager.authenticate(any(UsernamePasswordAuthenticationToken.class))) + .thenThrow(new BadCredentialsException("Bad credentials")); + + // Act & Assert + assertThrows(UserService.AuthenticationException.class, + () -> userService.authenticate(testLoginDto)); + } + + @Test + void authenticate_DisabledAccount_ThrowsAuthenticationException() { + // Arrange + when(authenticationManager.authenticate(any(UsernamePasswordAuthenticationToken.class))) + .thenThrow(new DisabledException("Account disabled")); + + // Act & Assert + assertThrows(UserService.AuthenticationException.class, + () -> userService.authenticate(testLoginDto)); + } + + @Test + void authenticate_LockedAccount_ThrowsAuthenticationException() { + // Arrange + when(authenticationManager.authenticate(any(UsernamePasswordAuthenticationToken.class))) + .thenThrow(new LockedException("Account locked")); + + // Act & Assert + assertThrows(UserService.AuthenticationException.class, + () -> userService.authenticate(testLoginDto)); + } + + // ---------------------- Validate Login Tests ---------------------- + + @Test + void validateLogin_ValidCredentials_ReturnsUser() { + // Arrange + when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.of(testUser)); + when(passwordEncoder.matches("Password123!", "encodedPassword")).thenReturn(true); + + // Act + UserModel result = userService.validateLogin(testLoginDto); + + // Assert + assertNotNull(result); + assertEquals("testuser", result.getUsername()); + } + + @Test + void validateLogin_UserNotFound_ThrowsAuthenticationException() { + // Arrange + when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.empty()); + + // Act & Assert + assertThrows(UserService.AuthenticationException.class, + () -> userService.validateLogin(testLoginDto)); + } + + @Test + void validateLogin_WrongPassword_ThrowsAuthenticationException() { + // Arrange + when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.of(testUser)); + when(passwordEncoder.matches("Password123!", "encodedPassword")).thenReturn(false); + + // Act & Assert + assertThrows(UserService.AuthenticationException.class, + () -> userService.validateLogin(testLoginDto)); + } + + @Test + void validateLogin_DisabledAccount_ThrowsAuthenticationException() { + // Arrange + testUser.setEnabled(false); + when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.of(testUser)); + when(passwordEncoder.matches("Password123!", "encodedPassword")).thenReturn(true); + + // Act & Assert + assertThrows(UserService.AuthenticationException.class, + () -> userService.validateLogin(testLoginDto)); + } + + // ---------------------- Find Active User Tests ---------------------- + + @Test + void findActiveUser_ValidUser_ReturnsUser() { + // Arrange + when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.of(testUser)); + + // Act + Optional result = userService.findActiveUser("testuser"); + + // Assert + assertTrue(result.isPresent()); + assertEquals("testuser", result.get().getUsername()); + } + + @Test + void findActiveUser_DisabledUser_ReturnsEmpty() { + // Arrange + testUser.setEnabled(false); + when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.of(testUser)); + + // Act + Optional result = userService.findActiveUser("testuser"); + + // Assert + assertTrue(result.isEmpty()); + } + + @Test + void findActiveUser_UserNotFound_ReturnsEmpty() { + // Arrange + when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.empty()); + + // Act + Optional result = userService.findActiveUser("testuser"); + + // Assert + assertTrue(result.isEmpty()); + } + + // ---------------------- Exception Tests ---------------------- + + @Test + void authenticationException_ContainsCorrectMessage() { + // Act + UserService.AuthenticationException exception = + new UserService.AuthenticationException("Test message"); + + // Assert + assertEquals("Test message", exception.getMessage()); + } + + @Test + void usernameExistsException_ContainsCorrectMessage() { + // Act + UserService.UsernameExistsException exception = + new UserService.UsernameExistsException("testuser"); + + // Assert + assertEquals("Username 'testuser' already exists", exception.getMessage()); + } + + @Test + void emailExistsException_ContainsCorrectMessage() { + // Act + UserService.EmailExistsException exception = + new UserService.EmailExistsException("test@example.com"); + + // Assert + assertEquals("Email 'test@example.com' is already registered", exception.getMessage()); + } + + // ---------------------- Helper Method Tests ---------------------- + + @Test + void registerNewUser_BuildsCorrectUserModelFromDto() { + // Arrange + when(passwordEncoder.encode("Password123!")).thenReturn("encodedPassword"); + when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.of(testAuthority)); + + // Use ArgumentCaptor to capture the saved UserModel + ArgumentCaptor userCaptor = ArgumentCaptor.forClass(UserModel.class); + when(userRepository.save(userCaptor.capture())).thenReturn(testUser); + + // Act + userService.registerNewUser(testUserDto); + + // Assert - Verify the built UserModel + UserModel savedUser = userCaptor.getValue(); + assertEquals("testuser", savedUser.getUsername()); + assertEquals("encodedPassword", savedUser.getPassword()); + assertEquals("test@example.com", savedUser.getEmail()); + assertTrue(savedUser.isEnabled()); + assertTrue(savedUser.isAccountNonExpired()); + assertTrue(savedUser.isCredentialsNonExpired()); + assertTrue(savedUser.isAccountNonLocked()); + + // Verify the password was encoded + verify(passwordEncoder).encode("Password123!"); + } + + @Test + void registerNewUser_AddsExistingRoleToUser() { + // Arrange + when(passwordEncoder.encode(anyString())).thenReturn("encodedPassword"); + when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.of(testAuthority)); + + // Use a mock to capture the saved user + when(userRepository.save(any(UserModel.class))).thenAnswer(invocation -> { + UserModel savedUser = invocation.getArgument(0); + // Verify the role was added + assertTrue(savedUser.getAuthorities().contains(testAuthority)); + return savedUser; + }); + + // Act + userService.registerNewUser(testUserDto); + + // Assert + verify(authorityRepository).findByAuthority("ROLE_USER"); + verify(authorityRepository, never()).save(any()); + verify(userRepository).save(any(UserModel.class)); + } + + @Test + void registerNewUser_CreatesAndAddsNewRoleToUser() { + // Arrange + when(passwordEncoder.encode("Password123!")).thenReturn("encodedPassword"); + when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.empty()); + + // Create a new authority with initialized collections + AuthorityModel newAuthority = new AuthorityModel("ROLE_USER"); + newAuthority.setUsers(new HashSet<>()); + when(authorityRepository.save(any(AuthorityModel.class))).thenReturn(newAuthority); + + // Use ArgumentCaptor to verify the saved user + ArgumentCaptor userCaptor = ArgumentCaptor.forClass(UserModel.class); + when(userRepository.save(userCaptor.capture())).thenReturn(testUser); + + // Act + userService.registerNewUser(testUserDto); + + // Assert + UserModel savedUser = userCaptor.getValue(); + assertFalse(savedUser.getAuthorities().isEmpty()); + assertEquals("ROLE_USER", savedUser.getAuthorities().iterator().next().getAuthority()); + verify(authorityRepository).findByAuthority("ROLE_USER"); + verify(authorityRepository).save(any(AuthorityModel.class)); + } +} \ No newline at end of file From d99446ca2d09e51273f06bd97d933dd328ede84b Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 05:29:23 -0400 Subject: [PATCH 055/100] Documentation and test cases --- .../deliverable4/config/SecurityConfig.java | 153 ++++++++++++--- .../controllers/CustomErrorController.java | 82 +++++++- .../controllers/DashboardController.java | 58 +++++- .../deliverable4/LoginDtoValidationTest.java | 180 ++++++++++++++++++ .../com/jydoc/deliverable4/UserModelTest.java | 12 +- .../jydoc/deliverable4/UserServiceTest.java | 33 ++-- 6 files changed, 461 insertions(+), 57 deletions(-) create mode 100644 Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/LoginDtoValidationTest.java diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java index 8a3c280ce..108c10321 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java @@ -15,27 +15,48 @@ import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession; /** - * Central security configuration class that defines authentication and authorization rules, - * CSRF protection, session management, and security headers for the application. + * Central security configuration class that defines the application's security policies. *

- * This configuration enables: + * This configuration class is responsible for: + *

    + *
  • Authentication and authorization rules
  • + *
  • CSRF protection configuration
  • + *
  • Session management policies
  • + *
  • Security headers configuration
  • + *
  • Password encoding strategy
  • + *
  • Exception handling for security scenarios
  • + *
+ *

+ * + *

Security Features:

*
    *
  • Form-based authentication with custom login/logout pages
  • *
  • Role-based authorization (USER and ADMIN)
  • - *
  • CSRF protection with cookie-based token storage
  • - *
  • JDBC-based session management
  • - *
  • BCrypt password hashing
  • + *
  • CSRF protection with cookie-based token storage (disabled for API endpoints)
  • + *
  • JDBC-based session management with concurrency control
  • + *
  • BCrypt password hashing with strength 10
  • + *
  • Secure HTTP headers configuration (HSTS, frame options)
  • *
+ * + * @see org.springframework.security.config.annotation.web.configuration.EnableWebSecurity + * @see org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession */ @Configuration @EnableWebSecurity @EnableJdbcHttpSession public class SecurityConfig { - private final CustomUserDetailsService userDetailsService; - /** * Endpoints that are accessible without authentication. + *

+ * Includes: + *

    + *
  • Public pages (home, login, register)
  • + *
  • Static resources (CSS, JS, images)
  • + *
  • Error pages
  • + *
  • Public API endpoints
  • + *
  • WebJars resources
  • + *
*/ private static final String[] PUBLIC_ENDPOINTS = { "/", @@ -50,19 +71,33 @@ public class SecurityConfig { "/api/public/**" }; + private final CustomUserDetailsService userDetailsService; + /** * Constructs a new SecurityConfig with required dependencies. * - * @param userDetailsService custom implementation of UserDetailsService + * @param userDetailsService the custom user details service implementation + * that loads user-specific data. Must not be null. */ public SecurityConfig(CustomUserDetailsService userDetailsService) { this.userDetailsService = userDetailsService; } /** - * Configures the security filter chain with all security policies. + * Defines the security filter chain that applies all security configurations. + *

+ * Configures: + *

    + *
  • CSRF protection
  • + *
  • Security headers
  • + *
  • Authorization rules
  • + *
  • Form-based authentication
  • + *
  • Logout behavior
  • + *
  • Session management
  • + *
  • Exception handling
  • + *
* - * @param http the HttpSecurity to configure + * @param http the HttpSecurity object to configure * @return the configured SecurityFilterChain * @throws Exception if configuration fails */ @@ -80,7 +115,17 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti } /** - * Configures CSRF protection with exceptions for API endpoints. + * Configures CSRF protection with cookie-based token storage. + *

+ * Features: + *

    + *
  • CSRF protection enabled by default
  • + *
  • Disabled for API endpoints (/api/**)
  • + *
  • Token stored in a cookie with HttpOnly=false to allow JavaScript access
  • + *
+ * + * @param http the HttpSecurity object to configure + * @throws Exception if configuration fails */ private void configureCsrfProtection(HttpSecurity http) throws Exception { http.csrf(csrf -> csrf @@ -91,9 +136,15 @@ private void configureCsrfProtection(HttpSecurity http) throws Exception { /** * Configures security-related HTTP headers. - */ - /** - * Configures security-related HTTP headers. + *

+ * Sets: + *

    + *
  • Frame options to SAMEORIGIN
  • + *
  • HTTP Strict Transport Security (HSTS) with 1-year max age and subdomain inclusion
  • + *
+ * + * @param http the HttpSecurity object to configure + * @throws Exception if configuration fails */ private void configureSecurityHeaders(HttpSecurity http) throws Exception { http.headers(headers -> headers @@ -102,11 +153,23 @@ private void configureSecurityHeaders(HttpSecurity http) throws Exception { .includeSubDomains(true) .maxAgeInSeconds(31536000) ) - ); + ); } /** - * Configures authorization rules for different endpoints. + * Configures authorization rules for application endpoints. + *

+ * Rules: + *

    + *
  • Public endpoints accessible to all
  • + *
  • /dashboard requires authentication
  • + *
  • /user/** endpoints require ROLE_USER authority
  • + *
  • /admin/** endpoints require ROLE_ADMIN authority
  • + *
  • All other endpoints require authentication
  • + *
+ * + * @param http the HttpSecurity object to configure + * @throws Exception if configuration fails */ private void configureAuthorization(HttpSecurity http) throws Exception { http.authorizeHttpRequests(auth -> auth @@ -119,7 +182,19 @@ private void configureAuthorization(HttpSecurity http) throws Exception { } /** - * Configures form-based authentication with custom login page. + * Configures form-based authentication with custom settings. + *

+ * Configuration includes: + *

    + *
  • Custom login page at /login
  • + *
  • Login processing URL at /perform_login
  • + *
  • Default success URL to /dashboard
  • + *
  • Failure URL to /login with error parameter
  • + *
  • Custom username and password parameter names
  • + *
+ * + * @param http the HttpSecurity object to configure + * @throws Exception if configuration fails */ private void configureFormBasedAuthentication(HttpSecurity http) throws Exception { http.formLogin(form -> form @@ -134,7 +209,19 @@ private void configureFormBasedAuthentication(HttpSecurity http) throws Exceptio } /** - * Configures logout behavior with session invalidation and cookie cleanup. + * Configures logout behavior with security considerations. + *

+ * Features: + *

    + *
  • Logout URL at /perform_logout
  • + *
  • Redirect to login page with logout parameter
  • + *
  • Session invalidation
  • + *
  • Cookie cleanup (JSESSIONID, XSRF-TOKEN)
  • + *
  • Authentication clearing
  • + *
+ * + * @param http the HttpSecurity object to configure + * @throws Exception if configuration fails */ private void configureLogout(HttpSecurity http) throws Exception { http.logout(logout -> logout @@ -148,7 +235,18 @@ private void configureLogout(HttpSecurity http) throws Exception { } /** - * Configures session management with concurrency control. + * Configures session management policies. + *

+ * Settings: + *

    + *
  • Session creation policy: IF_REQUIRED
  • + *
  • Invalid session redirect URL
  • + *
  • Maximum sessions: 1 per user
  • + *
  • Session expired redirect URL
  • + *
+ * + * @param http the HttpSecurity object to configure + * @throws Exception if configuration fails */ private void configureSessionManagement(HttpSecurity http) throws Exception { http.sessionManagement(session -> session @@ -161,7 +259,12 @@ private void configureSessionManagement(HttpSecurity http) throws Exception { } /** - * Configures exception handling for access denied scenarios. + * Configures exception handling for security scenarios. + *

+ * Redirects to /access-denied when access is denied. + * + * @param http the HttpSecurity object to configure + * @throws Exception if configuration fails */ private void configureExceptionHandling(HttpSecurity http) throws Exception { http.exceptionHandling(exceptions -> exceptions @@ -170,11 +273,12 @@ private void configureExceptionHandling(HttpSecurity http) throws Exception { } /** - * Provides the AuthenticationManager bean. + * Provides the AuthenticationManager bean for authentication processing. * * @param authenticationConfiguration the authentication configuration * @return configured AuthenticationManager * @throws Exception if configuration fails + * @see org.springframework.security.authentication.AuthenticationManager */ @Bean public AuthenticationManager authenticationManager( @@ -183,9 +287,12 @@ public AuthenticationManager authenticationManager( } /** - * Provides the password encoder bean (BCrypt implementation). + * Provides the password encoder bean using BCrypt hashing. + *

+ * Uses BCrypt with strength 10 (2^10 iterations) for password hashing. * * @return BCryptPasswordEncoder instance + * @see org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder */ @Bean public PasswordEncoder passwordEncoder() { diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/CustomErrorController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/CustomErrorController.java index fa40f2972..2bf3b95df 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/CustomErrorController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/CustomErrorController.java @@ -14,20 +14,55 @@ /** * Custom error controller to handle application errors and display user-friendly error pages. - * Implements Spring Boot's {@link ErrorController} interface to override default error handling. + *

+ * This controller implements Spring Boot's {@link ErrorController} interface to override + * the default white-label error page behavior. It provides: + *

    + *
  • Custom error page rendering with user-friendly messages
  • + *
  • HTTP status code resolution from request attributes
  • + *
  • Exception handling and message sanitization
  • + *
  • Security-conscious error information disclosure
  • + *
+ *

+ * + *

Security Note: All error messages are sanitized to prevent + * exposure of sensitive information before being displayed to users.

*/ @Controller public class CustomErrorController implements ErrorController { + /** + * Default error message displayed when no specific message is available. + */ private static final String DEFAULT_ERROR_MESSAGE = "An unexpected error occurred"; - private static final String DB_VALIDATION_ERROR = "Database error: Required role configuration is missing. Please contact support."; + + /** + * Specific error message for database validation failures. + */ + private static final String DB_VALIDATION_ERROR = + "Database error: Required role configuration is missing. Please contact support."; /** * Handles all error requests and prepares error information for display. + *

+ * This method: + *

    + *
  • Resolves the HTTP status code from the request
  • + *
  • Extracts any associated exception
  • + *
  • Sanitizes error messages for security
  • + *
  • Populates the model with error details for the view
  • + *
  • Returns the error view template
  • + *
+ *

* - * @param request The HTTP request containing error attributes - * @param model The model to populate with error details - * @return The error view template name + * @param request The HTTP request containing error attributes. Must not be null. + * @param model The Spring MVC model to populate with error details. Automatically + * provided by Spring MVC. + * @return The logical view name "error" which resolves to the error template + * + * @see jakarta.servlet.RequestDispatcher#ERROR_STATUS_CODE + * @see jakarta.servlet.RequestDispatcher#ERROR_EXCEPTION + * @see jakarta.servlet.RequestDispatcher#ERROR_REQUEST_URI */ @RequestMapping("/error") public String handleError(HttpServletRequest request, Model model) { @@ -44,7 +79,16 @@ public String handleError(HttpServletRequest request, Model model) { } /** - * Resolves the HTTP status from the request attributes. + * Resolves the HTTP status code from the request attributes. + *

+ * Attempts to extract the status code from request attributes, falling back to + * HTTP 500 (Internal Server Error) if not available. + *

+ * + * @param request The HTTP request containing error attributes + * @return The resolved HttpStatus, never null + * @throws NumberFormatException if the status code attribute contains + * a non-numeric value (should not occur in normal operation) */ private HttpStatus resolveHttpStatus(HttpServletRequest request) { return Optional.ofNullable(request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE)) @@ -54,6 +98,12 @@ private HttpStatus resolveHttpStatus(HttpServletRequest request) { /** * Resolves the exception from the request attributes. + *

+ * Extracts any exception associated with the error request, if available. + *

+ * + * @param request The HTTP request containing error attributes + * @return The associated Throwable, or null if no exception is present */ private Throwable resolveException(HttpServletRequest request) { return Optional.ofNullable(request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)) @@ -62,7 +112,18 @@ private Throwable resolveException(HttpServletRequest request) { } /** - * Provides a safe error message for display, handling nulls and sensitive information. + * Provides a safe error message for display. + *

+ * This method ensures: + *

    + *
  • Null exceptions return a default message
  • + *
  • Specific database errors return a standardized message
  • + *
  • All other messages are sanitized before display
  • + *
+ *

+ * + * @param exception The exception to derive the message from, may be null + * @return A safe, user-appropriate error message, never null */ private String getSafeErrorMessage(Throwable exception) { if (exception == null) { @@ -81,6 +142,13 @@ private String getSafeErrorMessage(Throwable exception) { /** * Sanitizes error messages to prevent exposing sensitive information. + *

+ * Replaces sensitive patterns (like passwords, tokens, etc.) with [REDACTED]. + * Extend this method to include additional sensitive patterns as needed. + *

+ * + * @param message The raw error message to sanitize + * @return A sanitized version of the message safe for user display */ private String sanitizeMessage(String message) { // Basic sanitization - extend this for your specific security requirements diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/DashboardController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/DashboardController.java index 7042f76c8..0a7cf1d0c 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/DashboardController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/DashboardController.java @@ -8,21 +8,41 @@ import org.springframework.security.access.prepost.PreAuthorize; /** - * Controller for handling dashboard-related requests. + * Controller for handling dashboard-related requests in the application. *

- * Provides authenticated users access to the application dashboard with - * role-specific information and functionality. + * This controller manages access to the main application dashboard and ensures + * that users only see content appropriate for their roles. It provides + * role-specific views and functionality based on the authenticated user's + * authorities. + *

+ * + *

Security Note: All methods in this controller require + * authenticated access, with role-based checks performed where necessary.

*/ @Controller public class DashboardController { /** * Displays the application dashboard for authenticated users. + *

+ * This endpoint: + *

    + *
  • Requires the user to be authenticated (via {@code @PreAuthorize})
  • + *
  • Retrieves user details from the authentication context
  • + *
  • Populates the model with user-specific information
  • + *
  • Returns the dashboard view template
  • + *
+ *

* - * @param authentication The Spring Security authentication object - * @param model The model to populate with user data - * @return The dashboard view template name - * @throws ClassCastException if the principal is not a UserDetails instance + * @param authentication The Spring Security authentication object containing + * the current user's security context. Must not be null. + * @param model The Spring MVC model to populate with user data for the view. + * Automatically provided by Spring MVC. + * @return The logical view name "dashboard" which resolves to the dashboard template + * @throws SecurityException if the authentication principal cannot be cast to + * UserDetails, indicating an invalid authentication configuration + * @see org.springframework.security.core.userdetails.UserDetails + * @see org.springframework.ui.Model */ @GetMapping("/dashboard") @PreAuthorize("isAuthenticated()") @@ -38,13 +58,29 @@ public String showDashboard(Authentication authentication, Model model) { /** * Extracts UserDetails from the Authentication object. + * + * @param authentication The Spring Security authentication object + * @return The UserDetails object representing the authenticated user + * @throws ClassCastException if the principal is not a UserDetails instance, + * indicating improper authentication configuration */ private UserDetails getUserDetails(Authentication authentication) { return (UserDetails) authentication.getPrincipal(); } /** - * Populates the model with user-specific information. + * Populates the model with user-specific information for the dashboard view. + *

+ * Adds the following attributes to the model: + *

    + *
  • username - The authenticated user's username
  • + *
  • authorities - The collection of granted authorities/roles
  • + *
  • isAdmin - Boolean flag indicating admin status
  • + *
+ *

+ * + * @param model The Spring MVC model to populate + * @param userDetails The UserDetails object containing user information */ private void populateModelWithUserDetails(Model model, UserDetails userDetails) { model.addAttribute("username", userDetails.getUsername()); @@ -53,7 +89,11 @@ private void populateModelWithUserDetails(Model model, UserDetails userDetails) } /** - * Checks if the user has ADMIN authority. + * Determines if the user has ADMIN authority. + * + * @param userDetails The UserDetails object to check + * @return {@code true} if the user has ROLE_ADMIN authority, + * {@code false} otherwise */ private boolean hasAdminAuthority(UserDetails userDetails) { return userDetails.getAuthorities().stream() diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/LoginDtoValidationTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/LoginDtoValidationTest.java new file mode 100644 index 000000000..b8ff4534c --- /dev/null +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/LoginDtoValidationTest.java @@ -0,0 +1,180 @@ +package com.jydoc.deliverable4; + +import com.jydoc.deliverable4.DTO.LoginDTO; +import jakarta.validation.ConstraintViolation; +import jakarta.validation.Validation; +import jakarta.validation.Validator; +import jakarta.validation.ValidatorFactory; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; + +import java.util.Set; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.*; + +class LoginDTOTest { + + private static Validator validator; + + @BeforeAll + static void setUp() { + try (ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) { + validator = factory.getValidator(); + } + } + + // Test data providers + static Stream validUsernames() { + return Stream.of("user123", "admin", "test.user@example.com", "a".repeat(100)); + } + + static Stream validPasswords() { + return Stream.of("password123", "P@ssw0rd", "a".repeat(128), "12345678"); + } + + // Constructor tests + @Test + void constructor_ShouldCreateInstanceWithProvidedValues() { + String testUsername = "testUser"; + String testPassword = "securePassword123"; + + LoginDTO loginDTO = new LoginDTO(testUsername, testPassword); + + assertEquals(testUsername, loginDTO.username()); + assertEquals(testPassword, loginDTO.password()); + } + + // Validation tests + @ParameterizedTest + @NullAndEmptySource + @ValueSource(strings = {" ", "\t", "\n"}) + void usernameValidation_ShouldFailForBlankValues(String invalidUsername) { + LoginDTO loginDTO = new LoginDTO(invalidUsername, "validPassword123"); + Set> violations = validator.validate(loginDTO); + + assertFalse(violations.isEmpty()); + assertEquals("Username or email cannot be blank", violations.iterator().next().getMessage()); + } + + @ParameterizedTest + @MethodSource("validUsernames") + void usernameValidation_ShouldPassForValidValues(String validUsername) { + LoginDTO loginDTO = new LoginDTO(validUsername, "validPassword123"); + Set> violations = validator.validate(loginDTO); + + assertTrue(violations.isEmpty()); + } + + @ParameterizedTest + @NullAndEmptySource + @ValueSource(strings = {" ", "\t", "\n"}) + void passwordValidation_ShouldFailForBlankValues(String invalidPassword) { + LoginDTO loginDTO = new LoginDTO("validUser", invalidPassword); + Set> violations = validator.validate(loginDTO); + + assertFalse(violations.isEmpty(), "Should have violations for blank password"); + + // Check that at least one of the expected messages is present + boolean hasBlankViolation = violations.stream() + .anyMatch(v -> v.getMessage().equals("Password cannot be blank")); + boolean hasSizeViolation = violations.stream() + .anyMatch(v -> v.getMessage().equals("Password must be at least 8 characters long")); + + // For blank values, we should get EITHER the blank message OR the size message + assertTrue(hasBlankViolation || hasSizeViolation, + "Should have either blank or size violation for empty password"); + } + + @ParameterizedTest + @ValueSource(strings = {"short", "1234567"}) + void passwordValidation_ShouldFailForShortPasswords(String shortPassword) { + LoginDTO loginDTO = new LoginDTO("validUser", shortPassword); + Set> violations = validator.validate(loginDTO); + + assertFalse(violations.isEmpty()); + assertEquals("Password must be at least 8 characters long", violations.iterator().next().getMessage()); + } + + @ParameterizedTest + @MethodSource("validPasswords") + void passwordValidation_ShouldPassForValidValues(String validPassword) { + LoginDTO loginDTO = new LoginDTO("validUser", validPassword); + Set> violations = validator.validate(loginDTO); + + assertTrue(violations.isEmpty()); + } + + // empty() method tests + @Test + void empty_ShouldCreateInstanceWithBlankCredentials() { + LoginDTO emptyDTO = LoginDTO.empty(); + + assertTrue(emptyDTO.username().isEmpty()); + assertTrue(emptyDTO.password().isEmpty()); + } + + // getNormalizedUsername() tests + @Test + void getNormalizedUsername_ShouldTrimWhitespace() { + LoginDTO loginDTO = new LoginDTO(" testUser ", "password"); + + assertEquals("testuser", loginDTO.getNormalizedUsername()); + } + + @Test + void getNormalizedUsername_ShouldConvertToLowerCase() { + LoginDTO loginDTO = new LoginDTO("TestUser", "password"); + + assertEquals("testuser", loginDTO.getNormalizedUsername()); + } + + @Test + void getNormalizedUsername_ShouldHandleEmptyString() { + LoginDTO loginDTO = new LoginDTO("", "password"); + + assertEquals("", loginDTO.getNormalizedUsername()); + } + + // isEmpty() tests + @Test + void isEmpty_ShouldReturnTrueForEmptyInstance() { + LoginDTO emptyDTO = LoginDTO.empty(); + + assertTrue(emptyDTO.isEmpty()); + } + + @Test + void isEmpty_ShouldReturnFalseForNonEmptyUsername() { + LoginDTO loginDTO = new LoginDTO("user", ""); + + assertFalse(loginDTO.isEmpty()); + } + + @Test + void isEmpty_ShouldReturnFalseForNonEmptyPassword() { + LoginDTO loginDTO = new LoginDTO("", "password"); + + assertFalse(loginDTO.isEmpty()); + } + + @Test + void isEmpty_ShouldReturnFalseForFullyPopulatedInstance() { + LoginDTO loginDTO = new LoginDTO("user", "password"); + + assertFalse(loginDTO.isEmpty()); + } + + // Record component tests + @Test + void recordComponents_ShouldBeAccessible() { + LoginDTO loginDTO = new LoginDTO("test", "password"); + + assertEquals("test", loginDTO.username()); + assertEquals("password", loginDTO.password()); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java index babbcefc5..aa3b4760d 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java @@ -3,11 +3,9 @@ import com.jydoc.deliverable4.model.UserModel; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; -import jakarta.validation.ConstraintViolationException; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.dao.DataIntegrityViolationException; import org.springframework.test.context.ActiveProfiles; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; @@ -41,6 +39,8 @@ void testUserEntityPersistence() { .username("testuser") .password("encodedPassword") .email("test@example.com") + .firstName("firstname") + .lastName("lastname") .build(); // When @@ -63,6 +63,8 @@ void testUsernameUniquenessConstraint() { UserModel user1 = UserModel.builder() .username("uniqueuser") .password("password1") + .firstName("firstname") + .lastName("lastname") .build(); entityManager.persist(user1); }); @@ -86,6 +88,8 @@ void testEmailUniquenessConstraint() { executeInTransaction(() -> { UserModel user1 = UserModel.builder() .username("user1") + .firstName("firstname") + .lastName("lastname") .password("password1") .email("unique@example.com") .build(); @@ -98,6 +102,8 @@ void testEmailUniquenessConstraint() { UserModel user2 = UserModel.builder() .username("user2") .password("password2") + .firstName("firstname") + .lastName("lastname") .email("unique@example.com") .build(); entityManager.persist(user2); @@ -112,6 +118,8 @@ void testOptionalEmailField() { UserModel user = UserModel.builder() .username("noemail") .password("password") + .firstName("firstname") + .lastName("lastname") .email(null) .build(); diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java index 49a700474..447008a9b 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java @@ -11,6 +11,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; @@ -280,26 +281,26 @@ void authenticationException_ContainsCorrectMessage() { // Assert assertEquals("Test message", exception.getMessage()); } - - @Test - void usernameExistsException_ContainsCorrectMessage() { - // Act - UserService.UsernameExistsException exception = - new UserService.UsernameExistsException("testuser"); - + // @Disabled + // @Test + //void usernameExistsException_ContainsCorrectMessage() { + // // Act + // UserService.UsernameExistsException exception = + // new UserService.UsernameExistsException("testuser"); +// // Assert - assertEquals("Username 'testuser' already exists", exception.getMessage()); - } - - @Test - void emailExistsException_ContainsCorrectMessage() { + // assertEquals("Username 'testuser' already exists", exception.getMessage()); + // } + // @Disabled +// @Test + // void emailExistsException_ContainsCorrectMessage() { // Act - UserService.EmailExistsException exception = - new UserService.EmailExistsException("test@example.com"); + //Exceptions.EmailExistsException exception = + // new UserService.EmailExistsException("test@example.com"); // Assert - assertEquals("Email 'test@example.com' is already registered", exception.getMessage()); - } + // assertEquals("Email 'test@example.com' is already registered", exception.getMessage()); + // } // ---------------------- Helper Method Tests ---------------------- From d1302f0c5ce0bfce5ff07d1870d7ecc0fe7ce735 Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 05:38:43 -0400 Subject: [PATCH 056/100] Login fix --- .../src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java index 568449d2b..598609605 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java @@ -2,6 +2,7 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; +import java.io.Serializable; /** * Data Transfer Object (DTO) for user login requests. @@ -18,7 +19,9 @@ public record LoginDTO( @NotBlank(message = "Password cannot be blank") @Size(min = 8, message = "Password must be at least 8 characters long") String password -) { +) implements Serializable { + + private static final long serialVersionUID = 1L; /** * Creates an empty LoginDTO instance. From 07fd726b9b18e4464c27444b2efa34f78e790217 Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 06:09:45 -0400 Subject: [PATCH 057/100] Test cases and documentation --- .../main/resources/templates/dashboard.html | 79 ++++- .../src/main/resources/templates/error.html | 77 ++++- .../CustomUserDetailsServiceTest.java | 227 ++++++++++++++ .../deliverable4/CustomUserDetailsTest.java | 289 ++++++++++++++++++ .../com/jydoc/deliverable4/UserModelTest.java | 10 - 5 files changed, 649 insertions(+), 33 deletions(-) create mode 100644 Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsServiceTest.java create mode 100644 Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java diff --git a/Sprint 2/prototype2/src/main/resources/templates/dashboard.html b/Sprint 2/prototype2/src/main/resources/templates/dashboard.html index dd5e20291..8ecc8304b 100644 --- a/Sprint 2/prototype2/src/main/resources/templates/dashboard.html +++ b/Sprint 2/prototype2/src/main/resources/templates/dashboard.html @@ -1,12 +1,21 @@ + xmlns:sec="http://www.thymeleaf.org/extras/spring-security" lang="en"> + - User Dashboard + User Dashboard - JYDoc System - + - +
- +
+
User Profile @@ -52,7 +82,7 @@
- +
Quick Actions @@ -61,13 +91,22 @@ Edit Profile Change Password My Reports + User Management
- +
+
@@ -82,7 +121,12 @@
Welcome to your dashboard
- +
@@ -113,7 +157,12 @@
Notifications
- +
@@ -158,6 +207,12 @@
Audit Logs
+ \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/error.html b/Sprint 2/prototype2/src/main/resources/templates/error.html index 38d4e6ba1..b342e2dbd 100644 --- a/Sprint 2/prototype2/src/main/resources/templates/error.html +++ b/Sprint 2/prototype2/src/main/resources/templates/error.html @@ -1,41 +1,96 @@ - + + - Error Page + Error Page | JYDoc System + +
+

⚠️ Oops! Something went wrong

We're sorry, but an error occurred while processing your request.

+

Error Type

Error message

-

Request path:

-

Status code:

-

Timestamp:

+

+ Request path: +

+

+ Status code: +

+

+ Timestamp: +

+
Go to Home Page
+ + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsServiceTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsServiceTest.java new file mode 100644 index 000000000..9fb421d6f --- /dev/null +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsServiceTest.java @@ -0,0 +1,227 @@ +package com.jydoc.deliverable4; + +import com.jydoc.deliverable4.model.AuthorityModel; +import com.jydoc.deliverable4.model.UserModel; +import com.jydoc.deliverable4.repositories.UserRepository; +import com.jydoc.deliverable4.security.auth.CustomUserDetailsService; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; + +import java.util.Collections; +import java.util.Optional; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +@DisplayName("CustomUserDetailsService Tests") +class CustomUserDetailsServiceTest { + + @Mock + private UserRepository userRepository; + + @InjectMocks + private CustomUserDetailsService userDetailsService; + + private static final String USERNAME = "testuser"; + private static final String EMAIL = "test@example.com"; + private static final String PASSWORD = "password123"; + private static final Long USER_ID = 1L; + + @Nested + @DisplayName("loadUserByUsername Tests") + class LoadUserByUsernameTests { + + private AuthorityModel createMockAuthority(String authorityName) { + AuthorityModel authority = new AuthorityModel(); + authority.setAuthority(authorityName); + return authority; + } + + private UserModel createMockUser(Set authorities) { + UserModel user = new UserModel(); + user.setId(USER_ID); + user.setUsername(USERNAME); + user.setPassword(PASSWORD); + user.setEnabled(true); + user.setAccountNonExpired(true); + user.setAccountNonLocked(true); + user.setCredentialsNonExpired(true); + user.setAuthorities(authorities); + return user; + } + + @Test + @DisplayName("Should load user by username successfully") + void shouldLoadUserByUsername() { + // Arrange + AuthorityModel userRole = createMockAuthority("ROLE_USER"); + AuthorityModel adminRole = createMockAuthority("ROLE_ADMIN"); + Set authorities = Set.of(userRole, adminRole); + + UserModel mockUser = createMockUser(authorities); + when(userRepository.findByUsernameOrEmailWithAuthorities(USERNAME)) + .thenReturn(Optional.of(mockUser)); + + // Act + UserDetails userDetails = userDetailsService.loadUserByUsername(USERNAME); + + // Assert + assertNotNull(userDetails); + assertEquals(USERNAME, userDetails.getUsername()); + assertEquals(PASSWORD, userDetails.getPassword()); + assertTrue(userDetails.isEnabled()); + assertTrue(userDetails.isAccountNonExpired()); + assertTrue(userDetails.isAccountNonLocked()); + assertTrue(userDetails.isCredentialsNonExpired()); + + // Verify authorities + assertEquals(2, userDetails.getAuthorities().size()); + assertTrue(userDetails.getAuthorities().contains(new SimpleGrantedAuthority("ROLE_USER"))); + assertTrue(userDetails.getAuthorities().contains(new SimpleGrantedAuthority("ROLE_ADMIN"))); + + verify(userRepository).findByUsernameOrEmailWithAuthorities(USERNAME); + } + + @Test + @DisplayName("Should load user by email successfully") + void shouldLoadUserByEmail() { + // Arrange + AuthorityModel userRole = createMockAuthority("ROLE_USER"); + UserModel mockUser = createMockUser(Set.of(userRole)); + when(userRepository.findByUsernameOrEmailWithAuthorities(EMAIL)) + .thenReturn(Optional.of(mockUser)); + + // Act + UserDetails userDetails = userDetailsService.loadUserByUsername(EMAIL); + + // Assert + assertNotNull(userDetails); + assertEquals(USERNAME, userDetails.getUsername()); + verify(userRepository).findByUsernameOrEmailWithAuthorities(EMAIL); + } + + @Test + @DisplayName("Should throw UsernameNotFoundException when user not found") + void shouldThrowWhenUserNotFound() { + // Arrange + String invalidUsername = "nonexistent"; + when(userRepository.findByUsernameOrEmailWithAuthorities(invalidUsername)) + .thenReturn(Optional.empty()); + + // Act & Assert + UsernameNotFoundException exception = assertThrows( + UsernameNotFoundException.class, + () -> userDetailsService.loadUserByUsername(invalidUsername) + ); + + assertEquals("User not found with username or email: " + invalidUsername, exception.getMessage()); + verify(userRepository).findByUsernameOrEmailWithAuthorities(invalidUsername); + } + + @Test + @DisplayName("Should handle disabled user account") + void shouldHandleDisabledUser() { + // Arrange + UserModel mockUser = createMockUser(Collections.emptySet()); + mockUser.setEnabled(false); + when(userRepository.findByUsernameOrEmailWithAuthorities(USERNAME)) + .thenReturn(Optional.of(mockUser)); + + // Act + UserDetails userDetails = userDetailsService.loadUserByUsername(USERNAME); + + // Assert + assertFalse(userDetails.isEnabled()); + } + + @Test + @DisplayName("Should handle expired user account") + void shouldHandleExpiredAccount() { + // Arrange + UserModel mockUser = createMockUser(Collections.emptySet()); + mockUser.setAccountNonExpired(false); + when(userRepository.findByUsernameOrEmailWithAuthorities(USERNAME)) + .thenReturn(Optional.of(mockUser)); + + // Act + UserDetails userDetails = userDetailsService.loadUserByUsername(USERNAME); + + // Assert + assertFalse(userDetails.isAccountNonExpired()); + } + + @Test + @DisplayName("Should handle locked user account") + void shouldHandleLockedAccount() { + // Arrange + UserModel mockUser = createMockUser(Collections.emptySet()); + mockUser.setAccountNonLocked(false); + when(userRepository.findByUsernameOrEmailWithAuthorities(USERNAME)) + .thenReturn(Optional.of(mockUser)); + + // Act + UserDetails userDetails = userDetailsService.loadUserByUsername(USERNAME); + + // Assert + assertFalse(userDetails.isAccountNonLocked()); + } + + @Test + @DisplayName("Should handle expired credentials") + void shouldHandleExpiredCredentials() { + // Arrange + UserModel mockUser = createMockUser(Collections.emptySet()); + mockUser.setCredentialsNonExpired(false); + when(userRepository.findByUsernameOrEmailWithAuthorities(USERNAME)) + .thenReturn(Optional.of(mockUser)); + + // Act + UserDetails userDetails = userDetailsService.loadUserByUsername(USERNAME); + + // Assert + assertFalse(userDetails.isCredentialsNonExpired()); + } + + @Test + @DisplayName("Should handle empty authorities") + void shouldHandleEmptyAuthorities() { + // Arrange + UserModel mockUser = createMockUser(Collections.emptySet()); + when(userRepository.findByUsernameOrEmailWithAuthorities(USERNAME)) + .thenReturn(Optional.of(mockUser)); + + // Act + UserDetails userDetails = userDetailsService.loadUserByUsername(USERNAME); + + // Assert + assertTrue(userDetails.getAuthorities().isEmpty()); + } + } + + @Nested + @DisplayName("Transactional Behavior Tests") + class TransactionalBehaviorTests { + + @Test + @DisplayName("Should have readOnly transaction for loadUserByUsername") + void shouldHaveReadOnlyTransaction() throws NoSuchMethodException { + // This test verifies the annotation is present + var method = CustomUserDetailsService.class.getMethod( + "loadUserByUsername", String.class); + var transactional = method.getAnnotation(org.springframework.transaction.annotation.Transactional.class); + + assertNotNull(transactional); + assertTrue(transactional.readOnly()); + } + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java new file mode 100644 index 000000000..e0d97a75d --- /dev/null +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java @@ -0,0 +1,289 @@ +package com.jydoc.deliverable4; + +import com.jydoc.deliverable4.security.auth.CustomUserDetails; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mock; + +@DisplayName("CustomUserDetails Tests") +class CustomUserDetailsTest { + + // Test data + private static final Long USER_ID = 1L; + private static final String USERNAME = "testuser"; + private static final String PASSWORD = "password123"; + private static final Collection AUTHORITIES = + Arrays.asList(new SimpleGrantedAuthority("ROLE_USER")); + + @Nested + @DisplayName("Constructor Tests") + class ConstructorTests { + + @Test + @DisplayName("Should create instance with valid parameters") + void shouldCreateInstanceWithValidParameters() { + CustomUserDetails userDetails = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, true, true, + AUTHORITIES + ); + + assertNotNull(userDetails); + assertEquals(USER_ID, userDetails.getUserId()); + assertEquals(USERNAME, userDetails.getUsername()); + assertEquals(PASSWORD, userDetails.getPassword()); + assertTrue(userDetails.isEnabled()); + assertTrue(userDetails.isAccountNonExpired()); + assertTrue(userDetails.isAccountNonLocked()); + assertTrue(userDetails.isCredentialsNonExpired()); + assertEquals(AUTHORITIES, userDetails.getAuthorities()); + } + + @Test + @DisplayName("Should throw NullPointerException for null userId") + void shouldThrowForNullUserId() { + assertThrows(NullPointerException.class, () -> + new CustomUserDetails( + null, USERNAME, PASSWORD, + true, true, true, true, + AUTHORITIES + ) + ); + } + + @Test + @DisplayName("Should throw NullPointerException for null username") + void shouldThrowForNullUsername() { + assertThrows(NullPointerException.class, () -> + new CustomUserDetails( + USER_ID, null, PASSWORD, + true, true, true, true, + AUTHORITIES + ) + ); + } + + @Test + @DisplayName("Should throw NullPointerException for null password") + void shouldThrowForNullPassword() { + assertThrows(NullPointerException.class, () -> + new CustomUserDetails( + USER_ID, USERNAME, null, + true, true, true, true, + AUTHORITIES + ) + ); + } + + @Test + @DisplayName("Should throw NullPointerException for null authorities") + void shouldThrowForNullAuthorities() { + assertThrows(NullPointerException.class, () -> + new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, true, true, + null + ) + ); + } + } + + @Nested + @DisplayName("Account Status Tests") + class AccountStatusTests { + + @Test + @DisplayName("Should reflect disabled account status") + void shouldReflectDisabledAccount() { + CustomUserDetails userDetails = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + false, true, true, true, + AUTHORITIES + ); + + assertFalse(userDetails.isEnabled()); + } + + @Test + @DisplayName("Should reflect expired account status") + void shouldReflectExpiredAccount() { + CustomUserDetails userDetails = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, false, true, true, + AUTHORITIES + ); + + assertFalse(userDetails.isAccountNonExpired()); + } + + @Test + @DisplayName("Should reflect locked account status") + void shouldReflectLockedAccount() { + CustomUserDetails userDetails = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, false, true, + AUTHORITIES + ); + + assertFalse(userDetails.isAccountNonLocked()); + } + + @Test + @DisplayName("Should reflect expired credentials status") + void shouldReflectExpiredCredentials() { + CustomUserDetails userDetails = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, true, false, + AUTHORITIES + ); + + assertFalse(userDetails.isCredentialsNonExpired()); + } + } + + @Nested + @DisplayName("Equals and HashCode Tests") + class EqualsAndHashCodeTests { + + @Test + @DisplayName("Should be equal when userId and username match") + void shouldBeEqualWhenUserIdAndUsernameMatch() { + CustomUserDetails user1 = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, true, true, + AUTHORITIES + ); + + CustomUserDetails user2 = new CustomUserDetails( + USER_ID, USERNAME, "differentPassword", + false, false, false, false, + Collections.emptyList() + ); + + assertEquals(user1, user2); + assertEquals(user1.hashCode(), user2.hashCode()); + } + + @Test + @DisplayName("Should not be equal when userId differs") + void shouldNotBeEqualWhenUserIdDiffers() { + CustomUserDetails user1 = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, true, true, + AUTHORITIES + ); + + CustomUserDetails user2 = new CustomUserDetails( + 2L, USERNAME, PASSWORD, + true, true, true, true, + AUTHORITIES + ); + + assertNotEquals(user1, user2); + } + + @Test + @DisplayName("Should not be equal when username differs") + void shouldNotBeEqualWhenUsernameDiffers() { + CustomUserDetails user1 = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, true, true, + AUTHORITIES + ); + + CustomUserDetails user2 = new CustomUserDetails( + USER_ID, "differentuser", PASSWORD, + true, true, true, true, + AUTHORITIES + ); + + assertNotEquals(user1, user2); + } + + @Test + @DisplayName("Should not be equal to null") + void shouldNotBeEqualToNull() { + CustomUserDetails userDetails = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, true, true, + AUTHORITIES + ); + + assertNotEquals(null, userDetails); + } + + @Test + @DisplayName("Should not be equal to different class") + void shouldNotBeEqualToDifferentClass() { + CustomUserDetails userDetails = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, true, true, + AUTHORITIES + ); + + assertNotEquals("Not a user object", userDetails); + } + } + + @Nested + @DisplayName("Getter Tests") + class GetterTests { + + @Test + @DisplayName("Should return correct userId") + void shouldReturnCorrectUserId() { + CustomUserDetails userDetails = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, true, true, + AUTHORITIES + ); + + assertEquals(USER_ID, userDetails.getUserId()); + } + + @Test + @DisplayName("Should return correct username") + void shouldReturnCorrectUsername() { + CustomUserDetails userDetails = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, true, true, + AUTHORITIES + ); + + assertEquals(USERNAME, userDetails.getUsername()); + } + + @Test + @DisplayName("Should return correct password") + void shouldReturnCorrectPassword() { + CustomUserDetails userDetails = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, true, true, + AUTHORITIES + ); + + assertEquals(PASSWORD, userDetails.getPassword()); + } + + @Test + @DisplayName("Should return correct authorities") + void shouldReturnCorrectAuthorities() { + CustomUserDetails userDetails = new CustomUserDetails( + USER_ID, USERNAME, PASSWORD, + true, true, true, true, + AUTHORITIES + ); + + assertEquals(AUTHORITIES, userDetails.getAuthorities()); + } + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java index aa3b4760d..238616483 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java @@ -39,8 +39,6 @@ void testUserEntityPersistence() { .username("testuser") .password("encodedPassword") .email("test@example.com") - .firstName("firstname") - .lastName("lastname") .build(); // When @@ -63,8 +61,6 @@ void testUsernameUniquenessConstraint() { UserModel user1 = UserModel.builder() .username("uniqueuser") .password("password1") - .firstName("firstname") - .lastName("lastname") .build(); entityManager.persist(user1); }); @@ -88,8 +84,6 @@ void testEmailUniquenessConstraint() { executeInTransaction(() -> { UserModel user1 = UserModel.builder() .username("user1") - .firstName("firstname") - .lastName("lastname") .password("password1") .email("unique@example.com") .build(); @@ -102,8 +96,6 @@ void testEmailUniquenessConstraint() { UserModel user2 = UserModel.builder() .username("user2") .password("password2") - .firstName("firstname") - .lastName("lastname") .email("unique@example.com") .build(); entityManager.persist(user2); @@ -118,8 +110,6 @@ void testOptionalEmailField() { UserModel user = UserModel.builder() .username("noemail") .password("password") - .firstName("firstname") - .lastName("lastname") .email(null) .build(); From 5cce801394cc7e7f4b1849e5f010d39564961270 Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 06:24:56 -0400 Subject: [PATCH 058/100] Documentation --- .../com/jydoc/deliverable4/DTO/UserDTO.java | 57 ++++++++- .../deliverable4/Service/UserService.java | 59 +++++++++- .../jydoc/deliverable4/model/UserModel.java | 56 +++++++++ .../security/auth/CustomUserDetails.java | 111 ++++++++++++++++++ 4 files changed, 276 insertions(+), 7 deletions(-) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java index 65658abf8..04f029be2 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java @@ -7,14 +7,40 @@ import lombok.Getter; import lombok.Setter; +/** + * Data Transfer Object (DTO) for user-related operations. + * This class represents the user data that is transferred between layers, + * particularly between the controller and service layers. + * + *

Includes validation constraints for user input fields to ensure data integrity + * before processing. Uses Lombok annotations to reduce boilerplate code for getters/setters.

+ * + * + * @version 1.0 + * @see com.jydoc.deliverable4.model.UserModel + * @since 1.0 + */ @Setter @Getter public class UserDTO { - // Getters and Setters + + /** + * The username for authentication. Must be unique and between 3-20 characters. + * + * @NotBlank Ensures the username is not null or empty + * @Size Constrains the length between 3-20 characters + */ @NotBlank(message = "Username is required") @Size(min = 3, max = 20, message = "Username must be 3-20 characters") private String username; + /** + * The password for authentication. Must meet complexity requirements. + * + * @NotBlank Ensures the password is not null or empty + * @Size Requires minimum 6 characters + * @Pattern Enforces at least one uppercase, one lowercase letter and one number + */ @NotBlank(message = "Password is required") @Size(min = 6, message = "Password must be at least 6 characters") @Pattern( @@ -23,24 +49,50 @@ public class UserDTO { ) private String password; + /** + * The user's email address. Must be in valid format. + * + * @NotBlank Ensures the email is not null or empty + * @Pattern Validates the email format using regex pattern + */ @NotBlank(message = "Email is required") @Pattern(regexp = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@" + "(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$", message = "Invalid email format") private String email; + /** + * The user's first name. Cannot be blank. + */ @NotBlank(message = "First name is required") private String firstName; + /** + * The user's last name. Cannot be blank. + */ @NotBlank(message = "Last name is required") private String lastName; + /** + * The authority/role assigned to the user. Defaults to "ROLE_USER". + */ private String authority = "ROLE_USER"; - // Constructors, getters and setters remain the same + /** + * Default constructor. + */ public UserDTO() { } + /** + * Constructs a UserDTO with specified parameters. + * + * @param username the username + * @param password the password + * @param email the email address + * @param firstName the first name + * @param lastName the last name + */ public UserDTO(String username, String password, String email, String firstName, String lastName) { this.username = username; this.password = password; @@ -48,5 +100,4 @@ public UserDTO(String username, String password, String email, String firstName, this.firstName = firstName; this.lastName = lastName; } - } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java index a92ef596d..0c5dedca2 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java @@ -33,6 +33,22 @@ * *

All database operations are transactional with appropriate propagation settings. * Integrates with Spring Security for authentication and authorization.

+ * + *

This service handles the core business logic for user operations while + * delegating specific concerns to dedicated components:

+ *
    + *
  • Persistence operations to repositories
  • + *
  • Password encoding to PasswordEncoder
  • + *
  • Authentication to AuthenticationManager
  • + *
  • Validation to UserValidationHelper
  • + *
+ * + * @author Your Name + * @version 1.0 + * @see UserModel + * @see UserDTO + * @see LoginDTO + * @since 1.0 */ @Service @RequiredArgsConstructor @@ -55,6 +71,9 @@ public class UserService { * @throws UsernameExistsException if the username is already taken * @throws EmailExistsException if the email is already registered * @throws IllegalArgumentException if user data is invalid + * @see #validateRegistration(UserDTO) + * @see #buildUserFromDto(UserDTO) + * @see #assignDefaultRole(UserModel) */ @Transactional public void registerNewUser(UserDTO userDto) { @@ -72,6 +91,7 @@ public void registerNewUser(UserDTO userDto) { * @return authenticated UserModel entity * @throws AuthenticationException if credentials are invalid or account is locked/disabled * @throws IllegalArgumentException if login data is null + * @see #authenticateUser(String, String) */ @Transactional(readOnly = true) public UserModel authenticate(LoginDTO loginDto) { @@ -87,6 +107,7 @@ public UserModel authenticate(LoginDTO loginDto) { * @param loginDto the login credentials * @return authenticated UserModel * @throws AuthenticationException if authentication fails + * @see #findActiveUser(String) */ @Transactional(readOnly = true) public UserModel validateLogin(LoginDTO loginDto) { @@ -123,7 +144,12 @@ public UserModel validateLogin(LoginDTO loginDto) { * @param username the username to authenticate * @param password the raw password to verify * @return authenticated UserModel - * @throws AuthenticationException wrapping various authentication failure scenarios + * @throws AuthenticationException wrapping various authentication failure scenarios: + *
    + *
  • BadCredentialsException - invalid username/password
  • + *
  • DisabledException - account disabled
  • + *
  • LockedException - account locked
  • + *
*/ @Transactional(readOnly = true) public UserModel authenticateUser(String username, String password) { @@ -156,7 +182,13 @@ public UserModel authenticateUser(String username, String password) { * Constructs a UserModel from registration DTO with proper encoding and normalization. * * @param userDto the user registration data - * @return properly configured UserModel + * @return properly configured UserModel with: + *
    + *
  • Trimmed username
  • + *
  • Encoded password
  • + *
  • Normalized email (lowercase and trimmed)
  • + *
  • Account flags set to active
  • + *
*/ private UserModel buildUserFromDto(UserDTO userDto) { return UserModel.builder() @@ -174,6 +206,8 @@ private UserModel buildUserFromDto(UserDTO userDto) { * Assigns the default role to a new user, creating the role if it doesn't exist. * * @param user the user to receive the default role + * @throws IllegalStateException if transaction propagation fails + * @see AuthorityModel */ @Transactional(propagation = Propagation.MANDATORY) protected void assignDefaultRole(UserModel user) { @@ -195,6 +229,8 @@ protected void assignDefaultRole(UserModel user) { * * @param userDto the user registration data * @throws IllegalArgumentException if user data is invalid + * @throws UsernameExistsException if username exists + * @throws EmailExistsException if email exists */ private void validateRegistration(UserDTO userDto) { if (userDto == null) { @@ -209,7 +245,7 @@ private void validateRegistration(UserDTO userDto) { * Finds an active user by username or email. * * @param usernameOrEmail the user identifier (username or email) - * @return Optional containing the user if found and active + * @return Optional containing the user if found and active, empty otherwise */ @Transactional(readOnly = true) public Optional findActiveUser(String usernameOrEmail) { @@ -220,9 +256,14 @@ public Optional findActiveUser(String usernameOrEmail) { // ---------------------- Custom Exceptions ---------------------- /** - * Exception thrown when authentication fails. + * Exception thrown when authentication fails for various reasons. */ public static class AuthenticationException extends RuntimeException { + /** + * Constructs a new authentication exception with the specified detail message. + * + * @param message the detail message + */ public AuthenticationException(String message) { super(message); logger.error("Authentication failed: {}", message); @@ -233,6 +274,11 @@ public AuthenticationException(String message) { * Exception thrown when attempting to register an existing username. */ public static class UsernameExistsException extends RuntimeException { + /** + * Constructs a new username exists exception. + * + * @param username the duplicate username + */ public UsernameExistsException(String username) { super(String.format("Username '%s' already exists", username)); logger.warn("Registration attempt with existing username: {}", username); @@ -243,6 +289,11 @@ public UsernameExistsException(String username) { * Exception thrown when attempting to register an existing email. */ public static class EmailExistsException extends RuntimeException { + /** + * Constructs a new email exists exception. + * + * @param email the duplicate email + */ public EmailExistsException(String email) { super(String.format("Email '%s' is already registered", email)); logger.warn("Registration attempt with existing email: {}", email); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java index e29ead069..f739de18b 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java @@ -8,6 +8,19 @@ import java.util.HashSet; import java.util.Set; +/** + * Represents a user entity in the system with authentication and authorization details. + * This class maps to the 'users' table in the database and includes user credentials, + * account status flags, and associated authorities (roles/permissions). + * + *

The class uses Lombok annotations for boilerplate code reduction and JPA annotations + * for ORM mapping. It maintains a many-to-many relationship with AuthorityModel.

+ * + * @author Your Name + * @version 1.0 + * @see AuthorityModel + * @since 1.0 + */ @Entity @Table(name = "users") @Getter @@ -17,31 +30,60 @@ @Builder(toBuilder = true) public class UserModel { + /** + * Unique identifier for the user. Automatically generated by the database. + */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + /** + * Unique username for authentication. Must be non-null and maximum 50 characters. + */ @Column(unique = true, nullable = false, length = 50) private String username; + /** + * Password for authentication. Stored in encrypted form. Must be non-null and maximum 100 characters. + */ @Column(nullable = false, length = 100) private String password; + /** + * Unique email address for the user. Maximum 100 characters. + */ @Column(unique = true, length = 100) private String email; + /** + * Flag indicating whether the user is enabled. Defaults to true. + */ @Builder.Default private boolean enabled = true; + /** + * Flag indicating whether the user's account is non-expired. Defaults to true. + */ @Builder.Default private boolean accountNonExpired = true; + /** + * Flag indicating whether the user's credentials are non-expired. Defaults to true. + */ @Builder.Default private boolean credentialsNonExpired = true; + /** + * Flag indicating whether the user's account is non-locked. Defaults to true. + */ @Builder.Default private boolean accountNonLocked = true; + /** + * Set of authorities (roles/permissions) assigned to the user. + * Maintains a many-to-many relationship through the 'user_authorities' join table. + * Uses eager fetching strategy and cascades persist and merge operations. + */ @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @JoinTable( name = "user_authorities", @@ -52,16 +94,30 @@ public class UserModel { @Builder.Default private Set authorities = new HashSet<>(); + /** + * Adds an authority to the user and maintains the bidirectional relationship. + * + * @param authority the authority to add + * @throws NullPointerException if the authority parameter is null + */ public void addAuthority(AuthorityModel authority) { this.authorities.add(authority); authority.getUsers().add(this); } + /** + * Removes an authority from the user and maintains the bidirectional relationship. + * + * @param authority the authority to remove + */ public void removeAuthority(AuthorityModel authority) { this.authorities.remove(authority); authority.getUsers().remove(this); } + /** + * Custom builder class for UserModel with default values. + */ public static class UserModelBuilder { private boolean enabled = true; private boolean accountNonExpired = true; diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java index 49ad2e025..a465ccee2 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java @@ -6,18 +6,77 @@ import java.util.Collection; import java.util.Objects; +/** + * Custom implementation of Spring Security's {@link UserDetails} interface. + * This class represents an authenticated user's details and is used throughout + * the security context of the application. + * + *

It extends Spring Security's core user details with additional user ID field + * while implementing all required authentication and authorization contract methods.

+ * + *

The class is immutable and thread-safe by design, with all fields being final.

+ * + * @author Your Name + * @version 1.0 + * @see org.springframework.security.core.userdetails.UserDetails + * @since 1.0 + */ public class CustomUserDetails implements UserDetails { private static final long serialVersionUID = 1L; + /** + * The unique identifier of the user in the system + */ private final Long userId; + + /** + * The username used to authenticate the user + */ private final String username; + + /** + * The encrypted password of the user + */ private final String password; + + /** + * Flag indicating whether the user is enabled + */ private final boolean enabled; + + /** + * Flag indicating whether the user's account is non-expired + */ private final boolean accountNonExpired; + + /** + * Flag indicating whether the user's account is non-locked + */ private final boolean accountNonLocked; + + /** + * Flag indicating whether the user's credentials are non-expired + */ private final boolean credentialsNonExpired; + + /** + * Collection of authorities (roles/permissions) granted to the user + */ private final Collection authorities; + /** + * Constructs a new CustomUserDetails with the specified parameters. + * + * @param userId the unique identifier of the user (cannot be null) + * @param username the username used for authentication (cannot be null) + * @param password the encrypted password (cannot be null) + * @param enabled whether the user is enabled + * @param accountNonExpired whether the account is non-expired + * @param accountNonLocked whether the account is non-locked + * @param credentialsNonExpired whether the credentials are non-expired + * @param authorities the collection of granted authorities (cannot be null) + * @throws NullPointerException if any of the non-null parameters are null + */ public CustomUserDetails(Long userId, String username, String password, boolean enabled, boolean accountNonExpired, boolean accountNonLocked, boolean credentialsNonExpired, @@ -32,45 +91,92 @@ public CustomUserDetails(Long userId, String username, String password, this.authorities = Objects.requireNonNull(authorities); } + /** + * Returns the unique identifier of the user. + * + * @return the user ID + */ public Long getUserId() { return userId; } + /** + * Returns the authorities granted to the user. + * + * @return a collection of granted authorities + */ @Override public Collection getAuthorities() { return authorities; } + /** + * Returns the password used to authenticate the user. + * + * @return the password + */ @Override public String getPassword() { return password; } + /** + * Returns the username used to authenticate the user. + * + * @return the username + */ @Override public String getUsername() { return username; } + /** + * Indicates whether the user's account has expired. + * + * @return true if the account is non-expired, false otherwise + */ @Override public boolean isAccountNonExpired() { return accountNonExpired; } + /** + * Indicates whether the user is locked or unlocked. + * + * @return true if the account is non-locked, false otherwise + */ @Override public boolean isAccountNonLocked() { return accountNonLocked; } + /** + * Indicates whether the user's credentials (password) have expired. + * + * @return true if the credentials are non-expired, false otherwise + */ @Override public boolean isCredentialsNonExpired() { return credentialsNonExpired; } + /** + * Indicates whether the user is enabled or disabled. + * + * @return true if the user is enabled, false otherwise + */ @Override public boolean isEnabled() { return enabled; } + /** + * Compares this CustomUserDetails with another object for equality. + * Two CustomUserDetails are considered equal if they have the same userId and username. + * + * @param o the object to compare with + * @return true if the objects are equal, false otherwise + */ @Override public boolean equals(Object o) { if (this == o) return true; @@ -80,6 +186,11 @@ public boolean equals(Object o) { Objects.equals(username, that.username); } + /** + * Returns a hash code value for this CustomUserDetails. + * + * @return a hash code value based on userId and username + */ @Override public int hashCode() { return Objects.hash(userId, username); From 912bdc1c19eb33a75cf6979483c59709c687cb74 Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 06:31:17 -0400 Subject: [PATCH 059/100] Documentation --- .../main/resources/templates/register.html | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/Sprint 2/prototype2/src/main/resources/templates/register.html b/Sprint 2/prototype2/src/main/resources/templates/register.html index f4e1ee768..f0f453f26 100644 --- a/Sprint 2/prototype2/src/main/resources/templates/register.html +++ b/Sprint 2/prototype2/src/main/resources/templates/register.html @@ -3,31 +3,69 @@ Register + +
+

Register

- +
+
+
+ +
+
+ +
+
+ +
+

Already have an account? Login here

From 428adb6804262c77112b982158152a3beb8cb408 Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 06:37:14 -0400 Subject: [PATCH 060/100] Documentation --- .../deliverable4/Deliverable4Application.java | 78 ++++++++++++++----- .../auth/CustomUserDetailsService.java | 44 +++++++++++ .../src/main/resources/templates/index.html | 36 +++++++-- 3 files changed, 133 insertions(+), 25 deletions(-) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Deliverable4Application.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Deliverable4Application.java index bfc32f45c..88cfb58b7 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Deliverable4Application.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Deliverable4Application.java @@ -13,10 +13,15 @@ *
  • Spring Boot auto-configuration
  • *
  • Component scanning within the base package and sub-packages
  • *
  • Externalized configuration through application.properties/yml
  • + *
  • Embedded server startup
  • * * - * @SpringBootApplication is a convenience annotation that combines: - * @Configuration, @EnableAutoConfiguration, and @ComponentScan + *

    The {@code @SpringBootApplication} annotation is a convenience annotation that combines: + *

      + *
    • {@code @Configuration} - Tags the class as a source of bean definitions
    • + *
    • {@code @EnableAutoConfiguration} - Enables Spring Boot's autoconfiguration
    • + *
    • {@code @ComponentScan} - Enables component scanning within the package
    • + *
    */ @SpringBootApplication public class Deliverable4Application { @@ -25,9 +30,20 @@ public class Deliverable4Application { * Main method that serves as the entry point for the Spring Boot application. *

    * Initializes the Spring application context and starts the embedded server. + * Performs the following operations: + *

      + *
    1. Creates a new SpringApplication instance
    2. + *
    3. Applies custom configuration
    4. + *
    5. Runs the application
    6. + *
    7. Logs startup information
    8. + *
    * - * @param args command line arguments passed to the application - * (can include Spring profile activation, property overrides, etc.) + * @param args command line arguments passed to the application. These can include: + *
      + *
    • Spring profile activation (--spring.profiles.active=dev)
    • + *
    • Property overrides (--server.port=9090)
    • + *
    • Other Spring Boot configuration options
    • + *
    */ public static void main(String[] args) { // Create and configure the Spring application @@ -44,36 +60,52 @@ public static void main(String[] args) { } /** - * Configures additional Spring application settings. + * Configures additional Spring application settings before startup. *

    - * Placeholder for custom application configuration that needs to execute - * before the application context is refreshed. + * This method provides a hook for custom application configuration that needs to execute + * before the application context is refreshed. Current implementation serves as a + * placeholder for potential customizations. * * @param application the SpringApplication instance being configured + * @see org.springframework.boot.SpringApplication + * + *

    Example customizations that could be added:

    + *
    {@code
    +	 * // Disable Spring banner
    +	 * application.setBannerMode(Banner.Mode.OFF);
    +	 *
    +	 * // Set additional profiles
    +	 * application.setAdditionalProfiles("dev");
    +	 *
    +	 * // Disable startup info logging
    +	 * application.setLogStartupInfo(false);
    +	 * }
    */ private static void configureApplication(SpringApplication application) { - // Example custom configurations: - // application.setBannerMode(Banner.Mode.OFF); - // application.setAdditionalProfiles("dev"); - // application.setLogStartupInfo(false); + // Configuration placeholder - see method documentation for examples } /** - * Logs application startup information including: + * Logs comprehensive application startup information including: *
      - *
    • Access URLs
    • + *
    • Application name
    • + *
    • Access URLs (local and external)
    • *
    • Active profiles
    • *
    • Protocol (HTTP/HTTPS)
    • *
    * * @param env the Spring Environment containing configuration properties + * @see org.springframework.core.env.Environment + * + *

    The method detects SSL configuration to determine the protocol + * and formats a visual startup banner with key information.

    */ private static void logApplicationStartup(Environment env) { - // Determine protocol (HTTP/HTTPS) + // Determine protocol (HTTP/HTTPS) based on SSL configuration String protocol = env.getProperty("server.ssl.key-store") != null ? "https" : "http"; - // Get server configuration - String serverPort = env.getProperty("server.port", "8080"); // Default to 8080 if not set + // Get server configuration with defaults + String serverPort = env.getProperty("server.port", "8080"); String contextPath = env.getProperty("server.servlet.context-path", ""); String appName = env.getProperty("spring.application.name", "application"); @@ -99,13 +131,19 @@ private static void logApplicationStartup(Environment env) { /** * Gets the host address for external access display. *

    - * In a real production environment, this would get the actual host IP. + * Currently returns "localhost" but in a production environment could be extended to: + *

      + *
    • Detect actual host IP address
    • + *
    • Handle network interface enumeration
    • + *
    • Support containerized environments
    • + *
    + * + * @return the host address string, currently hardcoded to "localhost" * - * @return the host address string + * @implNote For production use, consider implementing with: + * {@code InetAddress.getLocalHost().getHostAddress()} */ private static String getHostAddress() { - // In production, you might use: - // return InetAddress.getLocalHost().getHostAddress(); return "localhost"; } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java index 3b3fd983b..758610b9b 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetailsService.java @@ -14,19 +14,63 @@ import java.util.Set; import java.util.stream.Collectors; +/** + * Custom implementation of Spring Security's {@link UserDetailsService}. + *

    + * This service is responsible for loading user-specific data during authentication. + * It bridges the application's {@link UserModel} with Spring Security's authentication framework. + * + *

    Key responsibilities include: + *

      + *
    • Loading user details by username or email
    • + *
    • Converting application roles to Spring Security authorities
    • + *
    • Handling user not found scenarios
    • + *
    • Providing transactional access to user data
    • + *
    + * + * @Service Marks this class as a Spring service component + * @RequiredArgsConstructor Generates constructor for final fields (Dependency Injection) + * @see UserDetailsService + * @see UserDetails + * @see UserModel + */ @Service @RequiredArgsConstructor public class CustomUserDetailsService implements UserDetailsService { + /** + * Repository for accessing user data. + * Injected automatically by Spring via constructor. + */ private final UserRepository userRepository; + /** + * Loads user details by username or email. + *

    + * This is the core method of the UserDetailsService interface. It: + *

      + *
    1. Attempts to find the user by username or email
    2. + *
    3. Throws UsernameNotFoundException if user not found
    4. + *
    5. Converts the user's authorities to Spring Security GrantedAuthority objects
    6. + *
    7. Constructs a CustomUserDetails object with all required authentication information
    8. + *
    + * + * @param usernameOrEmail the username or email address to search for + * @return UserDetails implementation containing the user's authentication information + * @throws UsernameNotFoundException if no user is found with the given username/email + * @implNote The method is transactional with readOnly=true since it only reads data + * @see CustomUserDetails + * @see Transactional + */ @Override @Transactional(readOnly = true) public UserDetails loadUserByUsername(String usernameOrEmail) throws UsernameNotFoundException { + // Find user with their authorities in a single query UserModel user = userRepository.findByUsernameOrEmailWithAuthorities(usernameOrEmail) .orElseThrow(() -> new UsernameNotFoundException( "User not found with username or email: " + usernameOrEmail)); + // Convert UserModel to Spring Security's UserDetails implementation return new CustomUserDetails( user.getId(), user.getUsername(), diff --git a/Sprint 2/prototype2/src/main/resources/templates/index.html b/Sprint 2/prototype2/src/main/resources/templates/index.html index c35664607..05f230b10 100644 --- a/Sprint 2/prototype2/src/main/resources/templates/index.html +++ b/Sprint 2/prototype2/src/main/resources/templates/index.html @@ -1,49 +1,68 @@ + + + + Welcome to Our App + + + + + + +
    +
    +

    Welcome to Our Platform

    Manage your account and access premium features

    +
    - + Dashboard - + Register - + Login - +
    +
    +
    +

    Features

    @@ -64,10 +85,13 @@

    Features

    + +

    Get Started

    Join our platform today to access all features.

    + Create Account @@ -79,11 +103,13 @@

    Get Started

    +
    + - + \ No newline at end of file From ee50c314e6d15d85fb198d511ab676bfc3709f9b Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 12:06:29 -0400 Subject: [PATCH 061/100] Additional testing --- Sprint 2/prototype2/pom.xml | 11 +- .../deliverable4/config/SecurityConfig.java | 186 +------------ .../config/TestSecurityConfig.java | 27 ++ .../resources/application-test.properties | 16 +- .../src/main/resources/templates/index.html | 81 +++--- .../com/jydoc/deliverable4/IndexPageTest.java | 251 ++++++++++++++++++ 6 files changed, 348 insertions(+), 224 deletions(-) create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/TestSecurityConfig.java create mode 100644 Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/IndexPageTest.java diff --git a/Sprint 2/prototype2/pom.xml b/Sprint 2/prototype2/pom.xml index 52710c21b..9e71cd761 100644 --- a/Sprint 2/prototype2/pom.xml +++ b/Sprint 2/prototype2/pom.xml @@ -102,7 +102,11 @@ org.springframework.boot spring-boot-starter-data-jpa - + + org.springframework.boot + spring-boot-test-autoconfigure + test + jakarta.validation jakarta.validation-api @@ -140,6 +144,7 @@ jakarta.el 3.0.4 + com.h2database h2 @@ -149,6 +154,10 @@ com.h2database h2 + + org.springframework.boot + spring-boot-test + diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java index 108c10321..5081e314b 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java @@ -12,52 +12,14 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.csrf.CookieCsrfTokenRepository; +import org.springframework.security.web.header.writers.XXssProtectionHeaderWriter; import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession; -/** - * Central security configuration class that defines the application's security policies. - *

    - * This configuration class is responsible for: - *

      - *
    • Authentication and authorization rules
    • - *
    • CSRF protection configuration
    • - *
    • Session management policies
    • - *
    • Security headers configuration
    • - *
    • Password encoding strategy
    • - *
    • Exception handling for security scenarios
    • - *
    - *

    - * - *

    Security Features:

    - *
      - *
    • Form-based authentication with custom login/logout pages
    • - *
    • Role-based authorization (USER and ADMIN)
    • - *
    • CSRF protection with cookie-based token storage (disabled for API endpoints)
    • - *
    • JDBC-based session management with concurrency control
    • - *
    • BCrypt password hashing with strength 10
    • - *
    • Secure HTTP headers configuration (HSTS, frame options)
    • - *
    - * - * @see org.springframework.security.config.annotation.web.configuration.EnableWebSecurity - * @see org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession - */ @Configuration @EnableWebSecurity @EnableJdbcHttpSession public class SecurityConfig { - /** - * Endpoints that are accessible without authentication. - *

    - * Includes: - *

      - *
    • Public pages (home, login, register)
    • - *
    • Static resources (CSS, JS, images)
    • - *
    • Error pages
    • - *
    • Public API endpoints
    • - *
    • WebJars resources
    • - *
    - */ private static final String[] PUBLIC_ENDPOINTS = { "/", "/home", @@ -73,34 +35,10 @@ public class SecurityConfig { private final CustomUserDetailsService userDetailsService; - /** - * Constructs a new SecurityConfig with required dependencies. - * - * @param userDetailsService the custom user details service implementation - * that loads user-specific data. Must not be null. - */ public SecurityConfig(CustomUserDetailsService userDetailsService) { this.userDetailsService = userDetailsService; } - /** - * Defines the security filter chain that applies all security configurations. - *

    - * Configures: - *

      - *
    • CSRF protection
    • - *
    • Security headers
    • - *
    • Authorization rules
    • - *
    • Form-based authentication
    • - *
    • Logout behavior
    • - *
    • Session management
    • - *
    • Exception handling
    • - *
    - * - * @param http the HttpSecurity object to configure - * @return the configured SecurityFilterChain - * @throws Exception if configuration fails - */ @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { configureCsrfProtection(http); @@ -114,19 +52,6 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti return http.build(); } - /** - * Configures CSRF protection with cookie-based token storage. - *

    - * Features: - *

      - *
    • CSRF protection enabled by default
    • - *
    • Disabled for API endpoints (/api/**)
    • - *
    • Token stored in a cookie with HttpOnly=false to allow JavaScript access
    • - *
    - * - * @param http the HttpSecurity object to configure - * @throws Exception if configuration fails - */ private void configureCsrfProtection(HttpSecurity http) throws Exception { http.csrf(csrf -> csrf .ignoringRequestMatchers("/api/**") @@ -134,43 +59,20 @@ private void configureCsrfProtection(HttpSecurity http) throws Exception { ); } - /** - * Configures security-related HTTP headers. - *

    - * Sets: - *

      - *
    • Frame options to SAMEORIGIN
    • - *
    • HTTP Strict Transport Security (HSTS) with 1-year max age and subdomain inclusion
    • - *
    - * - * @param http the HttpSecurity object to configure - * @throws Exception if configuration fails - */ private void configureSecurityHeaders(HttpSecurity http) throws Exception { http.headers(headers -> headers - .frameOptions(frame -> frame.sameOrigin()) - .httpStrictTransportSecurity(hsts -> hsts - .includeSubDomains(true) - .maxAgeInSeconds(31536000) + .xssProtection(xss -> xss + .headerValue(XXssProtectionHeaderWriter.HeaderValue.ENABLED_MODE_BLOCK) ) - ); + .contentSecurityPolicy(csp -> csp + .policyDirectives("default-src 'self'; script-src 'self' 'unsafe-inline' cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' cdn.jsdelivr.net; img-src 'self' data:") + ) + .frameOptions(frame -> frame.deny()) + .contentTypeOptions(contentType -> { + }) + ); } - /** - * Configures authorization rules for application endpoints. - *

    - * Rules: - *

      - *
    • Public endpoints accessible to all
    • - *
    • /dashboard requires authentication
    • - *
    • /user/** endpoints require ROLE_USER authority
    • - *
    • /admin/** endpoints require ROLE_ADMIN authority
    • - *
    • All other endpoints require authentication
    • - *
    - * - * @param http the HttpSecurity object to configure - * @throws Exception if configuration fails - */ private void configureAuthorization(HttpSecurity http) throws Exception { http.authorizeHttpRequests(auth -> auth .requestMatchers(PUBLIC_ENDPOINTS).permitAll() @@ -181,21 +83,6 @@ private void configureAuthorization(HttpSecurity http) throws Exception { ); } - /** - * Configures form-based authentication with custom settings. - *

    - * Configuration includes: - *

      - *
    • Custom login page at /login
    • - *
    • Login processing URL at /perform_login
    • - *
    • Default success URL to /dashboard
    • - *
    • Failure URL to /login with error parameter
    • - *
    • Custom username and password parameter names
    • - *
    - * - * @param http the HttpSecurity object to configure - * @throws Exception if configuration fails - */ private void configureFormBasedAuthentication(HttpSecurity http) throws Exception { http.formLogin(form -> form .loginPage("/login") @@ -208,21 +95,6 @@ private void configureFormBasedAuthentication(HttpSecurity http) throws Exceptio ); } - /** - * Configures logout behavior with security considerations. - *

    - * Features: - *

      - *
    • Logout URL at /perform_logout
    • - *
    • Redirect to login page with logout parameter
    • - *
    • Session invalidation
    • - *
    • Cookie cleanup (JSESSIONID, XSRF-TOKEN)
    • - *
    • Authentication clearing
    • - *
    - * - * @param http the HttpSecurity object to configure - * @throws Exception if configuration fails - */ private void configureLogout(HttpSecurity http) throws Exception { http.logout(logout -> logout .logoutUrl("/perform_logout") @@ -234,20 +106,6 @@ private void configureLogout(HttpSecurity http) throws Exception { ); } - /** - * Configures session management policies. - *

    - * Settings: - *

      - *
    • Session creation policy: IF_REQUIRED
    • - *
    • Invalid session redirect URL
    • - *
    • Maximum sessions: 1 per user
    • - *
    • Session expired redirect URL
    • - *
    - * - * @param http the HttpSecurity object to configure - * @throws Exception if configuration fails - */ private void configureSessionManagement(HttpSecurity http) throws Exception { http.sessionManagement(session -> session .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) @@ -258,42 +116,18 @@ private void configureSessionManagement(HttpSecurity http) throws Exception { ); } - /** - * Configures exception handling for security scenarios. - *

    - * Redirects to /access-denied when access is denied. - * - * @param http the HttpSecurity object to configure - * @throws Exception if configuration fails - */ private void configureExceptionHandling(HttpSecurity http) throws Exception { http.exceptionHandling(exceptions -> exceptions .accessDeniedPage("/access-denied") ); } - /** - * Provides the AuthenticationManager bean for authentication processing. - * - * @param authenticationConfiguration the authentication configuration - * @return configured AuthenticationManager - * @throws Exception if configuration fails - * @see org.springframework.security.authentication.AuthenticationManager - */ @Bean public AuthenticationManager authenticationManager( AuthenticationConfiguration authenticationConfiguration) throws Exception { return authenticationConfiguration.getAuthenticationManager(); } - /** - * Provides the password encoder bean using BCrypt hashing. - *

    - * Uses BCrypt with strength 10 (2^10 iterations) for password hashing. - * - * @return BCryptPasswordEncoder instance - * @see org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder - */ @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/TestSecurityConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/TestSecurityConfig.java new file mode 100644 index 000000000..50ce575c1 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/TestSecurityConfig.java @@ -0,0 +1,27 @@ +package com.jydoc.deliverable4.config; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Profile; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.web.SecurityFilterChain; + +@TestConfiguration +@EnableWebSecurity +@Profile("test") +public class TestSecurityConfig { + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http + .csrf(csrf -> csrf.disable()) + .authorizeHttpRequests(auth -> auth + .anyRequest().permitAll() + ) + .headers(headers -> headers + .frameOptions(frame -> frame.disable()) + ); + return http.build(); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/application-test.properties b/Sprint 2/prototype2/src/main/resources/application-test.properties index 34be3ec30..e4c29e99f 100644 --- a/Sprint 2/prototype2/src/main/resources/application-test.properties +++ b/Sprint 2/prototype2/src/main/resources/application-test.properties @@ -2,6 +2,12 @@ # Test Metadata # ====================== spring.application.name=prototype2-test +spring.main.allow-bean-definition-overriding=true +# ====================== +# Security Test Configuration +# ====================== +# Disable security auto-configuration for tests +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration # ====================== # Test Database Configuration (H2) @@ -23,11 +29,12 @@ spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true spring.sql.init.enabled=false +spring.jpa.defer-datasource-initialization=true # ====================== # Test Session Management # ====================== -spring.session.store-type=jdbc +spring.session.store-type=none spring.session.jdbc.initialize-schema=always spring.session.jdbc.table-name=SPRING_SESSION server.servlet.session.timeout=1m @@ -42,4 +49,9 @@ logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE logging.level.org.springframework.jdbc.core=DEBUG # Disable banner for cleaner test output -spring.main.banner-mode=off \ No newline at end of file +spring.main.banner-mode=off +# Enable H2 console for test debugging +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console + + diff --git a/Sprint 2/prototype2/src/main/resources/templates/index.html b/Sprint 2/prototype2/src/main/resources/templates/index.html index 05f230b10..9f8431a98 100644 --- a/Sprint 2/prototype2/src/main/resources/templates/index.html +++ b/Sprint 2/prototype2/src/main/resources/templates/index.html @@ -1,101 +1,97 @@ - - - - - - + + Welcome to Our App - - - - - - + + + - -

    -
    -

    Welcome to Our Platform

    Manage your account and access premium features

    -
    -
    -

    Features

      -
    • Secure authentication
    • -
    • User dashboard
    • -
    • Responsive design
    • +
    • Secure + authentication +
    • +
    • User + dashboard +
    • +
    • + Responsive design +
    -

    Get Started

    Join our platform today to access all features.

    - - + Create Account - + Go to Dashboard
    @@ -103,13 +99,8 @@

    Get Started

    -
    - - - - \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/IndexPageTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/IndexPageTest.java new file mode 100644 index 000000000..77f232b3c --- /dev/null +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/IndexPageTest.java @@ -0,0 +1,251 @@ +package com.jydoc.deliverable4; + +import com.jydoc.deliverable4.config.TestSecurityConfig; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Import; +import org.springframework.security.test.context.support.WithAnonymousUser; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import static org.hamcrest.Matchers.*; +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@SpringBootTest( + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = { + "spring.main.allow-bean-definition-overriding=true", + "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration" + } +) + + +@AutoConfigureMockMvc +@ActiveProfiles("test") +@Import(TestSecurityConfig.class) +public class IndexPageTest { + + @Autowired + private WebApplicationContext context; + + @Autowired + private MockMvc mockMvc; + + @BeforeEach + public void setup() { + mockMvc = MockMvcBuilders + .webAppContextSetup(context) + .apply(springSecurity()) + .alwaysDo(print()) + .build(); + } + + @Test + public void testIndexPageLoadsSuccessfully() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(view().name("index")) + .andExpect(content().string(containsString("Welcome to Our Platform"))); + } + + + // ============ CORE PAGE STRUCTURE TESTS ============ + @Test + public void testPageMetadata() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(view().name("index")) + .andExpect(xpath("//meta[@charset='UTF-8']").exists()) + .andExpect(xpath("//meta[@name='viewport']").exists()) + .andExpect(xpath("//meta[@name='viewport'][@content='width=device-width, initial-scale=1.0']").exists()) + .andExpect(xpath("//title").string("Welcome to Our App")); + } + + @Test + public void testCSSResources() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + // Test for regular href attributes instead of th:href + .andExpect(xpath("//link[@rel='stylesheet' and contains(@href,'styles.css')]").exists()) + .andExpect(xpath("//link[@rel='stylesheet' and contains(@href,'bootstrap.min.css')]").exists()); + } + + @Test + public void testJSResources() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(xpath("//script[contains(@src,'bootstrap.bundle.min.js')]").exists()); + } + + @Test + public void testIconResources() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(xpath("//link[@rel='stylesheet'][contains(@href,'bootstrap-icons.css')]").exists()); + } + + // ============ HEADER/FOOTER TESTS ============ + @Test + public void testHeaderFragmentInclusion() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + // Check for any recognizable header element + .andExpect(xpath("//header | //*[contains(@class,'header') or contains(@class,'navbar') or contains(@class,'navigation')]").exists()) + + // Check for any interactive element + .andExpect(xpath("//header//*[@href or @onclick or @role='button'] | " + + "//*[contains(@class,'header')]//*[@href or @onclick or @role='button'] | " + + "//*[contains(@class,'navbar')]//*[@href or @onclick or @role='button']").exists()); + } + + @Test + public void testFooterFragmentInclusion() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + // Check for any footer container + .andExpect(xpath("//*[contains(@class,'footer') or local-name()='footer']").exists()) + // Check for any copyright text (more flexible matching) + .andExpect(xpath("//*[contains(@class,'footer') or local-name()='footer']" + + "//*[contains(translate(., '©', ''), 'Copyright') or " + + "contains(., 'All rights reserved')]").exists()); + } + + + // ============ HERO SECTION TESTS ============ + @Test + public void testHeroSectionStructure() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(xpath("//div[contains(@class,'bg-white') and contains(@class,'rounded-3')]").exists()) + .andExpect(xpath("//h1[contains(@class,'display-5') and contains(text(),'Welcome to Our Platform')]").exists()) + .andExpect(xpath("//p[contains(@class,'fs-4') and contains(text(),'Manage your account')]").exists()); + } + + // ============ AUTHENTICATION-AWARE ELEMENT TESTS ============ + @Test + @WithAnonymousUser + public void testAnonymousUserElements() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + // Should be visible + .andExpect(xpath("//a[contains(@href,'/register') and contains(@class,'btn-success')]").exists()) + .andExpect(xpath("//a[contains(@href,'/login') and contains(@class,'btn-outline-secondary')]").exists()) + .andExpect(xpath("//a[contains(@href,'/register') and contains(text(),'Create Account')]").exists()) + // Should be hidden + .andExpect(xpath("//a[contains(@href,'/dashboard')]").doesNotExist()) + .andExpect(xpath("//form[contains(@action,'/logout')]").doesNotExist()) + .andExpect(xpath("//a[contains(text(),'Go to Dashboard')]").doesNotExist()); + } + + @Test + @WithMockUser + public void testAuthenticatedUserElements() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + // Should be visible for authenticated users + .andExpect(xpath("//a[contains(@href,'/dashboard') and contains(@class,'btn-primary')]").exists()) + .andExpect(xpath("//form[contains(@action,'/logout')]").exists()) + .andExpect(xpath("//button[contains(@class,'btn-danger') and contains(.,'Logout')]").exists()) // Changed text() to . + .andExpect(xpath("//a[contains(.,'Go to Dashboard')]").exists()) // Changed text() to . + // Should be hidden for authenticated users + .andExpect(xpath("//a[contains(@href,'/register') and contains(@class,'btn-success')]").doesNotExist()) + .andExpect(xpath("//a[contains(@href,'/login')]").doesNotExist()) + .andExpect(xpath("//a[contains(.,'Create Account')]").doesNotExist()); + } + + @Test + @WithMockUser + public void testLogoutFormCSRF() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(xpath("//form[@action='/logout']/input[@type='hidden'][@name='_csrf']").exists()); + } + + // ============ FEATURE CARDS TESTS ============ + @Test + public void testFeatureCardsStructure() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(xpath("//div[contains(@class,'row') and contains(@class,'g-4')]").exists()) + // Only count col-md-6 divs within the features row + .andExpect(xpath("//div[contains(@class,'row') and contains(@class,'g-4')]/div[contains(@class,'col-md-6')]").nodeCount(2)); + } + + @ParameterizedTest + @ValueSource(strings = { + "Secure authentication", + "User dashboard", + "Responsive design" + }) + public void testFeatureListItems(String feature) throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(xpath(String.format("//li[contains(text(),'%s')]", feature)).exists()); + } + + @Test + public void testFeatureIcons() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(xpath("//i[contains(@class,'bi-check-circle-fill')]").nodeCount(3)); + } + + // ============ RESPONSIVE DESIGN TESTS ============ + @Test + public void testResponsiveClasses() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(xpath("//main[contains(@class,'container')]").exists()) + .andExpect(xpath("//div[contains(@class,'col-md-6')]").exists()) + .andExpect(xpath("//div[contains(@class,'d-sm-flex')]").exists()); + } + + // ============ ACCESSIBILITY TESTS ============ + @Test + public void testButtonAriaAttributes() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(xpath("//a[contains(@class,'btn') and not(@aria-label)]").doesNotExist()) + .andExpect(xpath("//button[not(@aria-label)]").doesNotExist()); + } + + @Test + public void testImagesHaveAltText() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(xpath("//img[not(@alt)]").doesNotExist()); + } + + // ============ SECURITY TESTS ============ + @Test + public void testSecurityHeaders() throws Exception { + mockMvc.perform(get("/")) + .andExpect(status().isOk()) + .andExpect(header().string("X-Content-Type-Options", "nosniff")) + .andExpect(header().string("X-Frame-Options", "DENY")) + .andExpect(header().string("X-XSS-Protection", "1; mode=block")); + } + + // ============ PERFORMANCE TESTS ============ + @Test + public void testPageLoadTime() throws Exception { + long startTime = System.currentTimeMillis(); + mockMvc.perform(get("/")).andExpect(status().isOk()); + long endTime = System.currentTimeMillis(); + long duration = endTime - startTime; + + // Fail if page takes more than 2 seconds to load + assert (duration < 2000) : "Page load time too slow: " + duration + "ms"; + } +} \ No newline at end of file From cb903c5dc7fe0e90607f6e1d03714dff2784206b Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 13:07:28 -0400 Subject: [PATCH 062/100] Admin dashboard --- .../deliverable4/Service/UserService.java | 73 +++++++++ .../controllers/AdminController.java | 94 +++++++++++ .../repositories/UserRepository.java | 27 +++ .../Exceptions/UserNotFoundException.java | 17 ++ .../src/main/resources/application.properties | 3 + .../resources/templates/admin/dashboard.html | 154 ++++++++++++++++++ .../templates/fragments/admin-footer.html | 12 ++ .../templates/fragments/admin-header.html | 13 ++ .../src/main/resources/templates/index.html | 19 ++- .../com/jydoc/deliverable4/IndexPageTest.java | 2 +- 10 files changed, 405 insertions(+), 9 deletions(-) create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java create mode 100644 Sprint 2/prototype2/src/main/resources/templates/admin/dashboard.html create mode 100644 Sprint 2/prototype2/src/main/resources/templates/fragments/admin-footer.html create mode 100644 Sprint 2/prototype2/src/main/resources/templates/fragments/admin-header.html diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java index 0c5dedca2..007eb79fc 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java @@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; +import java.util.List; import java.util.Optional; /** @@ -253,6 +254,78 @@ public Optional findActiveUser(String usernameOrEmail) { .filter(UserModel::isEnabled); } + /** + * Gets the total count of users in the system + * + * @return total user count + */ + @Transactional(readOnly = true) + public long getUserCount() { + return userRepository.count(); + } + +// /** TODO:Implement this +// * Gets a list of recently created users +// * @param limit maximum number of users to return +// * @return list of recent users ordered by creation date +// */ +// @Transactional(readOnly = true) +// public List getRecentUsers(int limit) { +// return userRepository.findTopNByOrderByCreatedDateDesc(limit); +// } + + /** + * Checks if a user exists with the given ID + * + * @param id the user ID to check + * @return true if user exists, false otherwise + */ + @Transactional(readOnly = true) + public boolean existsById(Long id) { + return userRepository.existsById(id); + } + + /** + * Gets all users in the system + * + * @return list of all users + */ + @Transactional(readOnly = true) + public List getAllUsers() { + return userRepository.findAll(); + } + + /** + * Finds a user by ID + * + * @param id user ID + * @return Optional containing the user if found + */ + @Transactional(readOnly = true) + public Optional getUserById(Long id) { + return userRepository.findById(id); + } + + /** + * Updates a user's information + * + * @param user the user with updated information + */ + @Transactional + public void updateUser(UserModel user) { + userRepository.save(user); + } + + /** + * Deletes a user by ID + * + * @param id the ID of the user to delete + */ + @Transactional + public void deleteUser(Long id) { + userRepository.deleteById(id); + } + // ---------------------- Custom Exceptions ---------------------- /** diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java new file mode 100644 index 000000000..140404aff --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java @@ -0,0 +1,94 @@ +package com.jydoc.deliverable4.controllers; + +import com.jydoc.deliverable4.model.UserModel; +import com.jydoc.deliverable4.Service.UserService; +import com.jydoc.deliverable4.exceptions.UserNotFoundException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; + +import javax.validation.Valid; +import java.util.List; + +@Controller +@RequestMapping("/admin") +@PreAuthorize("hasRole('ROLE_ADMIN')") +public class AdminController { + + private static final String USERS_REDIRECT = "redirect:/admin/users"; + private static final String USER_ATTR = "user"; + private static final String ERROR_ATTR = "error"; + private static final String MESSAGE_ATTR = "message"; + + private final UserService userService; + + @Autowired + public AdminController(UserService userService) { + this.userService = userService; + } + + + @GetMapping("/dashboard") + public String adminDashboard(Model model) { + model.addAttribute("userCount", userService.getUserCount()); + + return "admin/dashboard"; + } + + @GetMapping("/users") + public String userManagement(Model model) { + List users = userService.getAllUsers(); + model.addAttribute("users", users); + return "admin/users/list"; + } + + @GetMapping("/users/edit/{id}") + public String editUserForm(@PathVariable Long id, Model model) { + UserModel user = userService.getUserById(id) + .orElseThrow(() -> new UserNotFoundException(id)); + model.addAttribute(USER_ATTR, user); + return "admin/users/edit"; + } + + @PostMapping("/users/update") + public String updateUser(@Valid @ModelAttribute(USER_ATTR) UserModel user, + BindingResult result, + RedirectAttributes redirectAttributes) { + if (result.hasErrors()) { + return "admin/users/edit"; + } + userService.updateUser(user); + redirectAttributes.addFlashAttribute(MESSAGE_ATTR, "User updated successfully"); + return USERS_REDIRECT; + } + + @PostMapping("/users/delete/{id}") + public String deleteUser(@PathVariable Long id, RedirectAttributes redirectAttributes) { + if (!userService.existsById(id)) { + throw new UserNotFoundException(id); + } + userService.deleteUser(id); + redirectAttributes.addFlashAttribute("message", "User deleted successfully"); + return "redirect:/admin/users"; + } + + @ExceptionHandler(UserNotFoundException.class) + public String handleUserNotFound(UserNotFoundException ex, Model model) { + model.addAttribute(ERROR_ATTR, ex.getMessage()); + return "error/user-not-found"; + } + + @GetMapping("/settings") + public String systemSettings(Model model) { + return "admin/settings"; + } + + @GetMapping("/activity-logs") + public String viewActivityLogs(Model model) { + return "admin/activity-logs"; + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserRepository.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserRepository.java index 3dd557156..fbb20e295 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserRepository.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/repositories/UserRepository.java @@ -4,13 +4,16 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; /** * Repository for {@link UserModel} entities providing user lookup operations. * Includes methods for finding users with different loading strategies for authorities. */ +@Repository public interface UserRepository extends JpaRepository { // Basic user lookups @@ -42,4 +45,28 @@ public interface UserRepository extends JpaRepository { @Query("SELECT DISTINCT u FROM UserModel u LEFT JOIN FETCH u.authorities " + "WHERE u.username = :credential OR u.email = :credential") Optional findByUsernameOrEmailWithAuthorities(@Param("credential") String credential); + +// /** TODO: Implement this +// * Finds the most recent users ordered by creation date. +// * @param limit maximum number of users to return +// * @return list of recent users +// */ +// @Query("SELECT u FROM UserModel u ORDER BY u.createdDate DESC LIMIT :limit") +// List findTopNByOrderByCreatedDateDesc(@Param("limit") int limit); + + /** + * Finds all users with their authorities eagerly loaded. + * + * @return list of all users with authorities + */ + @Query("SELECT DISTINCT u FROM UserModel u LEFT JOIN FETCH u.authorities") + List findAllWithAuthorities(); + + /** + * Checks if a user exists by ID. + * + * @param id the user ID to check + * @return true if user exists, false otherwise + */ + boolean existsById(Long id); } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java new file mode 100644 index 000000000..c970af643 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java @@ -0,0 +1,17 @@ +package com.jydoc.deliverable4.exceptions; + +/** + * Exception thrown when a user cannot be found in the system. + */ +public class UserNotFoundException extends RuntimeException { + private final Long userId; + + public UserNotFoundException(Long userId) { + super("User not found with ID: " + userId); + this.userId = userId; + } + + public Long getUserId() { + return userId; + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/application.properties b/Sprint 2/prototype2/src/main/resources/application.properties index edf6c4f7a..ced8be571 100644 --- a/Sprint 2/prototype2/src/main/resources/application.properties +++ b/Sprint 2/prototype2/src/main/resources/application.properties @@ -49,6 +49,9 @@ logging.level.org.springframework.security=DEBUG logging.level.org.hibernate.SQL=DEBUG logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE logging.level.org.springframework.jdbc.core=DEBUG +#Thymeleaf +spring.thymeleaf.prefix=classpath:/templates/ +spring.thymeleaf.suffix=.html # ====================== # Profile-specific Notes diff --git a/Sprint 2/prototype2/src/main/resources/templates/admin/dashboard.html b/Sprint 2/prototype2/src/main/resources/templates/admin/dashboard.html new file mode 100644 index 000000000..74fa99c2d --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/admin/dashboard.html @@ -0,0 +1,154 @@ + + + + + + Admin Dashboard | System Control Panel + + + + + + + + + + + + +
    + +
    + + + + +
    + + + + +
    +
    +
    +
    +
    +
    +
    Total Users
    +

    0

    +
    +
    + +
    +
    +
    +
    +
    +
    + User statistics +
    +
    +
    +
    + + +
    + + +
    +
    +
    Recent Users
    +
    +
    +
    + + + + + + + + + + + + + + + + + +
    UsernameEmailRegisteredActions
    adminadmin@example.com2023-01-01 + + View + +
    +
    +
    +
    +
    +
    + + +
    + + + + + + + + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/fragments/admin-footer.html b/Sprint 2/prototype2/src/main/resources/templates/fragments/admin-footer.html new file mode 100644 index 000000000..ceffd7f54 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/fragments/admin-footer.html @@ -0,0 +1,12 @@ + + + +
    +
    +
    + Admin Panel Footer +
    +
    +
    + + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/fragments/admin-header.html b/Sprint 2/prototype2/src/main/resources/templates/fragments/admin-header.html new file mode 100644 index 000000000..964f17fcf --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/fragments/admin-header.html @@ -0,0 +1,13 @@ + + + +
    + +
    + + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/index.html b/Sprint 2/prototype2/src/main/resources/templates/index.html index 9f8431a98..2f9d79229 100644 --- a/Sprint 2/prototype2/src/main/resources/templates/index.html +++ b/Sprint 2/prototype2/src/main/resources/templates/index.html @@ -63,16 +63,19 @@

    Welcome to Our Platform

    -

    Features

    -
      -
    • Secure - authentication +

      Features

      +
        +
      • + + Secure authentication
      • -
      • User - dashboard +
      • + + User dashboard
      • -
      • - Responsive design +
      • + + Responsive design
    diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/IndexPageTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/IndexPageTest.java index 77f232b3c..84ddcc81b 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/IndexPageTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/IndexPageTest.java @@ -191,7 +191,7 @@ public void testFeatureCardsStructure() throws Exception { public void testFeatureListItems(String feature) throws Exception { mockMvc.perform(get("/")) .andExpect(status().isOk()) - .andExpect(xpath(String.format("//li[contains(text(),'%s')]", feature)).exists()); + .andExpect(xpath("//li[contains(., '" + feature + "')]").exists()); } @Test From 1e56c5662184592565d316dae66974014a75a7c3 Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 13:08:00 -0400 Subject: [PATCH 063/100] Bug fix --- .../deliverable4/security/Exceptions/UserNotFoundException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java index c970af643..46eedd8f2 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java @@ -1,4 +1,4 @@ -package com.jydoc.deliverable4.exceptions; +package com.jydoc.deliverable4.security.Exceptions; /** * Exception thrown when a user cannot be found in the system. From 0acb07a79751f289d20ff4f2f2b06c88fbb3ee9a Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 13:11:25 -0400 Subject: [PATCH 064/100] Bug fix --- .../deliverable4/controllers/AdminController.java | 2 +- .../security/Exceptions/UserNotFoundException.java | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java index 140404aff..d6444fdbb 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java @@ -2,7 +2,7 @@ import com.jydoc.deliverable4.model.UserModel; import com.jydoc.deliverable4.Service.UserService; -import com.jydoc.deliverable4.exceptions.UserNotFoundException; +import com.jydoc.deliverable4.security.Exceptions.UserNotFoundException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java index 46eedd8f2..acae398c8 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java @@ -1,17 +1,7 @@ package com.jydoc.deliverable4.security.Exceptions; -/** - * Exception thrown when a user cannot be found in the system. - */ public class UserNotFoundException extends RuntimeException { - private final Long userId; - - public UserNotFoundException(Long userId) { - super("User not found with ID: " + userId); - this.userId = userId; - } - - public Long getUserId() { - return userId; + public UserNotFoundException(Long id) { + super("Could not find user with id: " + id); } } \ No newline at end of file From bcfcc7c9a760b6ec0a82af2629468937f09927f1 Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 13:53:11 -0400 Subject: [PATCH 065/100] Bug fix --- .../controllers/AdminController.java | 100 +++++++++++++++--- 1 file changed, 87 insertions(+), 13 deletions(-) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java index d6444fdbb..6041bfff3 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java @@ -14,81 +14,155 @@ import javax.validation.Valid; import java.util.List; +/** + * Controller for handling administrative operations. + * Provides endpoints for user management, system settings, and activity logs. + * Requires ADMIN role for all operations. + */ @Controller @RequestMapping("/admin") @PreAuthorize("hasRole('ROLE_ADMIN')") public class AdminController { + // Constants for view names and attribute keys private static final String USERS_REDIRECT = "redirect:/admin/users"; private static final String USER_ATTR = "user"; private static final String ERROR_ATTR = "error"; private static final String MESSAGE_ATTR = "message"; + private static final String USERS_ATTR = "users"; + private static final String USER_COUNT_ATTR = "userCount"; + + // View paths + private static final String DASHBOARD_VIEW = "admin/dashboard"; + private static final String USER_LIST_VIEW = "admin/users/list"; + private static final String USER_EDIT_VIEW = "admin/users/edit"; + private static final String SETTINGS_VIEW = "admin/settings"; + private static final String ACTIVITY_LOGS_VIEW = "admin/activity-logs"; + private static final String ERROR_VIEW = "error/user-not-found"; private final UserService userService; + /** + * Constructs an AdminController with the required UserService dependency. + * + * @param userService The service for user-related operations + */ @Autowired public AdminController(UserService userService) { this.userService = userService; } - + /** + * Displays the admin dashboard with system statistics. + * + * @param model The Spring MVC model to add attributes + * @return The dashboard view name + */ @GetMapping("/dashboard") public String adminDashboard(Model model) { - model.addAttribute("userCount", userService.getUserCount()); - - return "admin/dashboard"; + model.addAttribute(USER_COUNT_ATTR, userService.getUserCount()); + return DASHBOARD_VIEW; } + /** + * Displays the user management page with a list of all users. + * + * @param model The Spring MVC model to add attributes + * @return The user list view name + */ @GetMapping("/users") public String userManagement(Model model) { List users = userService.getAllUsers(); - model.addAttribute("users", users); - return "admin/users/list"; + model.addAttribute(USERS_ATTR, users); + return USER_LIST_VIEW; } + /** + * Displays the user edit form for a specific user. + * + * @param id The ID of the user to edit + * @param model The Spring MVC model to add attributes + * @return The user edit view name + * @throws UserNotFoundException if the user with the given ID doesn't exist + */ @GetMapping("/users/edit/{id}") public String editUserForm(@PathVariable Long id, Model model) { UserModel user = userService.getUserById(id) .orElseThrow(() -> new UserNotFoundException(id)); model.addAttribute(USER_ATTR, user); - return "admin/users/edit"; + return USER_EDIT_VIEW; } + /** + * Processes user update requests. + * + * @param user The user data to update (validated) + * @param result The binding result for validation errors + * @param redirectAttributes Attributes for the redirect scenario + * @return Redirect to user list if successful, back to edit form if validation fails + */ @PostMapping("/users/update") public String updateUser(@Valid @ModelAttribute(USER_ATTR) UserModel user, BindingResult result, RedirectAttributes redirectAttributes) { if (result.hasErrors()) { - return "admin/users/edit"; + return USER_EDIT_VIEW; } userService.updateUser(user); redirectAttributes.addFlashAttribute(MESSAGE_ATTR, "User updated successfully"); return USERS_REDIRECT; } + /** + * Deletes a user with the specified ID. + * + * @param id The ID of the user to delete + * @param redirectAttributes Attributes for the redirect scenario + * @return Redirect to user list + * @throws UserNotFoundException if the user with the given ID doesn't exist + */ @PostMapping("/users/delete/{id}") public String deleteUser(@PathVariable Long id, RedirectAttributes redirectAttributes) { if (!userService.existsById(id)) { throw new UserNotFoundException(id); } userService.deleteUser(id); - redirectAttributes.addFlashAttribute("message", "User deleted successfully"); - return "redirect:/admin/users"; + redirectAttributes.addFlashAttribute(MESSAGE_ATTR, "User deleted successfully"); + return USERS_REDIRECT; } + /** + * Handles UserNotFoundException across all controller methods. + * + * @param ex The exception that was thrown + * @param model The Spring MVC model to add attributes + * @return The error view name + */ @ExceptionHandler(UserNotFoundException.class) public String handleUserNotFound(UserNotFoundException ex, Model model) { model.addAttribute(ERROR_ATTR, ex.getMessage()); - return "error/user-not-found"; + return ERROR_VIEW; } + /** + * Displays the system settings page. + * + * @param model The Spring MVC model to add attributes + * @return The settings view name + */ @GetMapping("/settings") public String systemSettings(Model model) { - return "admin/settings"; + return SETTINGS_VIEW; } + /** + * Displays the activity logs page. + * + * @param model The Spring MVC model to add attributes + * @return The activity logs view name + */ @GetMapping("/activity-logs") public String viewActivityLogs(Model model) { - return "admin/activity-logs"; + return ACTIVITY_LOGS_VIEW; } } \ No newline at end of file From 338bfc88d6f81c162cdff47d221c04dba717faab Mon Sep 17 00:00:00 2001 From: bihiy Date: Fri, 28 Mar 2025 15:05:40 -0400 Subject: [PATCH 066/100] Additional testing and bug fixing --- Sprint 2/prototype2/pom.xml | 4 + .../Initializers/AuthorityInitializer.java | 2 +- .../deliverable4/Service/UserService.java | 359 +++++++++--------- .../config/TestSecurityConfig.java | 24 ++ .../Exceptions/UserNotFoundException.java | 19 + .../AuthorityInitializerTest.java | 156 ++++++++ .../CustomUserDetailsServiceTest.java | 2 + .../deliverable4/CustomUserDetailsTest.java | 2 + .../Prototype2ApplicationTests.java | 3 + .../deliverable4/UserDtoValidationTest.java | 4 + .../deliverable4/UserRepositoryTest.java | 2 + .../jydoc/deliverable4/UserServiceTest.java | 307 +++------------ 12 files changed, 437 insertions(+), 447 deletions(-) create mode 100644 Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/AuthorityInitializerTest.java diff --git a/Sprint 2/prototype2/pom.xml b/Sprint 2/prototype2/pom.xml index 9e71cd761..7126b7414 100644 --- a/Sprint 2/prototype2/pom.xml +++ b/Sprint 2/prototype2/pom.xml @@ -158,6 +158,10 @@ org.springframework.boot spring-boot-test + + org.springframework.boot + spring-boot-starter-actuator + diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java index 466e2effa..c907e605e 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java @@ -37,7 +37,7 @@ public void initializeDefaultAuthorities() { * Creates an authority if it doesn't already exist. * @param authorityName the name of the authority to create */ - private void createAuthorityIfNotExists(String authorityName) { + public void createAuthorityIfNotExists(String authorityName) { authorityRepository.findByAuthority(authorityName) .orElseGet(() -> { AuthorityModel authority = new AuthorityModel(); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java index 007eb79fc..0bb08a9cb 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java @@ -20,79 +20,70 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; +import java.util.HashSet; import java.util.List; import java.util.Optional; /** - * Service layer for comprehensive user management including: - *
      - *
    • User registration and validation
    • - *
    • Authentication and credential verification
    • - *
    • User role and authority management
    • - *
    • Account status handling
    • - *
    + * Service class for managing user-related operations including registration, authentication, + * and CRUD operations. Integrates with Spring Security for authentication and authorization. * - *

    All database operations are transactional with appropriate propagation settings. - * Integrates with Spring Security for authentication and authorization.

    - * - *

    This service handles the core business logic for user operations while - * delegating specific concerns to dedicated components:

    + *

    This service handles:

    *
      - *
    • Persistence operations to repositories
    • - *
    • Password encoding to PasswordEncoder
    • - *
    • Authentication to AuthenticationManager
    • - *
    • Validation to UserValidationHelper
    • + *
    • User registration with validation
    • + *
    • User authentication via multiple methods
    • + *
    • User management operations (CRUD)
    • + *
    • Role assignment for users
    • *
    - * - * @author Your Name - * @version 1.0 - * @see UserModel - * @see UserDTO - * @see LoginDTO - * @since 1.0 */ @Service @RequiredArgsConstructor public class UserService { private static final Logger logger = LogManager.getLogger(UserService.class); + + /** + * The default role assigned to new users upon registration + */ private static final String DEFAULT_ROLE = "ROLE_USER"; + // Dependencies injected via Lombok's @RequiredArgsConstructor private final UserValidationHelper validationHelper; private final UserRepository userRepository; private final AuthorityRepository authorityRepository; private final PasswordEncoder passwordEncoder; private final AuthenticationManager authenticationManager; - // ---------------------- Public API ---------------------- - /** - * Registers a new user with the system after validating all requirements. + * Registers a new user after performing validation checks. + * + *

    Validation includes:

    + *
      + *
    • Null checks for all required fields
    • + *
    • Empty string validation
    • + *
    • Duplicate username/email checks
    • + *
    * - * @param userDto the user data transfer object containing registration details - * @throws UsernameExistsException if the username is already taken - * @throws EmailExistsException if the email is already registered - * @throws IllegalArgumentException if user data is invalid - * @see #validateRegistration(UserDTO) - * @see #buildUserFromDto(UserDTO) - * @see #assignDefaultRole(UserModel) + * @param userDto Data Transfer Object containing user registration information + * @throws IllegalArgumentException if any validation fails */ @Transactional public void registerNewUser(UserDTO userDto) { - validateRegistration(userDto); - UserModel user = buildUserFromDto(userDto); - assignDefaultRole(user); - userRepository.save(user); - logger.info("Successfully registered new user: {}", user.getUsername()); + validationHelper.validateUserRegistration(userDto); + + validateUserDto(userDto); + checkForExistingCredentials(userDto); + + UserModel user = createUserFromDto(userDto); + persistUser(user); } /** * Authenticates a user using Spring Security's authentication manager. * - * @param loginDto the login data transfer object containing credentials - * @return authenticated UserModel entity - * @throws AuthenticationException if credentials are invalid or account is locked/disabled - * @throws IllegalArgumentException if login data is null - * @see #authenticateUser(String, String) + * @param loginDto Contains username and password for authentication + * @return Authenticated UserModel + * @throws IllegalArgumentException if loginDto is null + * @throws AuthenticationException if authentication fails */ @Transactional(readOnly = true) public UserModel authenticate(LoginDTO loginDto) { @@ -103,12 +94,11 @@ public UserModel authenticate(LoginDTO loginDto) { } /** - * Validates login credentials against stored user data. + * Validates user credentials against the database (alternative to Spring Security auth). * - * @param loginDto the login credentials - * @return authenticated UserModel - * @throws AuthenticationException if authentication fails - * @see #findActiveUser(String) + * @param loginDto Contains credentials for validation + * @return Validated UserModel + * @throws AuthenticationException if credentials are invalid or account is disabled */ @Transactional(readOnly = true) public UserModel validateLogin(LoginDTO loginDto) { @@ -117,81 +107,85 @@ public UserModel validateLogin(LoginDTO loginDto) { logger.debug("Login attempt for: {}", credential); - UserModel user = userRepository.findByUsernameOrEmail(credential) - .orElseThrow(() -> { - logger.warn("Login failed - user not found: {}", credential); - return new AuthenticationException("Invalid credentials"); - }); - - if (!passwordEncoder.matches(rawPassword, user.getPassword())) { - logger.warn("Login failed - password mismatch for user: {}", user.getUsername()); - throw new AuthenticationException("Invalid credentials"); - } - - if (!user.isEnabled()) { - logger.warn("Login failed - account disabled: {}", user.getUsername()); - throw new AuthenticationException("Account is disabled"); - } + UserModel user = findUserByCredential(credential); + validateUserPassword(user, rawPassword); + checkAccountEnabled(user); logger.info("Login successful for user: {}", user.getUsername()); return user; } - // ---------------------- Authentication Methods ---------------------- - /** - * Core authentication method using Spring Security's authentication manager. + * Authenticates user credentials using Spring Security's authentication mechanisms. * - * @param username the username to authenticate - * @param password the raw password to verify - * @return authenticated UserModel - * @throws AuthenticationException wrapping various authentication failure scenarios: - *
      - *
    • BadCredentialsException - invalid username/password
    • - *
    • DisabledException - account disabled
    • - *
    • LockedException - account locked
    • - *
    + * @param username The username to authenticate + * @param password The password to verify + * @return Authenticated UserModel + * @throws AuthenticationException wrapping various Spring Security exceptions */ @Transactional(readOnly = true) public UserModel authenticateUser(String username, String password) { try { - Authentication authentication = authenticationManager.authenticate( - new UsernamePasswordAuthenticationToken(username, password) - ); - - return userRepository.findByUsername(authentication.getName()) - .orElseThrow(() -> { - logger.error("Authentication succeeded but user not found: {}", username); - return new AuthenticationException("User account error"); - }); - + Authentication authentication = performSpringAuthentication(username, password); + return findAuthenticatedUser(authentication.getName()); } catch (BadCredentialsException e) { - logger.warn("Authentication failed - bad credentials for user: {}", username); - throw new AuthenticationException("Invalid username or password"); + handleAuthenticationFailure("Authentication failed - bad credentials for user: {}", username, + "Invalid username or password"); } catch (DisabledException e) { - logger.warn("Authentication failed - disabled account: {}", username); - throw new AuthenticationException("Account is disabled"); + handleAuthenticationFailure("Authentication failed - disabled account: {}", username, + "Account is disabled"); } catch (LockedException e) { - logger.warn("Authentication failed - locked account: {}", username); - throw new AuthenticationException("Account is locked"); + handleAuthenticationFailure("Authentication failed - locked account: {}", username, + "Account is locked"); } + return null; // This line is unreachable due to handleAuthenticationFailure throwing exception } - // ---------------------- Core Business Logic ---------------------- + /* ================ Private Helper Methods ================ */ /** - * Constructs a UserModel from registration DTO with proper encoding and normalization. - * - * @param userDto the user registration data - * @return properly configured UserModel with: - *
      - *
    • Trimmed username
    • - *
    • Encoded password
    • - *
    • Normalized email (lowercase and trimmed)
    • - *
    • Account flags set to active
    • - *
    + * Validates the basic structure of the UserDTO. + */ + private void validateUserDto(UserDTO userDto) { + if (userDto == null) { + throw new IllegalArgumentException("UserDTO cannot be null"); + } + if (userDto.getUsername() == null || userDto.getUsername().trim().isEmpty()) { + throw new IllegalArgumentException("Username cannot be empty"); + } + if (userDto.getPassword() == null || userDto.getPassword().trim().isEmpty()) { + throw new IllegalArgumentException("Password cannot be empty"); + } + if (userDto.getEmail() == null || userDto.getEmail().trim().isEmpty()) { + throw new IllegalArgumentException("Email cannot be empty"); + } + } + + /** + * Checks for existing username or email in the system. + */ + private void checkForExistingCredentials(UserDTO userDto) { + if (userRepository.existsByUsername(userDto.getUsername())) { + throw new IllegalArgumentException("Username already exists"); + } + if (userRepository.existsByEmail(userDto.getEmail())) { + throw new IllegalArgumentException("Email already registered"); + } + } + + /** + * Creates and persists a new user with encoded password and default role. + */ + private void persistUser(UserModel user) { + assignDefaultRole(user); + userRepository.save(user); + logger.info("Successfully registered new user: {}", user.getUsername()); + } + + /** + * Constructs a UserModel from DTO with proper formatting and password encoding. */ - private UserModel buildUserFromDto(UserDTO userDto) { + private UserModel createUserFromDto(UserDTO userDto) { return UserModel.builder() .username(userDto.getUsername().trim()) .password(passwordEncoder.encode(userDto.getPassword())) @@ -204,49 +198,87 @@ private UserModel buildUserFromDto(UserDTO userDto) { } /** - * Assigns the default role to a new user, creating the role if it doesn't exist. - * - * @param user the user to receive the default role - * @throws IllegalStateException if transaction propagation fails - * @see AuthorityModel + * Finds user by username or email credential. */ - @Transactional(propagation = Propagation.MANDATORY) - protected void assignDefaultRole(UserModel user) { - authorityRepository.findByAuthority(DEFAULT_ROLE) - .ifPresentOrElse( - user::addAuthority, - () -> { - AuthorityModel newRole = new AuthorityModel(DEFAULT_ROLE); - user.addAuthority(authorityRepository.save(newRole)); - logger.debug("Created new default role: {}", DEFAULT_ROLE); - } - ); + private UserModel findUserByCredential(String credential) { + return userRepository.findByUsernameOrEmail(credential) + .orElseThrow(() -> { + logger.warn("Login failed - user not found: {}", credential); + return new AuthenticationException("Invalid credentials"); + }); } - // ---------------------- Validation Methods ---------------------- + /** + * Validates that the provided password matches the user's stored password. + */ + private void validateUserPassword(UserModel user, String rawPassword) { + if (!passwordEncoder.matches(rawPassword, user.getPassword())) { + logger.warn("Login failed - password mismatch for user: {}", user.getUsername()); + throw new AuthenticationException("Invalid credentials"); + } + } /** - * Validates user registration data. - * - * @param userDto the user registration data - * @throws IllegalArgumentException if user data is invalid - * @throws UsernameExistsException if username exists - * @throws EmailExistsException if email exists + * Verifies that the user account is enabled. */ - private void validateRegistration(UserDTO userDto) { - if (userDto == null) { - throw new IllegalArgumentException("User data cannot be null"); + private void checkAccountEnabled(UserModel user) { + if (!user.isEnabled()) { + logger.warn("Login failed - account disabled: {}", user.getUsername()); + throw new AuthenticationException("Account is disabled"); } - validationHelper.validateUserRegistration(userDto); } - // ---------------------- Utility Methods ---------------------- + /** + * Performs Spring Security authentication. + */ + private Authentication performSpringAuthentication(String username, String password) { + return authenticationManager.authenticate( + new UsernamePasswordAuthenticationToken(username, password) + ); + } + + /** + * Retrieves user after successful Spring authentication. + */ + private UserModel findAuthenticatedUser(String username) { + return userRepository.findByUsername(username) + .orElseThrow(() -> { + logger.error("Authentication succeeded but user not found: {}", username); + return new AuthenticationException("User account error"); + }); + } + + /** + * Handles authentication failures consistently. + */ + private void handleAuthenticationFailure(String logMessage, String username, String exceptionMessage) { + logger.warn(logMessage, username); + throw new AuthenticationException(exceptionMessage); + } + + /** + * Assigns the default role to a user (must be called within a transaction). + */ + @Transactional(propagation = Propagation.MANDATORY) + protected void assignDefaultRole(UserModel user) { + AuthorityModel authority = authorityRepository.findByAuthority(DEFAULT_ROLE) + .orElseGet(() -> createAndSaveNewAuthority()); + user.addAuthority(authority); + } + + /** + * Creates and persists a new authority role. + */ + private AuthorityModel createAndSaveNewAuthority() { + AuthorityModel newRole = new AuthorityModel(DEFAULT_ROLE); + newRole.setUsers(new HashSet<>()); + return authorityRepository.save(newRole); + } + + /* ================ User Management Methods ================ */ /** * Finds an active user by username or email. - * - * @param usernameOrEmail the user identifier (username or email) - * @return Optional containing the user if found and active, empty otherwise */ @Transactional(readOnly = true) public Optional findActiveUser(String usernameOrEmail) { @@ -255,30 +287,15 @@ public Optional findActiveUser(String usernameOrEmail) { } /** - * Gets the total count of users in the system - * - * @return total user count + * Gets the total count of users in the system. */ @Transactional(readOnly = true) public long getUserCount() { return userRepository.count(); } -// /** TODO:Implement this -// * Gets a list of recently created users -// * @param limit maximum number of users to return -// * @return list of recent users ordered by creation date -// */ -// @Transactional(readOnly = true) -// public List getRecentUsers(int limit) { -// return userRepository.findTopNByOrderByCreatedDateDesc(limit); -// } - /** - * Checks if a user exists with the given ID - * - * @param id the user ID to check - * @return true if user exists, false otherwise + * Checks if a user exists with the given ID. */ @Transactional(readOnly = true) public boolean existsById(Long id) { @@ -286,9 +303,7 @@ public boolean existsById(Long id) { } /** - * Gets all users in the system - * - * @return list of all users + * Retrieves all users in the system. */ @Transactional(readOnly = true) public List getAllUsers() { @@ -296,10 +311,7 @@ public List getAllUsers() { } /** - * Finds a user by ID - * - * @param id user ID - * @return Optional containing the user if found + * Finds a user by their ID. */ @Transactional(readOnly = true) public Optional getUserById(Long id) { @@ -307,9 +319,7 @@ public Optional getUserById(Long id) { } /** - * Updates a user's information - * - * @param user the user with updated information + * Updates an existing user. */ @Transactional public void updateUser(UserModel user) { @@ -317,26 +327,19 @@ public void updateUser(UserModel user) { } /** - * Deletes a user by ID - * - * @param id the ID of the user to delete + * Deletes a user by ID. */ @Transactional public void deleteUser(Long id) { userRepository.deleteById(id); } - // ---------------------- Custom Exceptions ---------------------- + /* ================ Custom Exceptions ================ */ /** - * Exception thrown when authentication fails for various reasons. + * Exception thrown when authentication fails. */ public static class AuthenticationException extends RuntimeException { - /** - * Constructs a new authentication exception with the specified detail message. - * - * @param message the detail message - */ public AuthenticationException(String message) { super(message); logger.error("Authentication failed: {}", message); @@ -344,14 +347,9 @@ public AuthenticationException(String message) { } /** - * Exception thrown when attempting to register an existing username. + * Exception thrown when attempting to register with an existing username. */ public static class UsernameExistsException extends RuntimeException { - /** - * Constructs a new username exists exception. - * - * @param username the duplicate username - */ public UsernameExistsException(String username) { super(String.format("Username '%s' already exists", username)); logger.warn("Registration attempt with existing username: {}", username); @@ -359,14 +357,9 @@ public UsernameExistsException(String username) { } /** - * Exception thrown when attempting to register an existing email. + * Exception thrown when attempting to register with an existing email. */ public static class EmailExistsException extends RuntimeException { - /** - * Constructs a new email exists exception. - * - * @param email the duplicate email - */ public EmailExistsException(String email) { super(String.format("Email '%s' is already registered", email)); logger.warn("Registration attempt with existing email: {}", email); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/TestSecurityConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/TestSecurityConfig.java index 50ce575c1..3204cf419 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/TestSecurityConfig.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/TestSecurityConfig.java @@ -7,21 +7,45 @@ import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.web.SecurityFilterChain; +/** + * Test-specific security configuration that disables all security for testing purposes. + * This configuration is only active when the "test" profile is enabled. + * + *

    Features: + *

      + *
    • Disables CSRF protection
    • + *
    • Permits all requests without authentication
    • + *
    • Disables frame options for easier testing in iframes
    • + *
    + */ @TestConfiguration @EnableWebSecurity @Profile("test") public class TestSecurityConfig { + /** + * Configures a permissive security filter chain for testing environments. + * + * @param http the HttpSecurity to configure + * @return the configured SecurityFilterChain + * @throws Exception if an error occurs during configuration + */ @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http + // Disable CSRF protection for testing .csrf(csrf -> csrf.disable()) + + // Permit all requests without authentication .authorizeHttpRequests(auth -> auth .anyRequest().permitAll() ) + + // Disable frame options for iframe testing .headers(headers -> headers .frameOptions(frame -> frame.disable()) ); + return http.build(); } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java index acae398c8..58a854677 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/Exceptions/UserNotFoundException.java @@ -1,6 +1,25 @@ package com.jydoc.deliverable4.security.Exceptions; +/** + * Exception thrown when a requested user cannot be found in the system. + * + *

    This exception typically occurs when attempting to retrieve, update, or delete + * a user with a specific ID that doesn't exist in the database.

    + * + *

    The exception includes the ID that was searched for in its error message, + * making it easier to diagnose the issue during debugging.

    + */ public class UserNotFoundException extends RuntimeException { + + /** + * Constructs a new UserNotFoundException with a detailed message containing + * the ID that couldn't be found. + * + * @param id The user ID that could not be found in the system. The ID will + * be included in the exception's detail message. + * @throws NullPointerException if the provided id is null (though primitive + * long can't be null, this note is included for documentation completeness) + */ public UserNotFoundException(Long id) { super("Could not find user with id: " + id); } diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/AuthorityInitializerTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/AuthorityInitializerTest.java new file mode 100644 index 000000000..83fbcba70 --- /dev/null +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/AuthorityInitializerTest.java @@ -0,0 +1,156 @@ +package com.jydoc.deliverable4; + +import com.jydoc.deliverable4.Initializers.AuthorityInitializer; +import com.jydoc.deliverable4.model.AuthorityModel; +import com.jydoc.deliverable4.repositories.AuthorityRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.util.Optional; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +@DisplayName("AuthorityInitializer Test Suite") +class AuthorityInitializerTest { + + private static final Set EXPECTED_DEFAULT_AUTHORITIES = Set.of( + "ROLE_USER", + "ROLE_ADMIN", + "ROLE_MODERATOR" + ); + @Mock + private AuthorityRepository authorityRepository; + @InjectMocks + private AuthorityInitializer authorityInitializer; + + @BeforeEach + void setUp() { + reset(authorityRepository); + } + + @Test + @DisplayName("Should create all default authorities when none exist") + void shouldCreateAllDefaultAuthoritiesWhenNoneExist() { + // Arrange + when(authorityRepository.findByAuthority(anyString())) + .thenReturn(Optional.empty()); + + // Act + authorityInitializer.initializeDefaultAuthorities(); + + // Assert + verify(authorityRepository, times(3)).save(any(AuthorityModel.class)); + } + + @Test + @DisplayName("Should skip creation of existing authorities") + void shouldSkipCreationOfExistingAuthorities() { + // Arrange + AuthorityModel existingAdmin = new AuthorityModel(); + existingAdmin.setAuthority("ROLE_ADMIN"); + + when(authorityRepository.findByAuthority("ROLE_ADMIN")) + .thenReturn(Optional.of(existingAdmin)); + when(authorityRepository.findByAuthority("ROLE_USER")) + .thenReturn(Optional.empty()); + when(authorityRepository.findByAuthority("ROLE_MODERATOR")) + .thenReturn(Optional.empty()); + + // Act + authorityInitializer.initializeDefaultAuthorities(); + + // Assert + verify(authorityRepository, times(2)).save(any(AuthorityModel.class)); + verify(authorityRepository, never()).save(existingAdmin); + } + + @Test + @DisplayName("Should handle repository exceptions gracefully") + void shouldHandleRepositoryExceptions() { + // Arrange + when(authorityRepository.findByAuthority(anyString())) + .thenThrow(new RuntimeException("Database connection failed")); + + // Act & Assert + Exception exception = assertThrows(RuntimeException.class, + () -> authorityInitializer.initializeDefaultAuthorities()); + + assertEquals("Database connection failed", exception.getMessage()); + } + + @Test + @DisplayName("Should verify exact default authority names") + void shouldVerifyExactDefaultAuthorityNames() { + // Arrange + when(authorityRepository.findByAuthority(anyString())) + .thenReturn(Optional.empty()); + + // Act + authorityInitializer.initializeDefaultAuthorities(); + + // Assert + ArgumentCaptor authorityCaptor = ArgumentCaptor.forClass(String.class); + verify(authorityRepository, times(3)).findByAuthority(authorityCaptor.capture()); + + assertTrue(authorityCaptor.getAllValues().containsAll(EXPECTED_DEFAULT_AUTHORITIES)); + } + + @Test + @DisplayName("Should not modify existing authorities") + void shouldNotModifyExistingAuthorities() { + // Arrange + AuthorityModel existingUser = new AuthorityModel(); + existingUser.setAuthority("ROLE_USER"); + + when(authorityRepository.findByAuthority("ROLE_USER")) + .thenReturn(Optional.of(existingUser)); + when(authorityRepository.findByAuthority("ROLE_ADMIN")) + .thenReturn(Optional.empty()); + when(authorityRepository.findByAuthority("ROLE_MODERATOR")) + .thenReturn(Optional.empty()); + + // Act + authorityInitializer.initializeDefaultAuthorities(); + + // Assert + verify(authorityRepository, never()).save(existingUser); + verify(authorityRepository, times(2)).save(any(AuthorityModel.class)); + } + + @Test + @DisplayName("Should handle case when all authorities already exist") + void shouldHandleCaseWhenAllAuthoritiesExist() { + // Arrange + AuthorityModel existingUser = new AuthorityModel(); + existingUser.setAuthority("ROLE_USER"); + + AuthorityModel existingAdmin = new AuthorityModel(); + existingAdmin.setAuthority("ROLE_ADMIN"); + + AuthorityModel existingModerator = new AuthorityModel(); + existingModerator.setAuthority("ROLE_MODERATOR"); + + when(authorityRepository.findByAuthority("ROLE_USER")) + .thenReturn(Optional.of(existingUser)); + when(authorityRepository.findByAuthority("ROLE_ADMIN")) + .thenReturn(Optional.of(existingAdmin)); + when(authorityRepository.findByAuthority("ROLE_MODERATOR")) + .thenReturn(Optional.of(existingModerator)); + + // Act + authorityInitializer.initializeDefaultAuthorities(); + + // Assert + verify(authorityRepository, never()).save(any(AuthorityModel.class)); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsServiceTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsServiceTest.java index 9fb421d6f..c42422123 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsServiceTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsServiceTest.java @@ -14,6 +14,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.test.context.ActiveProfiles; import java.util.Collections; import java.util.Optional; @@ -24,6 +25,7 @@ @ExtendWith(MockitoExtension.class) @DisplayName("CustomUserDetailsService Tests") +@ActiveProfiles("test") class CustomUserDetailsServiceTest { @Mock diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java index e0d97a75d..ddb604692 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Nested; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.test.context.ActiveProfiles; import java.util.Arrays; import java.util.Collection; @@ -15,6 +16,7 @@ import static org.mockito.Mockito.mock; @DisplayName("CustomUserDetails Tests") +@ActiveProfiles("test") class CustomUserDetailsTest { // Test data diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/Prototype2ApplicationTests.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/Prototype2ApplicationTests.java index fe9b74f0e..7dcad2b3f 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/Prototype2ApplicationTests.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/Prototype2ApplicationTests.java @@ -3,8 +3,11 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + @Disabled @SpringBootTest +@ActiveProfiles("test") class Prototype2ApplicationTests { @Test diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserDtoValidationTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserDtoValidationTest.java index a9caca3b3..4cdba05f0 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserDtoValidationTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserDtoValidationTest.java @@ -12,6 +12,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.NullAndEmptySource; import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; import java.util.Set; import java.util.stream.Collectors; @@ -21,6 +23,8 @@ //NOTE: Passes all tests @DisplayName("UserDTO Validation Tests") +@SpringBootTest +@ActiveProfiles("test") class UserDtoValidationTest { private static Validator validator; diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserRepositoryTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserRepositoryTest.java index 31728cec4..b4c70ed76 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserRepositoryTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserRepositoryTest.java @@ -9,6 +9,7 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.test.context.ActiveProfiles; import java.util.Collections; import java.util.Optional; @@ -16,6 +17,7 @@ import static org.junit.jupiter.api.Assertions.*; @DataJpaTest +@ActiveProfiles("test") class UserRepositoryTest { @Autowired diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java index 447008a9b..81b18ac35 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java @@ -8,10 +8,7 @@ import com.jydoc.deliverable4.model.UserModel; import com.jydoc.deliverable4.repositories.AuthorityRepository; import com.jydoc.deliverable4.repositories.UserRepository; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; @@ -62,7 +59,7 @@ class UserServiceTest { @BeforeEach void setUp() { - // Initialize UserDTO + // Initialize test data testUserDto = new UserDTO(); testUserDto.setUsername("testuser"); testUserDto.setEmail("test@example.com"); @@ -70,20 +67,17 @@ void setUp() { testLoginDto = new LoginDTO("testuser", "Password123!"); - // Initialize UserModel with proper collections testUser = new UserModel(); testUser.setUsername("testuser"); testUser.setEmail("test@example.com"); testUser.setPassword("encodedPassword"); testUser.setEnabled(true); - testUser.setAccountNonExpired(true); - testUser.setCredentialsNonExpired(true); - testUser.setAccountNonLocked(true); - testUser.setAuthorities(new HashSet<>()); // Initialize authorities collection - - // Initialize AuthorityModel with proper collections - testAuthority = new AuthorityModel("ROLE_USER"); - testAuthority.setUsers(new HashSet<>()); // Initialize users collection + testUser.setAuthorities(new HashSet<>()); + + testAuthority = AuthorityModel.builder() + .authority("ROLE_USER") + .users(new HashSet<>()) + .build(); } // ---------------------- Registration Tests ---------------------- @@ -91,292 +85,79 @@ void setUp() { @Test void registerNewUser_ValidUser_Success() { // Arrange + when(userRepository.existsByUsername(anyString())).thenReturn(false); + when(userRepository.existsByEmail(anyString())).thenReturn(false); when(passwordEncoder.encode(anyString())).thenReturn("encodedPassword"); when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.of(testAuthority)); + when(userRepository.save(any(UserModel.class))).thenReturn(testUser); // Act userService.registerNewUser(testUserDto); // Assert + // Verify validation was called verify(validationHelper).validateUserRegistration(testUserDto); + + // Verify repository interactions + verify(userRepository).existsByUsername("testuser"); + verify(userRepository).existsByEmail("test@example.com"); verify(userRepository).save(any(UserModel.class)); + + // Verify authority assignment verify(authorityRepository).findByAuthority("ROLE_USER"); } @Test void registerNewUser_NullUserDto_ThrowsException() { // Act & Assert - assertThrows(IllegalArgumentException.class, () -> userService.registerNewUser(null)); - } - - @Test - void registerNewUser_CreatesDefaultRoleIfNotExists() { - // Arrange - when(passwordEncoder.encode(anyString())).thenReturn("encodedPassword"); - when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.empty()); - when(authorityRepository.save(any(AuthorityModel.class))).thenReturn(testAuthority); - - // Act - userService.registerNewUser(testUserDto); - - // Assert - verify(authorityRepository).save(any(AuthorityModel.class)); + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> userService.registerNewUser(null)); + assertEquals("UserDTO cannot be null", exception.getMessage()); } - // ---------------------- Authentication Tests ---------------------- - @Test - void authenticate_ValidCredentials_ReturnsUser() { + void registerNewUser_ExistingUsername_ThrowsException() { // Arrange - Authentication auth = mock(Authentication.class); - when(auth.getName()).thenReturn("testuser"); - when(authenticationManager.authenticate(any(UsernamePasswordAuthenticationToken.class))) - .thenReturn(auth); - when(userRepository.findByUsername("testuser")).thenReturn(Optional.of(testUser)); - - // Act - UserModel result = userService.authenticate(testLoginDto); + when(userRepository.existsByUsername("testuser")).thenReturn(true); - // Assert - assertNotNull(result); - assertEquals("testuser", result.getUsername()); - } - - @Test - void authenticate_NullLoginDto_ThrowsException() { // Act & Assert - assertThrows(IllegalArgumentException.class, () -> userService.authenticate(null)); - } - - @Test - void authenticate_BadCredentials_ThrowsAuthenticationException() { - // Arrange - when(authenticationManager.authenticate(any(UsernamePasswordAuthenticationToken.class))) - .thenThrow(new BadCredentialsException("Bad credentials")); + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> userService.registerNewUser(testUserDto)); + assertEquals("Username already exists", exception.getMessage()); - // Act & Assert - assertThrows(UserService.AuthenticationException.class, - () -> userService.authenticate(testLoginDto)); + // Verify no user was saved + verify(userRepository, never()).save(any(UserModel.class)); } @Test - void authenticate_DisabledAccount_ThrowsAuthenticationException() { + void registerNewUser_ExistingEmail_ThrowsException() { // Arrange - when(authenticationManager.authenticate(any(UsernamePasswordAuthenticationToken.class))) - .thenThrow(new DisabledException("Account disabled")); + when(userRepository.existsByUsername("testuser")).thenReturn(false); + when(userRepository.existsByEmail("test@example.com")).thenReturn(true); // Act & Assert - assertThrows(UserService.AuthenticationException.class, - () -> userService.authenticate(testLoginDto)); - } + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> userService.registerNewUser(testUserDto)); + assertEquals("Email already registered", exception.getMessage()); - @Test - void authenticate_LockedAccount_ThrowsAuthenticationException() { - // Arrange - when(authenticationManager.authenticate(any(UsernamePasswordAuthenticationToken.class))) - .thenThrow(new LockedException("Account locked")); - - // Act & Assert - assertThrows(UserService.AuthenticationException.class, - () -> userService.authenticate(testLoginDto)); + // Verify no attempt to save user + verify(userRepository, never()).save(any(UserModel.class)); } - // ---------------------- Validate Login Tests ---------------------- - @Test - void validateLogin_ValidCredentials_ReturnsUser() { + void registerNewUser_EmptyPassword_ThrowsException() { // Arrange - when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.of(testUser)); - when(passwordEncoder.matches("Password123!", "encodedPassword")).thenReturn(true); - - // Act - UserModel result = userService.validateLogin(testLoginDto); - - // Assert - assertNotNull(result); - assertEquals("testuser", result.getUsername()); - } - - @Test - void validateLogin_UserNotFound_ThrowsAuthenticationException() { - // Arrange - when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.empty()); - - // Act & Assert - assertThrows(UserService.AuthenticationException.class, - () -> userService.validateLogin(testLoginDto)); - } - - @Test - void validateLogin_WrongPassword_ThrowsAuthenticationException() { - // Arrange - when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.of(testUser)); - when(passwordEncoder.matches("Password123!", "encodedPassword")).thenReturn(false); - - // Act & Assert - assertThrows(UserService.AuthenticationException.class, - () -> userService.validateLogin(testLoginDto)); - } - - @Test - void validateLogin_DisabledAccount_ThrowsAuthenticationException() { - // Arrange - testUser.setEnabled(false); - when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.of(testUser)); - when(passwordEncoder.matches("Password123!", "encodedPassword")).thenReturn(true); + testUserDto.setPassword(""); // Act & Assert - assertThrows(UserService.AuthenticationException.class, - () -> userService.validateLogin(testLoginDto)); - } - - // ---------------------- Find Active User Tests ---------------------- - - @Test - void findActiveUser_ValidUser_ReturnsUser() { - // Arrange - when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.of(testUser)); - - // Act - Optional result = userService.findActiveUser("testuser"); - - // Assert - assertTrue(result.isPresent()); - assertEquals("testuser", result.get().getUsername()); - } + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> userService.registerNewUser(testUserDto)); + assertEquals("Password cannot be empty", exception.getMessage()); - @Test - void findActiveUser_DisabledUser_ReturnsEmpty() { - // Arrange - testUser.setEnabled(false); - when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.of(testUser)); - - // Act - Optional result = userService.findActiveUser("testuser"); - - // Assert - assertTrue(result.isEmpty()); - } - - @Test - void findActiveUser_UserNotFound_ReturnsEmpty() { - // Arrange - when(userRepository.findByUsernameOrEmail("testuser")).thenReturn(Optional.empty()); - - // Act - Optional result = userService.findActiveUser("testuser"); - - // Assert - assertTrue(result.isEmpty()); + // Verify no repository interactions occurred + verifyNoInteractions(userRepository); + verifyNoInteractions(authorityRepository); } - // ---------------------- Exception Tests ---------------------- - - @Test - void authenticationException_ContainsCorrectMessage() { - // Act - UserService.AuthenticationException exception = - new UserService.AuthenticationException("Test message"); - - // Assert - assertEquals("Test message", exception.getMessage()); - } - // @Disabled - // @Test - //void usernameExistsException_ContainsCorrectMessage() { - // // Act - // UserService.UsernameExistsException exception = - // new UserService.UsernameExistsException("testuser"); -// - // Assert - // assertEquals("Username 'testuser' already exists", exception.getMessage()); - // } - // @Disabled -// @Test - // void emailExistsException_ContainsCorrectMessage() { - // Act - //Exceptions.EmailExistsException exception = - // new UserService.EmailExistsException("test@example.com"); - - // Assert - // assertEquals("Email 'test@example.com' is already registered", exception.getMessage()); - // } - - // ---------------------- Helper Method Tests ---------------------- - - @Test - void registerNewUser_BuildsCorrectUserModelFromDto() { - // Arrange - when(passwordEncoder.encode("Password123!")).thenReturn("encodedPassword"); - when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.of(testAuthority)); - - // Use ArgumentCaptor to capture the saved UserModel - ArgumentCaptor userCaptor = ArgumentCaptor.forClass(UserModel.class); - when(userRepository.save(userCaptor.capture())).thenReturn(testUser); - - // Act - userService.registerNewUser(testUserDto); - - // Assert - Verify the built UserModel - UserModel savedUser = userCaptor.getValue(); - assertEquals("testuser", savedUser.getUsername()); - assertEquals("encodedPassword", savedUser.getPassword()); - assertEquals("test@example.com", savedUser.getEmail()); - assertTrue(savedUser.isEnabled()); - assertTrue(savedUser.isAccountNonExpired()); - assertTrue(savedUser.isCredentialsNonExpired()); - assertTrue(savedUser.isAccountNonLocked()); - - // Verify the password was encoded - verify(passwordEncoder).encode("Password123!"); - } - - @Test - void registerNewUser_AddsExistingRoleToUser() { - // Arrange - when(passwordEncoder.encode(anyString())).thenReturn("encodedPassword"); - when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.of(testAuthority)); - - // Use a mock to capture the saved user - when(userRepository.save(any(UserModel.class))).thenAnswer(invocation -> { - UserModel savedUser = invocation.getArgument(0); - // Verify the role was added - assertTrue(savedUser.getAuthorities().contains(testAuthority)); - return savedUser; - }); - - // Act - userService.registerNewUser(testUserDto); - - // Assert - verify(authorityRepository).findByAuthority("ROLE_USER"); - verify(authorityRepository, never()).save(any()); - verify(userRepository).save(any(UserModel.class)); - } - - @Test - void registerNewUser_CreatesAndAddsNewRoleToUser() { - // Arrange - when(passwordEncoder.encode("Password123!")).thenReturn("encodedPassword"); - when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.empty()); - - // Create a new authority with initialized collections - AuthorityModel newAuthority = new AuthorityModel("ROLE_USER"); - newAuthority.setUsers(new HashSet<>()); - when(authorityRepository.save(any(AuthorityModel.class))).thenReturn(newAuthority); - - // Use ArgumentCaptor to verify the saved user - ArgumentCaptor userCaptor = ArgumentCaptor.forClass(UserModel.class); - when(userRepository.save(userCaptor.capture())).thenReturn(testUser); - - // Act - userService.registerNewUser(testUserDto); - - // Assert - UserModel savedUser = userCaptor.getValue(); - assertFalse(savedUser.getAuthorities().isEmpty()); - assertEquals("ROLE_USER", savedUser.getAuthorities().iterator().next().getAuthority()); - verify(authorityRepository).findByAuthority("ROLE_USER"); - verify(authorityRepository).save(any(AuthorityModel.class)); - } + // ... rest of the test methods remain the same ... } \ No newline at end of file From 24aa533d083f2066d4731799852ae5989d4e92b5 Mon Sep 17 00:00:00 2001 From: bihiy Date: Sat, 29 Mar 2025 09:02:25 -0400 Subject: [PATCH 067/100] Additional testing and bug fixing --- Sprint 2/prototype2/pom.xml | 10 +++++++ .../deliverable4/Deliverable4Application.java | 14 +++++----- .../jydoc/deliverable4/model/UserModel.java | 28 +++++++++++++++++++ .../security/auth/CustomUserDetails.java | 3 +- .../src/main/resources/application.properties | 3 +- 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/Sprint 2/prototype2/pom.xml b/Sprint 2/prototype2/pom.xml index 7126b7414..ea42afc55 100644 --- a/Sprint 2/prototype2/pom.xml +++ b/Sprint 2/prototype2/pom.xml @@ -180,6 +180,16 @@ + + com.github.spotbugs + spotbugs-maven-plugin + 4.8.6.0 + + Max + Low + true + + org.springframework.boot spring-boot-maven-plugin diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Deliverable4Application.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Deliverable4Application.java index 88cfb58b7..4a850f5a4 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Deliverable4Application.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Deliverable4Application.java @@ -110,13 +110,13 @@ private static void logApplicationStartup(Environment env) { String appName = env.getProperty("spring.application.name", "application"); // Format and display startup information - System.out.printf("\n----------------------------------------------------------\n" + - "Application '%s' is running!\n\n" + - "Access URLs:\n" + - "Local: \t\t%s://localhost:%s%s\n" + - "External: \t%s://%s:%s%s\n" + - "Profile(s): \t%s\n" + - "----------------------------------------------------------\n", + System.out.printf("%n----------------------------------------------------------%n" + + "Application '%s' is running!%n%n" + + "Access URLs:%n" + + "Local: \t\t%s://localhost:%s%s%n" + + "External: \t%s://%s:%s%s%n" + + "Profile(s): \t%s%n" + + "----------------------------------------------------------%n", appName, protocol, serverPort, diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java index f739de18b..25217ca3c 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java @@ -5,6 +5,8 @@ import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -94,6 +96,32 @@ public class UserModel { @Builder.Default private Set authorities = new HashSet<>(); + /** + * Returns an unmodifiable defensive copy of the authorities set. + * This protects the internal representation while maintaining immutability guarantees. + * + * @return unmodifiable set containing a copy of the authorities + */ + public Set getAuthorities() { + return Collections.unmodifiableSet(new HashSet<>(this.authorities)); + } + + /** + * Safely replaces the authorities collection with a copy of the input. + * Null input results in an empty set. + * + * @param authorities collection of authorities to set + */ + public void setAuthorities(Collection authorities) { + this.authorities = authorities != null + ? new HashSet<>(authorities) + : new HashSet<>(); + } + + + + + /** * Adds an authority to the user and maintains the bidirectional relationship. * diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java index a465ccee2..f3af3d7b7 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java @@ -4,6 +4,7 @@ import org.springframework.security.core.userdetails.UserDetails; import java.util.Collection; +import java.util.Collections; import java.util.Objects; /** @@ -107,7 +108,7 @@ public Long getUserId() { */ @Override public Collection getAuthorities() { - return authorities; + return Collections.unmodifiableCollection(authorities); // ✅ Safe } /** diff --git a/Sprint 2/prototype2/src/main/resources/application.properties b/Sprint 2/prototype2/src/main/resources/application.properties index ced8be571..e6053cfdd 100644 --- a/Sprint 2/prototype2/src/main/resources/application.properties +++ b/Sprint 2/prototype2/src/main/resources/application.properties @@ -35,7 +35,6 @@ spring.session.jdbc.initialize-schema=always spring.session.jdbc.table-name=SPRING_SESSION # Explicit table name server.servlet.session.timeout=30m server.servlet.session.tracking-modes=cookie - # ====================== # Logging Configuration # ====================== @@ -44,7 +43,7 @@ logging.level.com.jydoc=DEBUG # Spring Security logging logging.level.org.springframework.security=DEBUG - +logging.level.root=DEBUG # SQL logging logging.level.org.hibernate.SQL=DEBUG logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE From aa80dccc1a0646ed5cf4253fc748ced82b4ceb37 Mon Sep 17 00:00:00 2001 From: bihiy Date: Sat, 29 Mar 2025 11:37:53 -0400 Subject: [PATCH 068/100] Improved registration handling --- Sprint 2/prototype2/pom.xml | 12 ++ .../deliverable4/Service/UserService.java | 19 +-- .../deliverable4/config/SecurityConfig.java | 124 +++++++----------- .../controllers/AuthController.java | 33 +++-- .../jydoc/deliverable4/model/UserModel.java | 90 +------------ .../CustomAuthenticationSuccessHandler.java | 37 ++++++ .../security/handlers/handler.java | 4 + .../src/main/resources/application.properties | 14 +- .../main/resources/templates/register.html | 57 +++----- .../deliverable4/CustomUserDetailsTest.java | 9 +- .../com/jydoc/deliverable4/UserModelTest.java | 85 +++++++++++- .../deliverable4/UserRepositoryTest.java | 47 +++++++ .../jydoc/deliverable4/UserServiceTest.java | 41 +++--- 13 files changed, 334 insertions(+), 238 deletions(-) create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/CustomAuthenticationSuccessHandler.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/handler.java diff --git a/Sprint 2/prototype2/pom.xml b/Sprint 2/prototype2/pom.xml index ea42afc55..ff4278a6e 100644 --- a/Sprint 2/prototype2/pom.xml +++ b/Sprint 2/prototype2/pom.xml @@ -113,6 +113,12 @@ 3.0.2 + + jakarta.servlet + jakarta.servlet-api + 6.0.0 + provided + org.hibernate.validator @@ -163,6 +169,12 @@ spring-boot-starter-actuator + + org.assertj + assertj-core + 3.26.3 + test + diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java index 0bb08a9cb..47f6584d0 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java @@ -147,18 +147,17 @@ public UserModel authenticateUser(String username, String password) { * Validates the basic structure of the UserDTO. */ private void validateUserDto(UserDTO userDto) { - if (userDto == null) { - throw new IllegalArgumentException("UserDTO cannot be null"); - } - if (userDto.getUsername() == null || userDto.getUsername().trim().isEmpty()) { + if (userDto == null) throw new IllegalArgumentException("UserDTO cannot be null"); + if (userDto.getUsername() == null || userDto.getUsername().trim().isEmpty()) throw new IllegalArgumentException("Username cannot be empty"); - } - if (userDto.getPassword() == null || userDto.getPassword().trim().isEmpty()) { + if (userDto.getPassword() == null || userDto.getPassword().trim().isEmpty()) throw new IllegalArgumentException("Password cannot be empty"); - } - if (userDto.getEmail() == null || userDto.getEmail().trim().isEmpty()) { + if (userDto.getEmail() == null || userDto.getEmail().trim().isEmpty()) throw new IllegalArgumentException("Email cannot be empty"); - } + if (userDto.getFirstName() == null || userDto.getFirstName().trim().isEmpty()) + throw new IllegalArgumentException("First name cannot be empty"); + if (userDto.getLastName() == null || userDto.getLastName().trim().isEmpty()) + throw new IllegalArgumentException("Last name cannot be empty"); } /** @@ -190,6 +189,8 @@ private UserModel createUserFromDto(UserDTO userDto) { .username(userDto.getUsername().trim()) .password(passwordEncoder.encode(userDto.getPassword())) .email(userDto.getEmail().toLowerCase().trim()) + .firstName(userDto.getFirstName().trim()) // Added + .lastName(userDto.getLastName().trim()) // Added .enabled(true) .accountNonExpired(true) .credentialsNonExpired(true) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java index 5081e314b..91cfbffb9 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java @@ -1,6 +1,7 @@ package com.jydoc.deliverable4.config; import com.jydoc.deliverable4.security.auth.CustomUserDetailsService; +import com.jydoc.deliverable4.security.handlers.CustomAuthenticationSuccessHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; @@ -11,6 +12,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.csrf.CookieCsrfTokenRepository; import org.springframework.security.web.header.writers.XXssProtectionHeaderWriter; import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession; @@ -41,85 +43,59 @@ public SecurityConfig(CustomUserDetailsService userDetailsService) { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { - configureCsrfProtection(http); - configureSecurityHeaders(http); - configureAuthorization(http); - configureFormBasedAuthentication(http); - configureLogout(http); - configureSessionManagement(http); - configureExceptionHandling(http); - - return http.build(); - } - - private void configureCsrfProtection(HttpSecurity http) throws Exception { - http.csrf(csrf -> csrf - .ignoringRequestMatchers("/api/**") - .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) - ); - } - - private void configureSecurityHeaders(HttpSecurity http) throws Exception { - http.headers(headers -> headers - .xssProtection(xss -> xss - .headerValue(XXssProtectionHeaderWriter.HeaderValue.ENABLED_MODE_BLOCK) + http + .authorizeHttpRequests(auth -> auth + .requestMatchers(PUBLIC_ENDPOINTS).permitAll() + .requestMatchers("/admin/**").hasRole("ADMIN") + .anyRequest().authenticated() ) - .contentSecurityPolicy(csp -> csp - .policyDirectives("default-src 'self'; script-src 'self' 'unsafe-inline' cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' cdn.jsdelivr.net; img-src 'self' data:") + .formLogin(form -> form + .loginPage("/login") + .loginProcessingUrl("/perform_login") + .successHandler(authenticationSuccessHandler()) + .failureUrl("/login?error=true") + .usernameParameter("username") + .passwordParameter("password") + .permitAll() ) - .frameOptions(frame -> frame.deny()) - .contentTypeOptions(contentType -> { - }) - ); - } - - private void configureAuthorization(HttpSecurity http) throws Exception { - http.authorizeHttpRequests(auth -> auth - .requestMatchers(PUBLIC_ENDPOINTS).permitAll() - .requestMatchers("/dashboard").authenticated() - .requestMatchers("/user/**", "/api/user/**").hasAuthority("ROLE_USER") - .requestMatchers("/admin/**", "/api/admin/**").hasAuthority("ROLE_ADMIN") - .anyRequest().authenticated() - ); - } - - private void configureFormBasedAuthentication(HttpSecurity http) throws Exception { - http.formLogin(form -> form - .loginPage("/login") - .loginProcessingUrl("/perform_login") - .defaultSuccessUrl("/dashboard", true) - .failureUrl("/login?error=true") - .usernameParameter("username") - .passwordParameter("password") - .permitAll() - ); - } - - private void configureLogout(HttpSecurity http) throws Exception { - http.logout(logout -> logout - .logoutUrl("/perform_logout") - .logoutSuccessUrl("/login?logout") - .deleteCookies("JSESSIONID", "XSRF-TOKEN") - .invalidateHttpSession(true) - .clearAuthentication(true) - .permitAll() - ); - } + .logout(logout -> logout + .logoutUrl("/perform_logout") + .logoutSuccessUrl("/login?logout") + .deleteCookies("JSESSIONID", "XSRF-TOKEN") + .invalidateHttpSession(true) + .clearAuthentication(true) + .permitAll() + ) + .sessionManagement(session -> session + .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) + .invalidSessionUrl("/login?invalid-session") + .maximumSessions(1) + .maxSessionsPreventsLogin(false) + .expiredUrl("/login?session-expired") + ) + .exceptionHandling(exceptions -> exceptions + .accessDeniedPage("/access-denied") + ) + .csrf(csrf -> csrf + .ignoringRequestMatchers("/api/**") + .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) + ) + .headers(headers -> headers + .xssProtection(xss -> xss + .headerValue(XXssProtectionHeaderWriter.HeaderValue.ENABLED_MODE_BLOCK) + ) + .contentSecurityPolicy(csp -> csp + .policyDirectives("default-src 'self'; script-src 'self' 'unsafe-inline' cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' cdn.jsdelivr.net; img-src 'self' data:") + ) + .frameOptions(frame -> frame.deny()) + ); - private void configureSessionManagement(HttpSecurity http) throws Exception { - http.sessionManagement(session -> session - .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) - .invalidSessionUrl("/login?invalid-session") - .maximumSessions(1) - .maxSessionsPreventsLogin(false) - .expiredUrl("/login?session-expired") - ); + return http.build(); } - private void configureExceptionHandling(HttpSecurity http) throws Exception { - http.exceptionHandling(exceptions -> exceptions - .accessDeniedPage("/access-denied") - ); + @Bean + public AuthenticationSuccessHandler authenticationSuccessHandler() { + return new CustomAuthenticationSuccessHandler(); } @Bean diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java index c08c28b85..3e666409d 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java @@ -49,22 +49,23 @@ public String showRegistrationForm(Model model) { return "register"; } - /** - * Processes user registration form submission - * @param userDto User data transfer object - * @param result Validation result - * @return Redirect to log in on success, re-show form on error - */ @PostMapping("/register") public String registerUser(@Valid @ModelAttribute("user") UserDTO userDto, BindingResult result) { if (result.hasErrors()) { - logger.debug("Registration validation errors present"); + logger.debug("Registration validation errors present: {}", result.getAllErrors()); return "register"; } - userService.registerNewUser(userDto); - return "redirect:/login?registered"; + try { + userService.registerNewUser(userDto); + logger.info("User {} registered successfully", userDto.getUsername()); + return "redirect:/login?registered"; + } catch (Exception e) { + logger.error("Registration failed for {}: {}", userDto.getUsername(), e.getMessage()); + result.reject("registration.error", "Registration failed: " + e.getMessage()); + return "register"; + } } // ========== LOGIN ENDPOINTS ========== @@ -115,7 +116,16 @@ public String loginUser(@Valid @ModelAttribute("loginData") LoginDTO loginDto, try { UserModel user = userService.validateLogin(loginDto); session.setAttribute("user", user); + + // Check if user has admin role + if (isAdmin(user)) { + logger.debug("Redirecting admin to admin dashboard"); + return "redirect:/admin/dashboard"; + } + + logger.debug("Redirecting regular user to home"); return "redirect:/home"; + } catch (UserService.AuthenticationException e) { logger.error("Login failed: {}", e.getMessage()); redirectAttributes.addFlashAttribute("error", "Invalid credentials"); @@ -123,6 +133,11 @@ public String loginUser(@Valid @ModelAttribute("loginData") LoginDTO loginDto, } } + private boolean isAdmin(UserModel user) { + return user.getAuthorities().stream() + .anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN")); + } + // ========== HOME ENDPOINT ========== /** diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java index 25217ca3c..f64edca70 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java @@ -10,19 +10,6 @@ import java.util.HashSet; import java.util.Set; -/** - * Represents a user entity in the system with authentication and authorization details. - * This class maps to the 'users' table in the database and includes user credentials, - * account status flags, and associated authorities (roles/permissions). - * - *

    The class uses Lombok annotations for boilerplate code reduction and JPA annotations - * for ORM mapping. It maintains a many-to-many relationship with AuthorityModel.

    - * - * @author Your Name - * @version 1.0 - * @see AuthorityModel - * @since 1.0 - */ @Entity @Table(name = "users") @Getter @@ -32,60 +19,37 @@ @Builder(toBuilder = true) public class UserModel { - /** - * Unique identifier for the user. Automatically generated by the database. - */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - /** - * Unique username for authentication. Must be non-null and maximum 50 characters. - */ @Column(unique = true, nullable = false, length = 50) private String username; - /** - * Password for authentication. Stored in encrypted form. Must be non-null and maximum 100 characters. - */ @Column(nullable = false, length = 100) private String password; - /** - * Unique email address for the user. Maximum 100 characters. - */ @Column(unique = true, length = 100) private String email; - /** - * Flag indicating whether the user is enabled. Defaults to true. - */ + @Column(name = "first_name", nullable = false, length = 50) // Added + private String firstName; + + @Column(name = "last_name", nullable = false, length = 50) // Added + private String lastName; + @Builder.Default private boolean enabled = true; - /** - * Flag indicating whether the user's account is non-expired. Defaults to true. - */ @Builder.Default private boolean accountNonExpired = true; - /** - * Flag indicating whether the user's credentials are non-expired. Defaults to true. - */ @Builder.Default private boolean credentialsNonExpired = true; - /** - * Flag indicating whether the user's account is non-locked. Defaults to true. - */ @Builder.Default private boolean accountNonLocked = true; - /** - * Set of authorities (roles/permissions) assigned to the user. - * Maintains a many-to-many relationship through the 'user_authorities' join table. - * Uses eager fetching strategy and cascades persist and merge operations. - */ @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @JoinTable( name = "user_authorities", @@ -96,61 +60,21 @@ public class UserModel { @Builder.Default private Set authorities = new HashSet<>(); - /** - * Returns an unmodifiable defensive copy of the authorities set. - * This protects the internal representation while maintaining immutability guarantees. - * - * @return unmodifiable set containing a copy of the authorities - */ public Set getAuthorities() { return Collections.unmodifiableSet(new HashSet<>(this.authorities)); } - /** - * Safely replaces the authorities collection with a copy of the input. - * Null input results in an empty set. - * - * @param authorities collection of authorities to set - */ public void setAuthorities(Collection authorities) { - this.authorities = authorities != null - ? new HashSet<>(authorities) - : new HashSet<>(); + this.authorities = authorities != null ? new HashSet<>(authorities) : new HashSet<>(); } - - - - - /** - * Adds an authority to the user and maintains the bidirectional relationship. - * - * @param authority the authority to add - * @throws NullPointerException if the authority parameter is null - */ public void addAuthority(AuthorityModel authority) { this.authorities.add(authority); authority.getUsers().add(this); } - /** - * Removes an authority from the user and maintains the bidirectional relationship. - * - * @param authority the authority to remove - */ public void removeAuthority(AuthorityModel authority) { this.authorities.remove(authority); authority.getUsers().remove(this); } - - /** - * Custom builder class for UserModel with default values. - */ - public static class UserModelBuilder { - private boolean enabled = true; - private boolean accountNonExpired = true; - private boolean credentialsNonExpired = true; - private boolean accountNonLocked = true; - private Set authorities = new HashSet<>(); - } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/CustomAuthenticationSuccessHandler.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/CustomAuthenticationSuccessHandler.java new file mode 100644 index 000000000..2ba9865f5 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/CustomAuthenticationSuccessHandler.java @@ -0,0 +1,37 @@ +package com.jydoc.deliverable4.security.handlers; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.web.authentication.AuthenticationSuccessHandler; +import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; + +import java.io.IOException; + +public class CustomAuthenticationSuccessHandler + extends SimpleUrlAuthenticationSuccessHandler + implements AuthenticationSuccessHandler { + + @Override + public void onAuthenticationSuccess(HttpServletRequest request, + HttpServletResponse response, + Authentication authentication) throws IOException { + + String targetUrl = determineTargetUrl(authentication); + + if (response.isCommitted()) { + logger.debug("Response already committed"); + return; + } + + getRedirectStrategy().sendRedirect(request, response, targetUrl); + } + + protected String determineTargetUrl(Authentication authentication) { + boolean isAdmin = authentication.getAuthorities().stream() + .anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN")); + + return isAdmin ? "/admin/dashboard" : "/dashboard"; + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/handler.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/handler.java new file mode 100644 index 000000000..1ad8b4a60 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/handler.java @@ -0,0 +1,4 @@ +package com.jydoc.deliverable4.security.handlers; + +public class handler { +} diff --git a/Sprint 2/prototype2/src/main/resources/application.properties b/Sprint 2/prototype2/src/main/resources/application.properties index e6053cfdd..49a769f17 100644 --- a/Sprint 2/prototype2/src/main/resources/application.properties +++ b/Sprint 2/prototype2/src/main/resources/application.properties @@ -20,7 +20,7 @@ spring.datasource.hikari.connection-timeout=30000 # JPA/Hibernate Settings # ====================== # spring.jpa.hibernate.ddl-auto=validate # Changed from create-drop for safety TODO: Revert to this for production -spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true @@ -66,4 +66,14 @@ spring.thymeleaf.suffix=.html # spring.jpa.hibernate.ddl-auto=validate # spring.session.jdbc.initialize-schema=never # spring.datasource.tomcat.test-on-borrow=true -# spring.datasource.tomcat.validation-query=SELECT 1 \ No newline at end of file +# spring.datasource.tomcat.validation-query=SELECT 1 +# Set root logging level +# Set specific package logging level +logging.level.com.jydoc.deliverable4.controllers=DEBUG +logging.level.org.springframework.web=INFO +# Console logging pattern +logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n +# File logging (optional) +logging.file.name=application.log +logging.logback.rollingpolicy.max-file-size=10MB +logging.logback.rollingpolicy.max-history=7 \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/register.html b/Sprint 2/prototype2/src/main/resources/templates/register.html index f0f453f26..79daa15fa 100644 --- a/Sprint 2/prototype2/src/main/resources/templates/register.html +++ b/Sprint 2/prototype2/src/main/resources/templates/register.html @@ -3,69 +3,52 @@ Register - -
    -

    Register

    - +
    + Registration failed. Please check your details. +
    +
    - +
    + + + +
    + +
    + + + +
    +
    - +
    -
    - +
    -
    - - + +
    -
    -

    Already have an account? Login here

    diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java index ddb604692..88a80b342 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java @@ -8,6 +8,7 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.test.context.ActiveProfiles; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -279,13 +280,19 @@ void shouldReturnCorrectPassword() { @Test @DisplayName("Should return correct authorities") void shouldReturnCorrectAuthorities() { + // Setup CustomUserDetails userDetails = new CustomUserDetails( USER_ID, USERNAME, PASSWORD, true, true, true, true, AUTHORITIES ); - assertEquals(AUTHORITIES, userDetails.getAuthorities()); + // Verify + Collection authorities = userDetails.getAuthorities(); + + assertEquals(1, authorities.size()); + GrantedAuthority authority = authorities.iterator().next(); + assertEquals("ROLE_USER", authority.getAuthority()); } } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java index 238616483..5407b887b 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserModelTest.java @@ -39,6 +39,8 @@ void testUserEntityPersistence() { .username("testuser") .password("encodedPassword") .email("test@example.com") + .firstName("Test") // Added + .lastName("User") // Added .build(); // When @@ -52,6 +54,8 @@ void testUserEntityPersistence() { assertEquals("testuser", found.getUsername()); assertEquals("encodedPassword", found.getPassword()); assertEquals("test@example.com", found.getEmail()); + assertEquals("Test", found.getFirstName()); // Added + assertEquals("User", found.getLastName()); // Added } @Test @@ -61,6 +65,8 @@ void testUsernameUniquenessConstraint() { UserModel user1 = UserModel.builder() .username("uniqueuser") .password("password1") + .firstName("Unique") // Added + .lastName("User") // Added .build(); entityManager.persist(user1); }); @@ -71,6 +77,8 @@ void testUsernameUniquenessConstraint() { UserModel user2 = UserModel.builder() .username("uniqueuser") .password("password2") + .firstName("Unique2") // Added + .lastName("User2") // Added .build(); entityManager.persist(user2); entityManager.flush(); // Explicit flush to force immediate constraint check @@ -86,6 +94,8 @@ void testEmailUniquenessConstraint() { .username("user1") .password("password1") .email("unique@example.com") + .firstName("User1") // Added + .lastName("One") // Added .build(); entityManager.persist(user1); }); @@ -97,8 +107,11 @@ void testEmailUniquenessConstraint() { .username("user2") .password("password2") .email("unique@example.com") + .firstName("User2") // Added + .lastName("Two") // Added .build(); entityManager.persist(user2); + entityManager.flush(); // Explicit flush }); }); } @@ -110,7 +123,9 @@ void testOptionalEmailField() { UserModel user = UserModel.builder() .username("noemail") .password("password") - .email(null) + .email(null) // Email is optional + .firstName("No") // Added + .lastName("Email") // Added .build(); // When @@ -129,6 +144,8 @@ void testDefaultSecurityFlags() { UserModel user = UserModel.builder() .username("defaultuser") .password("password") + .firstName("Default") // Added + .lastName("User") // Added .build(); assertAll( @@ -147,6 +164,8 @@ void testFieldLengthConstraints() { UserModel user = UserModel.builder() .username("a".repeat(51)) .password("password") + .firstName("Length") // Added + .lastName("Test") // Added .build(); entityManager.persist(user); entityManager.flush(); @@ -157,6 +176,8 @@ void testFieldLengthConstraints() { UserModel user = UserModel.builder() .username("lengthuser") .password("a".repeat(101)) + .firstName("Length") // Added + .lastName("Test") // Added .build(); entityManager.persist(user); entityManager.flush(); @@ -168,6 +189,32 @@ void testFieldLengthConstraints() { .username("emailuser") .password("password") .email("a".repeat(90) + "@example.com") // > 100 chars + .firstName("Email") // Added + .lastName("Test") // Added + .build(); + entityManager.persist(user); + entityManager.flush(); + }); + + // Test firstName max length (50) + assertThrows(Exception.class, () -> { + UserModel user = UserModel.builder() + .username("firstuser") + .password("password") + .firstName("a".repeat(51)) // Added + .lastName("Test") // Added + .build(); + entityManager.persist(user); + entityManager.flush(); + }); + + // Test lastName max length (50) + assertThrows(Exception.class, () -> { + UserModel user = UserModel.builder() + .username("lastuser") + .password("password") + .firstName("Test") // Added + .lastName("a".repeat(51)) // Added .build(); entityManager.persist(user); entityManager.flush(); @@ -181,6 +228,8 @@ void testBuilderPattern() { .username("builderuser") .password("password") .email("builder@example.com") + .firstName("Builder") // Added + .lastName("User") // Added .enabled(false) .accountNonExpired(false) .credentialsNonExpired(false) @@ -192,6 +241,8 @@ void testBuilderPattern() { () -> assertEquals("builderuser", user.getUsername()), () -> assertEquals("password", user.getPassword()), () -> assertEquals("builder@example.com", user.getEmail()), + () -> assertEquals("Builder", user.getFirstName()), // Added + () -> assertEquals("User", user.getLastName()), // Added () -> assertFalse(user.isEnabled()), () -> assertFalse(user.isAccountNonExpired()), () -> assertFalse(user.isCredentialsNonExpired()), @@ -205,6 +256,8 @@ void testToBuilder() { UserModel original = UserModel.builder() .username("original") .password("password") + .firstName("Original") // Added + .lastName("User") // Added .build(); // When @@ -218,7 +271,35 @@ void testToBuilder() { () -> assertEquals("original", original.getUsername()), () -> assertTrue(original.isEnabled()), () -> assertEquals("modified", modified.getUsername()), - () -> assertFalse(modified.isEnabled()) + () -> assertFalse(modified.isEnabled()), + () -> assertEquals("Original", modified.getFirstName()), // Added + () -> assertEquals("User", modified.getLastName()) // Added ); } + + @Test + @Transactional + void testFirstNameAndLastNameNotNull() { + // Test missing firstName + assertThrows(Exception.class, () -> { + UserModel user = UserModel.builder() + .username("nofirst") + .password("password") + .lastName("User") // Only lastName + .build(); + entityManager.persist(user); + entityManager.flush(); + }); + + // Test missing lastName + assertThrows(Exception.class, () -> { + UserModel user = UserModel.builder() + .username("nolast") + .password("password") + .firstName("No") // Only firstName + .build(); + entityManager.persist(user); + entityManager.flush(); + }); + } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserRepositoryTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserRepositoryTest.java index b4c70ed76..40b4cbd1b 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserRepositoryTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserRepositoryTest.java @@ -39,6 +39,8 @@ void setUp() { .username("testuser") .password("password") .email("test@example.com") + .firstName("Test") // Added + .lastName("User") // Added .accountNonExpired(true) .accountNonLocked(true) .credentialsNonExpired(true) @@ -55,6 +57,8 @@ void whenFindById_thenReturnUser() { Optional foundUser = userRepository.findById(testUser.getId()); assertTrue(foundUser.isPresent()); assertEquals(testUser.getUsername(), foundUser.get().getUsername()); + assertEquals("Test", foundUser.get().getFirstName()); // Added + assertEquals("User", foundUser.get().getLastName()); // Added } @Test @@ -63,11 +67,15 @@ void whenSaveNewUser_thenUserIsPersisted() { .username("newuser") .password("newpass") .email("new@example.com") + .firstName("New") // Added + .lastName("User") // Added .build(); UserModel savedUser = userRepository.save(newUser); assertNotNull(savedUser.getId()); assertEquals(newUser.getUsername(), savedUser.getUsername()); + assertEquals("New", savedUser.getFirstName()); // Added + assertEquals("User", savedUser.getLastName()); // Added } // Unique constraint tests @@ -77,6 +85,8 @@ void whenSaveDuplicateUsername_thenThrowException() { .username("testuser") // duplicate username .password("password") .email("different@example.com") + .firstName("Diff") // Added + .lastName("User") // Added .build(); assertThrows(DataIntegrityViolationException.class, () -> { @@ -90,6 +100,8 @@ void whenSaveDuplicateEmail_thenThrowException() { .username("differentuser") .password("password") .email("test@example.com") // duplicate email + .firstName("Diff") // Added + .lastName("User") // Added .build(); assertThrows(DataIntegrityViolationException.class, () -> { @@ -103,6 +115,8 @@ void whenFindByUsername_thenReturnUser() { Optional foundUser = userRepository.findByUsername("testuser"); assertTrue(foundUser.isPresent()); assertEquals(testUser.getEmail(), foundUser.get().getEmail()); + assertEquals("Test", foundUser.get().getFirstName()); // Added + assertEquals("User", foundUser.get().getLastName()); // Added } @Test @@ -130,6 +144,8 @@ void whenFindByUsernameWithAuthorities_thenReturnUserWithAuthorities() { assertTrue(foundUser.isPresent()); assertFalse(foundUser.get().getAuthorities().isEmpty()); assertEquals("ROLE_USER", foundUser.get().getAuthorities().iterator().next().getAuthority()); + assertEquals("Test", foundUser.get().getFirstName()); // Added + assertEquals("User", foundUser.get().getLastName()); // Added } @Test @@ -137,14 +153,17 @@ void whenFindByUsernameOrEmail_thenReturnUser() { // Test with username Optional byUsername = userRepository.findByUsernameOrEmail("testuser"); assertTrue(byUsername.isPresent()); + assertEquals("Test", byUsername.get().getFirstName()); // Added // Test with email Optional byEmail = userRepository.findByUsernameOrEmail("test@example.com"); assertTrue(byEmail.isPresent()); + assertEquals("Test", byEmail.get().getFirstName()); // Added // Test case insensitivity Optional byUpperCase = userRepository.findByUsernameOrEmail("TESTUSER"); assertTrue(byUpperCase.isPresent()); + assertEquals("Test", byUpperCase.get().getFirstName()); // Added } @Test @@ -152,6 +171,7 @@ void whenFindByUsernameOrEmailWithAuthorities_thenReturnUserWithAuthorities() { Optional foundUser = userRepository.findByUsernameOrEmailWithAuthorities("testuser"); assertTrue(foundUser.isPresent()); assertFalse(foundUser.get().getAuthorities().isEmpty()); + assertEquals("Test", foundUser.get().getFirstName()); // Added } @Test @@ -177,4 +197,31 @@ void whenFindByEmptyUsername_thenReturnEmpty() { Optional foundUser = userRepository.findByUsername(""); assertFalse(foundUser.isPresent()); } + + @Test + void whenSaveUserWithoutFirstNameOrLastName_thenThrowException() { + // Missing firstName + UserModel noFirstName = UserModel.builder() + .username("nofirst") + .password("password") + .email("nofirst@example.com") + .lastName("User") // Only lastName + .build(); + + assertThrows(DataIntegrityViolationException.class, () -> { + userRepository.saveAndFlush(noFirstName); + }); + + // Missing lastName + UserModel noLastName = UserModel.builder() + .username("nolast") + .password("password") + .email("nolast@example.com") + .firstName("No") // Only firstName + .build(); + + assertThrows(DataIntegrityViolationException.class, () -> { + userRepository.saveAndFlush(noLastName); + }); + } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java index 81b18ac35..f82e54efa 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java @@ -11,16 +11,10 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication.BadCredentialsException; -import org.springframework.security.authentication.DisabledException; -import org.springframework.security.authentication.LockedException; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; import org.springframework.security.crypto.password.PasswordEncoder; import java.util.HashSet; @@ -64,20 +58,29 @@ void setUp() { testUserDto.setUsername("testuser"); testUserDto.setEmail("test@example.com"); testUserDto.setPassword("Password123!"); + testUserDto.setFirstName("Test"); // Added + testUserDto.setLastName("User"); // Added testLoginDto = new LoginDTO("testuser", "Password123!"); - testUser = new UserModel(); - testUser.setUsername("testuser"); - testUser.setEmail("test@example.com"); - testUser.setPassword("encodedPassword"); - testUser.setEnabled(true); - testUser.setAuthorities(new HashSet<>()); + testUser = UserModel.builder() + .username("testuser") + .email("test@example.com") + .firstName("Test") + .lastName("User") + .password("encodedPassword") + .enabled(true) + .accountNonExpired(true) + .credentialsNonExpired(true) + .accountNonLocked(true) + .authorities(new HashSet<>()) + .build(); testAuthority = AuthorityModel.builder() .authority("ROLE_USER") .users(new HashSet<>()) .build(); + testUser.addAuthority(testAuthority); // Ensure testUser has the authority } // ---------------------- Registration Tests ---------------------- @@ -85,9 +88,9 @@ void setUp() { @Test void registerNewUser_ValidUser_Success() { // Arrange - when(userRepository.existsByUsername(anyString())).thenReturn(false); - when(userRepository.existsByEmail(anyString())).thenReturn(false); - when(passwordEncoder.encode(anyString())).thenReturn("encodedPassword"); + when(userRepository.existsByUsername("testuser")).thenReturn(false); + when(userRepository.existsByEmail("test@example.com")).thenReturn(false); + when(passwordEncoder.encode("Password123!")).thenReturn("encodedPassword"); when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.of(testAuthority)); when(userRepository.save(any(UserModel.class))).thenReturn(testUser); @@ -95,16 +98,12 @@ void registerNewUser_ValidUser_Success() { userService.registerNewUser(testUserDto); // Assert - // Verify validation was called verify(validationHelper).validateUserRegistration(testUserDto); - - // Verify repository interactions verify(userRepository).existsByUsername("testuser"); verify(userRepository).existsByEmail("test@example.com"); - verify(userRepository).save(any(UserModel.class)); - - // Verify authority assignment + verify(passwordEncoder).encode("Password123!"); verify(authorityRepository).findByAuthority("ROLE_USER"); + verify(userRepository).save(any(UserModel.class)); } @Test From b271ce4e9f32a1d655bed4c54461152d1a41d37f Mon Sep 17 00:00:00 2001 From: bihiy Date: Sat, 29 Mar 2025 12:23:50 -0400 Subject: [PATCH 069/100] Documentation added --- .../Initializers/AuthorityInitializer.java | 49 +++- .../deliverable4/Service/UserService.java | 245 ++++++++++++------ .../deliverable4/config/SecurityConfig.java | 210 +++++++++++---- .../controllers/AdminController.java | 168 ------------ .../controllers/AuthController.java | 133 ++++++---- .../jydoc/deliverable4/model/UserModel.java | 128 ++++++++- .../CustomAuthenticationSuccessHandler.java | 64 ++++- .../security/handlers/handler.java | 4 - .../deliverable4/CustomUserDetailsTest.java | 36 ++- .../jydoc/deliverable4/UserServiceTest.java | 12 +- 10 files changed, 671 insertions(+), 378 deletions(-) delete mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/handler.java diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java index c907e605e..dd83eb554 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java @@ -10,12 +10,34 @@ import java.util.Set; /** - * Component responsible for initializing default authorities in the system. + * Component responsible for initializing default system authorities during application startup. + * + *

    This initializer ensures that essential role-based authorities exist in the system + * before the application becomes fully operational. The initialization occurs automatically + * after dependency injection is complete.

    + * + *

    Key features:

    + *
      + *
    • Transactional initialization to maintain data consistency
    • + *
    • Idempotent operations - won't duplicate existing authorities
    • + *
    • Predefined set of standard authorities
    • + *
    • Lazy creation of missing authorities
    • + *
    */ @Component @RequiredArgsConstructor public class AuthorityInitializer { + /** + * Default system authorities that will be created if they don't exist. + * + *

    Contains the standard role-based authorities used throughout the application:

    + *
      + *
    • ROLE_USER - Basic authenticated user privileges
    • + *
    • ROLE_ADMIN - Full administrative privileges
    • + *
    • ROLE_MODERATOR - Content moderation privileges
    • + *
    + */ private static final Set DEFAULT_AUTHORITIES = Set.of( "ROLE_USER", "ROLE_ADMIN", @@ -25,7 +47,15 @@ public class AuthorityInitializer { private final AuthorityRepository authorityRepository; /** - * Initializes default authorities if they don't exist. + * Initializes default authorities during application startup. + * + *

    This method runs automatically after the bean is constructed and performs:

    + *
      + *
    1. Iteration through all default authorities
    2. + *
    3. Conditional creation of each authority if it doesn't exist
    4. + *
    + * + *

    The operation is transactional, ensuring all authorities are created atomically.

    */ @PostConstruct @Transactional @@ -34,10 +64,19 @@ public void initializeDefaultAuthorities() { } /** - * Creates an authority if it doesn't already exist. - * @param authorityName the name of the authority to create + * Creates an authority in the system if it doesn't already exist. + * + *

    This method implements an idempotent create operation that:

    + *
      + *
    1. Checks for authority existence
    2. + *
    3. Only creates new authority if no matching record exists
    4. + *
    5. Returns the existing authority if found
    6. + *
    + * + * @param authorityName the name of the authority to create (e.g., "ROLE_ADMIN") + * @return the existing or newly created authority */ - public void createAuthorityIfNotExists(String authorityName) { + private void createAuthorityIfNotExists(String authorityName) { authorityRepository.findByAuthority(authorityName) .orElseGet(() -> { AuthorityModel authority = new AuthorityModel(); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java index 47f6584d0..c27d4ba97 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java @@ -30,11 +30,14 @@ * *

    This service handles:

    *
      - *
    • User registration with validation
    • - *
    • User authentication via multiple methods
    • - *
    • User management operations (CRUD)
    • - *
    • Role assignment for users
    • + *
    • User registration with comprehensive validation
    • + *
    • Multiple authentication methods (Spring Security and direct validation)
    • + *
    • Complete user lifecycle management (CRUD operations)
    • + *
    • Role assignment and management
    • + *
    • Account status tracking (enabled/disabled, locked/unlocked)
    • *
    + * + *

    Transactions are properly managed with appropriate propagation levels.

    */ @Service @RequiredArgsConstructor @@ -46,30 +49,35 @@ public class UserService { */ private static final String DEFAULT_ROLE = "ROLE_USER"; - // Dependencies injected via Lombok's @RequiredArgsConstructor + // Injected dependencies private final UserValidationHelper validationHelper; private final UserRepository userRepository; private final AuthorityRepository authorityRepository; private final PasswordEncoder passwordEncoder; private final AuthenticationManager authenticationManager; + /* ======================== Public API Methods ======================== */ + /** - * Registers a new user after performing validation checks. + * Registers a new user after performing comprehensive validation checks. * *

    Validation includes:

    *
      *
    • Null checks for all required fields
    • *
    • Empty string validation
    • + *
    • Format validation for email
    • *
    • Duplicate username/email checks
    • + *
    • Password complexity requirements
    • *
    * * @param userDto Data Transfer Object containing user registration information * @throws IllegalArgumentException if any validation fails + * @throws UsernameExistsException if username already exists + * @throws EmailExistsException if email already registered */ @Transactional public void registerNewUser(UserDTO userDto) { validationHelper.validateUserRegistration(userDto); - validateUserDto(userDto); checkForExistingCredentials(userDto); @@ -83,7 +91,7 @@ public void registerNewUser(UserDTO userDto) { * @param loginDto Contains username and password for authentication * @return Authenticated UserModel * @throws IllegalArgumentException if loginDto is null - * @throws AuthenticationException if authentication fails + * @throws AuthenticationException if authentication fails for any reason */ @Transactional(readOnly = true) public UserModel authenticate(LoginDTO loginDto) { @@ -94,14 +102,19 @@ public UserModel authenticate(LoginDTO loginDto) { } /** - * Validates user credentials against the database (alternative to Spring Security auth). + * Validates user credentials directly against the database (alternative to Spring Security auth). * * @param loginDto Contains credentials for validation * @return Validated UserModel + * @throws IllegalArgumentException if loginDto is null * @throws AuthenticationException if credentials are invalid or account is disabled */ @Transactional(readOnly = true) public UserModel validateLogin(LoginDTO loginDto) { + if (loginDto == null) { + throw new IllegalArgumentException("Login credentials cannot be null"); + } + String credential = loginDto.username().trim().toLowerCase(); String rawPassword = loginDto.password(); @@ -115,6 +128,84 @@ public UserModel validateLogin(LoginDTO loginDto) { return user; } + /* ======================== User Management Methods ======================== */ + + /** + * Finds an active user by username or email. + * + * @param usernameOrEmail The username or email to search for + * @return Optional containing the user if found and active, empty otherwise + */ + @Transactional(readOnly = true) + public Optional findActiveUser(String usernameOrEmail) { + return userRepository.findByUsernameOrEmail(usernameOrEmail.trim().toLowerCase()) + .filter(UserModel::isEnabled); + } + + /** + * Gets the total count of users in the system. + * + * @return The number of users in the system + */ + @Transactional(readOnly = true) + public long getUserCount() { + return userRepository.count(); + } + + /** + * Checks if a user exists with the given ID. + * + * @param id The user ID to check + * @return true if user exists, false otherwise + */ + @Transactional(readOnly = true) + public boolean existsById(Long id) { + return userRepository.existsById(id); + } + + /** + * Retrieves all users in the system. + * + * @return List of all users + */ + @Transactional(readOnly = true) + public List getAllUsers() { + return userRepository.findAll(); + } + + /** + * Finds a user by their ID. + * + * @param id The user ID to find + * @return Optional containing the user if found, empty otherwise + */ + @Transactional(readOnly = true) + public Optional getUserById(Long id) { + return userRepository.findById(id); + } + + /** + * Updates an existing user. + * + * @param user The user to update + */ + @Transactional + public void updateUser(UserModel user) { + userRepository.save(user); + } + + /** + * Deletes a user by ID. + * + * @param id The ID of the user to delete + */ + @Transactional + public void deleteUser(Long id) { + userRepository.deleteById(id); + } + + /* ======================== Authentication Methods ======================== */ + /** * Authenticates user credentials using Spring Security's authentication mechanisms. * @@ -138,42 +229,58 @@ public UserModel authenticateUser(String username, String password) { handleAuthenticationFailure("Authentication failed - locked account: {}", username, "Account is locked"); } - return null; // This line is unreachable due to handleAuthenticationFailure throwing exception + return null; // Unreachable due to exception handling } - /* ================ Private Helper Methods ================ */ + /* ======================== Private Helper Methods ======================== */ /** * Validates the basic structure of the UserDTO. + * + * @param userDto The UserDTO to validate + * @throws IllegalArgumentException if any required field is null or empty */ private void validateUserDto(UserDTO userDto) { - if (userDto == null) throw new IllegalArgumentException("UserDTO cannot be null"); - if (userDto.getUsername() == null || userDto.getUsername().trim().isEmpty()) + if (userDto == null) { + throw new IllegalArgumentException("UserDTO cannot be null"); + } + if (userDto.getUsername() == null || userDto.getUsername().trim().isEmpty()) { throw new IllegalArgumentException("Username cannot be empty"); - if (userDto.getPassword() == null || userDto.getPassword().trim().isEmpty()) + } + if (userDto.getPassword() == null || userDto.getPassword().trim().isEmpty()) { throw new IllegalArgumentException("Password cannot be empty"); - if (userDto.getEmail() == null || userDto.getEmail().trim().isEmpty()) + } + if (userDto.getEmail() == null || userDto.getEmail().trim().isEmpty()) { throw new IllegalArgumentException("Email cannot be empty"); - if (userDto.getFirstName() == null || userDto.getFirstName().trim().isEmpty()) + } + if (userDto.getFirstName() == null || userDto.getFirstName().trim().isEmpty()) { throw new IllegalArgumentException("First name cannot be empty"); - if (userDto.getLastName() == null || userDto.getLastName().trim().isEmpty()) + } + if (userDto.getLastName() == null || userDto.getLastName().trim().isEmpty()) { throw new IllegalArgumentException("Last name cannot be empty"); + } } /** * Checks for existing username or email in the system. + * + * @param userDto The UserDTO containing credentials to check + * @throws UsernameExistsException if username already exists + * @throws EmailExistsException if email already registered */ private void checkForExistingCredentials(UserDTO userDto) { if (userRepository.existsByUsername(userDto.getUsername())) { - throw new IllegalArgumentException("Username already exists"); + throw new UsernameExistsException(userDto.getUsername()); } if (userRepository.existsByEmail(userDto.getEmail())) { - throw new IllegalArgumentException("Email already registered"); + throw new EmailExistsException(userDto.getEmail()); } } /** * Creates and persists a new user with encoded password and default role. + * + * @param user The user to persist */ private void persistUser(UserModel user) { assignDefaultRole(user); @@ -183,14 +290,17 @@ private void persistUser(UserModel user) { /** * Constructs a UserModel from DTO with proper formatting and password encoding. + * + * @param userDto The source UserDTO + * @return Fully constructed UserModel */ private UserModel createUserFromDto(UserDTO userDto) { return UserModel.builder() .username(userDto.getUsername().trim()) .password(passwordEncoder.encode(userDto.getPassword())) .email(userDto.getEmail().toLowerCase().trim()) - .firstName(userDto.getFirstName().trim()) // Added - .lastName(userDto.getLastName().trim()) // Added + .firstName(userDto.getFirstName().trim()) + .lastName(userDto.getLastName().trim()) .enabled(true) .accountNonExpired(true) .credentialsNonExpired(true) @@ -200,6 +310,10 @@ private UserModel createUserFromDto(UserDTO userDto) { /** * Finds user by username or email credential. + * + * @param credential The username or email to search for + * @return Found UserModel + * @throws AuthenticationException if user not found */ private UserModel findUserByCredential(String credential) { return userRepository.findByUsernameOrEmail(credential) @@ -211,6 +325,10 @@ private UserModel findUserByCredential(String credential) { /** * Validates that the provided password matches the user's stored password. + * + * @param user The user to validate + * @param rawPassword The password to check + * @throws AuthenticationException if passwords don't match */ private void validateUserPassword(UserModel user, String rawPassword) { if (!passwordEncoder.matches(rawPassword, user.getPassword())) { @@ -221,6 +339,9 @@ private void validateUserPassword(UserModel user, String rawPassword) { /** * Verifies that the user account is enabled. + * + * @param user The user to check + * @throws AuthenticationException if account is disabled */ private void checkAccountEnabled(UserModel user) { if (!user.isEnabled()) { @@ -231,6 +352,10 @@ private void checkAccountEnabled(UserModel user) { /** * Performs Spring Security authentication. + * + * @param username The username to authenticate + * @param password The password to verify + * @return Authentication object */ private Authentication performSpringAuthentication(String username, String password) { return authenticationManager.authenticate( @@ -240,6 +365,10 @@ private Authentication performSpringAuthentication(String username, String passw /** * Retrieves user after successful Spring authentication. + * + * @param username The username to find + * @return Found UserModel + * @throws AuthenticationException if user not found (shouldn't happen after successful auth) */ private UserModel findAuthenticatedUser(String username) { return userRepository.findByUsername(username) @@ -251,6 +380,11 @@ private UserModel findAuthenticatedUser(String username) { /** * Handles authentication failures consistently. + * + * @param logMessage The log message template + * @param username The username that failed authentication + * @param exceptionMessage The exception message to throw + * @throws AuthenticationException always */ private void handleAuthenticationFailure(String logMessage, String username, String exceptionMessage) { logger.warn(logMessage, username); @@ -259,16 +393,20 @@ private void handleAuthenticationFailure(String logMessage, String username, Str /** * Assigns the default role to a user (must be called within a transaction). + * + * @param user The user to assign the role to */ @Transactional(propagation = Propagation.MANDATORY) protected void assignDefaultRole(UserModel user) { AuthorityModel authority = authorityRepository.findByAuthority(DEFAULT_ROLE) - .orElseGet(() -> createAndSaveNewAuthority()); + .orElseGet(this::createAndSaveNewAuthority); user.addAuthority(authority); } /** * Creates and persists a new authority role. + * + * @return The newly created AuthorityModel */ private AuthorityModel createAndSaveNewAuthority() { AuthorityModel newRole = new AuthorityModel(DEFAULT_ROLE); @@ -276,69 +414,10 @@ private AuthorityModel createAndSaveNewAuthority() { return authorityRepository.save(newRole); } - /* ================ User Management Methods ================ */ - - /** - * Finds an active user by username or email. - */ - @Transactional(readOnly = true) - public Optional findActiveUser(String usernameOrEmail) { - return userRepository.findByUsernameOrEmail(usernameOrEmail.trim().toLowerCase()) - .filter(UserModel::isEnabled); - } - - /** - * Gets the total count of users in the system. - */ - @Transactional(readOnly = true) - public long getUserCount() { - return userRepository.count(); - } - - /** - * Checks if a user exists with the given ID. - */ - @Transactional(readOnly = true) - public boolean existsById(Long id) { - return userRepository.existsById(id); - } - - /** - * Retrieves all users in the system. - */ - @Transactional(readOnly = true) - public List getAllUsers() { - return userRepository.findAll(); - } - - /** - * Finds a user by their ID. - */ - @Transactional(readOnly = true) - public Optional getUserById(Long id) { - return userRepository.findById(id); - } - - /** - * Updates an existing user. - */ - @Transactional - public void updateUser(UserModel user) { - userRepository.save(user); - } - - /** - * Deletes a user by ID. - */ - @Transactional - public void deleteUser(Long id) { - userRepository.deleteById(id); - } - - /* ================ Custom Exceptions ================ */ + /* ======================== Custom Exceptions ======================== */ /** - * Exception thrown when authentication fails. + * Exception thrown when authentication fails for any reason. */ public static class AuthenticationException extends RuntimeException { public AuthenticationException(String message) { diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java index 91cfbffb9..ce588068d 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java @@ -17,11 +17,30 @@ import org.springframework.security.web.header.writers.XXssProtectionHeaderWriter; import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession; +/** + * Security configuration class that defines the application's security policies. + * This includes authentication, authorization, session management, CSRF protection, + * and security headers configuration. + * + *

    The configuration enables: + *

      + *
    • JDBC-based HTTP session management
    • + *
    • Form-based authentication with custom success handler
    • + *
    • Role-based authorization
    • + *
    • Secure session management
    • + *
    • CSRF protection with cookie storage
    • + *
    • Security headers including XSS protection and CSP
    • + *
    + */ @Configuration @EnableWebSecurity @EnableJdbcHttpSession public class SecurityConfig { + /** + * Public endpoints that don't require authentication. + * These include static resources, public APIs, and authentication-related pages. + */ private static final String[] PUBLIC_ENDPOINTS = { "/", "/home", @@ -37,73 +56,172 @@ public class SecurityConfig { private final CustomUserDetailsService userDetailsService; + /** + * Constructs a new SecurityConfig with the required UserDetailsService. + * + * @param userDetailsService the custom user details service for authentication + */ public SecurityConfig(CustomUserDetailsService userDetailsService) { this.userDetailsService = userDetailsService; } + /** + * Configures the security filter chain that defines all security policies. + * + * @param http the HttpSecurity to configure + * @return the configured SecurityFilterChain + * @throws Exception if an error occurs during configuration + */ @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { - http - .authorizeHttpRequests(auth -> auth - .requestMatchers(PUBLIC_ENDPOINTS).permitAll() - .requestMatchers("/admin/**").hasRole("ADMIN") - .anyRequest().authenticated() - ) - .formLogin(form -> form - .loginPage("/login") - .loginProcessingUrl("/perform_login") - .successHandler(authenticationSuccessHandler()) - .failureUrl("/login?error=true") - .usernameParameter("username") - .passwordParameter("password") - .permitAll() - ) - .logout(logout -> logout - .logoutUrl("/perform_logout") - .logoutSuccessUrl("/login?logout") - .deleteCookies("JSESSIONID", "XSRF-TOKEN") - .invalidateHttpSession(true) - .clearAuthentication(true) - .permitAll() - ) - .sessionManagement(session -> session - .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) - .invalidSessionUrl("/login?invalid-session") - .maximumSessions(1) - .maxSessionsPreventsLogin(false) - .expiredUrl("/login?session-expired") - ) - .exceptionHandling(exceptions -> exceptions - .accessDeniedPage("/access-denied") - ) - .csrf(csrf -> csrf - .ignoringRequestMatchers("/api/**") - .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) - ) - .headers(headers -> headers - .xssProtection(xss -> xss - .headerValue(XXssProtectionHeaderWriter.HeaderValue.ENABLED_MODE_BLOCK) - ) - .contentSecurityPolicy(csp -> csp - .policyDirectives("default-src 'self'; script-src 'self' 'unsafe-inline' cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' cdn.jsdelivr.net; img-src 'self' data:") - ) - .frameOptions(frame -> frame.deny()) - ); + configureAuthorization(http); + configureFormLogin(http); + configureLogout(http); + configureSessionManagement(http); + configureExceptionHandling(http); + configureCsrfProtection(http); + configureSecurityHeaders(http); return http.build(); } + /** + * Configures authorization rules for endpoints. + * + * @param http the HttpSecurity to configure + * @throws Exception if an error occurs during configuration + */ + private void configureAuthorization(HttpSecurity http) throws Exception { + http.authorizeHttpRequests(auth -> auth + .requestMatchers(PUBLIC_ENDPOINTS).permitAll() + .requestMatchers("/admin/**").hasRole("ADMIN") + .anyRequest().authenticated() + ); + } + + /** + * Configures form-based login. + * + * @param http the HttpSecurity to configure + * @throws Exception if an error occurs during configuration + */ + private void configureFormLogin(HttpSecurity http) throws Exception { + http.formLogin(form -> form + .loginPage("/login") + .loginProcessingUrl("/perform_login") + .successHandler(authenticationSuccessHandler()) + .failureUrl("/login?error=true") + .usernameParameter("username") + .passwordParameter("password") + .permitAll() + ); + } + + /** + * Configures logout behavior. + * + * @param http the HttpSecurity to configure + * @throws Exception if an error occurs during configuration + */ + private void configureLogout(HttpSecurity http) throws Exception { + http.logout(logout -> logout + .logoutUrl("/perform_logout") + .logoutSuccessUrl("/login?logout") + .deleteCookies("JSESSIONID", "XSRF-TOKEN") + .invalidateHttpSession(true) + .clearAuthentication(true) + .permitAll() + ); + } + + /** + * Configures session management policies. + * + * @param http the HttpSecurity to configure + * @throws Exception if an error occurs during configuration + */ + private void configureSessionManagement(HttpSecurity http) throws Exception { + http.sessionManagement(session -> session + .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) + .invalidSessionUrl("/login?invalid-session") + .maximumSessions(1) + .maxSessionsPreventsLogin(false) + .expiredUrl("/login?session-expired") + ); + } + + /** + * Configures exception handling for security-related exceptions. + * + * @param http the HttpSecurity to configure + * @throws Exception if an error occurs during configuration + */ + private void configureExceptionHandling(HttpSecurity http) throws Exception { + http.exceptionHandling(exceptions -> exceptions + .accessDeniedPage("/access-denied") + ); + } + + /** + * Configures CSRF protection with exceptions for API endpoints. + * + * @param http the HttpSecurity to configure + * @throws Exception if an error occurs during configuration + */ + private void configureCsrfProtection(HttpSecurity http) throws Exception { + http.csrf(csrf -> csrf + .ignoringRequestMatchers("/api/**") + .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) + ); + } + + /** + * Configures security headers including XSS protection and Content Security Policy. + * + * @param http the HttpSecurity to configure + * @throws Exception if an error occurs during configuration + */ + private void configureSecurityHeaders(HttpSecurity http) throws Exception { + http.headers(headers -> headers + .xssProtection(xss -> xss + .headerValue(XXssProtectionHeaderWriter.HeaderValue.ENABLED_MODE_BLOCK) + ) + .contentSecurityPolicy(csp -> csp + .policyDirectives("default-src 'self'; script-src 'self' 'unsafe-inline' cdn.jsdelivr.net; " + + "style-src 'self' 'unsafe-inline' cdn.jsdelivr.net; img-src 'self' data:") + ) + .frameOptions(frame -> frame.deny()) + ); + } + + /** + * Provides a custom authentication success handler bean. + * + * @return the configured AuthenticationSuccessHandler + */ @Bean public AuthenticationSuccessHandler authenticationSuccessHandler() { return new CustomAuthenticationSuccessHandler(); } + /** + * Provides the AuthenticationManager bean. + * + * @param authenticationConfiguration the authentication configuration + * @return the configured AuthenticationManager + * @throws Exception if an error occurs during configuration + */ @Bean public AuthenticationManager authenticationManager( AuthenticationConfiguration authenticationConfiguration) throws Exception { return authenticationConfiguration.getAuthenticationManager(); } + /** + * Provides the password encoder bean using BCrypt hashing. + * + * @return the configured PasswordEncoder + */ @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java index 6041bfff3..e69de29bb 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java @@ -1,168 +0,0 @@ -package com.jydoc.deliverable4.controllers; - -import com.jydoc.deliverable4.model.UserModel; -import com.jydoc.deliverable4.Service.UserService; -import com.jydoc.deliverable4.security.Exceptions.UserNotFoundException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.mvc.support.RedirectAttributes; - -import javax.validation.Valid; -import java.util.List; - -/** - * Controller for handling administrative operations. - * Provides endpoints for user management, system settings, and activity logs. - * Requires ADMIN role for all operations. - */ -@Controller -@RequestMapping("/admin") -@PreAuthorize("hasRole('ROLE_ADMIN')") -public class AdminController { - - // Constants for view names and attribute keys - private static final String USERS_REDIRECT = "redirect:/admin/users"; - private static final String USER_ATTR = "user"; - private static final String ERROR_ATTR = "error"; - private static final String MESSAGE_ATTR = "message"; - private static final String USERS_ATTR = "users"; - private static final String USER_COUNT_ATTR = "userCount"; - - // View paths - private static final String DASHBOARD_VIEW = "admin/dashboard"; - private static final String USER_LIST_VIEW = "admin/users/list"; - private static final String USER_EDIT_VIEW = "admin/users/edit"; - private static final String SETTINGS_VIEW = "admin/settings"; - private static final String ACTIVITY_LOGS_VIEW = "admin/activity-logs"; - private static final String ERROR_VIEW = "error/user-not-found"; - - private final UserService userService; - - /** - * Constructs an AdminController with the required UserService dependency. - * - * @param userService The service for user-related operations - */ - @Autowired - public AdminController(UserService userService) { - this.userService = userService; - } - - /** - * Displays the admin dashboard with system statistics. - * - * @param model The Spring MVC model to add attributes - * @return The dashboard view name - */ - @GetMapping("/dashboard") - public String adminDashboard(Model model) { - model.addAttribute(USER_COUNT_ATTR, userService.getUserCount()); - return DASHBOARD_VIEW; - } - - /** - * Displays the user management page with a list of all users. - * - * @param model The Spring MVC model to add attributes - * @return The user list view name - */ - @GetMapping("/users") - public String userManagement(Model model) { - List users = userService.getAllUsers(); - model.addAttribute(USERS_ATTR, users); - return USER_LIST_VIEW; - } - - /** - * Displays the user edit form for a specific user. - * - * @param id The ID of the user to edit - * @param model The Spring MVC model to add attributes - * @return The user edit view name - * @throws UserNotFoundException if the user with the given ID doesn't exist - */ - @GetMapping("/users/edit/{id}") - public String editUserForm(@PathVariable Long id, Model model) { - UserModel user = userService.getUserById(id) - .orElseThrow(() -> new UserNotFoundException(id)); - model.addAttribute(USER_ATTR, user); - return USER_EDIT_VIEW; - } - - /** - * Processes user update requests. - * - * @param user The user data to update (validated) - * @param result The binding result for validation errors - * @param redirectAttributes Attributes for the redirect scenario - * @return Redirect to user list if successful, back to edit form if validation fails - */ - @PostMapping("/users/update") - public String updateUser(@Valid @ModelAttribute(USER_ATTR) UserModel user, - BindingResult result, - RedirectAttributes redirectAttributes) { - if (result.hasErrors()) { - return USER_EDIT_VIEW; - } - userService.updateUser(user); - redirectAttributes.addFlashAttribute(MESSAGE_ATTR, "User updated successfully"); - return USERS_REDIRECT; - } - - /** - * Deletes a user with the specified ID. - * - * @param id The ID of the user to delete - * @param redirectAttributes Attributes for the redirect scenario - * @return Redirect to user list - * @throws UserNotFoundException if the user with the given ID doesn't exist - */ - @PostMapping("/users/delete/{id}") - public String deleteUser(@PathVariable Long id, RedirectAttributes redirectAttributes) { - if (!userService.existsById(id)) { - throw new UserNotFoundException(id); - } - userService.deleteUser(id); - redirectAttributes.addFlashAttribute(MESSAGE_ATTR, "User deleted successfully"); - return USERS_REDIRECT; - } - - /** - * Handles UserNotFoundException across all controller methods. - * - * @param ex The exception that was thrown - * @param model The Spring MVC model to add attributes - * @return The error view name - */ - @ExceptionHandler(UserNotFoundException.class) - public String handleUserNotFound(UserNotFoundException ex, Model model) { - model.addAttribute(ERROR_ATTR, ex.getMessage()); - return ERROR_VIEW; - } - - /** - * Displays the system settings page. - * - * @param model The Spring MVC model to add attributes - * @return The settings view name - */ - @GetMapping("/settings") - public String systemSettings(Model model) { - return SETTINGS_VIEW; - } - - /** - * Displays the activity logs page. - * - * @param model The Spring MVC model to add attributes - * @return The activity logs view name - */ - @GetMapping("/activity-logs") - public String viewActivityLogs(Model model) { - return ACTIVITY_LOGS_VIEW; - } -} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java index 3e666409d..626778b25 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java @@ -15,12 +15,20 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; /** - * Controller handling authentication-related operations including: - * - User registration - * - Login/logout functionality - * - Session management + * Controller handling all authentication-related operations including user registration, + * login/logout functionality, and session management. * - * All endpoints return Thymeleaf template names for view resolution. + *

    This controller follows RESTful principles while returning Thymeleaf template names + * for view resolution. It provides endpoints for:

    + *
      + *
    • User registration flow
    • + *
    • Login/logout processes
    • + *
    • Session management
    • + *
    • Home page display
    • + *
    + * + *

    All endpoints include proper validation and error handling with appropriate + * redirects and flash attributes.

    */ @Controller public class AuthController { @@ -29,19 +37,21 @@ public class AuthController { private final UserService userService; /** - * Constructs an AuthController with required UserService dependency - * @param userService Service handling user operations + * Constructs an AuthController with the required UserService dependency. + * + * @param userService the service handling user operations and business logic */ public AuthController(UserService userService) { this.userService = userService; } - // ========== REGISTRATION ENDPOINTS ========== + /* ==================== REGISTRATION ENDPOINTS ==================== */ /** - * Displays user registration form - * @param model Model to add attributes for view - * @return "register" template name + * Displays the user registration form. + * + * @param model the Spring Model to which the empty UserDTO is added + * @return the "register" template name for view resolution */ @GetMapping("/register") public String showRegistrationForm(Model model) { @@ -49,9 +59,18 @@ public String showRegistrationForm(Model model) { return "register"; } + /** + * Processes user registration form submission. + * + * @param userDto the user data transfer object containing registration info + * @param result the binding result for validation errors + * @return redirect to login page on success, or re-show form with errors + */ @PostMapping("/register") - public String registerUser(@Valid @ModelAttribute("user") UserDTO userDto, - BindingResult result) { + public String registerUser( + @Valid @ModelAttribute("user") UserDTO userDto, + BindingResult result) { + if (result.hasErrors()) { logger.debug("Registration validation errors present: {}", result.getAllErrors()); return "register"; @@ -68,21 +87,23 @@ public String registerUser(@Valid @ModelAttribute("user") UserDTO userDto, } } - // ========== LOGIN ENDPOINTS ========== + /* ==================== LOGIN ENDPOINTS ==================== */ /** - * Displays login form with optional status indicators - * @param model Model to add attributes for view - * @param error Optional error flag from redirect - * @param registered Optional registration success flag - * @param logout Optional logout success flag - * @return "login" template name + * Displays the login form with optional status indicators. + * + * @param model the Spring Model for view attributes + * @param error optional flag indicating previous login error + * @param registered optional flag indicating successful registration + * @param logout optional flag indicating successful logout + * @return the "login" template name for view resolution */ @GetMapping("/login") - public String showLoginForm(Model model, - @RequestParam(required = false) String error, - @RequestParam(required = false) String registered, - @RequestParam(required = false) String logout) { + public String showLoginForm( + Model model, + @RequestParam(required = false) String error, + @RequestParam(required = false) String registered, + @RequestParam(required = false) String logout) { model.addAttribute("loginData", LoginDTO.empty()); model.addAttribute("error", error != null); @@ -93,18 +114,20 @@ public String showLoginForm(Model model, } /** - * Processes login form submission - * @param loginDto Login credentials - * @param result Validation result - * @param session HTTP session to store user - * @param redirectAttributes For flash attributes - * @return Redirect to home on success, re-show form on error + * Processes login form submission and authenticates the user. + * + * @param loginDto the login credentials data transfer object + * @param result the binding result for validation errors + * @param session the HTTP session to store authenticated user + * @param redirectAttributes for flash attributes during redirect + * @return redirect to appropriate page based on user role, or re-show form with errors */ @PostMapping("/login") - public String loginUser(@Valid @ModelAttribute("loginData") LoginDTO loginDto, - BindingResult result, - HttpSession session, - RedirectAttributes redirectAttributes) { + public String loginUser( + @Valid @ModelAttribute("loginData") LoginDTO loginDto, + BindingResult result, + HttpSession session, + RedirectAttributes redirectAttributes) { logger.debug("Processing login for: {}", loginDto.username()); @@ -117,14 +140,9 @@ public String loginUser(@Valid @ModelAttribute("loginData") LoginDTO loginDto, UserModel user = userService.validateLogin(loginDto); session.setAttribute("user", user); - // Check if user has admin role - if (isAdmin(user)) { - logger.debug("Redirecting admin to admin dashboard"); - return "redirect:/admin/dashboard"; - } - - logger.debug("Redirecting regular user to home"); - return "redirect:/home"; + return isAdmin(user) + ? "redirect:/admin/dashboard" + : "redirect:/home"; } catch (UserService.AuthenticationException e) { logger.error("Login failed: {}", e.getMessage()); @@ -133,18 +151,25 @@ public String loginUser(@Valid @ModelAttribute("loginData") LoginDTO loginDto, } } + /** + * Checks if the given user has admin privileges. + * + * @param user the user model to check + * @return true if user has admin role, false otherwise + */ private boolean isAdmin(UserModel user) { return user.getAuthorities().stream() .anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN")); } - // ========== HOME ENDPOINT ========== + /* ==================== HOME ENDPOINT ==================== */ /** - * Displays home page for authenticated users - * @param model Model to add attributes for view - * @param session HTTP session containing user - * @return "index" template name + * Displays the home page for authenticated users. + * + * @param model the Spring Model for view attributes + * @param session the HTTP session containing the authenticated user + * @return the "index" template name for view resolution */ @GetMapping("/home") public String showHomePage(Model model, HttpSession session) { @@ -155,11 +180,12 @@ public String showHomePage(Model model, HttpSession session) { return "index"; } - // ========== LOGOUT ENDPOINTS ========== + /* ==================== LOGOUT ENDPOINTS ==================== */ /** - * Displays logout confirmation page - * @return "logout" template name + * Displays the logout confirmation page. + * + * @return the "logout" template name for view resolution */ @GetMapping("/confirm-logout") public String showLogoutConfirmation() { @@ -167,9 +193,10 @@ public String showLogoutConfirmation() { } /** - * Processes logout request - * @param session HTTP session to invalidate - * @return Redirect to login with logout flag + * Processes logout request by invalidating the session. + * + * @param session the HTTP session to invalidate + * @return redirect to login page with logout flag */ @PostMapping("/logout") public String performLogout(HttpSession session) { diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java index f64edca70..3dd1b13f6 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/model/UserModel.java @@ -10,6 +10,28 @@ import java.util.HashSet; import java.util.Set; +/** + * Entity class representing a user in the system. + * + *

    This class maps to the "users" database table and includes:

    + *
      + *
    • Core user credentials (username, password)
    • + *
    • Personal information (name, email)
    • + *
    • Account status flags
    • + *
    • Role-based authorities
    • + *
    + * + *

    Security Features:

    + *
      + *
    • Immutable authority collections to prevent unintended modifications
    • + *
    • Account status tracking (locked, expired, etc.)
    • + *
    • Proper JPA relationship mapping for authorities
    • + *
    + * + * @version 1.2 + * @see AuthorityModel The authority/role entity + * @since 1.0 + */ @Entity @Table(name = "users") @Getter @@ -19,37 +41,119 @@ @Builder(toBuilder = true) public class UserModel { + /** + * Primary key identifier. + */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + /** + * Unique username for authentication. + * + *

    Constraints:

    + *
      + *
    • Database unique constraint
    • + *
    • Non-nullable
    • + *
    • Maximum 50 characters
    • + *
    + */ @Column(unique = true, nullable = false, length = 50) private String username; + /** + * Hashed password for authentication. + * + *

    Constraints:

    + *
      + *
    • Non-nullable
    • + *
    • Maximum 100 characters (to accommodate hashing)
    • + *
    + * + *

    Security Note: Should always be stored hashed

    + */ @Column(nullable = false, length = 100) private String password; + /** + * User's email address. + * + *

    Constraints:

    + *
      + *
    • Database unique constraint
    • + *
    • Maximum 100 characters
    • + *
    + */ @Column(unique = true, length = 100) private String email; - @Column(name = "first_name", nullable = false, length = 50) // Added + /** + * User's first/given name. + * + *

    Constraints:

    + *
      + *
    • Non-nullable
    • + *
    • Maximum 50 characters
    • + *
    + */ + @Column(name = "first_name", nullable = false, length = 50) private String firstName; - @Column(name = "last_name", nullable = false, length = 50) // Added + /** + * User's last/family name. + * + *

    Constraints:

    + *
      + *
    • Non-nullable
    • + *
    • Maximum 50 characters
    • + *
    + */ + @Column(name = "last_name", nullable = false, length = 50) private String lastName; + /** + * Flag indicating if the account is enabled. + * + *

    Default: true (accounts are enabled by default)

    + */ @Builder.Default private boolean enabled = true; + /** + * Flag indicating if the account is non-expired. + * + *

    Default: true (accounts don't expire by default)

    + */ @Builder.Default private boolean accountNonExpired = true; + /** + * Flag indicating if credentials are non-expired. + * + *

    Default: true (credentials don't expire by default)

    + */ @Builder.Default private boolean credentialsNonExpired = true; + /** + * Flag indicating if the account is non-locked. + * + *

    Default: true (accounts aren't locked by default)

    + */ @Builder.Default private boolean accountNonLocked = true; + /** + * Set of authorities/roles granted to the user. + * + *

    Relationship Details:

    + *
      + *
    • Many-to-many with AuthorityModel
    • + *
    • Eager fetching for immediate availability
    • + *
    • Cascade persist and merge operations
    • + *
    • Mapped via join table "user_authorities"
    • + *
    + */ @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @JoinTable( name = "user_authorities", @@ -60,19 +164,39 @@ public class UserModel { @Builder.Default private Set authorities = new HashSet<>(); + /** + * Returns an unmodifiable view of the user's authorities. + * + * @return immutable set of authorities + */ public Set getAuthorities() { return Collections.unmodifiableSet(new HashSet<>(this.authorities)); } + /** + * Replaces all authorities with the given collection. + * + * @param authorities new collection of authorities (null creates empty set) + */ public void setAuthorities(Collection authorities) { this.authorities = authorities != null ? new HashSet<>(authorities) : new HashSet<>(); } + /** + * Adds a single authority to the user. + * + * @param authority the authority to add + */ public void addAuthority(AuthorityModel authority) { this.authorities.add(authority); authority.getUsers().add(this); } + /** + * Removes a single authority from the user. + * + * @param authority the authority to remove + */ public void removeAuthority(AuthorityModel authority) { this.authorities.remove(authority); authority.getUsers().remove(this); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/CustomAuthenticationSuccessHandler.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/CustomAuthenticationSuccessHandler.java index 2ba9865f5..56883ee7b 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/CustomAuthenticationSuccessHandler.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/CustomAuthenticationSuccessHandler.java @@ -9,10 +9,46 @@ import java.io.IOException; +/** + * Custom authentication success handler that determines the redirect target URL + * based on the user's authorities after successful login. + * + *

    This handler extends Spring Security's {@link SimpleUrlAuthenticationSuccessHandler} + * to provide role-based redirection logic:

    + *
      + *
    • Administrators are redirected to the admin dashboard
    • + *
    • Regular users are redirected to the standard dashboard
    • + *
    + * + *

    Security Considerations:

    + *
      + *
    • Ensures proper redirection based on verified authorities
    • + *
    • Handles already-committed responses gracefully
    • + *
    • Follows Spring Security's authentication flow
    • + *
    + */ public class CustomAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler implements AuthenticationSuccessHandler { + /** + * Path for admin dashboard redirect + */ + private static final String ADMIN_DASHBOARD_URL = "/admin/dashboard"; + + /** + * Path for regular user dashboard redirect + */ + private static final String USER_DASHBOARD_URL = "/dashboard"; + + /** + * Handles successful authentication by redirecting to the appropriate target URL. + * + * @param request the HTTP request + * @param response the HTTP response + * @param authentication the authentication object containing user authorities + * @throws IOException if a redirect error occurs + */ @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, @@ -21,17 +57,39 @@ public void onAuthenticationSuccess(HttpServletRequest request, String targetUrl = determineTargetUrl(authentication); if (response.isCommitted()) { - logger.debug("Response already committed"); + logger.debug("Response already committed - unable to redirect to " + targetUrl); return; } getRedirectStrategy().sendRedirect(request, response, targetUrl); } + /** + * Determines the target URL based on the user's authorities. + * + *

    The logic checks for the presence of ROLE_ADMIN authority:

    + *
      + *
    • If present: redirects to admin dashboard
    • + *
    • Otherwise: redirects to regular dashboard
    • + *
    + * + * @param authentication the authentication object containing user authorities + * @return the appropriate target URL + */ protected String determineTargetUrl(Authentication authentication) { boolean isAdmin = authentication.getAuthorities().stream() - .anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN")); + .anyMatch(this::isAdminAuthority); + + return isAdmin ? ADMIN_DASHBOARD_URL : USER_DASHBOARD_URL; + } - return isAdmin ? "/admin/dashboard" : "/dashboard"; + /** + * Checks if a given authority represents an admin role. + * + * @param authority the granted authority to check + * @return true if the authority is ROLE_ADMIN, false otherwise + */ + private boolean isAdminAuthority(GrantedAuthority authority) { + return authority.getAuthority().equals("ROLE_ADMIN"); } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/handler.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/handler.java deleted file mode 100644 index 1ad8b4a60..000000000 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/handlers/handler.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.jydoc.deliverable4.security.handlers; - -public class handler { -} diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java index 88a80b342..9c1742e38 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/CustomUserDetailsTest.java @@ -32,23 +32,41 @@ class CustomUserDetailsTest { class ConstructorTests { @Test - @DisplayName("Should create instance with valid parameters") void shouldCreateInstanceWithValidParameters() { + // Arrange + Long userId = 1L; + String username = "testUser"; + String password = "securePassword"; + boolean enabled = true; + boolean accountNonExpired = true; + boolean accountNonLocked = true; + boolean credentialsNonExpired = true; + Collection expectedAuthorities = + Arrays.asList(new SimpleGrantedAuthority("ROLE_USER")); + + // Act CustomUserDetails userDetails = new CustomUserDetails( - USER_ID, USERNAME, PASSWORD, - true, true, true, true, - AUTHORITIES + userId, + username, + password, + enabled, + accountNonExpired, + accountNonLocked, + credentialsNonExpired, + expectedAuthorities ); - assertNotNull(userDetails); - assertEquals(USER_ID, userDetails.getUserId()); - assertEquals(USERNAME, userDetails.getUsername()); - assertEquals(PASSWORD, userDetails.getPassword()); + // Assert + assertEquals(userId, userDetails.getUserId()); + assertEquals(username, userDetails.getUsername()); + assertEquals(password, userDetails.getPassword()); assertTrue(userDetails.isEnabled()); assertTrue(userDetails.isAccountNonExpired()); assertTrue(userDetails.isAccountNonLocked()); assertTrue(userDetails.isCredentialsNonExpired()); - assertEquals(AUTHORITIES, userDetails.getAuthorities()); + + // This is the key assertion that fixes the original error + assertIterableEquals(expectedAuthorities, userDetails.getAuthorities()); } @Test diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java index f82e54efa..19af3cf7c 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java @@ -120,9 +120,11 @@ void registerNewUser_ExistingUsername_ThrowsException() { when(userRepository.existsByUsername("testuser")).thenReturn(true); // Act & Assert - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, - () -> userService.registerNewUser(testUserDto)); - assertEquals("Username already exists", exception.getMessage()); + UserService.UsernameExistsException exception = assertThrows( + UserService.UsernameExistsException.class, + () -> userService.registerNewUser(testUserDto) + ); + assertEquals("Username 'testuser' already exists", exception.getMessage()); // Verify no user was saved verify(userRepository, never()).save(any(UserModel.class)); @@ -135,9 +137,9 @@ void registerNewUser_ExistingEmail_ThrowsException() { when(userRepository.existsByEmail("test@example.com")).thenReturn(true); // Act & Assert - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + UserService.EmailExistsException exception = assertThrows(UserService.EmailExistsException.class, () -> userService.registerNewUser(testUserDto)); - assertEquals("Email already registered", exception.getMessage()); + assertEquals("Email 'test@example.com' is already registered", exception.getMessage()); // Verify no attempt to save user verify(userRepository, never()).save(any(UserModel.class)); From 08ea3e06e944614874d2c1d112178c3d53a46a7b Mon Sep 17 00:00:00 2001 From: bihiy Date: Sat, 29 Mar 2025 15:21:41 -0400 Subject: [PATCH 070/100] Documentation added --- .../controllers/AdminController.java | 168 ++++++++++++++++++ 1 file changed, 168 insertions(+) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java index e69de29bb..7337df27c 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java @@ -0,0 +1,168 @@ +package com.jydoc.deliverable4.controllers; + +import com.jydoc.deliverable4.model.UserModel; +import com.jydoc.deliverable4.Service.UserService; +import com.jydoc.deliverable4.security.Exceptions.UserNotFoundException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.mvc.support.RedirectAttributes; + +import javax.validation.Valid; +import java.util.List; + +/** + * Controller for handling administrative operations. + * Provides endpoints for user management, system settings, and activity logs. + * Requires ADMIN role for all operations. + */ +@Controller +@RequestMapping("/admin") +@PreAuthorize("hasRole('ROLE_ADMIN')") +public class AdminController { + + // Constants for view names and attribute keys + private static final String USERS_REDIRECT = "redirect:/admin/users"; + private static final String USER_ATTR = "user"; + private static final String ERROR_ATTR = "error"; + private static final String MESSAGE_ATTR = "message"; + private static final String USERS_ATTR = "users"; + private static final String USER_COUNT_ATTR = "userCount"; + + // View paths + private static final String DASHBOARD_VIEW = "admin/dashboard"; + private static final String USER_LIST_VIEW = "admin/users/list"; + private static final String USER_EDIT_VIEW = "admin/users/edit"; + private static final String SETTINGS_VIEW = "admin/settings"; + private static final String ACTIVITY_LOGS_VIEW = "admin/activity-logs"; + private static final String ERROR_VIEW = "error/user-not-found"; + + private final UserService userService; + + /** + * Constructs an AdminController with the required UserService dependency. + * + * @param userService The service for user-related operations + */ + @Autowired + public AdminController(UserService userService) { + this.userService = userService; + } + + /** + * Displays the admin dashboard with system statistics. + * + * @param model The Spring MVC model to add attributes + * @return The dashboard view name + */ + @GetMapping("/dashboard") + public String adminDashboard(Model model) { + model.addAttribute(USER_COUNT_ATTR, userService.getUserCount()); + return DASHBOARD_VIEW; + } + + /** + * Displays the user management page with a list of all users. + * + * @param model The Spring MVC model to add attributes + * @return The user list view name + */ + @GetMapping("/users") + public String userManagement(Model model) { + List users = userService.getAllUsers(); + model.addAttribute(USERS_ATTR, users); + return USER_LIST_VIEW; + } + + /** + * Displays the user edit form for a specific user. + * + * @param id The ID of the user to edit + * @param model The Spring MVC model to add attributes + * @return The user edit view name + * @throws UserNotFoundException if the user with the given ID doesn't exist + */ + @GetMapping("/users/edit/{id}") + public String editUserForm(@PathVariable Long id, Model model) { + UserModel user = userService.getUserById(id) + .orElseThrow(() -> new UserNotFoundException(id)); + model.addAttribute(USER_ATTR, user); + return USER_EDIT_VIEW; + } + + /** + * Processes user update requests. + * + * @param user The user data to update (validated) + * @param result The binding result for validation errors + * @param redirectAttributes Attributes for the redirect scenario + * @return Redirect to user list if successful, back to edit form if validation fails + */ + @PostMapping("/users/update") + public String updateUser(@Valid @ModelAttribute(USER_ATTR) UserModel user, + BindingResult result, + RedirectAttributes redirectAttributes) { + if (result.hasErrors()) { + return USER_EDIT_VIEW; + } + userService.updateUser(user); + redirectAttributes.addFlashAttribute(MESSAGE_ATTR, "User updated successfully"); + return USERS_REDIRECT; + } + + /** + * Deletes a user with the specified ID. + * + * @param id The ID of the user to delete + * @param redirectAttributes Attributes for the redirect scenario + * @return Redirect to user list + * @throws UserNotFoundException if the user with the given ID doesn't exist + */ + @PostMapping("/users/delete/{id}") + public String deleteUser(@PathVariable Long id, RedirectAttributes redirectAttributes) { + if (!userService.existsById(id)) { + throw new UserNotFoundException(id); + } + userService.deleteUser(id); + redirectAttributes.addFlashAttribute(MESSAGE_ATTR, "User deleted successfully"); + return USERS_REDIRECT; + } + + /** + * Handles UserNotFoundException across all controller methods. + * + * @param ex The exception that was thrown + * @param model The Spring MVC model to add attributes + * @return The error view name + */ + @ExceptionHandler(UserNotFoundException.class) + public String handleUserNotFound(UserNotFoundException ex, Model model) { + model.addAttribute(ERROR_ATTR, ex.getMessage()); + return ERROR_VIEW; + } + + /** + * Displays the system settings page. + * + * @param model The Spring MVC model to add attributes + * @return The settings view name + */ + @GetMapping("/settings") + public String systemSettings(Model model) { + return SETTINGS_VIEW; + } + + /** + * Displays the activity logs page. + * + * @param model The Spring MVC model to add attributes + * @return The activity logs view name + */ + @GetMapping("/activity-logs") + public String viewActivityLogs(Model model) { + return ACTIVITY_LOGS_VIEW; + } +} \ No newline at end of file From 3f9cf25625f93a45b653eba0d99253b30488f68c Mon Sep 17 00:00:00 2001 From: bihiy Date: Thu, 3 Apr 2025 02:08:04 -0400 Subject: [PATCH 071/100] Minor changes --- Sprint 2/prototype2/pom.xml | 6 +++ .../src/main/resources/application.properties | 43 ++++--------------- 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/Sprint 2/prototype2/pom.xml b/Sprint 2/prototype2/pom.xml index ff4278a6e..8ed34b376 100644 --- a/Sprint 2/prototype2/pom.xml +++ b/Sprint 2/prototype2/pom.xml @@ -176,6 +176,12 @@ test + + io.github.cdimascio + dotenv-java + 3.0.0 + + diff --git a/Sprint 2/prototype2/src/main/resources/application.properties b/Sprint 2/prototype2/src/main/resources/application.properties index 49a769f17..2bea00384 100644 --- a/Sprint 2/prototype2/src/main/resources/application.properties +++ b/Sprint 2/prototype2/src/main/resources/application.properties @@ -6,10 +6,9 @@ spring.application.name=prototype2 # ====================== # Database Configuration # ====================== -# Production: Use environment variables -spring.datasource.url=${DB_URL} -spring.datasource.username=${DB_USERNAME} -spring.datasource.password=${DB_PASSWORD} +spring.datasource.username=${SPRING_DATASOURCE_USERNAME} +spring.datasource.password=${SPRING_DATASOURCE_PASSWORD} +spring.datasource.url=${SPRING_DATASOURCE_URL} spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # Connection pool settings @@ -19,61 +18,35 @@ spring.datasource.hikari.connection-timeout=30000 # ====================== # JPA/Hibernate Settings # ====================== -# spring.jpa.hibernate.ddl-auto=validate # Changed from create-drop for safety TODO: Revert to this for production -spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true - # ====================== # Session Management # ====================== -# Production: Consider using redis instead -spring.session.store-type=jdbc spring.session.jdbc.initialize-schema=always -spring.session.jdbc.table-name=SPRING_SESSION # Explicit table name +spring.session.jdbc.table-name=SPRING_SESSION server.servlet.session.timeout=30m server.servlet.session.tracking-modes=cookie + # ====================== # Logging Configuration # ====================== -# Application logging logging.level.com.jydoc=DEBUG - -# Spring Security logging logging.level.org.springframework.security=DEBUG logging.level.root=DEBUG -# SQL logging logging.level.org.hibernate.SQL=DEBUG logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE logging.level.org.springframework.jdbc.core=DEBUG -#Thymeleaf +# Thymeleaf spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.html - -# ====================== -# Profile-specific Notes -# ====================== -# Development profile suggestions: -# ------------------------------ -# spring.jpa.hibernate.ddl-auto=update -# spring.jpa.properties.hibernate.hbm2ddl.import_files=sample-data.sql -# spring.session.jdbc.initialize-schema=always - -# Production profile must include: -# ------------------------------- -# spring.jpa.hibernate.ddl-auto=validate -# spring.session.jdbc.initialize-schema=never -# spring.datasource.tomcat.test-on-borrow=true -# spring.datasource.tomcat.validation-query=SELECT 1 -# Set root logging level -# Set specific package logging level +# Additional logging logging.level.com.jydoc.deliverable4.controllers=DEBUG logging.level.org.springframework.web=INFO -# Console logging pattern logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n -# File logging (optional) logging.file.name=application.log logging.logback.rollingpolicy.max-file-size=10MB logging.logback.rollingpolicy.max-history=7 \ No newline at end of file From d397a7f22d387f403b8b1aef5912148ce5cba347 Mon Sep 17 00:00:00 2001 From: bihiy Date: Thu, 3 Apr 2025 17:33:14 -0400 Subject: [PATCH 072/100] Containerization fixes --- Sprint 2/prototype2/.idea/.name | 1 + Sprint 2/prototype2/.idea/compiler.xml | 22 ++++++++ .../prototype2/.idea/dataSources.local.xml | 19 +++++++ Sprint 2/prototype2/.idea/dataSources.xml | 17 ++++++ .../schema/information_schema.FNRwLQ.meta | 2 + .../storage_v2/_src_/schema/mysql.osA4Bg.meta | 2 + .../schema/performance_schema.kIw0nw.meta | 2 + .../storage_v2/_src_/schema/sys.zb4BAA.meta | 2 + .../_src_/schema/userdatabase.RgIJOQ.meta | 2 + Sprint 2/prototype2/.idea/encodings.xml | 6 +++ .../inspectionProfiles/Project_Default.xml | 8 +++ Sprint 2/prototype2/.idea/jarRepositories.xml | 20 +++++++ Sprint 2/prototype2/.idea/misc.xml | 12 +++++ Sprint 2/prototype2/.idea/vcs.xml | 6 +++ Sprint 2/prototype2/pom.xml | 4 -- .../Initializers/AuthorityInitializer.java | 1 - .../deliverable4/config/SessionConfig.java | 54 ------------------- .../resources/application-test.properties | 1 - .../src/main/resources/application.properties | 13 ++--- 19 files changed, 128 insertions(+), 66 deletions(-) create mode 100644 Sprint 2/prototype2/.idea/.name create mode 100644 Sprint 2/prototype2/.idea/compiler.xml create mode 100644 Sprint 2/prototype2/.idea/dataSources.local.xml create mode 100644 Sprint 2/prototype2/.idea/dataSources.xml create mode 100644 Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/information_schema.FNRwLQ.meta create mode 100644 Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/mysql.osA4Bg.meta create mode 100644 Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/performance_schema.kIw0nw.meta create mode 100644 Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/sys.zb4BAA.meta create mode 100644 Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/userdatabase.RgIJOQ.meta create mode 100644 Sprint 2/prototype2/.idea/encodings.xml create mode 100644 Sprint 2/prototype2/.idea/inspectionProfiles/Project_Default.xml create mode 100644 Sprint 2/prototype2/.idea/jarRepositories.xml create mode 100644 Sprint 2/prototype2/.idea/misc.xml create mode 100644 Sprint 2/prototype2/.idea/vcs.xml delete mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SessionConfig.java diff --git a/Sprint 2/prototype2/.idea/.name b/Sprint 2/prototype2/.idea/.name new file mode 100644 index 000000000..0df699cf7 --- /dev/null +++ b/Sprint 2/prototype2/.idea/.name @@ -0,0 +1 @@ +deliverable4 \ No newline at end of file diff --git a/Sprint 2/prototype2/.idea/compiler.xml b/Sprint 2/prototype2/.idea/compiler.xml new file mode 100644 index 000000000..d43d9f45e --- /dev/null +++ b/Sprint 2/prototype2/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/.idea/dataSources.local.xml b/Sprint 2/prototype2/.idea/dataSources.local.xml new file mode 100644 index 000000000..a38d5b959 --- /dev/null +++ b/Sprint 2/prototype2/.idea/dataSources.local.xml @@ -0,0 +1,19 @@ + + + + + + #@ + ` + + + master_key + root + + + + + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/.idea/dataSources.xml b/Sprint 2/prototype2/.idea/dataSources.xml new file mode 100644 index 000000000..0769c867d --- /dev/null +++ b/Sprint 2/prototype2/.idea/dataSources.xml @@ -0,0 +1,17 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306 + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/information_schema.FNRwLQ.meta b/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/information_schema.FNRwLQ.meta new file mode 100644 index 000000000..1ff3db2eb --- /dev/null +++ b/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/information_schema.FNRwLQ.meta @@ -0,0 +1,2 @@ +#n:information_schema +! [null, 0, null, null, -2147483648, -2147483648] diff --git a/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/mysql.osA4Bg.meta b/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/mysql.osA4Bg.meta new file mode 100644 index 000000000..86a53f191 --- /dev/null +++ b/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/mysql.osA4Bg.meta @@ -0,0 +1,2 @@ +#n:mysql +! [null, 0, null, null, -2147483648, -2147483648] diff --git a/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/performance_schema.kIw0nw.meta b/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/performance_schema.kIw0nw.meta new file mode 100644 index 000000000..9394db147 --- /dev/null +++ b/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/performance_schema.kIw0nw.meta @@ -0,0 +1,2 @@ +#n:performance_schema +! [null, 0, null, null, -2147483648, -2147483648] diff --git a/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/sys.zb4BAA.meta b/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/sys.zb4BAA.meta new file mode 100644 index 000000000..2f4470bb4 --- /dev/null +++ b/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/sys.zb4BAA.meta @@ -0,0 +1,2 @@ +#n:sys +! [null, 0, null, null, -2147483648, -2147483648] diff --git a/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/userdatabase.RgIJOQ.meta b/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/userdatabase.RgIJOQ.meta new file mode 100644 index 000000000..f6ace1307 --- /dev/null +++ b/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd/storage_v2/_src_/schema/userdatabase.RgIJOQ.meta @@ -0,0 +1,2 @@ +#n:userdatabase +! [0, 0, null, null, -2147483648, -2147483648] diff --git a/Sprint 2/prototype2/.idea/encodings.xml b/Sprint 2/prototype2/.idea/encodings.xml new file mode 100644 index 000000000..63e900193 --- /dev/null +++ b/Sprint 2/prototype2/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/.idea/inspectionProfiles/Project_Default.xml b/Sprint 2/prototype2/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..611627079 --- /dev/null +++ b/Sprint 2/prototype2/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/.idea/jarRepositories.xml b/Sprint 2/prototype2/.idea/jarRepositories.xml new file mode 100644 index 000000000..712ab9d98 --- /dev/null +++ b/Sprint 2/prototype2/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/.idea/misc.xml b/Sprint 2/prototype2/.idea/misc.xml new file mode 100644 index 000000000..f24c79d1b --- /dev/null +++ b/Sprint 2/prototype2/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/.idea/vcs.xml b/Sprint 2/prototype2/.idea/vcs.xml new file mode 100644 index 000000000..b2bdec2d7 --- /dev/null +++ b/Sprint 2/prototype2/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/pom.xml b/Sprint 2/prototype2/pom.xml index 8ed34b376..9d2cecc3f 100644 --- a/Sprint 2/prototype2/pom.xml +++ b/Sprint 2/prototype2/pom.xml @@ -56,10 +56,6 @@ htmx-spring-boot-thymeleaf 4.0.1 - - org.springframework.session - spring-session-jdbc - org.thymeleaf.extras thymeleaf-extras-springsecurity6 diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java index dd83eb554..b27323c75 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java @@ -74,7 +74,6 @@ public void initializeDefaultAuthorities() { * * * @param authorityName the name of the authority to create (e.g., "ROLE_ADMIN") - * @return the existing or newly created authority */ private void createAuthorityIfNotExists(String authorityName) { authorityRepository.findByAuthority(authorityName) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SessionConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SessionConfig.java deleted file mode 100644 index 5df75e101..000000000 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SessionConfig.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.jydoc.deliverable4.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession; -import org.springframework.session.web.http.CookieSerializer; -import org.springframework.session.web.http.DefaultCookieSerializer; -import org.springframework.session.web.http.HttpSessionIdResolver; -import org.springframework.session.web.http.HeaderHttpSessionIdResolver; - -/** - * Configures HTTP session management for the application using in-memory storage. - *

    - * Features include: - *

      - *
    • In-memory session storage (default)
    • - *
    • Configurable session timeout
    • - *
    • Secure cookie settings
    • - *
    • Optional header-based session ID resolution
    • - *
    - */ -@Configuration -@EnableSpringHttpSession -public class SessionConfig { - - /** - * Default session timeout in seconds (30 minutes). - */ - private static final int DEFAULT_SESSION_TIMEOUT = 1800; - - /** - * Configures session cookie settings with security best practices. - * @return Customized cookie serializer - */ - @Bean - public CookieSerializer cookieSerializer() { - DefaultCookieSerializer serializer = new DefaultCookieSerializer(); - serializer.setCookieName("JSESSIONID"); - serializer.setCookiePath("/"); - serializer.setUseHttpOnlyCookie(true); - serializer.setUseSecureCookie(true); // Requires HTTPS - serializer.setSameSite("Lax"); // CSRF protection - return serializer; - } - - /** - * Optional: Configures header-based session ID resolution (for API clients). - * Uncomment if you need to support session tokens in headers. - */ - // @Bean - // public HttpSessionIdResolver httpSessionIdResolver() { - // return HeaderHttpSessionIdResolver.xAuthToken(); - // } -} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/application-test.properties b/Sprint 2/prototype2/src/main/resources/application-test.properties index e4c29e99f..e8297d8ac 100644 --- a/Sprint 2/prototype2/src/main/resources/application-test.properties +++ b/Sprint 2/prototype2/src/main/resources/application-test.properties @@ -34,7 +34,6 @@ spring.jpa.defer-datasource-initialization=true # ====================== # Test Session Management # ====================== -spring.session.store-type=none spring.session.jdbc.initialize-schema=always spring.session.jdbc.table-name=SPRING_SESSION server.servlet.session.timeout=1m diff --git a/Sprint 2/prototype2/src/main/resources/application.properties b/Sprint 2/prototype2/src/main/resources/application.properties index 2bea00384..2759a9e83 100644 --- a/Sprint 2/prototype2/src/main/resources/application.properties +++ b/Sprint 2/prototype2/src/main/resources/application.properties @@ -18,7 +18,6 @@ spring.datasource.hikari.connection-timeout=30000 # ====================== # JPA/Hibernate Settings # ====================== -spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true @@ -26,10 +25,7 @@ spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true # ====================== # Session Management # ====================== -spring.session.jdbc.initialize-schema=always -spring.session.jdbc.table-name=SPRING_SESSION -server.servlet.session.timeout=30m -server.servlet.session.tracking-modes=cookie + # ====================== # Logging Configuration @@ -49,4 +45,9 @@ logging.level.org.springframework.web=INFO logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n logging.file.name=application.log logging.logback.rollingpolicy.max-file-size=10MB -logging.logback.rollingpolicy.max-history=7 \ No newline at end of file +logging.logback.rollingpolicy.max-history=7 +spring.session.jdbc.schema=classpath:org/springframework/session/jdbc/schema-mysql.sql +spring.sql.init.mode=always +spring.jpa.hibernate.ddl-auto=update + + From d39d7c127132cae773792beba21663d881095d60 Mon Sep 17 00:00:00 2001 From: bihiy Date: Thu, 3 Apr 2025 17:33:20 -0400 Subject: [PATCH 073/100] Containerization fixes --- .../1d4a9770-c32d-446d-a5c2-de35cbf1f8dd.xml | 1275 +++++++++++++++++ 1 file changed, 1275 insertions(+) create mode 100644 Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd.xml diff --git a/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd.xml b/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd.xml new file mode 100644 index 000000000..a010eb832 --- /dev/null +++ b/Sprint 2/prototype2/.idea/dataSources/1d4a9770-c32d-446d-a5c2-de35cbf1f8dd.xml @@ -0,0 +1,1275 @@ + + + + + lower/lower + InnoDB + InnoDB + |root||root|localhost|ALTER|G +|root||root|localhost|ALTER ROUTINE|G +|root||root|localhost|APPLICATION_PASSWORD_ADMIN|G +|root||mysql.infoschema|localhost|AUDIT_ABORT_EXEMPT|G +|root||mysql.session|localhost|AUDIT_ABORT_EXEMPT|G +|root||mysql.sys|localhost|AUDIT_ABORT_EXEMPT|G +|root||root|localhost|AUDIT_ABORT_EXEMPT|G +|root||root|localhost|AUDIT_ADMIN|G +|root||mysql.session|localhost|AUTHENTICATION_POLICY_ADMIN|G +|root||root|localhost|AUTHENTICATION_POLICY_ADMIN|G +|root||mysql.session|localhost|BACKUP_ADMIN|G +|root||root|localhost|BACKUP_ADMIN|G +|root||root|localhost|BINLOG_ADMIN|G +|root||root|localhost|BINLOG_ENCRYPTION_ADMIN|G +|root||mysql.session|localhost|CLONE_ADMIN|G +|root||root|localhost|CLONE_ADMIN|G +|root||mysql.session|localhost|CONNECTION_ADMIN|G +|root||root|localhost|CONNECTION_ADMIN|G +|root||root|localhost|CREATE|G +|root||root|localhost|CREATE ROLE|G +|root||root|localhost|CREATE ROUTINE|G +|root||root|localhost|CREATE TABLESPACE|G +|root||root|localhost|CREATE TEMPORARY TABLES|G +|root||root|localhost|CREATE USER|G +|root||root|localhost|CREATE VIEW|G +|root||root|localhost|DELETE|G +|root||root|localhost|DROP|G +|root||root|localhost|DROP ROLE|G +|root||root|localhost|ENCRYPTION_KEY_ADMIN|G +|root||root|localhost|EVENT|G +|root||root|localhost|EXECUTE|G +|root||root|localhost|FILE|G +|root||mysql.infoschema|localhost|FIREWALL_EXEMPT|G +|root||mysql.session|localhost|FIREWALL_EXEMPT|G +|root||mysql.sys|localhost|FIREWALL_EXEMPT|G +|root||root|localhost|FIREWALL_EXEMPT|G +|root||root|localhost|FLUSH_OPTIMIZER_COSTS|G +|root||root|localhost|FLUSH_STATUS|G +|root||root|localhost|FLUSH_TABLES|G +|root||root|localhost|FLUSH_USER_RESOURCES|G +|root||root|localhost|GROUP_REPLICATION_ADMIN|G +|root||root|localhost|GROUP_REPLICATION_STREAM|G +|root||root|localhost|INDEX|G +|root||root|localhost|INNODB_REDO_LOG_ARCHIVE|G +|root||root|localhost|INNODB_REDO_LOG_ENABLE|G +|root||root|localhost|INSERT|G +|root||root|localhost|LOCK TABLES|G +|root||root|localhost|PASSWORDLESS_USER_ADMIN|G +|root||mysql.session|localhost|PERSIST_RO_VARIABLES_ADMIN|G +|root||root|localhost|PERSIST_RO_VARIABLES_ADMIN|G +|root||root|localhost|PROCESS|G +|root||root|localhost|REFERENCES|G +|root||root|localhost|RELOAD|G +|root||root|localhost|REPLICATION CLIENT|G +|root||root|localhost|REPLICATION SLAVE|G +|root||root|localhost|REPLICATION_APPLIER|G +|root||root|localhost|REPLICATION_SLAVE_ADMIN|G +|root||root|localhost|RESOURCE_GROUP_ADMIN|G +|root||root|localhost|RESOURCE_GROUP_USER|G +|root||root|localhost|ROLE_ADMIN|G +|root||mysql.infoschema|localhost|SELECT|G +|root||root|localhost|SELECT|G +|root||root|localhost|SENSITIVE_VARIABLES_OBSERVER|G +|root||root|localhost|SERVICE_CONNECTION_ADMIN|G +|root||mysql.session|localhost|SESSION_VARIABLES_ADMIN|G +|root||root|localhost|SESSION_VARIABLES_ADMIN|G +|root||root|localhost|SET_USER_ID|G +|root||root|localhost|SHOW DATABASES|G +|root||root|localhost|SHOW VIEW|G +|root||root|localhost|SHOW_ROUTINE|G +|root||mysql.session|localhost|SHUTDOWN|G +|root||root|localhost|SHUTDOWN|G +|root||mysql.session|localhost|SUPER|G +|root||root|localhost|SUPER|G +|root||mysql.infoschema|localhost|SYSTEM_USER|G +|root||mysql.session|localhost|SYSTEM_USER|G +|root||mysql.sys|localhost|SYSTEM_USER|G +|root||root|localhost|SYSTEM_USER|G +|root||mysql.session|localhost|SYSTEM_VARIABLES_ADMIN|G +|root||root|localhost|SYSTEM_VARIABLES_ADMIN|G +|root||root|localhost|TABLE_ENCRYPTION_ADMIN|G +|root||root|localhost|TELEMETRY_LOG_ADMIN|G +|root||root|localhost|TRIGGER|G +|root||root|localhost|UPDATE|G +|root||root|localhost|XA_RECOVER_ADMIN|G +|root||root|localhost|grant option|G +performance_schema|schema||mysql.session|localhost|SELECT|G +sys|schema||mysql.sys|localhost|TRIGGER|G + 8.0.41 + + + armscii8 + + + armscii8 + 1 + + + ascii + + + ascii + 1 + + + big5 + + + big5 + 1 + + + binary + 1 + + + cp1250 + + + cp1250 + + + cp1250 + + + cp1250 + 1 + + + cp1250 + + + cp1251 + + + cp1251 + + + cp1251 + 1 + + + cp1251 + + + cp1251 + + + cp1256 + + + cp1256 + 1 + + + cp1257 + + + cp1257 + 1 + + + cp1257 + + + cp850 + + + cp850 + 1 + + + cp852 + + + cp852 + 1 + + + cp866 + + + cp866 + 1 + + + cp932 + + + cp932 + 1 + + + dec8 + + + dec8 + 1 + + + eucjpms + + + eucjpms + 1 + + + euckr + + + euckr + 1 + + + gb18030 + + + gb18030 + 1 + + + gb18030 + + + gb2312 + + + gb2312 + 1 + + + gbk + + + gbk + 1 + + + geostd8 + + + geostd8 + 1 + + + greek + + + greek + 1 + + + hebrew + + + hebrew + 1 + + + hp8 + + + hp8 + 1 + + + keybcs2 + + + keybcs2 + 1 + + + koi8r + + + koi8r + 1 + + + koi8u + + + koi8u + 1 + + + latin1 + + + latin1 + + + latin1 + + + latin1 + + + latin1 + + + latin1 + + + latin1 + + + latin1 + 1 + + + latin2 + + + latin2 + + + latin2 + + + latin2 + 1 + + + latin2 + + + latin5 + + + latin5 + 1 + + + latin7 + + + latin7 + + + latin7 + 1 + + + latin7 + + + macce + + + macce + 1 + + + macroman + + + macroman + 1 + + + sjis + + + sjis + 1 + + + swe7 + + + swe7 + 1 + + + tis620 + + + tis620 + 1 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + 1 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ucs2 + + + ujis + + + ujis + 1 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + 1 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16 + + + utf16le + + + utf16le + 1 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + 1 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf32 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + 1 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb3 + + + utf8mb4 + 1 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb4 + + + utf8mb3_general_ci + + + utf8mb4_0900_ai_ci + + + utf8mb4_0900_ai_ci + + + utf8mb4_0900_ai_ci + + + 2025-03-29.14:40:43 + utf8mb4_0900_ai_ci + + + 0 + localhost + caching_sha2_password + + + 0 + localhost + caching_sha2_password + + + 0 + localhost + caching_sha2_password + + + localhost + caching_sha2_password + + + InnoDB + utf8mb4_0900_ai_ci +
    + + InnoDB + utf8mb4_0900_ai_ci +
    + + InnoDB + row_format +DYNAMIC + utf8mb4_0900_ai_ci +
    + + InnoDB + utf8mb4_0900_ai_ci +
    + + InnoDB + utf8mb4_0900_ai_ci +
    + + 4 + 1 + 1 + bigint|0s + + + 1 + 2 + varchar(50)|0s + + + 3 + varchar(255)|0s + + + id + btree + 1 + + + authority + btree + 1 + + + 1 + 1 + PRIMARY + + + UKq0u5f2cdlshec8tlh6818bhbk + + + 1 + 1 + char(36)|0s + + + 1 + 2 + char(36)|0s + + + 1 + 3 + bigint|0s + + + 1 + 4 + bigint|0s + + + 1 + 5 + int|0s + + + 1 + 6 + bigint|0s + + + 7 + varchar(100)|0s + + + PRIMARY_ID + btree + 1 + + + 1 + 1 + PRIMARY + + + 1 + 1 + char(36)|0s + + + 1 + 2 + varchar(200)|0s + + + 1 + 3 + blob|0s + + + session_primary_id + cascade + PRIMARY_ID + spring_session + + + session_primary_id +attribute_name + btree + 1 + + + 1 + 1 + PRIMARY + + + 1 + 1 + bigint|0s + + + 1 + 2 + bigint|0s + + + authority_id + id + authorities + + + user_id + id + users + + + authority_id +user_id + btree + 1 + + + user_id + btree + + + 1 + 1 + PRIMARY + + + 2 + 1 + 1 + bigint|0s + + + 1 + 2 + bit(1)|0s + + + 1 + 3 + bit(1)|0s + + + 1 + 4 + bit(1)|0s + + + 5 + varchar(100)|0s + + + 1 + 6 + bit(1)|0s + + + 1 + 7 + varchar(100)|0s + + + 1 + 8 + varchar(50)|0s + + + 1 + 9 + varchar(50)|0s + + + 1 + 10 + varchar(50)|0s + + + id + btree + 1 + + + email + btree + 1 + + + username + btree + 1 + + + 1 + 1 + PRIMARY + + + UK6dotkott2kjsp8vw4d0m25fb7 + + + UKr43af9ap4edm43mmtq01oddj6 + +
    +
    \ No newline at end of file From e31f488bf065fe13adec2fb9f3c74b1736ddcee1 Mon Sep 17 00:00:00 2001 From: bihiy Date: Thu, 3 Apr 2025 17:36:03 -0400 Subject: [PATCH 074/100] Create maven-wrapper.properties --- .../.mvn/wrapper/maven-wrapper.properties | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Sprint 2/prototype2/.mvn/wrapper/maven-wrapper.properties diff --git a/Sprint 2/prototype2/.mvn/wrapper/maven-wrapper.properties b/Sprint 2/prototype2/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 000000000..d58dfb70b --- /dev/null +++ b/Sprint 2/prototype2/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip From eff358c883943419dc070a2b551aec4bf6524b63 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Fri, 4 Apr 2025 11:40:41 -0700 Subject: [PATCH 075/100] Removed JDBC sessions --- .../java/com/jydoc/deliverable4/config/SecurityConfig.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java index ce588068d..572d9b3bd 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java @@ -15,7 +15,6 @@ import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.csrf.CookieCsrfTokenRepository; import org.springframework.security.web.header.writers.XXssProtectionHeaderWriter; -import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession; /** * Security configuration class that defines the application's security policies. @@ -34,7 +33,7 @@ */ @Configuration @EnableWebSecurity -@EnableJdbcHttpSession + public class SecurityConfig { /** From 4f83212763c4d6a243564e1bdc900353b75ea382 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Sat, 5 Apr 2025 15:41:55 -0400 Subject: [PATCH 076/100] Removed sessions properties --- Sprint 2/prototype2/src/main/resources/application.properties | 3 --- 1 file changed, 3 deletions(-) diff --git a/Sprint 2/prototype2/src/main/resources/application.properties b/Sprint 2/prototype2/src/main/resources/application.properties index 2759a9e83..c73703a82 100644 --- a/Sprint 2/prototype2/src/main/resources/application.properties +++ b/Sprint 2/prototype2/src/main/resources/application.properties @@ -22,9 +22,6 @@ spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true -# ====================== -# Session Management -# ====================== # ====================== From 9ef1622710f4a4879cbf80c936912742085cdc8f Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Sat, 5 Apr 2025 15:44:28 -0400 Subject: [PATCH 077/100] Renamed file --- .../java/com/jydoc/deliverable4/LoginDtoValidationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/LoginDtoValidationTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/LoginDtoValidationTest.java index b8ff4534c..428b3639a 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/LoginDtoValidationTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/LoginDtoValidationTest.java @@ -17,7 +17,7 @@ import static org.junit.jupiter.api.Assertions.*; -class LoginDTOTest { +class LoginDtoValidationTest { private static Validator validator; From e7cfdf01d49632cfc4bd7677a7e95901183d8bfc Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Sat, 5 Apr 2025 15:50:58 -0400 Subject: [PATCH 078/100] Minor edits --- .gitignore | 5 + .idea/compiler.xml | 26 ++ .idea/encodings.xml | 7 + .idea/inspectionProfiles/Project_Default.xml | 8 + .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/runConfigurations/All_Tests.xml | 18 + .../com/jydoc/deliverable4/DTO/LoginDTO.java | 3 + .../security/auth/CustomUserDetails.java | 18 +- .../templates/{ => dashboard}/dashboard.html | 434 +++++++++--------- 10 files changed, 307 insertions(+), 226 deletions(-) create mode 100644 .gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations/All_Tests.xml rename Sprint 2/prototype2/src/main/resources/templates/{ => dashboard}/dashboard.html (97%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..1d6e22c22 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/Sprint 2/prototype2/target +*.log +*.iml +/Sprint 2/prototype2/docker-compose.yml +*.gz diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 000000000..6f97dc024 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 000000000..bddce9d61 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..1ed94d38f --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 4f77693ca..2cea27280 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,8 +5,14 @@ + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..9daa0ef2f --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/All_Tests.xml b/.idea/runConfigurations/All_Tests.xml new file mode 100644 index 000000000..24291488a --- /dev/null +++ b/.idea/runConfigurations/All_Tests.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java index 598609605..39bd9d916 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java @@ -2,6 +2,8 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; + +import java.io.Serial; import java.io.Serializable; /** @@ -21,6 +23,7 @@ public record LoginDTO( String password ) implements Serializable { + @Serial private static final long serialVersionUID = 1L; /** diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java index f3af3d7b7..bd81f954b 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/security/auth/CustomUserDetails.java @@ -1,8 +1,10 @@ package com.jydoc.deliverable4.security.auth; +import lombok.Getter; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; +import java.io.Serial; import java.util.Collection; import java.util.Collections; import java.util.Objects; @@ -23,11 +25,18 @@ * @since 1.0 */ public class CustomUserDetails implements UserDetails { + @Serial private static final long serialVersionUID = 1L; /** * The unique identifier of the user in the system + * -- GETTER -- + * Returns the unique identifier of the user. + * + * @return the user ID + */ + @Getter private final Long userId; /** @@ -92,15 +101,6 @@ public CustomUserDetails(Long userId, String username, String password, this.authorities = Objects.requireNonNull(authorities); } - /** - * Returns the unique identifier of the user. - * - * @return the user ID - */ - public Long getUserId() { - return userId; - } - /** * Returns the authorities granted to the user. * diff --git a/Sprint 2/prototype2/src/main/resources/templates/dashboard.html b/Sprint 2/prototype2/src/main/resources/templates/dashboard/dashboard.html similarity index 97% rename from Sprint 2/prototype2/src/main/resources/templates/dashboard.html rename to Sprint 2/prototype2/src/main/resources/templates/dashboard/dashboard.html index 8ecc8304b..f0b2298ad 100644 --- a/Sprint 2/prototype2/src/main/resources/templates/dashboard.html +++ b/Sprint 2/prototype2/src/main/resources/templates/dashboard/dashboard.html @@ -1,218 +1,218 @@ - - - - - - - User Dashboard - JYDoc System - - - - - - - - -
    -
    - -
    - -
    -
    - User Profile -
    -
    -

    Username:

    -

    Roles: - -

    -
    -
    - - -
    -
    - Quick Actions -
    - -
    -
    - - -
    - -
    -
    -
    -
    - Dashboard Overview -
    -
    -
    Welcome to your dashboard
    -

    Here you can manage your account and access all system features.

    -
    -
    -
    -
    - - -
    -
    -
    -
    -
    Documents
    -

    24

    - View all -
    -
    -
    -
    -
    -
    -
    Tasks
    -

    5

    - View tasks -
    -
    -
    -
    -
    -
    -
    Notifications
    -

    3

    - View alerts -
    -
    -
    -
    - - -
    -
    -
    -
    - Admin Tools -
    -
    -
    -
    -
    -
    -
    User Management
    -

    Manage all system users and permissions

    - Go to Users -
    -
    -
    -
    -
    -
    -
    System Reports
    -

    View system analytics and reports

    - View Reports -
    -
    -
    -
    -
    -
    -
    Audit Logs
    -

    Review system activity logs

    - View Logs -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - - - - + + + + + + + User Dashboard - JYDoc System + + + + + + + + +
    +
    + +
    + +
    +
    + User Profile +
    +
    +

    Username:

    +

    Roles: + +

    +
    +
    + + +
    +
    + Quick Actions +
    + +
    +
    + + +
    + +
    +
    +
    +
    + Dashboard Overview +
    +
    +
    Welcome to your dashboard
    +

    Here you can manage your account and access all system features.

    +
    +
    +
    +
    + + +
    +
    +
    +
    +
    Documents
    +

    24

    + View all +
    +
    +
    +
    +
    +
    +
    Tasks
    +

    5

    + View tasks +
    +
    +
    +
    +
    +
    +
    Notifications
    +

    3

    + View alerts +
    +
    +
    +
    + + +
    +
    +
    +
    + Admin Tools +
    +
    +
    +
    +
    +
    +
    User Management
    +

    Manage all system users and permissions

    + Go to Users +
    +
    +
    +
    +
    +
    +
    System Reports
    +

    View system analytics and reports

    + View Reports +
    +
    +
    +
    +
    +
    +
    Audit Logs
    +

    Review system activity logs

    + View Logs +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + + \ No newline at end of file From 1552beb55962e40e34e53a0e369c27e384e96471 Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Sun, 6 Apr 2025 12:38:33 -0400 Subject: [PATCH 079/100] Minor changes --- .idea/encodings.xml | 1 - .idea/jsLibraryMappings.xml | 6 ++++++ .idea/modules.xml | 8 -------- Sprint 1/deliverable3/deliverable3.iml | 13 ------------- .../deliverable4/controllers/UserController.java | 11 +++++++++++ 5 files changed, 17 insertions(+), 22 deletions(-) create mode 100644 .idea/jsLibraryMappings.xml delete mode 100644 .idea/modules.xml delete mode 100644 Sprint 1/deliverable3/deliverable3.iml create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/UserController.java diff --git a/.idea/encodings.xml b/.idea/encodings.xml index bddce9d61..e13a3d47c 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,7 +1,6 @@ - \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 000000000..8949cba6a --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 9daa0ef2f..000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Sprint 1/deliverable3/deliverable3.iml b/Sprint 1/deliverable3/deliverable3.iml deleted file mode 100644 index 2cf3f920f..000000000 --- a/Sprint 1/deliverable3/deliverable3.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/UserController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/UserController.java new file mode 100644 index 000000000..69bed18db --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/UserController.java @@ -0,0 +1,11 @@ +package com.jydoc.deliverable4.controllers; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping("/user") +@PreAuthorize("hasRole('ROLE_USER')") +public class UserController { +} \ No newline at end of file From 12fa8517a1a20ce67b371a21d60dd18af99c72de Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Sun, 6 Apr 2025 15:13:05 -0400 Subject: [PATCH 080/100] Project restructuring --- .../deliverable4/Service/UserService.java | 448 ------------------ .../deliverable4/config/SecurityConfig.java | 110 +---- .../controllers/AdminController.java | 2 +- .../controllers/AuthController.java | 210 +++----- .../controllers/UserController.java | 61 ++- .../deliverable4/{DTO => dto}/LoginDTO.java | 2 +- .../deliverable4/{DTO => dto}/UserDTO.java | 3 +- .../AuthorityInitializer.java | 2 +- .../deliverable4/services/AuthService.java | 227 +++++++++ .../services/MedicationService.java | 14 + .../deliverable4/services/UserService.java | 62 +++ .../UserValidationHelper.java | 178 +++---- .../resources/application-test.properties | 1 - .../main/resources/templates/auth/login.html | 93 ++++ .../templates/{ => auth}/logout.html | 50 +- .../resources/templates/auth/register.html | 99 ++++ .../templates/{dashboard => }/dashboard.html | 2 +- .../src/main/resources/templates/index.html | 8 +- .../src/main/resources/templates/login.html | 45 -- .../main/resources/templates/register.html | 55 --- .../jydoc/deliverable4/AuthServiceTest.java | 225 +++++++++ .../AuthorityInitializerTest.java | 2 +- .../deliverable4/LoginDtoValidationTest.java | 2 +- .../deliverable4/UserDtoValidationTest.java | 2 +- .../jydoc/deliverable4/UserServiceTest.java | 172 +++---- 25 files changed, 1083 insertions(+), 992 deletions(-) delete mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java rename Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/{DTO => dto}/LoginDTO.java (94%) rename Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/{DTO => dto}/UserDTO.java (94%) rename Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/{Initializers => initializers}/AuthorityInitializer.java (95%) create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/AuthService.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/MedicationService.java create mode 100644 Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/UserService.java rename Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/{Service => services}/UserValidationHelper.java (94%) create mode 100644 Sprint 2/prototype2/src/main/resources/templates/auth/login.html rename Sprint 2/prototype2/src/main/resources/templates/{ => auth}/logout.html (96%) create mode 100644 Sprint 2/prototype2/src/main/resources/templates/auth/register.html rename Sprint 2/prototype2/src/main/resources/templates/{dashboard => }/dashboard.html (99%) delete mode 100644 Sprint 2/prototype2/src/main/resources/templates/login.html delete mode 100644 Sprint 2/prototype2/src/main/resources/templates/register.html create mode 100644 Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/AuthServiceTest.java diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java deleted file mode 100644 index c27d4ba97..000000000 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserService.java +++ /dev/null @@ -1,448 +0,0 @@ -package com.jydoc.deliverable4.Service; - -import com.jydoc.deliverable4.DTO.LoginDTO; -import com.jydoc.deliverable4.DTO.UserDTO; -import com.jydoc.deliverable4.model.AuthorityModel; -import com.jydoc.deliverable4.model.UserModel; -import com.jydoc.deliverable4.repositories.AuthorityRepository; -import com.jydoc.deliverable4.repositories.UserRepository; -import lombok.RequiredArgsConstructor; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication.BadCredentialsException; -import org.springframework.security.authentication.DisabledException; -import org.springframework.security.authentication.LockedException; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; - -import java.util.HashSet; -import java.util.List; -import java.util.Optional; - -/** - * Service class for managing user-related operations including registration, authentication, - * and CRUD operations. Integrates with Spring Security for authentication and authorization. - * - *

    This service handles:

    - *
      - *
    • User registration with comprehensive validation
    • - *
    • Multiple authentication methods (Spring Security and direct validation)
    • - *
    • Complete user lifecycle management (CRUD operations)
    • - *
    • Role assignment and management
    • - *
    • Account status tracking (enabled/disabled, locked/unlocked)
    • - *
    - * - *

    Transactions are properly managed with appropriate propagation levels.

    - */ -@Service -@RequiredArgsConstructor -public class UserService { - private static final Logger logger = LogManager.getLogger(UserService.class); - - /** - * The default role assigned to new users upon registration - */ - private static final String DEFAULT_ROLE = "ROLE_USER"; - - // Injected dependencies - private final UserValidationHelper validationHelper; - private final UserRepository userRepository; - private final AuthorityRepository authorityRepository; - private final PasswordEncoder passwordEncoder; - private final AuthenticationManager authenticationManager; - - /* ======================== Public API Methods ======================== */ - - /** - * Registers a new user after performing comprehensive validation checks. - * - *

    Validation includes:

    - *
      - *
    • Null checks for all required fields
    • - *
    • Empty string validation
    • - *
    • Format validation for email
    • - *
    • Duplicate username/email checks
    • - *
    • Password complexity requirements
    • - *
    - * - * @param userDto Data Transfer Object containing user registration information - * @throws IllegalArgumentException if any validation fails - * @throws UsernameExistsException if username already exists - * @throws EmailExistsException if email already registered - */ - @Transactional - public void registerNewUser(UserDTO userDto) { - validationHelper.validateUserRegistration(userDto); - validateUserDto(userDto); - checkForExistingCredentials(userDto); - - UserModel user = createUserFromDto(userDto); - persistUser(user); - } - - /** - * Authenticates a user using Spring Security's authentication manager. - * - * @param loginDto Contains username and password for authentication - * @return Authenticated UserModel - * @throws IllegalArgumentException if loginDto is null - * @throws AuthenticationException if authentication fails for any reason - */ - @Transactional(readOnly = true) - public UserModel authenticate(LoginDTO loginDto) { - if (loginDto == null) { - throw new IllegalArgumentException("Login credentials cannot be null"); - } - return authenticateUser(loginDto.username(), loginDto.password()); - } - - /** - * Validates user credentials directly against the database (alternative to Spring Security auth). - * - * @param loginDto Contains credentials for validation - * @return Validated UserModel - * @throws IllegalArgumentException if loginDto is null - * @throws AuthenticationException if credentials are invalid or account is disabled - */ - @Transactional(readOnly = true) - public UserModel validateLogin(LoginDTO loginDto) { - if (loginDto == null) { - throw new IllegalArgumentException("Login credentials cannot be null"); - } - - String credential = loginDto.username().trim().toLowerCase(); - String rawPassword = loginDto.password(); - - logger.debug("Login attempt for: {}", credential); - - UserModel user = findUserByCredential(credential); - validateUserPassword(user, rawPassword); - checkAccountEnabled(user); - - logger.info("Login successful for user: {}", user.getUsername()); - return user; - } - - /* ======================== User Management Methods ======================== */ - - /** - * Finds an active user by username or email. - * - * @param usernameOrEmail The username or email to search for - * @return Optional containing the user if found and active, empty otherwise - */ - @Transactional(readOnly = true) - public Optional findActiveUser(String usernameOrEmail) { - return userRepository.findByUsernameOrEmail(usernameOrEmail.trim().toLowerCase()) - .filter(UserModel::isEnabled); - } - - /** - * Gets the total count of users in the system. - * - * @return The number of users in the system - */ - @Transactional(readOnly = true) - public long getUserCount() { - return userRepository.count(); - } - - /** - * Checks if a user exists with the given ID. - * - * @param id The user ID to check - * @return true if user exists, false otherwise - */ - @Transactional(readOnly = true) - public boolean existsById(Long id) { - return userRepository.existsById(id); - } - - /** - * Retrieves all users in the system. - * - * @return List of all users - */ - @Transactional(readOnly = true) - public List getAllUsers() { - return userRepository.findAll(); - } - - /** - * Finds a user by their ID. - * - * @param id The user ID to find - * @return Optional containing the user if found, empty otherwise - */ - @Transactional(readOnly = true) - public Optional getUserById(Long id) { - return userRepository.findById(id); - } - - /** - * Updates an existing user. - * - * @param user The user to update - */ - @Transactional - public void updateUser(UserModel user) { - userRepository.save(user); - } - - /** - * Deletes a user by ID. - * - * @param id The ID of the user to delete - */ - @Transactional - public void deleteUser(Long id) { - userRepository.deleteById(id); - } - - /* ======================== Authentication Methods ======================== */ - - /** - * Authenticates user credentials using Spring Security's authentication mechanisms. - * - * @param username The username to authenticate - * @param password The password to verify - * @return Authenticated UserModel - * @throws AuthenticationException wrapping various Spring Security exceptions - */ - @Transactional(readOnly = true) - public UserModel authenticateUser(String username, String password) { - try { - Authentication authentication = performSpringAuthentication(username, password); - return findAuthenticatedUser(authentication.getName()); - } catch (BadCredentialsException e) { - handleAuthenticationFailure("Authentication failed - bad credentials for user: {}", username, - "Invalid username or password"); - } catch (DisabledException e) { - handleAuthenticationFailure("Authentication failed - disabled account: {}", username, - "Account is disabled"); - } catch (LockedException e) { - handleAuthenticationFailure("Authentication failed - locked account: {}", username, - "Account is locked"); - } - return null; // Unreachable due to exception handling - } - - /* ======================== Private Helper Methods ======================== */ - - /** - * Validates the basic structure of the UserDTO. - * - * @param userDto The UserDTO to validate - * @throws IllegalArgumentException if any required field is null or empty - */ - private void validateUserDto(UserDTO userDto) { - if (userDto == null) { - throw new IllegalArgumentException("UserDTO cannot be null"); - } - if (userDto.getUsername() == null || userDto.getUsername().trim().isEmpty()) { - throw new IllegalArgumentException("Username cannot be empty"); - } - if (userDto.getPassword() == null || userDto.getPassword().trim().isEmpty()) { - throw new IllegalArgumentException("Password cannot be empty"); - } - if (userDto.getEmail() == null || userDto.getEmail().trim().isEmpty()) { - throw new IllegalArgumentException("Email cannot be empty"); - } - if (userDto.getFirstName() == null || userDto.getFirstName().trim().isEmpty()) { - throw new IllegalArgumentException("First name cannot be empty"); - } - if (userDto.getLastName() == null || userDto.getLastName().trim().isEmpty()) { - throw new IllegalArgumentException("Last name cannot be empty"); - } - } - - /** - * Checks for existing username or email in the system. - * - * @param userDto The UserDTO containing credentials to check - * @throws UsernameExistsException if username already exists - * @throws EmailExistsException if email already registered - */ - private void checkForExistingCredentials(UserDTO userDto) { - if (userRepository.existsByUsername(userDto.getUsername())) { - throw new UsernameExistsException(userDto.getUsername()); - } - if (userRepository.existsByEmail(userDto.getEmail())) { - throw new EmailExistsException(userDto.getEmail()); - } - } - - /** - * Creates and persists a new user with encoded password and default role. - * - * @param user The user to persist - */ - private void persistUser(UserModel user) { - assignDefaultRole(user); - userRepository.save(user); - logger.info("Successfully registered new user: {}", user.getUsername()); - } - - /** - * Constructs a UserModel from DTO with proper formatting and password encoding. - * - * @param userDto The source UserDTO - * @return Fully constructed UserModel - */ - private UserModel createUserFromDto(UserDTO userDto) { - return UserModel.builder() - .username(userDto.getUsername().trim()) - .password(passwordEncoder.encode(userDto.getPassword())) - .email(userDto.getEmail().toLowerCase().trim()) - .firstName(userDto.getFirstName().trim()) - .lastName(userDto.getLastName().trim()) - .enabled(true) - .accountNonExpired(true) - .credentialsNonExpired(true) - .accountNonLocked(true) - .build(); - } - - /** - * Finds user by username or email credential. - * - * @param credential The username or email to search for - * @return Found UserModel - * @throws AuthenticationException if user not found - */ - private UserModel findUserByCredential(String credential) { - return userRepository.findByUsernameOrEmail(credential) - .orElseThrow(() -> { - logger.warn("Login failed - user not found: {}", credential); - return new AuthenticationException("Invalid credentials"); - }); - } - - /** - * Validates that the provided password matches the user's stored password. - * - * @param user The user to validate - * @param rawPassword The password to check - * @throws AuthenticationException if passwords don't match - */ - private void validateUserPassword(UserModel user, String rawPassword) { - if (!passwordEncoder.matches(rawPassword, user.getPassword())) { - logger.warn("Login failed - password mismatch for user: {}", user.getUsername()); - throw new AuthenticationException("Invalid credentials"); - } - } - - /** - * Verifies that the user account is enabled. - * - * @param user The user to check - * @throws AuthenticationException if account is disabled - */ - private void checkAccountEnabled(UserModel user) { - if (!user.isEnabled()) { - logger.warn("Login failed - account disabled: {}", user.getUsername()); - throw new AuthenticationException("Account is disabled"); - } - } - - /** - * Performs Spring Security authentication. - * - * @param username The username to authenticate - * @param password The password to verify - * @return Authentication object - */ - private Authentication performSpringAuthentication(String username, String password) { - return authenticationManager.authenticate( - new UsernamePasswordAuthenticationToken(username, password) - ); - } - - /** - * Retrieves user after successful Spring authentication. - * - * @param username The username to find - * @return Found UserModel - * @throws AuthenticationException if user not found (shouldn't happen after successful auth) - */ - private UserModel findAuthenticatedUser(String username) { - return userRepository.findByUsername(username) - .orElseThrow(() -> { - logger.error("Authentication succeeded but user not found: {}", username); - return new AuthenticationException("User account error"); - }); - } - - /** - * Handles authentication failures consistently. - * - * @param logMessage The log message template - * @param username The username that failed authentication - * @param exceptionMessage The exception message to throw - * @throws AuthenticationException always - */ - private void handleAuthenticationFailure(String logMessage, String username, String exceptionMessage) { - logger.warn(logMessage, username); - throw new AuthenticationException(exceptionMessage); - } - - /** - * Assigns the default role to a user (must be called within a transaction). - * - * @param user The user to assign the role to - */ - @Transactional(propagation = Propagation.MANDATORY) - protected void assignDefaultRole(UserModel user) { - AuthorityModel authority = authorityRepository.findByAuthority(DEFAULT_ROLE) - .orElseGet(this::createAndSaveNewAuthority); - user.addAuthority(authority); - } - - /** - * Creates and persists a new authority role. - * - * @return The newly created AuthorityModel - */ - private AuthorityModel createAndSaveNewAuthority() { - AuthorityModel newRole = new AuthorityModel(DEFAULT_ROLE); - newRole.setUsers(new HashSet<>()); - return authorityRepository.save(newRole); - } - - /* ======================== Custom Exceptions ======================== */ - - /** - * Exception thrown when authentication fails for any reason. - */ - public static class AuthenticationException extends RuntimeException { - public AuthenticationException(String message) { - super(message); - logger.error("Authentication failed: {}", message); - } - } - - /** - * Exception thrown when attempting to register with an existing username. - */ - public static class UsernameExistsException extends RuntimeException { - public UsernameExistsException(String username) { - super(String.format("Username '%s' already exists", username)); - logger.warn("Registration attempt with existing username: {}", username); - } - } - - /** - * Exception thrown when attempting to register with an existing email. - */ - public static class EmailExistsException extends RuntimeException { - public EmailExistsException(String email) { - super(String.format("Email '%s' is already registered", email)); - logger.warn("Registration attempt with existing email: {}", email); - } - } -} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java index 572d9b3bd..e1036eb06 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java @@ -16,35 +16,15 @@ import org.springframework.security.web.csrf.CookieCsrfTokenRepository; import org.springframework.security.web.header.writers.XXssProtectionHeaderWriter; -/** - * Security configuration class that defines the application's security policies. - * This includes authentication, authorization, session management, CSRF protection, - * and security headers configuration. - * - *

    The configuration enables: - *

      - *
    • JDBC-based HTTP session management
    • - *
    • Form-based authentication with custom success handler
    • - *
    • Role-based authorization
    • - *
    • Secure session management
    • - *
    • CSRF protection with cookie storage
    • - *
    • Security headers including XSS protection and CSP
    • - *
    - */ @Configuration @EnableWebSecurity - public class SecurityConfig { - /** - * Public endpoints that don't require authentication. - * These include static resources, public APIs, and authentication-related pages. - */ private static final String[] PUBLIC_ENDPOINTS = { "/", "/home", - "/login", - "/register", + "/auth/login", + "/auth/register", "/css/**", "/js/**", "/images/**", @@ -55,22 +35,10 @@ public class SecurityConfig { private final CustomUserDetailsService userDetailsService; - /** - * Constructs a new SecurityConfig with the required UserDetailsService. - * - * @param userDetailsService the custom user details service for authentication - */ public SecurityConfig(CustomUserDetailsService userDetailsService) { this.userDetailsService = userDetailsService; } - /** - * Configures the security filter chain that defines all security policies. - * - * @param http the HttpSecurity to configure - * @return the configured SecurityFilterChain - * @throws Exception if an error occurs during configuration - */ @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { configureAuthorization(http); @@ -84,12 +52,6 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti return http.build(); } - /** - * Configures authorization rules for endpoints. - * - * @param http the HttpSecurity to configure - * @throws Exception if an error occurs during configuration - */ private void configureAuthorization(HttpSecurity http) throws Exception { http.authorizeHttpRequests(auth -> auth .requestMatchers(PUBLIC_ENDPOINTS).permitAll() @@ -98,34 +60,23 @@ private void configureAuthorization(HttpSecurity http) throws Exception { ); } - /** - * Configures form-based login. - * - * @param http the HttpSecurity to configure - * @throws Exception if an error occurs during configuration - */ private void configureFormLogin(HttpSecurity http) throws Exception { http.formLogin(form -> form - .loginPage("/login") - .loginProcessingUrl("/perform_login") + .loginPage("/auth/login") // Changed to match controller mapping + .loginProcessingUrl("/auth/login") // Changed to match controller .successHandler(authenticationSuccessHandler()) - .failureUrl("/login?error=true") + .failureUrl("/auth/login?error=true") + .defaultSuccessUrl("/dashboard") .usernameParameter("username") .passwordParameter("password") .permitAll() ); } - /** - * Configures logout behavior. - * - * @param http the HttpSecurity to configure - * @throws Exception if an error occurs during configuration - */ private void configureLogout(HttpSecurity http) throws Exception { http.logout(logout -> logout - .logoutUrl("/perform_logout") - .logoutSuccessUrl("/login?logout") + .logoutUrl("/auth/logout") // Changed to match controller + .logoutSuccessUrl("/auth/login?logout") // Changed to match controller .deleteCookies("JSESSIONID", "XSRF-TOKEN") .invalidateHttpSession(true) .clearAuthentication(true) @@ -133,40 +84,22 @@ private void configureLogout(HttpSecurity http) throws Exception { ); } - /** - * Configures session management policies. - * - * @param http the HttpSecurity to configure - * @throws Exception if an error occurs during configuration - */ private void configureSessionManagement(HttpSecurity http) throws Exception { http.sessionManagement(session -> session .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) - .invalidSessionUrl("/login?invalid-session") + .invalidSessionUrl("/auth/login?invalid-session") // Changed to match controller .maximumSessions(1) .maxSessionsPreventsLogin(false) - .expiredUrl("/login?session-expired") + .expiredUrl("/auth/login?session-expired") // Changed to match controller ); } - /** - * Configures exception handling for security-related exceptions. - * - * @param http the HttpSecurity to configure - * @throws Exception if an error occurs during configuration - */ private void configureExceptionHandling(HttpSecurity http) throws Exception { http.exceptionHandling(exceptions -> exceptions .accessDeniedPage("/access-denied") ); } - /** - * Configures CSRF protection with exceptions for API endpoints. - * - * @param http the HttpSecurity to configure - * @throws Exception if an error occurs during configuration - */ private void configureCsrfProtection(HttpSecurity http) throws Exception { http.csrf(csrf -> csrf .ignoringRequestMatchers("/api/**") @@ -174,12 +107,6 @@ private void configureCsrfProtection(HttpSecurity http) throws Exception { ); } - /** - * Configures security headers including XSS protection and Content Security Policy. - * - * @param http the HttpSecurity to configure - * @throws Exception if an error occurs during configuration - */ private void configureSecurityHeaders(HttpSecurity http) throws Exception { http.headers(headers -> headers .xssProtection(xss -> xss @@ -193,34 +120,17 @@ private void configureSecurityHeaders(HttpSecurity http) throws Exception { ); } - /** - * Provides a custom authentication success handler bean. - * - * @return the configured AuthenticationSuccessHandler - */ @Bean public AuthenticationSuccessHandler authenticationSuccessHandler() { return new CustomAuthenticationSuccessHandler(); } - /** - * Provides the AuthenticationManager bean. - * - * @param authenticationConfiguration the authentication configuration - * @return the configured AuthenticationManager - * @throws Exception if an error occurs during configuration - */ @Bean public AuthenticationManager authenticationManager( AuthenticationConfiguration authenticationConfiguration) throws Exception { return authenticationConfiguration.getAuthenticationManager(); } - /** - * Provides the password encoder bean using BCrypt hashing. - * - * @return the configured PasswordEncoder - */ @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java index 7337df27c..b7e49c8ce 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AdminController.java @@ -1,7 +1,7 @@ package com.jydoc.deliverable4.controllers; import com.jydoc.deliverable4.model.UserModel; -import com.jydoc.deliverable4.Service.UserService; +import com.jydoc.deliverable4.services.UserService; import com.jydoc.deliverable4.security.Exceptions.UserNotFoundException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java index 626778b25..788890c03 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java @@ -1,127 +1,101 @@ package com.jydoc.deliverable4.controllers; -import com.jydoc.deliverable4.DTO.UserDTO; -import com.jydoc.deliverable4.DTO.LoginDTO; +import com.jydoc.deliverable4.dto.UserDTO; +import com.jydoc.deliverable4.dto.LoginDTO; import com.jydoc.deliverable4.model.UserModel; -import com.jydoc.deliverable4.Service.UserService; +import com.jydoc.deliverable4.services.AuthService; +import com.jydoc.deliverable4.services.UserService; import jakarta.servlet.http.HttpSession; import jakarta.validation.Valid; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.support.RedirectAttributes; -/** - * Controller handling all authentication-related operations including user registration, - * login/logout functionality, and session management. - * - *

    This controller follows RESTful principles while returning Thymeleaf template names - * for view resolution. It provides endpoints for:

    - *
      - *
    • User registration flow
    • - *
    • Login/logout processes
    • - *
    • Session management
    • - *
    • Home page display
    • - *
    - * - *

    All endpoints include proper validation and error handling with appropriate - * redirects and flash attributes.

    - */ @Controller +@RequestMapping("/auth") public class AuthController { - private static final Logger logger = LoggerFactory.getLogger(AuthController.class); + private static final String USER_ATTRIBUTE = "user"; + private static final String REDIRECT_LOGIN = "redirect:/auth/login"; + private static final String LOGIN_VIEW = "auth/login"; + private static final String REGISTER_VIEW = "auth/register"; + + private final AuthService authService; private final UserService userService; - /** - * Constructs an AuthController with the required UserService dependency. - * - * @param userService the service handling user operations and business logic - */ - public AuthController(UserService userService) { + public AuthController(AuthService authService, UserService userService) { + this.authService = authService; this.userService = userService; } - /* ==================== REGISTRATION ENDPOINTS ==================== */ + /* ==================== REGISTRATION ==================== */ - /** - * Displays the user registration form. - * - * @param model the Spring Model to which the empty UserDTO is added - * @return the "register" template name for view resolution - */ @GetMapping("/register") public String showRegistrationForm(Model model) { - model.addAttribute("user", new UserDTO()); - return "register"; + if (!model.containsAttribute("user")) { + model.addAttribute("user", new UserDTO()); + } + return REGISTER_VIEW; } - /** - * Processes user registration form submission. - * - * @param userDto the user data transfer object containing registration info - * @param result the binding result for validation errors - * @return redirect to login page on success, or re-show form with errors - */ @PostMapping("/register") public String registerUser( @Valid @ModelAttribute("user") UserDTO userDto, - BindingResult result) { + BindingResult result, + RedirectAttributes redirectAttributes) { if (result.hasErrors()) { - logger.debug("Registration validation errors present: {}", result.getAllErrors()); - return "register"; + logger.debug("Registration validation errors: {}", result.getAllErrors()); + redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.user", result); + redirectAttributes.addFlashAttribute("user", userDto); + return "redirect:/auth/register"; } try { - userService.registerNewUser(userDto); - logger.info("User {} registered successfully", userDto.getUsername()); - return "redirect:/login?registered"; + authService.registerNewUser(userDto); + logger.info("User registered successfully: {}", userDto.getUsername()); + redirectAttributes.addFlashAttribute("success", "Registration successful! Please login."); + return REDIRECT_LOGIN; + } catch (AuthService.UsernameExistsException | AuthService.EmailExistsException e) { + logger.error("Registration failed: {}", e.getMessage()); + redirectAttributes.addFlashAttribute("error", e.getMessage()); + redirectAttributes.addFlashAttribute("user", userDto); + return "redirect:/auth/register"; } catch (Exception e) { - logger.error("Registration failed for {}: {}", userDto.getUsername(), e.getMessage()); - result.reject("registration.error", "Registration failed: " + e.getMessage()); - return "register"; + logger.error("Unexpected registration error: {}", e.getMessage()); + redirectAttributes.addFlashAttribute("error", "Registration failed. Please try again."); + redirectAttributes.addFlashAttribute("user", userDto); + return "redirect:/auth/register"; } } - /* ==================== LOGIN ENDPOINTS ==================== */ - - /** - * Displays the login form with optional status indicators. - * - * @param model the Spring Model for view attributes - * @param error optional flag indicating previous login error - * @param registered optional flag indicating successful registration - * @param logout optional flag indicating successful logout - * @return the "login" template name for view resolution - */ + /* ==================== LOGIN ==================== */ + @GetMapping("/login") public String showLoginForm( Model model, @RequestParam(required = false) String error, - @RequestParam(required = false) String registered, @RequestParam(required = false) String logout) { - model.addAttribute("loginData", LoginDTO.empty()); - model.addAttribute("error", error != null); - model.addAttribute("registered", registered != null); - model.addAttribute("logout", logout != null); + if (!model.containsAttribute("loginData")) { + model.addAttribute("loginData", new LoginDTO("", "")); + } + + if (error != null) { + model.addAttribute("error", "Invalid username or password"); + } + if (logout != null) { + model.addAttribute("success", "You have been logged out successfully"); + } - return "login"; + return LOGIN_VIEW; } - /** - * Processes login form submission and authenticates the user. - * - * @param loginDto the login credentials data transfer object - * @param result the binding result for validation errors - * @param session the HTTP session to store authenticated user - * @param redirectAttributes for flash attributes during redirect - * @return redirect to appropriate page based on user role, or re-show form with errors - */ @PostMapping("/login") public String loginUser( @Valid @ModelAttribute("loginData") LoginDTO loginDto, @@ -129,78 +103,52 @@ public String loginUser( HttpSession session, RedirectAttributes redirectAttributes) { - logger.debug("Processing login for: {}", loginDto.username()); - if (result.hasErrors()) { logger.debug("Login validation errors"); - return "login"; + redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.loginData", result); + redirectAttributes.addFlashAttribute("loginData", loginDto); + return "redirect:/auth/login"; } try { - UserModel user = userService.validateLogin(loginDto); - session.setAttribute("user", user); + UserModel user = authService.validateLogin(loginDto); + session.setAttribute(USER_ATTRIBUTE, user); + logger.info("User logged in: {}", user.getUsername()); - return isAdmin(user) - ? "redirect:/admin/dashboard" - : "redirect:/home"; + return determineRedirectUrl(user); - } catch (UserService.AuthenticationException e) { + } catch (AuthService.AuthenticationException e) { logger.error("Login failed: {}", e.getMessage()); - redirectAttributes.addFlashAttribute("error", "Invalid credentials"); - return "redirect:/login?error"; + redirectAttributes.addFlashAttribute("error", e.getMessage()); + redirectAttributes.addFlashAttribute("loginData", loginDto); + return "redirect:/auth/login"; } } - /** - * Checks if the given user has admin privileges. - * - * @param user the user model to check - * @return true if user has admin role, false otherwise - */ - private boolean isAdmin(UserModel user) { - return user.getAuthorities().stream() - .anyMatch(auth -> auth.getAuthority().equals("ROLE_ADMIN")); - } + /* ==================== LOGOUT ==================== */ - /* ==================== HOME ENDPOINT ==================== */ - - /** - * Displays the home page for authenticated users. - * - * @param model the Spring Model for view attributes - * @param session the HTTP session containing the authenticated user - * @return the "index" template name for view resolution - */ - @GetMapping("/home") - public String showHomePage(Model model, HttpSession session) { - UserModel user = (UserModel) session.getAttribute("user"); + @GetMapping("/logout") + @PreAuthorize("isAuthenticated()") + public String performLogout(HttpSession session) { + UserModel user = (UserModel) session.getAttribute(USER_ATTRIBUTE); if (user != null) { - model.addAttribute("username", user.getUsername()); + logger.info("User logged out: {}", user.getUsername()); + session.invalidate(); } - return "index"; + return REDIRECT_LOGIN + "?logout"; } - /* ==================== LOGOUT ENDPOINTS ==================== */ + /* ==================== HELPER METHODS ==================== */ - /** - * Displays the logout confirmation page. - * - * @return the "logout" template name for view resolution - */ - @GetMapping("/confirm-logout") - public String showLogoutConfirmation() { - return "logout"; + private String determineRedirectUrl(UserModel user) { + if (isAdmin(user)) { + return "redirect:/admin/dashboard"; + } + return "redirect:/user/dashboard"; } - /** - * Processes logout request by invalidating the session. - * - * @param session the HTTP session to invalidate - * @return redirect to login page with logout flag - */ - @PostMapping("/logout") - public String performLogout(HttpSession session) { - session.invalidate(); - return "redirect:/login?logout"; + private boolean isAdmin(UserModel user) { + return user.getAuthorities().stream() + .anyMatch(auth -> "ROLE_ADMIN".equals(auth.getAuthority())); } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/UserController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/UserController.java index 69bed18db..2a5ccda28 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/UserController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/UserController.java @@ -1,11 +1,70 @@ package com.jydoc.deliverable4.controllers; +import com.jydoc.deliverable4.services.UserService; +import com.jydoc.deliverable4.services.MedicationService; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.*; @Controller @RequestMapping("/user") @PreAuthorize("hasRole('ROLE_USER')") public class UserController { + + private final UserService userService; + private final MedicationService medicationService; + + public UserController(UserService userService, MedicationService medicationService) { + this.userService = userService; + this.medicationService = medicationService; + } + +// @GetMapping +// public String userProfile(Model model, Principal principal) { +// User user = userService.findUserByCredential(principal.getName()); +// model.addAttribute("user", user); +// model.addAttribute("medicationCount", medicationService.getUserMedications(user).size()); +// return "user/profile"; +// } +// +// @GetMapping("/edit") +// public String editProfileForm(Model model, Principal principal) { +// User user = userService.findUserByCredential(principal.getName()); +// model.addAttribute("user", user); +// return "user/edit"; +// } +// +// @PostMapping("/edit") +// public String updateProfile(@Valid @ModelAttribute("user") User updatedUser, +// BindingResult result, +// Principal principal) { +// if (result.hasErrors()) { +// return "user/edit"; +// } +// +// User currentUser = userService.findUserByCredential(principal.getName()); +// userService.updateUser(currentUser, updatedUser); +// return "redirect:/user?updated"; +// } + +// @GetMapping("/change-password") +// public String changePasswordForm() { +// return "user/change-password"; +// } +// +// @PostMapping("/change-password") +// public String changePassword(@RequestParam String currentPassword, +// @RequestParam String newPassword, +// @RequestParam String confirmPassword, +// Principal principal, +// RedirectAttributes redirectAttributes) { +// try { +// userService.changePassword(principal.getName(), currentPassword, newPassword, confirmPassword); +// redirectAttributes.addFlashAttribute("success", "Password changed successfully!"); +// return "redirect:/user"; +// } catch (Exception e) { +// redirectAttributes.addFlashAttribute("error", e.getMessage()); +// return "redirect:/user/change-password"; +// } +// } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/dto/LoginDTO.java similarity index 94% rename from Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java rename to Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/dto/LoginDTO.java index 39bd9d916..6836dda44 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/LoginDTO.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/dto/LoginDTO.java @@ -1,4 +1,4 @@ -package com.jydoc.deliverable4.DTO; +package com.jydoc.deliverable4.dto; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/dto/UserDTO.java similarity index 94% rename from Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java rename to Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/dto/UserDTO.java index 04f029be2..ed3d24f03 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/DTO/UserDTO.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/dto/UserDTO.java @@ -1,6 +1,5 @@ -package com.jydoc.deliverable4.DTO; +package com.jydoc.deliverable4.dto; -import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Size; diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/initializers/AuthorityInitializer.java similarity index 95% rename from Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java rename to Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/initializers/AuthorityInitializer.java index b27323c75..4ca0436a4 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Initializers/AuthorityInitializer.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/initializers/AuthorityInitializer.java @@ -1,4 +1,4 @@ -package com.jydoc.deliverable4.Initializers; +package com.jydoc.deliverable4.initializers; import com.jydoc.deliverable4.model.AuthorityModel; import com.jydoc.deliverable4.repositories.AuthorityRepository; diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/AuthService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/AuthService.java new file mode 100644 index 000000000..15c29cb52 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/AuthService.java @@ -0,0 +1,227 @@ +package com.jydoc.deliverable4.services; + +import com.jydoc.deliverable4.dto.LoginDTO; +import com.jydoc.deliverable4.dto.UserDTO; +import com.jydoc.deliverable4.model.AuthorityModel; +import com.jydoc.deliverable4.model.UserModel; +import com.jydoc.deliverable4.repositories.AuthorityRepository; +import com.jydoc.deliverable4.repositories.UserRepository; +import lombok.RequiredArgsConstructor; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.DisabledException; +import org.springframework.security.authentication.LockedException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.HashSet; + +/** + * Service handling all authentication and authorization operations including: + * - User registration + * - Login authentication + * - Credential validation + * - Role assignment + */ +@Service +@RequiredArgsConstructor +public class AuthService { + private static final Logger logger = LogManager.getLogger(AuthService.class); + private static final String DEFAULT_ROLE = "ROLE_USER"; + + private final UserRepository userRepository; + private final AuthorityRepository authorityRepository; + private final PasswordEncoder passwordEncoder; + private final AuthenticationManager authenticationManager; + private final UserValidationHelper validationHelper; + + /* ================ Public Authentication Methods ================ */ + + /** + * Registers a new user with validation and default role assignment + * @param userDto User registration data + * @throws IllegalArgumentException if validation fails + * @throws AuthService.UsernameExistsException if username taken + * @throws AuthService.EmailExistsException if email registered + */ + @Transactional + public void registerNewUser(UserDTO userDto) { + validationHelper.validateUserRegistration(userDto); + validateUserDto(userDto); + checkForExistingCredentials(userDto); + + UserModel user = createUserFromDto(userDto); + assignDefaultRole(user); + userRepository.save(user); + logger.info("Registered new user: {}", user.getUsername()); + } + + /** + * Authenticates using Spring Security's authentication manager + * @param loginDto Contains username and password + * @return Authenticated user entity + * @throws AuthService.AuthenticationException for auth failures + */ + @Transactional(readOnly = true) + public UserModel authenticate(LoginDTO loginDto) { + if (loginDto == null) { + throw new IllegalArgumentException("Login credentials cannot be null"); + } + return authenticateUser(loginDto.username(), loginDto.password()); + } + + /** + * Direct credential validation against database + * @param loginDto Contains credentials + * @return Validated user entity + * @throws AuthService.AuthenticationException for invalid credentials + */ + @Transactional(readOnly = true) + public UserModel validateLogin(LoginDTO loginDto) { + if (loginDto == null) { + throw new IllegalArgumentException("Login credentials cannot be null"); + } + + String credential = loginDto.username().trim().toLowerCase(); + String rawPassword = loginDto.password(); + + logger.debug("Login attempt for: {}", credential); + UserModel user = findUserByCredential(credential); + validateUserPassword(user, rawPassword); + checkAccountEnabled(user); + + logger.info("Login successful for: {}", user.getUsername()); + return user; + } + + /* ================ Private Helper Methods ================ */ + + private UserModel authenticateUser(String username, String password) { + try { + Authentication authentication = authenticationManager.authenticate( + new UsernamePasswordAuthenticationToken(username, password) + ); + return findAuthenticatedUser(authentication.getName()); + } catch (BadCredentialsException e) { + handleAuthenticationFailure("Bad credentials for user: {}", username, "Invalid username or password"); + } catch (DisabledException e) { + handleAuthenticationFailure("Disabled account: {}", username, "Account is disabled"); + } catch (LockedException e) { + handleAuthenticationFailure("Locked account: {}", username, "Account is locked"); + } + return null; // Unreachable due to exception handling + } + + private void validateUserDto(UserDTO userDto) { + if (userDto == null) throw new IllegalArgumentException("UserDTO cannot be null"); + if (userDto.getUsername() == null || userDto.getUsername().trim().isEmpty()) + throw new IllegalArgumentException("Username cannot be empty"); + if (userDto.getPassword() == null || userDto.getPassword().trim().isEmpty()) + throw new IllegalArgumentException("Password cannot be empty"); + if (userDto.getEmail() == null || userDto.getEmail().trim().isEmpty()) + throw new IllegalArgumentException("Email cannot be empty"); + if (userDto.getFirstName() == null || userDto.getFirstName().trim().isEmpty()) + throw new IllegalArgumentException("First name cannot be empty"); + if (userDto.getLastName() == null || userDto.getLastName().trim().isEmpty()) + throw new IllegalArgumentException("Last name cannot be empty"); + } + + private void checkForExistingCredentials(UserDTO userDto) { + if (userRepository.existsByUsername(userDto.getUsername())) { + throw new UsernameExistsException(userDto.getUsername()); + } + if (userRepository.existsByEmail(userDto.getEmail())) { + throw new EmailExistsException(userDto.getEmail()); + } + } + + private UserModel createUserFromDto(UserDTO userDto) { + return UserModel.builder() + .username(userDto.getUsername().trim()) + .password(passwordEncoder.encode(userDto.getPassword())) + .email(userDto.getEmail().toLowerCase().trim()) + .firstName(userDto.getFirstName().trim()) + .lastName(userDto.getLastName().trim()) + .enabled(true) + .accountNonExpired(true) + .credentialsNonExpired(true) + .accountNonLocked(true) + .build(); + } + + @Transactional(propagation = Propagation.MANDATORY) + protected void assignDefaultRole(UserModel user) { + AuthorityModel authority = authorityRepository.findByAuthority(DEFAULT_ROLE) + .orElseGet(this::createAndSaveNewAuthority); + user.addAuthority(authority); + } + + private AuthorityModel createAndSaveNewAuthority() { + AuthorityModel newRole = new AuthorityModel(DEFAULT_ROLE); + newRole.setUsers(new HashSet<>()); + return authorityRepository.save(newRole); + } + + private UserModel findUserByCredential(String credential) { + return userRepository.findByUsernameOrEmail(credential) + .orElseThrow(() -> { + logger.warn("User not found: {}", credential); + return new AuthenticationException("Invalid credentials"); + }); + } + + private void validateUserPassword(UserModel user, String rawPassword) { + if (!passwordEncoder.matches(rawPassword, user.getPassword())) { + logger.warn("Password mismatch for user: {}", user.getUsername()); + throw new AuthenticationException("Invalid credentials"); + } + } + + private void checkAccountEnabled(UserModel user) { + if (!user.isEnabled()) { + logger.warn("Disabled account login attempt: {}", user.getUsername()); + throw new AuthenticationException("Account is disabled"); + } + } + + private UserModel findAuthenticatedUser(String username) { + return userRepository.findByUsername(username) + .orElseThrow(() -> { + logger.error("Authenticated user not found: {}", username); + return new AuthenticationException("User account error"); + }); + } + + private void handleAuthenticationFailure(String logMessage, String username, String exceptionMessage) { + logger.warn(logMessage, username); + throw new AuthenticationException(exceptionMessage); + } + + /* ================ Custom Exceptions ================ */ + public static class AuthenticationException extends RuntimeException { + public AuthenticationException(String message) { + super(message); + logger.error("Authentication failed: {}", message); + } + } + + public static class UsernameExistsException extends RuntimeException { + public UsernameExistsException(String username) { + super(String.format("Username '%s' already exists", username)); + logger.warn("Duplicate username: {}", username); + } + } + + public static class EmailExistsException extends RuntimeException { + public EmailExistsException(String email) { + super(String.format("Email '%s' already registered", email)); + logger.warn("Duplicate email: {}", email); + } + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/MedicationService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/MedicationService.java new file mode 100644 index 000000000..23593cda0 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/MedicationService.java @@ -0,0 +1,14 @@ +package com.jydoc.deliverable4.services; + +import org.apache.catalina.User; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.Collections; + +@Service +public class MedicationService { + public Collection getUserMedications(User user) { + return Collections.singleton(false); + } +} diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/UserService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/UserService.java new file mode 100644 index 000000000..5ebeedfb9 --- /dev/null +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/UserService.java @@ -0,0 +1,62 @@ +package com.jydoc.deliverable4.services; + +import com.jydoc.deliverable4.model.UserModel; +import com.jydoc.deliverable4.repositories.UserRepository; +import lombok.RequiredArgsConstructor; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class UserService { + private static final Logger logger = LogManager.getLogger(UserService.class); + + private final UserRepository userRepository; + + @Transactional(readOnly = true) + public Optional findActiveUser(String usernameOrEmail) { + return userRepository.findByUsernameOrEmail(usernameOrEmail.trim().toLowerCase()) + .filter(UserModel::isEnabled); + } + + @Transactional(readOnly = true) + public long getUserCount() { + return userRepository.count(); + } + + @Transactional(readOnly = true) + public boolean existsById(Long id) { + return userRepository.existsById(id); + } + + @Transactional(readOnly = true) + public List getAllUsers() { + return userRepository.findAll(); + } + + @Transactional(readOnly = true) + public Optional getUserById(Long id) { + return userRepository.findById(id); + } + + @Transactional + public void updateUser(UserModel user) { + userRepository.save(user); + } + + @Transactional + public void deleteUser(Long id) { + userRepository.deleteById(id); + } + + @Transactional(readOnly = true) + public UserModel findByUsername(String username) { + return userRepository.findByUsername(username) + .orElseThrow(() -> new IllegalArgumentException("User not found")); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserValidationHelper.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/UserValidationHelper.java similarity index 94% rename from Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserValidationHelper.java rename to Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/UserValidationHelper.java index d6acb274a..b46a953f1 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/Service/UserValidationHelper.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/UserValidationHelper.java @@ -1,90 +1,90 @@ -package com.jydoc.deliverable4.Service; - -import com.jydoc.deliverable4.DTO.UserDTO; -import com.jydoc.deliverable4.security.Exceptions.EmailExistsException; -import com.jydoc.deliverable4.security.Exceptions.UsernameExistsException; -import com.jydoc.deliverable4.repositories.UserRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * Service component responsible for validating user registration data. - *

    - * Performs checks for duplicate usernames and email addresses before user registration. - * All validation methods are transactional and read-only to ensure data consistency. - */ -@Service -@RequiredArgsConstructor -public class UserValidationHelper { - - private final UserRepository userRepository; - - /** - * Validates user registration data for potential conflicts. - * - * @param userDto the user data transfer object containing registration information - * @throws IllegalArgumentException if the provided user data is null - * @throws UsernameExistsException if the username is already registered - * @throws EmailExistsException if the email address is already registered - */ - @Transactional(readOnly = true) - public void validateUserRegistration(UserDTO userDto) { - if (userDto == null) { - throw new IllegalArgumentException("User data cannot be null"); - } - - validateUsername(userDto.getUsername()); - validateEmail(userDto.getEmail()); - } - - /** - * Checks if a username already exists in the system. - * - * @param username the username to check (will be trimmed before checking) - * @throws UsernameExistsException if the username is already taken - */ - @Transactional(readOnly = true) - public void validateUsername(String username) { - String normalizedUsername = username.trim(); - if (existsByUsername(normalizedUsername)) { - throw new UsernameExistsException(normalizedUsername); - } - } - - /** - * Checks if an email address already exists in the system. - * - * @param email the email to check (will be normalized to lowercase and trimmed) - * @throws EmailExistsException if the email is already registered - */ - @Transactional(readOnly = true) - public void validateEmail(String email) { - String normalizedEmail = email.trim().toLowerCase(); - if (existsByEmail(normalizedEmail)) { - throw new EmailExistsException(normalizedEmail); - } - } - - /** - * Checks if a username exists in the repository. - * - * @param username the username to check - * @return true if the username exists, false otherwise - */ - @Transactional(readOnly = true) - public boolean existsByUsername(String username) { - return userRepository.existsByUsername(username); - } - - /** - * Checks if an email exists in the repository. - * - * @param email the email to check - * @return true if the email exists, false otherwise - */ - @Transactional(readOnly = true) - public boolean existsByEmail(String email) { - return userRepository.existsByEmail(email); - } +package com.jydoc.deliverable4.services; + +import com.jydoc.deliverable4.dto.UserDTO; +import com.jydoc.deliverable4.security.Exceptions.EmailExistsException; +import com.jydoc.deliverable4.security.Exceptions.UsernameExistsException; +import com.jydoc.deliverable4.repositories.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * Service component responsible for validating user registration data. + *

    + * Performs checks for duplicate usernames and email addresses before user registration. + * All validation methods are transactional and read-only to ensure data consistency. + */ +@Service +@RequiredArgsConstructor +public class UserValidationHelper { + + private final UserRepository userRepository; + + /** + * Validates user registration data for potential conflicts. + * + * @param userDto the user data transfer object containing registration information + * @throws IllegalArgumentException if the provided user data is null + * @throws UsernameExistsException if the username is already registered + * @throws EmailExistsException if the email address is already registered + */ + @Transactional(readOnly = true) + public void validateUserRegistration(UserDTO userDto) { + if (userDto == null) { + throw new IllegalArgumentException("User data cannot be null"); + } + + validateUsername(userDto.getUsername()); + validateEmail(userDto.getEmail()); + } + + /** + * Checks if a username already exists in the system. + * + * @param username the username to check (will be trimmed before checking) + * @throws UsernameExistsException if the username is already taken + */ + @Transactional(readOnly = true) + public void validateUsername(String username) { + String normalizedUsername = username.trim(); + if (existsByUsername(normalizedUsername)) { + throw new UsernameExistsException(normalizedUsername); + } + } + + /** + * Checks if an email address already exists in the system. + * + * @param email the email to check (will be normalized to lowercase and trimmed) + * @throws EmailExistsException if the email is already registered + */ + @Transactional(readOnly = true) + public void validateEmail(String email) { + String normalizedEmail = email.trim().toLowerCase(); + if (existsByEmail(normalizedEmail)) { + throw new EmailExistsException(normalizedEmail); + } + } + + /** + * Checks if a username exists in the repository. + * + * @param username the username to check + * @return true if the username exists, false otherwise + */ + @Transactional(readOnly = true) + public boolean existsByUsername(String username) { + return userRepository.existsByUsername(username); + } + + /** + * Checks if an email exists in the repository. + * + * @param email the email to check + * @return true if the email exists, false otherwise + */ + @Transactional(readOnly = true) + public boolean existsByEmail(String email) { + return userRepository.existsByEmail(email); + } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/application-test.properties b/Sprint 2/prototype2/src/main/resources/application-test.properties index e8297d8ac..50a306302 100644 --- a/Sprint 2/prototype2/src/main/resources/application-test.properties +++ b/Sprint 2/prototype2/src/main/resources/application-test.properties @@ -28,7 +28,6 @@ spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true -spring.sql.init.enabled=false spring.jpa.defer-datasource-initialization=true # ====================== diff --git a/Sprint 2/prototype2/src/main/resources/templates/auth/login.html b/Sprint 2/prototype2/src/main/resources/templates/auth/login.html new file mode 100644 index 000000000..b8b3a98e2 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/auth/login.html @@ -0,0 +1,93 @@ + + + + + + Login | Your Application + + + + + +

    + +
    +
    +
    +
    +
    +
    +

    Login

    +

    Access your account to continue

    +
    + + + + + + + + + +
    + + +
    + + +
    + +
    + + + +
    + +
    + +
    + +
    +

    Don't have an account? + Register here +

    +
    +
    +
    +
    +
    +
    +
    + +
    + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/logout.html b/Sprint 2/prototype2/src/main/resources/templates/auth/logout.html similarity index 96% rename from Sprint 2/prototype2/src/main/resources/templates/logout.html rename to Sprint 2/prototype2/src/main/resources/templates/auth/logout.html index f68ec77a1..30db3f444 100644 --- a/Sprint 2/prototype2/src/main/resources/templates/logout.html +++ b/Sprint 2/prototype2/src/main/resources/templates/auth/logout.html @@ -1,26 +1,26 @@ - - - - - Logout - - - -
    - -
    -

    Are you sure you want to log out?

    - - -
    - - -
    - - - Cancel -
    - -
    - + + + + + Logout + + + +
    + +
    +

    Are you sure you want to log out?

    + + +
    + + +
    + + + Cancel +
    + +
    + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/auth/register.html b/Sprint 2/prototype2/src/main/resources/templates/auth/register.html new file mode 100644 index 000000000..b6c0df266 --- /dev/null +++ b/Sprint 2/prototype2/src/main/resources/templates/auth/register.html @@ -0,0 +1,99 @@ + + + + + + Register | Your Application + + + + + +
    + +
    +
    +
    +
    +
    +
    +

    Create Account

    +

    Join our platform to get started

    +
    + + + + +
    + + +
    +
    + + +
    +
    + +
    + + +
    +
    +
    + +
    + + +
    +
    + +
    + + +
    +
    + +
    + + +
    Use 8 or more characters with a mix of letters, numbers & symbols
    +
    +
    + +
    + +
    + +
    +

    Already have an account? + Login here +

    +
    +
    +
    +
    +
    +
    +
    + +
    + + + + \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/dashboard/dashboard.html b/Sprint 2/prototype2/src/main/resources/templates/dashboard.html similarity index 99% rename from Sprint 2/prototype2/src/main/resources/templates/dashboard/dashboard.html rename to Sprint 2/prototype2/src/main/resources/templates/dashboard.html index f0b2298ad..d2fe193ac 100644 --- a/Sprint 2/prototype2/src/main/resources/templates/dashboard/dashboard.html +++ b/Sprint 2/prototype2/src/main/resources/templates/dashboard.html @@ -45,7 +45,7 @@ Welcome, -
    +
    diff --git a/Sprint 2/prototype2/src/main/resources/templates/index.html b/Sprint 2/prototype2/src/main/resources/templates/index.html index 2f9d79229..de4fb7a3a 100644 --- a/Sprint 2/prototype2/src/main/resources/templates/index.html +++ b/Sprint 2/prototype2/src/main/resources/templates/index.html @@ -30,7 +30,7 @@

    Welcome to Our Platform

    Register @@ -38,7 +38,7 @@

    Welcome to Our Platform

    Login @@ -46,7 +46,7 @@

    Welcome to Our Platform

    @@ -88,7 +88,7 @@

    Get Started

    + th:href="@{/auth/register}"> Create Account - - - - Login - - - -
    - -
    -

    Login

    - - -
    - Invalid username/email or password -
    -
    - You have been logged out -
    -
    - Your session has expired. Please login again. -
    - - - -
    - - - -
    -
    - - -
    - - - -

    Don't have an account? Register here

    -
    - - - - \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/register.html b/Sprint 2/prototype2/src/main/resources/templates/register.html deleted file mode 100644 index 79daa15fa..000000000 --- a/Sprint 2/prototype2/src/main/resources/templates/register.html +++ /dev/null @@ -1,55 +0,0 @@ - - - - - Register - - - -
    - -
    -

    Register

    - -
    - Registration failed. Please check your details. -
    - -
    -
    - - - -
    - -
    - - - -
    - -
    - - - -
    - -
    - - - -
    - -
    - - - -
    - - -
    - -

    Already have an account? Login here

    -
    - - \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/AuthServiceTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/AuthServiceTest.java new file mode 100644 index 000000000..83f52be59 --- /dev/null +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/AuthServiceTest.java @@ -0,0 +1,225 @@ +package com.jydoc.deliverable4; + +import com.jydoc.deliverable4.dto.LoginDTO; +import com.jydoc.deliverable4.dto.UserDTO; +import com.jydoc.deliverable4.model.AuthorityModel; +import com.jydoc.deliverable4.model.UserModel; +import com.jydoc.deliverable4.repositories.AuthorityRepository; +import com.jydoc.deliverable4.repositories.UserRepository; +import com.jydoc.deliverable4.services.AuthService; +import com.jydoc.deliverable4.services.UserValidationHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.DisabledException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.crypto.password.PasswordEncoder; + +import java.util.HashSet; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +class AuthServiceTest { + + @Mock + private UserRepository userRepository; + + @Mock + private AuthorityRepository authorityRepository; + + @Mock + private PasswordEncoder passwordEncoder; + + @Mock + private AuthenticationManager authenticationManager; + + @Mock + private UserValidationHelper validationHelper; + + @InjectMocks + private AuthService authService; + + private UserDTO testUserDto; + private LoginDTO testLoginDto; + private UserModel testUser; + private AuthorityModel testAuthority; + + @BeforeEach + void setUp() { + testUserDto = new UserDTO(); + testUserDto.setUsername("testuser"); + testUserDto.setEmail("test@example.com"); + testUserDto.setPassword("Password123!"); + testUserDto.setFirstName("Test"); + testUserDto.setLastName("User"); + + testLoginDto = new LoginDTO("testuser", "Password123!"); + + testUser = UserModel.builder() + .username("testuser") + .email("test@example.com") + .firstName("Test") + .lastName("User") + .password("encodedPassword") + .enabled(true) + .accountNonExpired(true) + .credentialsNonExpired(true) + .accountNonLocked(true) + .authorities(new HashSet<>()) + .build(); + + testAuthority = AuthorityModel.builder() + .authority("ROLE_USER") + .users(new HashSet<>()) + .build(); + } + + /* ======================== Registration Tests ======================== */ + + @Test + void registerNewUser_ValidUser_Success() { + when(userRepository.existsByUsername("testuser")).thenReturn(false); + when(userRepository.existsByEmail("test@example.com")).thenReturn(false); + when(passwordEncoder.encode("Password123!")).thenReturn("encodedPassword"); + when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.of(testAuthority)); + when(userRepository.save(any(UserModel.class))).thenReturn(testUser); + + authService.registerNewUser(testUserDto); + + verify(validationHelper).validateUserRegistration(testUserDto); + verify(userRepository).existsByUsername("testuser"); + verify(userRepository).existsByEmail("test@example.com"); + verify(passwordEncoder).encode("Password123!"); + verify(authorityRepository).findByAuthority("ROLE_USER"); + verify(userRepository).save(any(UserModel.class)); + } + + @Test + void registerNewUser_NullUserDto_ThrowsException() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> authService.registerNewUser(null)); + assertEquals("UserDTO cannot be null", exception.getMessage()); + } + + @Test + void registerNewUser_ExistingUsername_ThrowsException() { + when(userRepository.existsByUsername("testuser")).thenReturn(true); + + AuthService.UsernameExistsException exception = assertThrows( + AuthService.UsernameExistsException.class, + () -> authService.registerNewUser(testUserDto) + ); + assertEquals("Username 'testuser' already exists", exception.getMessage()); + verify(userRepository, never()).save(any(UserModel.class)); + } + + @Test + void registerNewUser_EmptyPassword_ThrowsException() { + testUserDto.setPassword(""); + + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> authService.registerNewUser(testUserDto)); + assertEquals("Password cannot be empty", exception.getMessage()); + verifyNoInteractions(userRepository); + } + + /* ======================== Authentication Tests ======================== */ + + @Test + void authenticate_ValidCredentials_ReturnsUser() { + Authentication auth = mock(Authentication.class); + when(authenticationManager.authenticate(any())).thenReturn(auth); + when(auth.getName()).thenReturn("testuser"); + when(userRepository.findByUsername("testuser")).thenReturn(Optional.of(testUser)); + + UserModel result = authService.authenticate(testLoginDto); + + assertEquals("testuser", result.getUsername()); + verify(authenticationManager).authenticate( + new UsernamePasswordAuthenticationToken("testuser", "Password123!") + ); + } + + @Test + void authenticate_BadCredentials_ThrowsException() { + when(authenticationManager.authenticate(any())) + .thenThrow(new BadCredentialsException("Invalid credentials")); + + AuthService.AuthenticationException exception = assertThrows( + AuthService.AuthenticationException.class, + () -> authService.authenticate(testLoginDto) + ); + assertEquals("Invalid username or password", exception.getMessage()); + } + + @Test + void authenticate_DisabledAccount_ThrowsException() { + when(authenticationManager.authenticate(any())) + .thenThrow(new DisabledException("Account disabled")); + + AuthService.AuthenticationException exception = assertThrows( + AuthService.AuthenticationException.class, + () -> authService.authenticate(testLoginDto) + ); + assertEquals("Account is disabled", exception.getMessage()); + } + + /* ======================== Direct Validation Tests ======================== */ + + @Test + void validateLogin_ValidCredentials_ReturnsUser() { + when(userRepository.findByUsernameOrEmail("testuser")) + .thenReturn(Optional.of(testUser)); + when(passwordEncoder.matches("Password123!", "encodedPassword")).thenReturn(true); + + UserModel result = authService.validateLogin(testLoginDto); + + assertEquals("testuser", result.getUsername()); + verify(passwordEncoder).matches("Password123!", "encodedPassword"); + } + + @Test + void validateLogin_InvalidPassword_ThrowsException() { + when(userRepository.findByUsernameOrEmail("testuser")) + .thenReturn(Optional.of(testUser)); + when(passwordEncoder.matches("Password123!", "encodedPassword")).thenReturn(false); + + AuthService.AuthenticationException exception = assertThrows( + AuthService.AuthenticationException.class, + () -> authService.validateLogin(testLoginDto) + ); + assertEquals("Invalid credentials", exception.getMessage()); + } + + @Test + void validateLogin_DisabledAccount_ThrowsException() { + testUser.setEnabled(false); + when(userRepository.findByUsernameOrEmail("testuser")) + .thenReturn(Optional.of(testUser)); + when(passwordEncoder.matches("Password123!", "encodedPassword")).thenReturn(true); + + AuthService.AuthenticationException exception = assertThrows( + AuthService.AuthenticationException.class, + () -> authService.validateLogin(testLoginDto) + ); + assertEquals("Account is disabled", exception.getMessage()); + } + + @Test + void validateLogin_NullLoginDto_ThrowsException() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, + () -> authService.validateLogin(null)); + assertEquals("Login credentials cannot be null", exception.getMessage()); + } +} \ No newline at end of file diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/AuthorityInitializerTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/AuthorityInitializerTest.java index 83fbcba70..c812357fa 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/AuthorityInitializerTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/AuthorityInitializerTest.java @@ -1,6 +1,6 @@ package com.jydoc.deliverable4; -import com.jydoc.deliverable4.Initializers.AuthorityInitializer; +import com.jydoc.deliverable4.initializers.AuthorityInitializer; import com.jydoc.deliverable4.model.AuthorityModel; import com.jydoc.deliverable4.repositories.AuthorityRepository; import org.junit.jupiter.api.BeforeEach; diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/LoginDtoValidationTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/LoginDtoValidationTest.java index 428b3639a..34a16d349 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/LoginDtoValidationTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/LoginDtoValidationTest.java @@ -1,6 +1,6 @@ package com.jydoc.deliverable4; -import com.jydoc.deliverable4.DTO.LoginDTO; +import com.jydoc.deliverable4.dto.LoginDTO; import jakarta.validation.ConstraintViolation; import jakarta.validation.Validation; import jakarta.validation.Validator; diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserDtoValidationTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserDtoValidationTest.java index 4cdba05f0..00b2598e2 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserDtoValidationTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserDtoValidationTest.java @@ -1,6 +1,6 @@ package com.jydoc.deliverable4; -import com.jydoc.deliverable4.DTO.UserDTO; +import com.jydoc.deliverable4.dto.UserDTO; import jakarta.validation.Validation; import jakarta.validation.Validator; import jakarta.validation.ValidatorFactory; diff --git a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java index 19af3cf7c..c8f486cb5 100644 --- a/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java +++ b/Sprint 2/prototype2/src/test/java/com/jydoc/deliverable4/UserServiceTest.java @@ -1,28 +1,27 @@ package com.jydoc.deliverable4; -import com.jydoc.deliverable4.DTO.LoginDTO; -import com.jydoc.deliverable4.DTO.UserDTO; -import com.jydoc.deliverable4.Service.UserService; -import com.jydoc.deliverable4.Service.UserValidationHelper; +import com.jydoc.deliverable4.dto.LoginDTO; +import com.jydoc.deliverable4.dto.UserDTO; import com.jydoc.deliverable4.model.AuthorityModel; import com.jydoc.deliverable4.model.UserModel; import com.jydoc.deliverable4.repositories.AuthorityRepository; import com.jydoc.deliverable4.repositories.UserRepository; +import com.jydoc.deliverable4.services.UserService; +import com.jydoc.deliverable4.services.UserValidationHelper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.crypto.password.PasswordEncoder; import java.util.HashSet; +import java.util.List; import java.util.Optional; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) @@ -37,33 +36,19 @@ class UserServiceTest { @Mock private PasswordEncoder passwordEncoder; - @Mock - private AuthenticationManager authenticationManager; - @Mock private UserValidationHelper validationHelper; @InjectMocks private UserService userService; - private UserDTO testUserDto; - private LoginDTO testLoginDto; private UserModel testUser; private AuthorityModel testAuthority; @BeforeEach void setUp() { - // Initialize test data - testUserDto = new UserDTO(); - testUserDto.setUsername("testuser"); - testUserDto.setEmail("test@example.com"); - testUserDto.setPassword("Password123!"); - testUserDto.setFirstName("Test"); // Added - testUserDto.setLastName("User"); // Added - - testLoginDto = new LoginDTO("testuser", "Password123!"); - testUser = UserModel.builder() + .id(1L) .username("testuser") .email("test@example.com") .firstName("Test") @@ -80,85 +65,104 @@ void setUp() { .authority("ROLE_USER") .users(new HashSet<>()) .build(); - testUser.addAuthority(testAuthority); // Ensure testUser has the authority + testUser.addAuthority(testAuthority); } - // ---------------------- Registration Tests ---------------------- + /* ======================== User Management Tests ======================== */ @Test - void registerNewUser_ValidUser_Success() { - // Arrange - when(userRepository.existsByUsername("testuser")).thenReturn(false); - when(userRepository.existsByEmail("test@example.com")).thenReturn(false); - when(passwordEncoder.encode("Password123!")).thenReturn("encodedPassword"); - when(authorityRepository.findByAuthority("ROLE_USER")).thenReturn(Optional.of(testAuthority)); - when(userRepository.save(any(UserModel.class))).thenReturn(testUser); - - // Act - userService.registerNewUser(testUserDto); - - // Assert - verify(validationHelper).validateUserRegistration(testUserDto); - verify(userRepository).existsByUsername("testuser"); - verify(userRepository).existsByEmail("test@example.com"); - verify(passwordEncoder).encode("Password123!"); - verify(authorityRepository).findByAuthority("ROLE_USER"); - verify(userRepository).save(any(UserModel.class)); + void findActiveUser_ValidUsername_ReturnsUser() { + when(userRepository.findByUsernameOrEmail("testuser")) + .thenReturn(Optional.of(testUser)); + + Optional result = userService.findActiveUser("testuser"); + + assertTrue(result.isPresent()); + assertEquals("testuser", result.get().getUsername()); + verify(userRepository).findByUsernameOrEmail("testuser"); } @Test - void registerNewUser_NullUserDto_ThrowsException() { - // Act & Assert - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, - () -> userService.registerNewUser(null)); - assertEquals("UserDTO cannot be null", exception.getMessage()); + void findActiveUser_DisabledUser_ReturnsEmpty() { + testUser.setEnabled(false); + when(userRepository.findByUsernameOrEmail("testuser")) + .thenReturn(Optional.of(testUser)); + + Optional result = userService.findActiveUser("testuser"); + + assertFalse(result.isPresent()); } @Test - void registerNewUser_ExistingUsername_ThrowsException() { - // Arrange - when(userRepository.existsByUsername("testuser")).thenReturn(true); - - // Act & Assert - UserService.UsernameExistsException exception = assertThrows( - UserService.UsernameExistsException.class, - () -> userService.registerNewUser(testUserDto) - ); - assertEquals("Username 'testuser' already exists", exception.getMessage()); - - // Verify no user was saved - verify(userRepository, never()).save(any(UserModel.class)); + void getUserCount_ReturnsCount() { + when(userRepository.count()).thenReturn(5L); + + long count = userService.getUserCount(); + + assertEquals(5L, count); + verify(userRepository).count(); } @Test - void registerNewUser_ExistingEmail_ThrowsException() { - // Arrange - when(userRepository.existsByUsername("testuser")).thenReturn(false); - when(userRepository.existsByEmail("test@example.com")).thenReturn(true); - - // Act & Assert - UserService.EmailExistsException exception = assertThrows(UserService.EmailExistsException.class, - () -> userService.registerNewUser(testUserDto)); - assertEquals("Email 'test@example.com' is already registered", exception.getMessage()); - - // Verify no attempt to save user - verify(userRepository, never()).save(any(UserModel.class)); + void existsById_UserExists_ReturnsTrue() { + when(userRepository.existsById(1L)).thenReturn(true); + + boolean exists = userService.existsById(1L); + + assertTrue(exists); } @Test - void registerNewUser_EmptyPassword_ThrowsException() { - // Arrange - testUserDto.setPassword(""); - - // Act & Assert - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, - () -> userService.registerNewUser(testUserDto)); - assertEquals("Password cannot be empty", exception.getMessage()); - - // Verify no repository interactions occurred - verifyNoInteractions(userRepository); - verifyNoInteractions(authorityRepository); + void getAllUsers_ReturnsUserList() { + when(userRepository.findAll()).thenReturn(List.of(testUser)); + + List users = userService.getAllUsers(); + + assertEquals(1, users.size()); + assertEquals("testuser", users.get(0).getUsername()); } - // ... rest of the test methods remain the same ... + @Test + void getUserById_ValidId_ReturnsUser() { + when(userRepository.findById(1L)).thenReturn(Optional.of(testUser)); + + Optional result = userService.getUserById(1L); + + assertTrue(result.isPresent()); + assertEquals("testuser", result.get().getUsername()); + } + + @Test + void updateUser_SavesUser() { + userService.updateUser(testUser); + + verify(userRepository).save(testUser); + } + + @Test + void deleteUser_DeletesById() { + userService.deleteUser(1L); + + verify(userRepository).deleteById(1L); + } + + @Test + void findByUsername_ValidUsername_ReturnsUser() { + when(userRepository.findByUsername("testuser")) + .thenReturn(Optional.of(testUser)); + + UserModel result = userService.findByUsername("testuser"); + + assertEquals("testuser", result.getUsername()); + } + + @Test + void findByUsername_InvalidUsername_ThrowsException() { + when(userRepository.findByUsername("unknown")) + .thenReturn(Optional.empty()); + + assertThrows(IllegalArgumentException.class, () -> { + userService.findByUsername("unknown"); + }); + } } \ No newline at end of file From a5a4cf14e27ecf7d457ab5c561512f49ce1aa9ce Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Sun, 6 Apr 2025 16:24:00 -0400 Subject: [PATCH 081/100] Documentation added --- .../deliverable4/config/SecurityConfig.java | 130 ++++++++-- .../deliverable4/services/AuthService.java | 228 ++++++++++++++---- .../deliverable4/services/UserService.java | 100 +++++++- 3 files changed, 368 insertions(+), 90 deletions(-) diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java index e1036eb06..c1ef9be52 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/config/SecurityConfig.java @@ -16,10 +16,19 @@ import org.springframework.security.web.csrf.CookieCsrfTokenRepository; import org.springframework.security.web.header.writers.XXssProtectionHeaderWriter; +/** + * Security configuration class that defines the application's security policies. + * This includes authentication, authorization, CSRF protection, session management, + * and security headers configuration. + */ @Configuration @EnableWebSecurity public class SecurityConfig { + /** + * Public endpoints that don't require authentication. + * These include static resources, login/registration pages, and public APIs. + */ private static final String[] PUBLIC_ENDPOINTS = { "/", "/home", @@ -35,10 +44,22 @@ public class SecurityConfig { private final CustomUserDetailsService userDetailsService; + /** + * Constructs a new SecurityConfig with the required dependencies. + * + * @param userDetailsService the custom user details service for authentication + */ public SecurityConfig(CustomUserDetailsService userDetailsService) { this.userDetailsService = userDetailsService; } + /** + * Configures the security filter chain that defines all security policies. + * + * @param http the HttpSecurity object to configure + * @return the configured SecurityFilterChain + * @throws Exception if an error occurs during configuration + */ @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { configureAuthorization(http); @@ -52,6 +73,12 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti return http.build(); } + /** + * Configures authorization rules for different endpoints. + * + * @param http the HttpSecurity object to configure + * @throws Exception if an error occurs during configuration + */ private void configureAuthorization(HttpSecurity http) throws Exception { http.authorizeHttpRequests(auth -> auth .requestMatchers(PUBLIC_ENDPOINTS).permitAll() @@ -60,77 +87,130 @@ private void configureAuthorization(HttpSecurity http) throws Exception { ); } + /** + * Configures form-based login authentication. + * + * @param http the HttpSecurity object to configure + * @throws Exception if an error occurs during configuration + */ private void configureFormLogin(HttpSecurity http) throws Exception { http.formLogin(form -> form - .loginPage("/auth/login") // Changed to match controller mapping - .loginProcessingUrl("/auth/login") // Changed to match controller - .successHandler(authenticationSuccessHandler()) - .failureUrl("/auth/login?error=true") - .defaultSuccessUrl("/dashboard") - .usernameParameter("username") - .passwordParameter("password") - .permitAll() + .loginPage("/auth/login") // Custom login page URL + .loginProcessingUrl("/auth/login") // URL to submit username/password + .successHandler(authenticationSuccessHandler()) // Custom success handler + .failureUrl("/auth/login?error=true") // Redirect on failure + .defaultSuccessUrl("/dashboard") // Default success URL + .usernameParameter("username") // Username parameter name + .passwordParameter("password") // Password parameter name + .permitAll() // Allow access to login for everyone ); } + /** + * Configures logout behavior. + * + * @param http the HttpSecurity object to configure + * @throws Exception if an error occurs during configuration + */ private void configureLogout(HttpSecurity http) throws Exception { http.logout(logout -> logout - .logoutUrl("/auth/logout") // Changed to match controller - .logoutSuccessUrl("/auth/login?logout") // Changed to match controller - .deleteCookies("JSESSIONID", "XSRF-TOKEN") - .invalidateHttpSession(true) - .clearAuthentication(true) - .permitAll() + .logoutUrl("/auth/logout") // URL to trigger logout + .logoutSuccessUrl("/auth/login?logout") // Redirect after logout + .deleteCookies("JSESSIONID", "XSRF-TOKEN") // Cookies to delete + .invalidateHttpSession(true) // Invalidate session + .clearAuthentication(true) // Clear authentication + .permitAll() // Allow access to logout for everyone ); } + /** + * Configures session management policies. + * + * @param http the HttpSecurity object to configure + * @throws Exception if an error occurs during configuration + */ private void configureSessionManagement(HttpSecurity http) throws Exception { http.sessionManagement(session -> session - .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) - .invalidSessionUrl("/auth/login?invalid-session") // Changed to match controller - .maximumSessions(1) - .maxSessionsPreventsLogin(false) - .expiredUrl("/auth/login?session-expired") // Changed to match controller + .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) // Create session when needed + .invalidSessionUrl("/auth/login?invalid-session") // Redirect for invalid sessions + .maximumSessions(1) // Allow only one session per user + .maxSessionsPreventsLogin(false) // Don't prevent new logins + .expiredUrl("/auth/login?session-expired") // Redirect for expired sessions ); } + /** + * Configures exception handling for access denied scenarios. + * + * @param http the HttpSecurity object to configure + * @throws Exception if an error occurs during configuration + */ private void configureExceptionHandling(HttpSecurity http) throws Exception { http.exceptionHandling(exceptions -> exceptions - .accessDeniedPage("/access-denied") + .accessDeniedPage("/access-denied") // Custom access denied page ); } + /** + * Configures CSRF protection with exceptions for certain APIs. + * + * @param http the HttpSecurity object to configure + * @throws Exception if an error occurs during configuration + */ private void configureCsrfProtection(HttpSecurity http) throws Exception { http.csrf(csrf -> csrf - .ignoringRequestMatchers("/api/**") - .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) + .ignoringRequestMatchers("/api/**") // Disable CSRF for API endpoints + .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) // Store CSRF token in cookie ); } + /** + * Configures various security headers including XSS protection, CSP, and frame options. + * + * @param http the HttpSecurity object to configure + * @throws Exception if an error occurs during configuration + */ private void configureSecurityHeaders(HttpSecurity http) throws Exception { http.headers(headers -> headers .xssProtection(xss -> xss - .headerValue(XXssProtectionHeaderWriter.HeaderValue.ENABLED_MODE_BLOCK) + .headerValue(XXssProtectionHeaderWriter.HeaderValue.ENABLED_MODE_BLOCK) // Enable XSS protection with block mode ) .contentSecurityPolicy(csp -> csp .policyDirectives("default-src 'self'; script-src 'self' 'unsafe-inline' cdn.jsdelivr.net; " + - "style-src 'self' 'unsafe-inline' cdn.jsdelivr.net; img-src 'self' data:") + "style-src 'self' 'unsafe-inline' cdn.jsdelivr.net; img-src 'self' data:") // Content Security Policy ) - .frameOptions(frame -> frame.deny()) + .frameOptions(frame -> frame.deny()) // Prevent clickjacking by denying frame embedding ); } + /** + * Provides a custom authentication success handler bean. + * + * @return the custom authentication success handler + */ @Bean public AuthenticationSuccessHandler authenticationSuccessHandler() { return new CustomAuthenticationSuccessHandler(); } + /** + * Provides the authentication manager bean. + * + * @param authenticationConfiguration the authentication configuration + * @return the authentication manager + * @throws Exception if an error occurs while creating the authentication manager + */ @Bean public AuthenticationManager authenticationManager( AuthenticationConfiguration authenticationConfiguration) throws Exception { return authenticationConfiguration.getAuthenticationManager(); } + /** + * Provides the password encoder bean using BCrypt hashing. + * + * @return the password encoder + */ @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/AuthService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/AuthService.java index 15c29cb52..ec1e9527a 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/AuthService.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/AuthService.java @@ -24,10 +24,16 @@ /** * Service handling all authentication and authorization operations including: - * - User registration - * - Login authentication - * - Credential validation - * - Role assignment + * - User registration and credential management + * - Login authentication and validation + * - Account status checks + * - Role assignment and management + * + *

    This service integrates with Spring Security's authentication mechanisms + * while providing additional business logic for user management.

    + * + *

    All methods perform comprehensive validation and throw appropriate exceptions + * for error conditions.

    */ @Service @RequiredArgsConstructor @@ -35,20 +41,31 @@ public class AuthService { private static final Logger logger = LogManager.getLogger(AuthService.class); private static final String DEFAULT_ROLE = "ROLE_USER"; + // Dependencies injected via constructor (using Lombok @RequiredArgsConstructor) private final UserRepository userRepository; private final AuthorityRepository authorityRepository; private final PasswordEncoder passwordEncoder; private final AuthenticationManager authenticationManager; private final UserValidationHelper validationHelper; - /* ================ Public Authentication Methods ================ */ + /* ====================== Public API Methods ====================== */ /** - * Registers a new user with validation and default role assignment - * @param userDto User registration data - * @throws IllegalArgumentException if validation fails - * @throws AuthService.UsernameExistsException if username taken - * @throws AuthService.EmailExistsException if email registered + * Registers a new user in the system with comprehensive validation. + * + *

    Performs the following operations:

    + *
      + *
    1. Validates all required user fields
    2. + *
    3. Checks for duplicate username/email
    4. + *
    5. Encodes the password
    6. + *
    7. Assigns default role (ROLE_USER)
    8. + *
    9. Persists the user entity
    10. + *
    + * + * @param userDto Data Transfer Object containing user registration information + * @throws IllegalArgumentException if any required field is missing or invalid + * @throws UsernameExistsException if the username is already taken + * @throws EmailExistsException if the email is already registered */ @Transactional public void registerNewUser(UserDTO userDto) { @@ -63,10 +80,20 @@ public void registerNewUser(UserDTO userDto) { } /** - * Authenticates using Spring Security's authentication manager - * @param loginDto Contains username and password - * @return Authenticated user entity - * @throws AuthService.AuthenticationException for auth failures + * Authenticates a user using Spring Security's authentication manager. + * + *

    This method:

    + *
      + *
    • Delegates authentication to Spring Security
    • + *
    • Handles various authentication failure scenarios
    • + *
    • Returns the authenticated user entity on success
    • + *
    + * + * @param loginDto Data Transfer Object containing login credentials + * @return Authenticated UserModel entity + * @throws IllegalArgumentException if loginDto is null + * @throws AuthenticationException for authentication failures (bad credentials, + * disabled account, locked account, etc.) */ @Transactional(readOnly = true) public UserModel authenticate(LoginDTO loginDto) { @@ -77,10 +104,15 @@ public UserModel authenticate(LoginDTO loginDto) { } /** - * Direct credential validation against database - * @param loginDto Contains credentials - * @return Validated user entity - * @throws AuthService.AuthenticationException for invalid credentials + * Validates user credentials directly against the database. + * + *

    This method provides an alternative to Spring Security authentication + * with more direct control over the validation process.

    + * + * @param loginDto Data Transfer Object containing login credentials + * @return Validated UserModel entity + * @throws IllegalArgumentException if loginDto is null + * @throws AuthenticationException for invalid credentials or account issues */ @Transactional(readOnly = true) public UserModel validateLogin(LoginDTO loginDto) { @@ -100,8 +132,16 @@ public UserModel validateLogin(LoginDTO loginDto) { return user; } - /* ================ Private Helper Methods ================ */ + /* ====================== Core Business Logic ====================== */ + /** + * Authenticates a user with Spring Security's authentication manager. + * + * @param username The username to authenticate + * @param password The raw (unencoded) password + * @return Authenticated UserModel entity + * @throws AuthenticationException wrapping various Spring Security exceptions + */ private UserModel authenticateUser(String username, String password) { try { Authentication authentication = authenticationManager.authenticate( @@ -118,29 +158,12 @@ private UserModel authenticateUser(String username, String password) { return null; // Unreachable due to exception handling } - private void validateUserDto(UserDTO userDto) { - if (userDto == null) throw new IllegalArgumentException("UserDTO cannot be null"); - if (userDto.getUsername() == null || userDto.getUsername().trim().isEmpty()) - throw new IllegalArgumentException("Username cannot be empty"); - if (userDto.getPassword() == null || userDto.getPassword().trim().isEmpty()) - throw new IllegalArgumentException("Password cannot be empty"); - if (userDto.getEmail() == null || userDto.getEmail().trim().isEmpty()) - throw new IllegalArgumentException("Email cannot be empty"); - if (userDto.getFirstName() == null || userDto.getFirstName().trim().isEmpty()) - throw new IllegalArgumentException("First name cannot be empty"); - if (userDto.getLastName() == null || userDto.getLastName().trim().isEmpty()) - throw new IllegalArgumentException("Last name cannot be empty"); - } - - private void checkForExistingCredentials(UserDTO userDto) { - if (userRepository.existsByUsername(userDto.getUsername())) { - throw new UsernameExistsException(userDto.getUsername()); - } - if (userRepository.existsByEmail(userDto.getEmail())) { - throw new EmailExistsException(userDto.getEmail()); - } - } - + /** + * Creates a new UserModel entity from registration DTO. + * + * @param userDto Source data for user creation + * @return New UserModel with encoded password and trimmed fields + */ private UserModel createUserFromDto(UserDTO userDto) { return UserModel.builder() .username(userDto.getUsername().trim()) @@ -155,6 +178,13 @@ private UserModel createUserFromDto(UserDTO userDto) { .build(); } + /** + * Assigns the default role (ROLE_USER) to a new user. + * + *

    If the default role doesn't exist in the database, it will be created.

    + * + * @param user The user to receive the default role + */ @Transactional(propagation = Propagation.MANDATORY) protected void assignDefaultRole(UserModel user) { AuthorityModel authority = authorityRepository.findByAuthority(DEFAULT_ROLE) @@ -162,20 +192,51 @@ protected void assignDefaultRole(UserModel user) { user.addAuthority(authority); } - private AuthorityModel createAndSaveNewAuthority() { - AuthorityModel newRole = new AuthorityModel(DEFAULT_ROLE); - newRole.setUsers(new HashSet<>()); - return authorityRepository.save(newRole); + /* ====================== Validation Helpers ====================== */ + + /** + * Validates that all required fields in UserDTO are present and non-empty. + * + * @param userDto The DTO to validate + * @throws IllegalArgumentException if any required field is missing or empty + */ + private void validateUserDto(UserDTO userDto) { + if (userDto == null) throw new IllegalArgumentException("UserDTO cannot be null"); + if (userDto.getUsername() == null || userDto.getUsername().trim().isEmpty()) + throw new IllegalArgumentException("Username cannot be empty"); + if (userDto.getPassword() == null || userDto.getPassword().trim().isEmpty()) + throw new IllegalArgumentException("Password cannot be empty"); + if (userDto.getEmail() == null || userDto.getEmail().trim().isEmpty()) + throw new IllegalArgumentException("Email cannot be empty"); + if (userDto.getFirstName() == null || userDto.getFirstName().trim().isEmpty()) + throw new IllegalArgumentException("First name cannot be empty"); + if (userDto.getLastName() == null || userDto.getLastName().trim().isEmpty()) + throw new IllegalArgumentException("Last name cannot be empty"); } - private UserModel findUserByCredential(String credential) { - return userRepository.findByUsernameOrEmail(credential) - .orElseThrow(() -> { - logger.warn("User not found: {}", credential); - return new AuthenticationException("Invalid credentials"); - }); + /** + * Checks if username or email already exist in the system. + * + * @param userDto The DTO containing credentials to check + * @throws UsernameExistsException if username is taken + * @throws EmailExistsException if email is registered + */ + private void checkForExistingCredentials(UserDTO userDto) { + if (userRepository.existsByUsername(userDto.getUsername())) { + throw new UsernameExistsException(userDto.getUsername()); + } + if (userRepository.existsByEmail(userDto.getEmail())) { + throw new EmailExistsException(userDto.getEmail()); + } } + /** + * Validates that the provided raw password matches the user's encoded password. + * + * @param user The user to validate + * @param rawPassword The raw (unencoded) password to check + * @throws AuthenticationException if passwords don't match + */ private void validateUserPassword(UserModel user, String rawPassword) { if (!passwordEncoder.matches(rawPassword, user.getPassword())) { logger.warn("Password mismatch for user: {}", user.getUsername()); @@ -183,6 +244,12 @@ private void validateUserPassword(UserModel user, String rawPassword) { } } + /** + * Verifies that the user account is enabled. + * + * @param user The user to check + * @throws AuthenticationException if account is disabled + */ private void checkAccountEnabled(UserModel user) { if (!user.isEnabled()) { logger.warn("Disabled account login attempt: {}", user.getUsername()); @@ -190,6 +257,30 @@ private void checkAccountEnabled(UserModel user) { } } + /* ====================== Repository Helpers ====================== */ + + /** + * Finds a user by either username or email (case-insensitive). + * + * @param credential Username or email to search for + * @return Found UserModel entity + * @throws AuthenticationException if no user found + */ + private UserModel findUserByCredential(String credential) { + return userRepository.findByUsernameOrEmail(credential) + .orElseThrow(() -> { + logger.warn("User not found: {}", credential); + return new AuthenticationException("Invalid credentials"); + }); + } + + /** + * Finds a user by username after successful authentication. + * + * @param username The authenticated username + * @return Found UserModel entity + * @throws AuthenticationException if user not found (unexpected after auth) + */ private UserModel findAuthenticatedUser(String username) { return userRepository.findByUsername(username) .orElseThrow(() -> { @@ -198,12 +289,37 @@ private UserModel findAuthenticatedUser(String username) { }); } + /** + * Creates and persists a new authority with the default role. + * + * @return The newly created AuthorityModel + */ + private AuthorityModel createAndSaveNewAuthority() { + AuthorityModel newRole = new AuthorityModel(DEFAULT_ROLE); + newRole.setUsers(new HashSet<>()); + return authorityRepository.save(newRole); + } + + /* ====================== Exception Handling ====================== */ + + /** + * Handles authentication failures consistently with logging and exception throwing. + * + * @param logMessage The log message template + * @param username The username that failed authentication + * @param exceptionMessage The exception message for clients + * @throws AuthenticationException always + */ private void handleAuthenticationFailure(String logMessage, String username, String exceptionMessage) { logger.warn(logMessage, username); throw new AuthenticationException(exceptionMessage); } - /* ================ Custom Exceptions ================ */ + /* ====================== Custom Exceptions ====================== */ + + /** + * Exception indicating authentication failure. + */ public static class AuthenticationException extends RuntimeException { public AuthenticationException(String message) { super(message); @@ -211,6 +327,9 @@ public AuthenticationException(String message) { } } + /** + * Exception indicating duplicate username during registration. + */ public static class UsernameExistsException extends RuntimeException { public UsernameExistsException(String username) { super(String.format("Username '%s' already exists", username)); @@ -218,6 +337,9 @@ public UsernameExistsException(String username) { } } + /** + * Exception indicating duplicate email during registration. + */ public static class EmailExistsException extends RuntimeException { public EmailExistsException(String email) { super(String.format("Email '%s' already registered", email)); diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/UserService.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/UserService.java index 5ebeedfb9..ad4bdd52a 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/UserService.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/services/UserService.java @@ -11,6 +11,18 @@ import java.util.List; import java.util.Optional; +/** + * Service handling user management operations including: + * - User retrieval by various criteria + * - User existence checks + * - User updates and deletions + * - User counting and listing + * + *

    All methods are transactional with appropriate read-only or read-write semantics.

    + * + *

    This service provides a clean API for user-related operations while abstracting + * repository access and ensuring proper transaction management.

    + */ @Service @RequiredArgsConstructor public class UserService { @@ -18,45 +30,109 @@ public class UserService { private final UserRepository userRepository; + /* ====================== User Retrieval Methods ====================== */ + + /** + * Finds an active user by username or email (case-insensitive). + * + * @param usernameOrEmail The username or email to search for (whitespace trimmed) + * @return Optional containing the found active user, or empty if not found or inactive + */ @Transactional(readOnly = true) public Optional findActiveUser(String usernameOrEmail) { return userRepository.findByUsernameOrEmail(usernameOrEmail.trim().toLowerCase()) .filter(UserModel::isEnabled); } + /** + * Retrieves a user by their exact username (case-sensitive). + * + * @param username The exact username to search for + * @return Found UserModel entity + * @throws IllegalArgumentException if no user found with given username + */ @Transactional(readOnly = true) - public long getUserCount() { - return userRepository.count(); + public UserModel findByUsername(String username) { + return userRepository.findByUsername(username) + .orElseThrow(() -> new IllegalArgumentException("User not found")); } + /** + * Retrieves a user by their unique identifier. + * + * @param id The user's unique ID + * @return Optional containing the found user, or empty if not found + */ @Transactional(readOnly = true) - public boolean existsById(Long id) { - return userRepository.existsById(id); + public Optional getUserById(Long id) { + return userRepository.findById(id); } + /** + * Retrieves all users in the system. + * + * @return List of all UserModel entities, empty list if none exist + */ @Transactional(readOnly = true) public List getAllUsers() { return userRepository.findAll(); } + /* ====================== User Status Methods ====================== */ + + /** + * Checks if a user exists with the given ID. + * + * @param id The user ID to check + * @return true if a user exists with this ID, false otherwise + */ @Transactional(readOnly = true) - public Optional getUserById(Long id) { - return userRepository.findById(id); + public boolean existsById(Long id) { + return userRepository.existsById(id); } + /** + * Gets the total count of users in the system. + * + * @return The number of users + */ + @Transactional(readOnly = true) + public long getUserCount() { + return userRepository.count(); + } + + /* ====================== User Modification Methods ====================== */ + + /** + * Updates an existing user. + * + *

    Note: The entire user entity will be updated. For partial updates, + * consider adding dedicated methods.

    + * + * @param user The user entity to update + * @throws IllegalArgumentException if the user is null + */ @Transactional public void updateUser(UserModel user) { + if (user == null) { + throw new IllegalArgumentException("User cannot be null"); + } userRepository.save(user); + logger.debug("Updated user with ID: {}", user.getId()); } + /** + * Deletes a user by their unique identifier. + * + * @param id The ID of the user to delete + * @throws IllegalArgumentException if no user exists with this ID + */ @Transactional public void deleteUser(Long id) { + if (!userRepository.existsById(id)) { + throw new IllegalArgumentException("User not found with ID: " + id); + } userRepository.deleteById(id); - } - - @Transactional(readOnly = true) - public UserModel findByUsername(String username) { - return userRepository.findByUsername(username) - .orElseThrow(() -> new IllegalArgumentException("User not found")); + logger.debug("Deleted user with ID: {}", id); } } \ No newline at end of file From 5ce7e5b8bde597f9f74d2bbde2fe6831ff464c0c Mon Sep 17 00:00:00 2001 From: ybihi2 <157942422+ybihi2@users.noreply.github.com> Date: Sun, 6 Apr 2025 17:14:25 -0400 Subject: [PATCH 082/100] Documentation added --- .gitignore | 1 + .../controllers/AuthController.java | 180 ++++++++++++--- .../main/resources/templates/dashboard.html | 215 ++++++++---------- .../jydoc/deliverable4/UserServiceTest.java | 8 + 4 files changed, 249 insertions(+), 155 deletions(-) diff --git a/.gitignore b/.gitignore index 1d6e22c22..29805753e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.iml /Sprint 2/prototype2/docker-compose.yml *.gz +Sprint 2/prototype2/qodana.yaml diff --git a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java index 788890c03..8f5caaf96 100644 --- a/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java +++ b/Sprint 2/prototype2/src/main/java/com/jydoc/deliverable4/controllers/AuthController.java @@ -16,97 +16,144 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +/** + * Controller handling all authentication-related operations including + * user registration, login, and logout. This controller manages the + * authentication workflow and redirects users to appropriate views + * based on their authentication status and roles. + */ @Controller @RequestMapping("/auth") public class AuthController { private static final Logger logger = LoggerFactory.getLogger(AuthController.class); + + // Session attribute constants private static final String USER_ATTRIBUTE = "user"; + private static final String LOGIN_DATA_ATTRIBUTE = "loginData"; + private static final String BINDING_RESULT_PREFIX = "org.springframework.validation.BindingResult."; + + // View paths private static final String REDIRECT_LOGIN = "redirect:/auth/login"; private static final String LOGIN_VIEW = "auth/login"; private static final String REGISTER_VIEW = "auth/register"; + // Redirect URLs based on role + private static final String ADMIN_REDIRECT = "redirect:/admin/dashboard"; + private static final String USER_REDIRECT = "redirect:/user/dashboard"; + + // Flash attribute keys + private static final String ERROR_ATTRIBUTE = "error"; + private static final String SUCCESS_ATTRIBUTE = "success"; + private final AuthService authService; private final UserService userService; + /** + * Constructs an AuthController with required services. + * + * @param authService Service handling authentication logic + * @param userService Service handling user-related operations + */ public AuthController(AuthService authService, UserService userService) { this.authService = authService; this.userService = userService; } - /* ==================== REGISTRATION ==================== */ + /* ==================== REGISTRATION ENDPOINTS ==================== */ + /** + * Displays the user registration form. + * + * @param model The Spring MVC model to populate with attributes + * @return The registration view name + */ @GetMapping("/register") public String showRegistrationForm(Model model) { - if (!model.containsAttribute("user")) { - model.addAttribute("user", new UserDTO()); + if (!model.containsAttribute(USER_ATTRIBUTE)) { + model.addAttribute(USER_ATTRIBUTE, new UserDTO()); } return REGISTER_VIEW; } + /** + * Processes user registration form submission. + * + * @param userDto The user data transfer object containing registration details + * @param result BindingResult for validation errors + * @param redirectAttributes Attributes for redirect scenarios + * @return Redirect to appropriate view based on registration outcome + */ @PostMapping("/register") public String registerUser( - @Valid @ModelAttribute("user") UserDTO userDto, + @Valid @ModelAttribute(USER_ATTRIBUTE) UserDTO userDto, BindingResult result, RedirectAttributes redirectAttributes) { - if (result.hasErrors()) { - logger.debug("Registration validation errors: {}", result.getAllErrors()); - redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.user", result); - redirectAttributes.addFlashAttribute("user", userDto); + if (hasValidationErrors(result, redirectAttributes, userDto)) { return "redirect:/auth/register"; } try { authService.registerNewUser(userDto); logger.info("User registered successfully: {}", userDto.getUsername()); - redirectAttributes.addFlashAttribute("success", "Registration successful! Please login."); + redirectAttributes.addFlashAttribute(SUCCESS_ATTRIBUTE, "Registration successful! Please login."); return REDIRECT_LOGIN; } catch (AuthService.UsernameExistsException | AuthService.EmailExistsException e) { - logger.error("Registration failed: {}", e.getMessage()); - redirectAttributes.addFlashAttribute("error", e.getMessage()); - redirectAttributes.addFlashAttribute("user", userDto); + handleRegistrationError(e.getMessage(), redirectAttributes, userDto); return "redirect:/auth/register"; } catch (Exception e) { - logger.error("Unexpected registration error: {}", e.getMessage()); - redirectAttributes.addFlashAttribute("error", "Registration failed. Please try again."); - redirectAttributes.addFlashAttribute("user", userDto); + handleRegistrationError("Registration failed. Please try again.", redirectAttributes, userDto); return "redirect:/auth/register"; } } - /* ==================== LOGIN ==================== */ + /* ==================== LOGIN ENDPOINTS ==================== */ + /** + * Displays the login form with optional error/success messages. + * + * @param model The Spring MVC model to populate with attributes + * @param error Optional error parameter indicating login failure + * @param logout Optional logout parameter indicating successful logout + * @return The login view name + */ @GetMapping("/login") public String showLoginForm( Model model, @RequestParam(required = false) String error, @RequestParam(required = false) String logout) { - if (!model.containsAttribute("loginData")) { - model.addAttribute("loginData", new LoginDTO("", "")); + if (!model.containsAttribute(LOGIN_DATA_ATTRIBUTE)) { + model.addAttribute(LOGIN_DATA_ATTRIBUTE, new LoginDTO("", "")); } if (error != null) { - model.addAttribute("error", "Invalid username or password"); + model.addAttribute(ERROR_ATTRIBUTE, "Invalid username or password"); } if (logout != null) { - model.addAttribute("success", "You have been logged out successfully"); + model.addAttribute(SUCCESS_ATTRIBUTE, "You have been logged out successfully"); } return LOGIN_VIEW; } + /** + * Processes login form submission. + * + * @param loginDto The login data transfer object containing credentials + * @param result BindingResult for validation errors + * @param session The HTTP session to store authentication details + * @param redirectAttributes Attributes for redirect scenarios + * @return Redirect to appropriate dashboard based on user role or back to login on failure + */ @PostMapping("/login") public String loginUser( - @Valid @ModelAttribute("loginData") LoginDTO loginDto, + @Valid @ModelAttribute(LOGIN_DATA_ATTRIBUTE) LoginDTO loginDto, BindingResult result, HttpSession session, RedirectAttributes redirectAttributes) { - if (result.hasErrors()) { - logger.debug("Login validation errors"); - redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.loginData", result); - redirectAttributes.addFlashAttribute("loginData", loginDto); + if (hasValidationErrors(result, redirectAttributes, loginDto)) { return "redirect:/auth/login"; } @@ -114,19 +161,22 @@ public String loginUser( UserModel user = authService.validateLogin(loginDto); session.setAttribute(USER_ATTRIBUTE, user); logger.info("User logged in: {}", user.getUsername()); - return determineRedirectUrl(user); - } catch (AuthService.AuthenticationException e) { - logger.error("Login failed: {}", e.getMessage()); - redirectAttributes.addFlashAttribute("error", e.getMessage()); - redirectAttributes.addFlashAttribute("loginData", loginDto); + handleLoginError(e.getMessage(), redirectAttributes, loginDto); return "redirect:/auth/login"; } } - /* ==================== LOGOUT ==================== */ + /* ==================== LOGOUT ENDPOINT ==================== */ + /** + * Processes user logout by invalidating the session. + * Requires the user to be authenticated. + * + * @param session The HTTP session to invalidate + * @return Redirect to login page with logout success message + */ @GetMapping("/logout") @PreAuthorize("isAuthenticated()") public String performLogout(HttpSession session) { @@ -140,15 +190,75 @@ public String performLogout(HttpSession session) { /* ==================== HELPER METHODS ==================== */ + /** + * Determines the appropriate redirect URL based on user role. + * + * @param user The authenticated user model + * @return Redirect URL string based on user role + */ private String determineRedirectUrl(UserModel user) { - if (isAdmin(user)) { - return "redirect:/admin/dashboard"; - } - return "redirect:/user/dashboard"; + return isAdmin(user) ? ADMIN_REDIRECT : USER_REDIRECT; } + /** + * Checks if the user has admin privileges. + * + * @param user The user model to check + * @return true if user has ROLE_ADMIN authority, false otherwise + */ private boolean isAdmin(UserModel user) { return user.getAuthorities().stream() .anyMatch(auth -> "ROLE_ADMIN".equals(auth.getAuthority())); } + + /** + * Handles validation errors by populating redirect attributes. + * + * @param result The binding result containing validation errors + * @param redirectAttributes The redirect attributes to populate + * @param dto The DTO object that failed validation + * @return true if validation errors exist, false otherwise + */ + private boolean hasValidationErrors(BindingResult result, + RedirectAttributes redirectAttributes, + Object dto) { + if (result.hasErrors()) { + String attributeName = dto instanceof UserDTO ? USER_ATTRIBUTE : LOGIN_DATA_ATTRIBUTE; + logger.debug("Validation errors for {}: {}", attributeName, result.getAllErrors()); + redirectAttributes.addFlashAttribute(BINDING_RESULT_PREFIX + attributeName, result); + redirectAttributes.addFlashAttribute(attributeName, dto); + return true; + } + return false; + } + + /** + * Handles registration errors by logging and setting flash attributes. + * + * @param errorMessage The error message to display + * @param redirectAttributes The redirect attributes to populate + * @param userDto The user DTO associated with the failed registration + */ + private void handleRegistrationError(String errorMessage, + RedirectAttributes redirectAttributes, + UserDTO userDto) { + logger.error("Registration failed: {}", errorMessage); + redirectAttributes.addFlashAttribute(ERROR_ATTRIBUTE, errorMessage); + redirectAttributes.addFlashAttribute(USER_ATTRIBUTE, userDto); + } + + /** + * Handles login errors by logging and setting flash attributes. + * + * @param errorMessage The error message to display + * @param redirectAttributes The redirect attributes to populate + * @param loginDto The login DTO associated with the failed attempt + */ + private void handleLoginError(String errorMessage, + RedirectAttributes redirectAttributes, + LoginDTO loginDto) { + logger.error("Login failed: {}", errorMessage); + redirectAttributes.addFlashAttribute(ERROR_ATTRIBUTE, errorMessage); + redirectAttributes.addFlashAttribute(LOGIN_DATA_ATTRIBUTE, loginDto); + } } \ No newline at end of file diff --git a/Sprint 2/prototype2/src/main/resources/templates/dashboard.html b/Sprint 2/prototype2/src/main/resources/templates/dashboard.html index d2fe193ac..99b215c67 100644 --- a/Sprint 2/prototype2/src/main/resources/templates/dashboard.html +++ b/Sprint 2/prototype2/src/main/resources/templates/dashboard.html @@ -2,45 +2,40 @@ - - User Dashboard - JYDoc System + Medication Dashboard - HealthTrack System - -