From 5db196eebb04155491630b5396d1b7a7f2eab4e6 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Tue, 11 Feb 2025 21:30:34 -0600 Subject: Push initial release 1.0.0 --- .gitattributes | 2 + .mvn/wrapper/maven-wrapper.properties | 19 ++ mvnw | 259 +++++++++++++++++++++ mvnw.cmd | 149 ++++++++++++ pom.xml | 109 +++++++++ .../org/berzerkula/builddb/BuilddbApplication.java | 19 ++ .../berzerkula/builddb/config/SecurityConfig.java | 79 +++++++ .../builddb/controllers/AccountController.java | 141 +++++++++++ .../builddb/controllers/DashboardController.java | 27 +++ .../builddb/controllers/HomeController.java | 47 ++++ .../builddb/controllers/PkgController.java | 169 ++++++++++++++ .../org/berzerkula/builddb/models/AppUser.java | 107 +++++++++ .../java/org/berzerkula/builddb/models/Pkg.java | 118 ++++++++++ .../java/org/berzerkula/builddb/models/PkgDto.java | 104 +++++++++ .../org/berzerkula/builddb/models/RegisterDto.java | 84 +++++++ .../builddb/repositories/AppUserRepository.java | 10 + .../builddb/repositories/PkgRepository.java | 8 + .../builddb/services/AppUserService.java | 36 +++ src/main/resources/application.properties | 15 ++ .../resources/templates/actuatorDashboard.html | 39 ++++ src/main/resources/templates/admin.html | 53 +++++ src/main/resources/templates/client.html | 53 +++++ src/main/resources/templates/contact.html | 53 +++++ src/main/resources/templates/index.html | 37 +++ src/main/resources/templates/login.html | 87 +++++++ src/main/resources/templates/navbar.html | 77 ++++++ src/main/resources/templates/pkgs/add.html | 109 +++++++++ src/main/resources/templates/pkgs/edit.html | 109 +++++++++ src/main/resources/templates/pkgs/index.html | 62 +++++ src/main/resources/templates/pkgs/sorting.html | 6 + src/main/resources/templates/profile.html | 84 +++++++ src/main/resources/templates/register.html | 155 ++++++++++++ src/main/resources/templates/user.html | 53 +++++ .../builddb/BuilddbApplicationAppUserTests.java | 111 +++++++++ .../builddb/BuilddbApplicationPkgTests.java | 113 +++++++++ .../berzerkula/builddb/BuilddbApplicationTest.java | 24 ++ .../controllers/BuilddbTestAccountController.java | 137 +++++++++++ .../BuilddbTestDashboardController.java | 62 +++++ .../controllers/BuilddbTestHomeController.java | 33 +++ .../controllers/BuilddbTestPkgController.java | 89 +++++++ .../repositories/AppUserRepositoryTest.java | 31 +++ .../builddb/repositories/PkgRepositoryTest.java | 32 +++ .../repositories/TestH2AppUserRepository.java | 7 + .../builddb/repositories/TestH2PkgRepository.java | 7 + .../builddb/services/AppUserServiceTest.java | 54 +++++ src/test/resources/application.properties | 9 + 46 files changed, 3188 insertions(+) create mode 100644 .gitattributes create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100644 mvnw create mode 100644 mvnw.cmd create mode 100644 pom.xml create mode 100644 src/main/java/org/berzerkula/builddb/BuilddbApplication.java create mode 100644 src/main/java/org/berzerkula/builddb/config/SecurityConfig.java create mode 100644 src/main/java/org/berzerkula/builddb/controllers/AccountController.java create mode 100644 src/main/java/org/berzerkula/builddb/controllers/DashboardController.java create mode 100644 src/main/java/org/berzerkula/builddb/controllers/HomeController.java create mode 100644 src/main/java/org/berzerkula/builddb/controllers/PkgController.java create mode 100644 src/main/java/org/berzerkula/builddb/models/AppUser.java create mode 100644 src/main/java/org/berzerkula/builddb/models/Pkg.java create mode 100644 src/main/java/org/berzerkula/builddb/models/PkgDto.java create mode 100644 src/main/java/org/berzerkula/builddb/models/RegisterDto.java create mode 100644 src/main/java/org/berzerkula/builddb/repositories/AppUserRepository.java create mode 100644 src/main/java/org/berzerkula/builddb/repositories/PkgRepository.java create mode 100644 src/main/java/org/berzerkula/builddb/services/AppUserService.java create mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/templates/actuatorDashboard.html create mode 100644 src/main/resources/templates/admin.html create mode 100644 src/main/resources/templates/client.html create mode 100644 src/main/resources/templates/contact.html create mode 100644 src/main/resources/templates/index.html create mode 100644 src/main/resources/templates/login.html create mode 100644 src/main/resources/templates/navbar.html create mode 100644 src/main/resources/templates/pkgs/add.html create mode 100644 src/main/resources/templates/pkgs/edit.html create mode 100644 src/main/resources/templates/pkgs/index.html create mode 100644 src/main/resources/templates/pkgs/sorting.html create mode 100644 src/main/resources/templates/profile.html create mode 100644 src/main/resources/templates/register.html create mode 100644 src/main/resources/templates/user.html create mode 100644 src/test/java/org/berzerkula/builddb/BuilddbApplicationAppUserTests.java create mode 100644 src/test/java/org/berzerkula/builddb/BuilddbApplicationPkgTests.java create mode 100644 src/test/java/org/berzerkula/builddb/BuilddbApplicationTest.java create mode 100644 src/test/java/org/berzerkula/builddb/controllers/BuilddbTestAccountController.java create mode 100644 src/test/java/org/berzerkula/builddb/controllers/BuilddbTestDashboardController.java create mode 100644 src/test/java/org/berzerkula/builddb/controllers/BuilddbTestHomeController.java create mode 100644 src/test/java/org/berzerkula/builddb/controllers/BuilddbTestPkgController.java create mode 100644 src/test/java/org/berzerkula/builddb/repositories/AppUserRepositoryTest.java create mode 100644 src/test/java/org/berzerkula/builddb/repositories/PkgRepositoryTest.java create mode 100644 src/test/java/org/berzerkula/builddb/repositories/TestH2AppUserRepository.java create mode 100644 src/test/java/org/berzerkula/builddb/repositories/TestH2PkgRepository.java create mode 100644 src/test/java/org/berzerkula/builddb/services/AppUserServiceTest.java create mode 100644 src/test/resources/application.properties diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..d58dfb7 --- /dev/null +++ b/.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 diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..19529dd --- /dev/null +++ b/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/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..249bdf3 --- /dev/null +++ b/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/pom.xml b/pom.xml new file mode 100644 index 0000000..c9ab951 --- /dev/null +++ b/pom.xml @@ -0,0 +1,109 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.2 + + + org.berzerkula + builddb + 0.0.1-SNAPSHOT + builddb + builddb + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + 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 + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.thymeleaf.extras + thymeleaf-extras-springsecurity6 + + + + com.h2database + h2 + runtime + + + com.mysql + mysql-connector-j + runtime + + + org.springframework.security + spring-security-test + test + + + + com.github.ulisesbocchio + jasypt-spring-boot-starter + 3.0.5 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + true + + + + + com.github.ulisesbocchio + jasypt-maven-plugin + 3.0.5 + + + + + diff --git a/src/main/java/org/berzerkula/builddb/BuilddbApplication.java b/src/main/java/org/berzerkula/builddb/BuilddbApplication.java new file mode 100644 index 0000000..7ab9042 --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/BuilddbApplication.java @@ -0,0 +1,19 @@ +package org.berzerkula.builddb; + +import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@EnableEncryptableProperties +@SpringBootApplication +public class BuilddbApplication { + + private static final Logger logger = LoggerFactory.getLogger(BuilddbApplication.class); + + public static void main(String[] args) { + SpringApplication.run(BuilddbApplication.class, args); + } + +} diff --git a/src/main/java/org/berzerkula/builddb/config/SecurityConfig.java b/src/main/java/org/berzerkula/builddb/config/SecurityConfig.java new file mode 100644 index 0000000..dbaacd5 --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/config/SecurityConfig.java @@ -0,0 +1,79 @@ +package org.berzerkula.builddb.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.SecurityFilterChain; + +@Configuration +@EnableWebSecurity +@EnableMethodSecurity +public class SecurityConfig { + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + return http + .authorizeHttpRequests( auth -> auth + .requestMatchers("/").permitAll() + .requestMatchers("/actuator/**").hasRole("admin") + .requestMatchers("/env/**").hasRole("admin") + .requestMatchers("/health/**").hasRole("admin") + .requestMatchers("/info/**").hasRole("admin") + .requestMatchers("/contact").permitAll() + .requestMatchers("/pkgs/**").hasRole("client") + .requestMatchers("/register").permitAll() + .requestMatchers("/login").permitAll() + .requestMatchers("/logout").permitAll() + .anyRequest().authenticated() + ) + .formLogin(form -> form + .loginPage("/login") + .usernameParameter("email") + .passwordParameter("password") + .defaultSuccessUrl("/", true) + ) + .logout(config -> config.logoutSuccessUrl("/")) + .build(); + } + + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/berzerkula/builddb/controllers/AccountController.java b/src/main/java/org/berzerkula/builddb/controllers/AccountController.java new file mode 100644 index 0000000..6cec175 --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/controllers/AccountController.java @@ -0,0 +1,141 @@ +package org.berzerkula.builddb.controllers; + +import java.util.Date; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; + +import org.berzerkula.builddb.models.AppUser; +import org.berzerkula.builddb.models.RegisterDto; +import org.berzerkula.builddb.repositories.AppUserRepository; + +import jakarta.validation.Valid; + +@Controller +public class AccountController { + + @Autowired + private AppUserRepository repo; + + @GetMapping("/profile") + public String profile(Authentication auth, Model model) { + AppUser user = repo.findByEmail(auth.getName()); + model.addAttribute("appUser", user); + + return "profile"; + } + + @GetMapping("/login") + public String login() { + return "login"; + } + + @GetMapping("/register") + public String register(Model model) { + RegisterDto registerDto = new RegisterDto(); + model.addAttribute(registerDto); + model.addAttribute("success", false); + return "register"; + } + + @PostMapping("/register") + public String register( + Model model, + @Valid @ModelAttribute RegisterDto registerDto, + BindingResult result + ) { + + if (!registerDto.getPassword().equals(registerDto.getConfirmPassword())) { + result.addError( + new FieldError("registerDto", "confirmPassword" + , "Password and Confirm Password do not match") + ); + } + + + AppUser appUser = repo.findByEmail(registerDto.getEmail()); + if (appUser != null) { + result.addError( + new FieldError("registerDto", "email" + , "Email address is already used") + ); + } + + + if (result.hasErrors()) { + return "register"; + } + + + try { + // create new account + var bCryptEncoder = new BCryptPasswordEncoder(); + + + AppUser newUser = new AppUser(); + newUser.setFirstName(registerDto.getFirstName()); + newUser.setLastName(registerDto.getLastName()); + newUser.setEmail(registerDto.getEmail()); + newUser.setPhone(registerDto.getPhone()); + newUser.setAddress(registerDto.getAddress()); + newUser.setRole("client"); + newUser.setCreatedAt(new Date()); + newUser.setPassword(bCryptEncoder.encode(registerDto.getPassword())); + + repo.save(newUser); + + + model.addAttribute("registerDto", new RegisterDto()); + model.addAttribute("success", true); + } + catch(Exception ex) { + result.addError( + new FieldError("registerDto", "firstName" + , ex.getMessage()) + ); + } + + return "register"; + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/berzerkula/builddb/controllers/DashboardController.java b/src/main/java/org/berzerkula/builddb/controllers/DashboardController.java new file mode 100644 index 0000000..e928312 --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/controllers/DashboardController.java @@ -0,0 +1,27 @@ +package org.berzerkula.builddb.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class DashboardController { + + @GetMapping("/user") + public String userDashboard() { + return "user"; + } + + @GetMapping("/client") + public String clientDashboard() { + return "client"; + } + + @GetMapping("/admin") + public String adminDashboard() { + return "admin"; + } + + @GetMapping("/actuatorDashboard") + public String actuatorDashboard() { return "actuatorDashboard"; } + +} diff --git a/src/main/java/org/berzerkula/builddb/controllers/HomeController.java b/src/main/java/org/berzerkula/builddb/controllers/HomeController.java new file mode 100644 index 0000000..ad171c8 --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/controllers/HomeController.java @@ -0,0 +1,47 @@ +package org.berzerkula.builddb.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class HomeController { + + @GetMapping("/contact") + public String contact() { + return "contact"; + } + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/berzerkula/builddb/controllers/PkgController.java b/src/main/java/org/berzerkula/builddb/controllers/PkgController.java new file mode 100644 index 0000000..404a58b --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/controllers/PkgController.java @@ -0,0 +1,169 @@ +package org.berzerkula.builddb.controllers; + + +import jakarta.persistence.OrderBy; +import jakarta.validation.Valid; +import org.berzerkula.builddb.models.Pkg; +import org.berzerkula.builddb.models.PkgDto; +import org.berzerkula.builddb.repositories.PkgRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Objects; + +@Controller +@RequestMapping("/pkgs") +public class PkgController { + + private static final Logger logger = LoggerFactory.getLogger(PkgController.class); + + @Autowired + private PkgRepository repo; + + @GetMapping({"", "/", "/index"}) + public String showPkgList(Model model, + @RequestParam(defaultValue = "sequence,asc") String[] sort, + @RequestParam(defaultValue = "") String repotable) { + try { + String sortField = sort[0]; + String sortDirection = sort[1]; + + Sort.Direction direction = sortDirection.equals("desc") ? Sort.Direction.DESC : Sort.Direction.ASC; + Sort.Order order = new Sort.Order(direction, sortField); + + List pkgs = repo.findAll(Sort.by(order)); + + model.addAttribute("pkgs", pkgs); + model.addAttribute("sortField", sortField); + model.addAttribute("sortDirection", sortDirection); + model.addAttribute("reverseSortDirection", sortDirection.equals("asc") ? "desc" : "asc"); + + } catch (Exception e) { + logger.error(e.getMessage()); + } + + return "pkgs/index"; + } + + @GetMapping("/add") + public String showAddPkgForm(Model model) { + PkgDto pkgDto = new PkgDto(); + model.addAttribute("pkgDto", pkgDto); + return "pkgs/add"; + } + + @PostMapping("/add") + public String addPkg( + @Valid + @ModelAttribute + PkgDto pkgDto, BindingResult result ) { + + if (result.hasErrors()) { + return "pkgs/add"; + } + + try { + + Pkg pkg = new Pkg(); + pkg.setSequence(pkgDto.getSequence()); + pkg.setName(pkgDto.getName()); + pkg.setVersion(pkgDto.getVersion()); + pkg.setConfigure(pkgDto.getConfigure()); + pkg.setBuild(pkgDto.getBuild()); + pkg.setInstall(pkgDto.getInstall()); + pkg.setSetup(pkgDto.getSetup()); + pkg.setNotes(pkgDto.getNotes()); + pkg.setUrl(pkgDto.getUrl()); + + repo.save(pkg); + + } catch (Exception e) { + logger.error(e.getMessage()); + } + + return "redirect:/pkgs"; + } + + @GetMapping("/edit") + public String showEditPkgForm(Model model, @RequestParam int id) { + + try { + Pkg pkg = repo.findById(id).get(); + model.addAttribute("pkg", pkg); + + PkgDto pkgDto = new PkgDto(); + pkgDto.setSequence(pkg.getSequence()); + pkgDto.setName(pkg.getName()); + pkgDto.setVersion(pkg.getVersion()); + pkgDto.setConfigure(pkg.getConfigure()); + pkgDto.setBuild(pkg.getBuild()); + pkgDto.setInstall(pkg.getInstall()); + pkgDto.setSetup(pkg.getSetup()); + pkgDto.setNotes(pkg.getNotes()); + pkgDto.setUrl(pkg.getUrl()); + + model.addAttribute("pkgDto", pkgDto); + + } catch(Exception ex) { + logger.error("Exception: {}", ex.getMessage()); + } + + return "pkgs/edit"; + } + + @PostMapping("/edit") + public String editPkg( + Model model, + @RequestParam int id, + @Valid + @ModelAttribute PkgDto pkgDto, BindingResult result ) { + + try { + Pkg pkg = repo.findById(id).get(); + model.addAttribute("pkg", pkg); + + if (result.hasErrors()) { + return "pkgs/edit"; + } + + pkg.setSequence(pkgDto.getSequence()); + pkg.setName(pkgDto.getName()); + pkg.setVersion(pkgDto.getVersion()); + pkg.setConfigure(pkgDto.getConfigure()); + pkg.setBuild(pkgDto.getBuild()); + pkg.setInstall(pkgDto.getInstall()); + pkg.setSetup(pkgDto.getSetup()); + pkg.setNotes(pkgDto.getNotes()); + pkg.setUrl(pkgDto.getUrl()); + + repo.save(pkg); + + } catch(Exception ex) { + logger.error("Exception: {}", ex.getMessage()); + } + return "redirect:/pkgs/#" + id; + + } + + @GetMapping("/delete") + public String deletePkg(@RequestParam int id) { + + try { + Pkg pkg = repo.findById(id).get(); + + repo.delete(pkg); + + } catch (Exception ex) { + logger.error("Exception: {}", ex.getMessage()); + } + + return "redirect:/pkgs/"; + } +} diff --git a/src/main/java/org/berzerkula/builddb/models/AppUser.java b/src/main/java/org/berzerkula/builddb/models/AppUser.java new file mode 100644 index 0000000..21c5a33 --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/models/AppUser.java @@ -0,0 +1,107 @@ +package org.berzerkula.builddb.models; + +import jakarta.persistence.*; + +import java.util.Date; + +@Entity +@Table(name="users") +public class AppUser { + + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + private int id; + + private String firstName; + private String lastName; + + @Column(unique = true, nullable = false) + private String email; + + private String phone; + private String address; + private String password; + private String role; + private Date createdAt; + + public AppUser(String firstName, String lastName, String email, String phone, String address, + String password, String role) { + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + this.password = password; + this.role = role; + this.createdAt = new Date(); + } + + public AppUser() {} + + public int getId() { + return id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + +} diff --git a/src/main/java/org/berzerkula/builddb/models/Pkg.java b/src/main/java/org/berzerkula/builddb/models/Pkg.java new file mode 100644 index 0000000..5ce80ba --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/models/Pkg.java @@ -0,0 +1,118 @@ +package org.berzerkula.builddb.models; + +import jakarta.persistence.*; + +@Entity +@Table(name = "rock5b_srv_bld") +public class Pkg { + @Id + @GeneratedValue(strategy= GenerationType.IDENTITY) + private int id; + + private String name; + private Integer sequence; + private String version; + @Column(columnDefinition = "TEXT") + private String configure; + @Column(columnDefinition = "TEXT") + private String build; + @Column(columnDefinition = "TEXT") + private String install; + @Column(columnDefinition = "TEXT") + private String setup; + @Column(columnDefinition = "TEXT") + private String notes; + @Column(columnDefinition = "TEXT") + private String url; + + public Pkg(Integer sequence, String name, String version, String configure, String build, String install, + String setup, String notes, String url) { + this.sequence = sequence; + this.name = name; + this.version = version; + this.configure = configure; + this.build = build; + this.install = install; + this.setup = setup; + this.notes = notes; + this.url = url; + } + + public Pkg() {} + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getSequence() { + return sequence; + } + + public void setSequence(Integer seq) { + this.sequence = seq; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getConfigure() { + return configure; + } + + public void setConfigure(String configure) { + this.configure = configure; + } + + public String getBuild() { + return build; + } + + public void setBuild(String build) { + this.build = build; + } + + public String getInstall() { + return install; + } + + public void setInstall(String install) { + this.install = install; + } + + public String getSetup() { + return setup; + } + + public void setSetup(String setup) { + this.setup = setup; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } +} diff --git a/src/main/java/org/berzerkula/builddb/models/PkgDto.java b/src/main/java/org/berzerkula/builddb/models/PkgDto.java new file mode 100644 index 0000000..04c47ea --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/models/PkgDto.java @@ -0,0 +1,104 @@ +package org.berzerkula.builddb.models; + +import jakarta.validation.constraints.Digits; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import org.springframework.data.annotation.ReadOnlyProperty; + +public class PkgDto { + @ReadOnlyProperty + private Integer id; + + @NotNull(message = "Required") + @Digits(integer = 4, fraction = 0) + private Integer sequence; + + @NotEmpty(message = "Required") + private String name; + + @NotEmpty(message = "Required") + private String version; + + private String configure; + private String build; + private String install; + private String setup; + private String notes; + private String url; + + public Integer getSequence() { + return sequence; + } + + public void setSequence(Integer sequence) { + this.sequence = sequence; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getConfigure() { + return configure; + } + + public void setConfigure(String configure) { + this.configure = configure; + } + + public String getBuild() { + return build; + } + + public void setBuild(String build) { + this.build = build; + } + + public String getInstall() { + return install; + } + + public void setInstall(String install) { + this.install = install; + } + + public String getSetup() { + return setup; + } + + public void setSetup(String setup) { + this.setup = setup; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + + public Integer getId() { + return id; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } +} diff --git a/src/main/java/org/berzerkula/builddb/models/RegisterDto.java b/src/main/java/org/berzerkula/builddb/models/RegisterDto.java new file mode 100644 index 0000000..eebf014 --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/models/RegisterDto.java @@ -0,0 +1,84 @@ +package org.berzerkula.builddb.models; + +import jakarta.validation.constraints.*; + +public class RegisterDto { + + @NotEmpty + private String firstName; + + @NotEmpty + private String lastName; + + @NotEmpty + @Email + private String email; + + private String phone; + + private String address; + + @Size(min = 6, message = "Minimum Password length is 6 characters") + private String password; + + private String confirmPassword; + + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getConfirmPassword() { + return confirmPassword; + } + + public void setConfirmPassword(String confirmPassword) { + this.confirmPassword = confirmPassword; + } + + +} diff --git a/src/main/java/org/berzerkula/builddb/repositories/AppUserRepository.java b/src/main/java/org/berzerkula/builddb/repositories/AppUserRepository.java new file mode 100644 index 0000000..756d56a --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/repositories/AppUserRepository.java @@ -0,0 +1,10 @@ +package org.berzerkula.builddb.repositories; + +import org.springframework.data.jpa.repository.JpaRepository; + +import org.berzerkula.builddb.models.AppUser; + +public interface AppUserRepository extends JpaRepository { + + public AppUser findByEmail(String email); +} diff --git a/src/main/java/org/berzerkula/builddb/repositories/PkgRepository.java b/src/main/java/org/berzerkula/builddb/repositories/PkgRepository.java new file mode 100644 index 0000000..30e80eb --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/repositories/PkgRepository.java @@ -0,0 +1,8 @@ +package org.berzerkula.builddb.repositories; + +import org.berzerkula.builddb.models.Pkg; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PkgRepository extends JpaRepository { + +} diff --git a/src/main/java/org/berzerkula/builddb/services/AppUserService.java b/src/main/java/org/berzerkula/builddb/services/AppUserService.java new file mode 100644 index 0000000..02cc89f --- /dev/null +++ b/src/main/java/org/berzerkula/builddb/services/AppUserService.java @@ -0,0 +1,36 @@ +package org.berzerkula.builddb.services; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.User; +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.berzerkula.builddb.models.AppUser; +import org.berzerkula.builddb.repositories.AppUserRepository; + +@Service +public class AppUserService implements UserDetailsService { + @Autowired + private AppUserRepository repo; + + @Override + public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { + AppUser appUser = repo.findByEmail(email); + + + if (appUser != null) { + var springUser = User.withUsername(appUser.getEmail()) + .password(appUser.getPassword()) + .roles(appUser.getRole()) + .build(); + + return springUser; + } + + + return null; + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..f6a7814 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,15 @@ +spring.application.name=builddb + +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.url=jdbc:mysql://nucleus.berzerkula.org:3306/builddb_users +spring.datasource.username=kb0iic +spring.datasource.password=ENC(1xjvlowHDUgzAYCjEEaYcSQOQHL2SHo8) + +spring.jpa.show-sql=true +spring.jpa.hibernate.ddl-auto=update + +jasypt.encryptor.algorithm=PBEWithMD5AndDES +jasypt.encryptor.iv-generator-classname=org.jasypt.iv.NoIvGenerator +jasypt.encryptor.password=builddb + +management.endpoints.web.exposure.include=* \ No newline at end of file diff --git a/src/main/resources/templates/actuatorDashboard.html b/src/main/resources/templates/actuatorDashboard.html new file mode 100644 index 0000000..e97bb8f --- /dev/null +++ b/src/main/resources/templates/actuatorDashboard.html @@ -0,0 +1,39 @@ + + + + spring-boot-actuator + + + + +
+ + +
+
+ + Home +
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/admin.html b/src/main/resources/templates/admin.html new file mode 100644 index 0000000..16f8f7f --- /dev/null +++ b/src/main/resources/templates/admin.html @@ -0,0 +1,53 @@ + + + + + + builddb + + + + +
+
+

Admin Page

+
+ Home +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/templates/client.html b/src/main/resources/templates/client.html new file mode 100644 index 0000000..487d427 --- /dev/null +++ b/src/main/resources/templates/client.html @@ -0,0 +1,53 @@ + + + + + + builddb + + + + +
+
+

Client Page

+
+ Home +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/templates/contact.html b/src/main/resources/templates/contact.html new file mode 100644 index 0000000..f1c6a3f --- /dev/null +++ b/src/main/resources/templates/contact.html @@ -0,0 +1,53 @@ + + + + + + builddb + + + + +
+
+

Contact

+
+ Home +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..b33e45f --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,37 @@ + + + + + + builddb + + + + + + + +
+ +
+

Builddb

+ + + + Packages +
+ +
+ + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html new file mode 100644 index 0000000..0893fa0 --- /dev/null +++ b/src/main/resources/templates/login.html @@ -0,0 +1,87 @@ + + + + + + builddb + + + + +
+
+

Login

+
+ + + + +
+ + + +
+ + +
+ +
+ + +
+ +
+
+ +
+
+ Cancel +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/templates/navbar.html b/src/main/resources/templates/navbar.html new file mode 100644 index 0000000..0aa60e0 --- /dev/null +++ b/src/main/resources/templates/navbar.html @@ -0,0 +1,77 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/pkgs/add.html b/src/main/resources/templates/pkgs/add.html new file mode 100644 index 0000000..107784f --- /dev/null +++ b/src/main/resources/templates/pkgs/add.html @@ -0,0 +1,109 @@ + + + + + + builddb + + + + + + +
+ +
+
+

Add Package

+ +
+ + +
+ +
+ +

+
+
+ +
+ +
+ +

+
+
+ +
+ +
+ +

+
+
+ +
+ +
+