From aad1f02bfdee8cefbd7e7f6037987d57ef938979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BB=D1=8C=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=D1=8C?= Date: Thu, 22 Jun 2017 17:52:56 +0300 Subject: [PATCH 1/2] Users done, working on Projects --- .gitignore | 24 ++ .mvn/wrapper/maven-wrapper.jar | 0 .mvn/wrapper/maven-wrapper.properties | 1 + README.md | 1 - mvnw | 225 ++++++++++++++++++ mvnw.cmd | 143 +++++++++++ pom.xml | 147 ++++++++++++ .../factage_web/FactageWebApplication.java | 12 + .../bootstrap/SpringJpaBootstrap.java | 148 ++++++++++++ .../configuration/CommonBeanConfig.java | 28 +++ .../configuration/SecurityConfiguration.java | 59 +++++ .../controllers/IndexController.java | 12 + .../controllers/ProjectController.java | 55 +++++ .../controllers/UserController.java | 80 +++++++ .../converters/UserToUserDetails.java | 34 +++ .../creators/UserFormModelCreator.java | 8 + .../creators/UserFormModelCreatorImpl.java | 53 +++++ .../domain/AbstractDomainClass.java | 23 ++ .../factage_web/domain/DomainObject.java | 7 + .../com/ibcon/factage_web/domain/Project.java | 42 ++++ .../com/ibcon/factage_web/domain/Role.java | 77 ++++++ .../com/ibcon/factage_web/domain/User.java | 117 +++++++++ .../repositories/ProjectRepository.java | 8 + .../repositories/RoleRepository.java | 7 + .../repositories/UserRepository.java | 8 + .../factage_web/services/UserService1.java | 13 + .../factage_web/services/UserServiceImpl.java | 37 +++ .../services/crud/CrudService.java | 13 + .../services/crud/project/ProjectService.java | 8 + .../crud/project/ProjectServiceImpl.java | 46 ++++ .../services/crud/role/RoleService.java | 7 + .../services/crud/role/RoleServiceImpl.java | 44 ++++ .../services/crud/user/UserDetailsImpl.java | 66 +++++ .../crud/user/UserDetailsServiceImpl.java | 33 +++ .../services/crud/user/UserServiceCrud.java | 8 + .../crud/user/UserServiceCrudImp.java | 61 +++++ .../encryption/EncryptionService.java | 6 + .../encryption/EncryptionServiceImpl.java | 24 ++ src/main/resources/application.properties | 9 + src/main/resources/static/css/style.css | 0 .../resources/static/images/user_header.gif | Bin 0 -> 2067 bytes .../resources/templates/fragments/header.html | 48 ++++ .../templates/fragments/headerinc.html | 22 ++ src/main/resources/templates/index.html | 12 + src/main/resources/templates/login.html | 36 +++ src/main/resources/templates/projects.html | 36 +++ src/main/resources/templates/userform.html | 61 +++++ src/main/resources/templates/users.html | 37 +++ src/main/resources/templates/usershow.html | 46 ++++ .../FactageWebApplicationTests.java | 16 ++ .../repositories/UserRepositoryTest.java | 77 ++++++ 51 files changed, 2084 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .mvn/wrapper/maven-wrapper.jar create mode 100644 .mvn/wrapper/maven-wrapper.properties delete mode 100644 README.md create mode 100644 mvnw create mode 100644 mvnw.cmd create mode 100644 pom.xml create mode 100644 src/main/java/com/ibcon/factage_web/FactageWebApplication.java create mode 100644 src/main/java/com/ibcon/factage_web/bootstrap/SpringJpaBootstrap.java create mode 100644 src/main/java/com/ibcon/factage_web/configuration/CommonBeanConfig.java create mode 100644 src/main/java/com/ibcon/factage_web/configuration/SecurityConfiguration.java create mode 100644 src/main/java/com/ibcon/factage_web/controllers/IndexController.java create mode 100644 src/main/java/com/ibcon/factage_web/controllers/ProjectController.java create mode 100644 src/main/java/com/ibcon/factage_web/controllers/UserController.java create mode 100644 src/main/java/com/ibcon/factage_web/converters/UserToUserDetails.java create mode 100644 src/main/java/com/ibcon/factage_web/creators/UserFormModelCreator.java create mode 100644 src/main/java/com/ibcon/factage_web/creators/UserFormModelCreatorImpl.java create mode 100644 src/main/java/com/ibcon/factage_web/domain/AbstractDomainClass.java create mode 100644 src/main/java/com/ibcon/factage_web/domain/DomainObject.java create mode 100644 src/main/java/com/ibcon/factage_web/domain/Project.java create mode 100644 src/main/java/com/ibcon/factage_web/domain/Role.java create mode 100644 src/main/java/com/ibcon/factage_web/domain/User.java create mode 100644 src/main/java/com/ibcon/factage_web/repositories/ProjectRepository.java create mode 100644 src/main/java/com/ibcon/factage_web/repositories/RoleRepository.java create mode 100644 src/main/java/com/ibcon/factage_web/repositories/UserRepository.java create mode 100644 src/main/java/com/ibcon/factage_web/services/UserService1.java create mode 100644 src/main/java/com/ibcon/factage_web/services/UserServiceImpl.java create mode 100644 src/main/java/com/ibcon/factage_web/services/crud/CrudService.java create mode 100644 src/main/java/com/ibcon/factage_web/services/crud/project/ProjectService.java create mode 100644 src/main/java/com/ibcon/factage_web/services/crud/project/ProjectServiceImpl.java create mode 100644 src/main/java/com/ibcon/factage_web/services/crud/role/RoleService.java create mode 100644 src/main/java/com/ibcon/factage_web/services/crud/role/RoleServiceImpl.java create mode 100644 src/main/java/com/ibcon/factage_web/services/crud/user/UserDetailsImpl.java create mode 100644 src/main/java/com/ibcon/factage_web/services/crud/user/UserDetailsServiceImpl.java create mode 100644 src/main/java/com/ibcon/factage_web/services/crud/user/UserServiceCrud.java create mode 100644 src/main/java/com/ibcon/factage_web/services/crud/user/UserServiceCrudImp.java create mode 100644 src/main/java/com/ibcon/factage_web/services/encryption/EncryptionService.java create mode 100644 src/main/java/com/ibcon/factage_web/services/encryption/EncryptionServiceImpl.java create mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/static/css/style.css create mode 100644 src/main/resources/static/images/user_header.gif create mode 100644 src/main/resources/templates/fragments/header.html create mode 100644 src/main/resources/templates/fragments/headerinc.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/projects.html create mode 100644 src/main/resources/templates/userform.html create mode 100644 src/main/resources/templates/users.html create mode 100644 src/main/resources/templates/usershow.html create mode 100644 src/test/java/com/ibcon/factage_web/FactageWebApplicationTests.java create mode 100644 src/test/java/com/ibcon/factage_web/repositories/UserRepositoryTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2af7cef --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ \ No newline at end of file diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..e69de29 diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..c315043 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip diff --git a/README.md b/README.md deleted file mode 100644 index bdbdbc7..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# 3SProject \ No newline at end of file diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/mvnw @@ -0,0 +1,225 @@ +#!/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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + 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" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,143 @@ +@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 Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..bcaea09 --- /dev/null +++ b/pom.xml @@ -0,0 +1,147 @@ + + + 4.0.0 + + com.ibcon + factage_web + 0.0.1-SNAPSHOT + jar + + factage_web + + + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + com.ibcon.factage_web.FactageWebApplication + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + 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-web + + + + com.microsoft.sqlserver + mssql-jdbc + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.webjars + bootstrap + 3.3.4 + + + org.webjars + jquery + 2.1.4 + + + org.webjars + jquery-ui + 1.9.2 + + + + + org.springframework.boot + spring-boot-devtools + true + + + + org.jasypt + jasypt + 1.9.2 + + + org.jasypt + jasypt-springsecurity3 + 1.9.2 + + + + org.springframework.security + spring-security-taglibs + 4.2.3.RELEASE + + + org.thymeleaf.extras + thymeleaf-extras-springsecurity4 + + + + org.projectlombok + lombok + 1.16.16 + provided + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + maven-resources-plugin + 2.6 + + + copy-resources + validate + + copy-resources + + + ${basedir}/target/classes/static + + + src/main/webapps + true + + + + + + + + + + + diff --git a/src/main/java/com/ibcon/factage_web/FactageWebApplication.java b/src/main/java/com/ibcon/factage_web/FactageWebApplication.java new file mode 100644 index 0000000..f1337d5 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/FactageWebApplication.java @@ -0,0 +1,12 @@ +package com.ibcon.factage_web; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class FactageWebApplication { + + public static void main(String[] args) { + SpringApplication.run(FactageWebApplication.class, args); + } +} diff --git a/src/main/java/com/ibcon/factage_web/bootstrap/SpringJpaBootstrap.java b/src/main/java/com/ibcon/factage_web/bootstrap/SpringJpaBootstrap.java new file mode 100644 index 0000000..a92e579 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/bootstrap/SpringJpaBootstrap.java @@ -0,0 +1,148 @@ +package com.ibcon.factage_web.bootstrap; + +import com.ibcon.factage_web.domain.Project; +import com.ibcon.factage_web.domain.Role; +import com.ibcon.factage_web.domain.User; +import com.ibcon.factage_web.services.crud.project.ProjectService; +import com.ibcon.factage_web.services.crud.user.UserServiceCrud; +import com.ibcon.factage_web.services.crud.role.RoleService; +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationListener; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.stereotype.Component; + +import java.util.Date; +import java.time.LocalDate; +import java.util.List; + +@Component +public class SpringJpaBootstrap implements ApplicationListener { + private UserServiceCrud userServiceCrud; + private RoleService roleService; + private ProjectService projectService; + + private Logger log = Logger.getLogger(SpringJpaBootstrap.class); + + @Autowired + public void setUserServiceCrud(UserServiceCrud userServiceCrud) { + this.userServiceCrud = userServiceCrud; + } + + @Autowired + public void setRoleService(RoleService roleService) { + this.roleService = roleService; + } + + @Autowired + public void setProjectService(ProjectService projectService) { + this.projectService = projectService; + } + + @Override + public void onApplicationEvent(ContextRefreshedEvent event) { +// loadUsers(); +// loadRoles(); +// assignUsersToUserRole(); +// assignUsersToAdminRole(); +// loadProjects(); +// assignProjectsToRole(); + } + + private void loadUsers() { + User user1 = new User(); + user1.setName("user"); + user1.setPassword("user"); + user1.setExpirationDate(new Date()); + user1.setActive(true); + userServiceCrud.saveOrUpdate(user1); + + User user2 = new User(); + user2.setName("admin"); + user2.setPassword("admin"); + user2.setExpirationDate(new Date()); + user2.setActive(true); + userServiceCrud.saveOrUpdate(user2); + } + + private void loadRoles() { + Role role = new Role(); + role.setName("USER"); + roleService.saveOrUpdate(role); + log.info("Saved role" + role.getName()); + Role adminRole = new Role(); + adminRole.setName("ADMIN"); + roleService.saveOrUpdate(adminRole); + log.info("Saved role" + adminRole.getName()); + } + + private void loadProjects() { + Project project1 = new Project(); + project1.setProjectObjectId(1); + project1.setPrimaveraId("prim"); + project1.setProjectName("First Project"); + project1.setProjectDbName("3SWEB"); + project1.setProjectWbsId(1); + project1.setProjectCode("code"); + project1.setConfigId(1); + project1.setIndexNumber(1); + projectService.saveOrUpdate(project1); + + Project project2 = new Project(); + project2.setProjectObjectId(2); + project2.setPrimaveraId("prim2"); + project2.setProjectName("Second Project"); + project2.setProjectDbName("3SWEB"); + project2.setProjectWbsId(2); + project2.setProjectCode("code2"); + project2.setConfigId(2); + project2.setIndexNumber(2); + projectService.saveOrUpdate(project2); + } + + private void assignUsersToUserRole() { + List roles = (List) roleService.listAll(); + List users = (List) userServiceCrud.listAll(); + + roles.forEach(role -> { + if (role.getName().equalsIgnoreCase("USER")) { + users.forEach(user -> { + if (user.getName().equals("user")) { + user.addRole(role); + userServiceCrud.saveOrUpdate(user); + } + }); + } + }); + } + + private void assignUsersToAdminRole() { + List roles = (List) roleService.listAll(); + List users = (List) userServiceCrud.listAll(); + + roles.forEach(role -> { + if (role.getName().equalsIgnoreCase("ADMIN")) { + users.forEach(user -> { + if (user.getName().equals("admin")) { + user.addRole(role); + userServiceCrud.saveOrUpdate(user); + } + }); + } + }); + } + + private void assignProjectsToRole() { + List roles = (List) roleService.listAll(); + List projects = (List) projectService.listAll(); + + + Project project1 = projectService.findByProjectObjectId(1); + project1.addRole(roles.get(0)); + projectService.saveOrUpdate(project1); + + Project project2 = projectService.findByProjectObjectId(2); + project2.addRole(roles.get(2)); + projectService.saveOrUpdate(project2); + } +} diff --git a/src/main/java/com/ibcon/factage_web/configuration/CommonBeanConfig.java b/src/main/java/com/ibcon/factage_web/configuration/CommonBeanConfig.java new file mode 100644 index 0000000..8afb993 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/configuration/CommonBeanConfig.java @@ -0,0 +1,28 @@ +package com.ibcon.factage_web.configuration; + +import com.ibcon.factage_web.services.crud.role.RoleService; +import com.ibcon.factage_web.services.crud.role.RoleServiceImpl; +import com.ibcon.factage_web.services.crud.user.UserServiceCrud; +import com.ibcon.factage_web.services.crud.user.UserServiceCrudImp; +import org.jasypt.util.password.StrongPasswordEncryptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class CommonBeanConfig { + + @Bean + public StrongPasswordEncryptor strongEncryptor(){ + return new StrongPasswordEncryptor(); + } + + @Bean + public RoleService roleService() { + return new RoleServiceImpl(); + } + + @Bean + public UserServiceCrud userServiceCrud() { + return new UserServiceCrudImp(); + } +} diff --git a/src/main/java/com/ibcon/factage_web/configuration/SecurityConfiguration.java b/src/main/java/com/ibcon/factage_web/configuration/SecurityConfiguration.java new file mode 100644 index 0000000..bed7b47 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/configuration/SecurityConfiguration.java @@ -0,0 +1,59 @@ +package com.ibcon.factage_web.configuration; + +import org.jasypt.springsecurity3.authentication.encoding.PasswordEncoder; +import org.jasypt.util.password.StrongPasswordEncryptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.userdetails.UserDetailsService; + +@Configuration +public class SecurityConfiguration extends WebSecurityConfigurerAdapter { + + private AuthenticationProvider authenticationProvider; + + @Bean + public PasswordEncoder passwordEncoder(StrongPasswordEncryptor passwordEncryptor){ + PasswordEncoder passwordEncoder = new PasswordEncoder(); + passwordEncoder.setPasswordEncryptor(passwordEncryptor); + return passwordEncoder; + } + + @Autowired + @Qualifier("daoAuthenticationProvider") + public void setAuthenticationProvider(AuthenticationProvider authenticationProvider) { + this.authenticationProvider = authenticationProvider; + } + + @Bean + public DaoAuthenticationProvider daoAuthenticationProvider(PasswordEncoder passwordEncoder, + UserDetailsService userDetailsService){ + + DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider(); + daoAuthenticationProvider.setPasswordEncoder(passwordEncoder); + daoAuthenticationProvider.setUserDetailsService(userDetailsService); + return daoAuthenticationProvider; + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests().antMatchers("/").permitAll() + .antMatchers("/user*").hasAuthority("ADMIN") + .anyRequest().authenticated() + .and() + .formLogin().loginPage("/login").permitAll() + .and() + .logout().permitAll(); +// http.authorizeRequests().antMatchers("/users/**").hasAuthority("ADMIN"); + +// http.csrf().disable(); + http.headers().frameOptions().disable(); + } + +} diff --git a/src/main/java/com/ibcon/factage_web/controllers/IndexController.java b/src/main/java/com/ibcon/factage_web/controllers/IndexController.java new file mode 100644 index 0000000..496e4c0 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/controllers/IndexController.java @@ -0,0 +1,12 @@ +package com.ibcon.factage_web.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class IndexController { + @RequestMapping("/") + public String index() { + return "index"; + } +} diff --git a/src/main/java/com/ibcon/factage_web/controllers/ProjectController.java b/src/main/java/com/ibcon/factage_web/controllers/ProjectController.java new file mode 100644 index 0000000..c278941 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/controllers/ProjectController.java @@ -0,0 +1,55 @@ +package com.ibcon.factage_web.controllers; + +import com.ibcon.factage_web.domain.Project; +import com.ibcon.factage_web.services.crud.project.ProjectService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +@Controller +public class ProjectController { + ProjectService projectService; + + @Autowired + public void setProjectService(ProjectService projectService) { + this.projectService = projectService; + } + + @RequestMapping(value = "/projects", method = RequestMethod.GET) + public String listAllProjects(Model model) { + model.addAttribute("projects", projectService.listAll()); + return "projects"; + } + @RequestMapping("project/new") + public String create(Model model) { + model.addAttribute("project", new Project()); + return "projectform"; + } + + @RequestMapping(value = "project", method = RequestMethod.POST) + public String save(Project project) { + projectService.saveOrUpdate(project); + return "redirect:/project/" + project.getId(); + } + + @RequestMapping("project/{id}") + public String showUser(@PathVariable Integer id, Model model) { + model.addAttribute("project", projectService.getById(id)); + return "projectshow"; + } + + @RequestMapping("project/edit/{id}") + public String edit(@PathVariable Integer id, Model model) { + model.addAttribute("user", projectService.getById(id)); + return "projectform"; + } + + @RequestMapping("project/delete/{id}") + public String delete(@PathVariable Integer id) { + projectService.delete(id); + return "redirect:/projects"; + } +} diff --git a/src/main/java/com/ibcon/factage_web/controllers/UserController.java b/src/main/java/com/ibcon/factage_web/controllers/UserController.java new file mode 100644 index 0000000..d4a8b73 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/controllers/UserController.java @@ -0,0 +1,80 @@ +package com.ibcon.factage_web.controllers; + +import com.ibcon.factage_web.creators.UserFormModelCreatorImpl; +import com.ibcon.factage_web.domain.User; +import com.ibcon.factage_web.services.crud.role.RoleService; +import com.ibcon.factage_web.services.crud.user.UserServiceCrud; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.propertyeditors.CustomDateEditor; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.*; + +import java.text.SimpleDateFormat; +import java.util.Date; + +@Controller +public class UserController { + private UserServiceCrud userServiceCrud; + private RoleService roleService; + + @Autowired + public void setUserServiceCrud(UserServiceCrud userServiceCrud) { + this.userServiceCrud = userServiceCrud; + } + + @Autowired + public void setRoleService(RoleService roleService) { + this.roleService = roleService; + } + + @InitBinder + protected void initBinder(WebDataBinder binder) { + SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); + binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); + } + @RequestMapping("user/new") + public String create(Model model) { + UserFormModelCreatorImpl userFormModelCreator = new UserFormModelCreatorImpl(roleService.listAll()); + userFormModelCreator.getUser().setExpirationDate(new Date()); + model.addAttribute("createUserFormModel", userFormModelCreator); + return "userform"; + } + + @RequestMapping(value = "user", method = RequestMethod.POST) + public String save(@ModelAttribute("createUserFormModel") UserFormModelCreatorImpl userFormModelCreatorImpl) { + User user = userFormModelCreatorImpl.createUser(roleService); + userServiceCrud.saveOrUpdate(user); + return "redirect:/user/" + user.getId(); + } + + @RequestMapping("user/{id}") + public String showUser(@PathVariable Integer id, Model model) { + model.addAttribute("user", userServiceCrud.getById(id)); + return "usershow"; + } + + @RequestMapping(value = "/users", method = RequestMethod.GET) + public String listAllUsers(Model model) { + model.addAttribute("users", userServiceCrud.listAll()); + return "users"; + } + + @RequestMapping("user/edit/{id}") + public String edit(@PathVariable Integer id, Model model) { + model.addAttribute("user", userServiceCrud.getById(id)); + return "userform"; + } + + @RequestMapping("user/delete/{id}") + public String delete(@PathVariable Integer id) { + userServiceCrud.delete(id); + return "redirect:/users"; + } + + @RequestMapping(value = "/login", method = RequestMethod.GET) + public String login(){ + return "login"; + } +} diff --git a/src/main/java/com/ibcon/factage_web/converters/UserToUserDetails.java b/src/main/java/com/ibcon/factage_web/converters/UserToUserDetails.java new file mode 100644 index 0000000..8843f14 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/converters/UserToUserDetails.java @@ -0,0 +1,34 @@ +package com.ibcon.factage_web.converters; + +import com.ibcon.factage_web.domain.User; +import com.ibcon.factage_web.services.crud.user.UserDetailsImpl; +import org.springframework.core.convert.converter.Converter; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Collection; + +//Позволяет использовать роли в шаблонах +@Component +public class UserToUserDetails implements Converter { + @Override + public UserDetails convert(User user) { + UserDetailsImpl userDetails = new UserDetailsImpl(); + + if (user != null) { + userDetails.setUsername(user.getName()); + userDetails.setPassword(user.getEncryptedPassword()); + //TODO работает? + userDetails.setActive(user.isActive()); + Collection authorities = new ArrayList<>(); + user.getRoles().forEach(role -> { + authorities.add(new SimpleGrantedAuthority(role.getName())); + }); + userDetails.setAuthorities(authorities); + } + + return userDetails; + } +} \ No newline at end of file diff --git a/src/main/java/com/ibcon/factage_web/creators/UserFormModelCreator.java b/src/main/java/com/ibcon/factage_web/creators/UserFormModelCreator.java new file mode 100644 index 0000000..6e6d0da --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/creators/UserFormModelCreator.java @@ -0,0 +1,8 @@ +package com.ibcon.factage_web.creators; + +import com.ibcon.factage_web.domain.User; +import com.ibcon.factage_web.services.crud.role.RoleService; + +public interface UserFormModelCreator { + User createUser(RoleService roleService); +} diff --git a/src/main/java/com/ibcon/factage_web/creators/UserFormModelCreatorImpl.java b/src/main/java/com/ibcon/factage_web/creators/UserFormModelCreatorImpl.java new file mode 100644 index 0000000..3b9ca53 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/creators/UserFormModelCreatorImpl.java @@ -0,0 +1,53 @@ +package com.ibcon.factage_web.creators; + +import com.ibcon.factage_web.domain.Role; +import com.ibcon.factage_web.domain.User; +import com.ibcon.factage_web.services.crud.role.RoleService; + +import java.util.ArrayList; +import java.util.List; + +public class UserFormModelCreatorImpl implements UserFormModelCreator { + private User user = new User(); + private List allRoles; + private List roleIds = new ArrayList<>(); + + public UserFormModelCreatorImpl() { + } + + public UserFormModelCreatorImpl(List objects) { + this.allRoles = (List) objects; + } + + @Override + public User createUser(RoleService roleService) { + for (Integer roleId : roleIds) { + user.addRole(roleService.getById(roleId)); + } + return user; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public List getAllRoles() { + return allRoles; + } + + public void setAllRoles(List allRoles) { + this.allRoles = allRoles; + } + + public List getRoleIds() { + return roleIds; + } + + public void setRoleIds(List roleIds) { + this.roleIds = roleIds; + } +} diff --git a/src/main/java/com/ibcon/factage_web/domain/AbstractDomainClass.java b/src/main/java/com/ibcon/factage_web/domain/AbstractDomainClass.java new file mode 100644 index 0000000..eae1c18 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/domain/AbstractDomainClass.java @@ -0,0 +1,23 @@ +package com.ibcon.factage_web.domain; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +@MappedSuperclass +public class AbstractDomainClass implements DomainObject { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + Integer id; + + @Override + public Integer getId() { + return this.id; + } + + @Override + public void setId(Integer id) { + this.id = id; + } +} diff --git a/src/main/java/com/ibcon/factage_web/domain/DomainObject.java b/src/main/java/com/ibcon/factage_web/domain/DomainObject.java new file mode 100644 index 0000000..35cc1b6 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/domain/DomainObject.java @@ -0,0 +1,7 @@ +package com.ibcon.factage_web.domain; + +public interface DomainObject { + Integer getId(); + + void setId(Integer id); +} diff --git a/src/main/java/com/ibcon/factage_web/domain/Project.java b/src/main/java/com/ibcon/factage_web/domain/Project.java new file mode 100644 index 0000000..caec4fc --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/domain/Project.java @@ -0,0 +1,42 @@ +package com.ibcon.factage_web.domain; + +import lombok.Data; +import org.springframework.boot.autoconfigure.domain.EntityScan; + +import javax.persistence.*; +import java.util.HashSet; +import java.util.Set; + +@EntityScan +@Entity +@Table(name = "projects") +public @Data class Project extends AbstractDomainClass { + private Integer projectObjectId; + private String primaveraId; + private String projectName; + private String projectDbName; + private Integer projectWbsId; + private String projectCode; + private Integer configId; + private Integer indexNumber; + + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "projects_roles", joinColumns = @JoinColumn(name = "project_id"), + inverseJoinColumns = @JoinColumn(name = "role_id")) + private Set roles = new HashSet<>(); + + public void addRole(Role role) { + if (!this.getRoles().contains(role)) { + this.getRoles().add(role); + } + + if(!role.getProjects().contains(this)){ + role.getProjects().add(this); + } + } + + public void removeRole(Role role){ + this.getRoles().remove(role); + role.getProjects().remove(this); + } +} diff --git a/src/main/java/com/ibcon/factage_web/domain/Role.java b/src/main/java/com/ibcon/factage_web/domain/Role.java new file mode 100644 index 0000000..8e764cf --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/domain/Role.java @@ -0,0 +1,77 @@ +package com.ibcon.factage_web.domain; + +import javax.persistence.*; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Entity +@Table(name = "roles") +public class Role extends AbstractDomainClass { + private String name; + + @ManyToMany(fetch = FetchType.EAGER, mappedBy = "roles") + private Set users = new HashSet<>(); + + @ManyToMany(fetch = FetchType.EAGER, mappedBy = "roles") + private Set projects = new HashSet<>(); + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set getUsers() { + return users; + } + + public void setUsers(Set users) { + this.users = users; + } + + public Set getProjects() { + return projects; + } + + public void setProjects(Set projects) { + this.projects = projects; + } + + public void addUser(User user){ + if(!this.getUsers().contains(user)){ + this.getUsers().add(user); + } + + if(!user.getRoles().contains(this)){ + user.getRoles().add(this); + } + } + + public void removeUser(User user){ + this.getUsers().remove(user); + user.getRoles().remove(this); + } + + public void addProject(Project project){ + if(!this.getProjects().contains(project)){ + this.getProjects().add(project); + } + + if(!project.getRoles().contains(this)){ + project.getRoles().add(this); + } + } + + public void removeProject(Project project){ + this.getProjects().remove(project); + project.getRoles().remove(this); + } + + @Override + public String toString() { + return name; + } +} diff --git a/src/main/java/com/ibcon/factage_web/domain/User.java b/src/main/java/com/ibcon/factage_web/domain/User.java new file mode 100644 index 0000000..bc32e8e --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/domain/User.java @@ -0,0 +1,117 @@ +package com.ibcon.factage_web.domain; + +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.*; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@EntityScan +@Entity +@Table(name = "users") +public class User extends AbstractDomainClass { + + private String name; + + @Transient + private String password; + + private String encryptedPassword; + + @Temporal(TemporalType.DATE) + @DateTimeFormat(pattern = "dd-MM-yyyy") + private Date expirationDate; + + private boolean active; + + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable(name = "users_roles", joinColumns = @JoinColumn(name = "user_id"), + inverseJoinColumns = @JoinColumn(name = "role_id")) + private Set roles = new HashSet<>(); + + public User() { + } + + public User(String name, Date expirationDate, boolean isActive) { + this.name = name; + this.expirationDate = expirationDate; + this.active = isActive; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getEncryptedPassword() { + return encryptedPassword; + } + + public void setEncryptedPassword(String encryptedPassword) { + this.encryptedPassword = encryptedPassword; + } + + public Date getExpirationDate() { + return expirationDate; + } + + public void setExpirationDate(Date expirationDate) { + this.expirationDate = expirationDate; + } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public Set getRoles() { + return roles; + } + + public void setRoles(Set roles) { + this.roles = roles; + } + + public void addRole(Role role) { + if (!this.getRoles().contains(role)) { + this.getRoles().add(role); + } + + if(!role.getUsers().contains(this)){ + role.getUsers().add(this); + } + } + + public void removeRole(Role role){ + this.getRoles().remove(role); + role.getUsers().remove(this); + } + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", name='" + name + '\'' + + ", expirationDate=" + expirationDate + + ", active=" + active + + '}'; + } +} diff --git a/src/main/java/com/ibcon/factage_web/repositories/ProjectRepository.java b/src/main/java/com/ibcon/factage_web/repositories/ProjectRepository.java new file mode 100644 index 0000000..ff2a10a --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/repositories/ProjectRepository.java @@ -0,0 +1,8 @@ +package com.ibcon.factage_web.repositories; + +import com.ibcon.factage_web.domain.Project; +import org.springframework.data.repository.CrudRepository; + +public interface ProjectRepository extends CrudRepository { + Project findByProjectObjectId(Integer projectObjectId); +} diff --git a/src/main/java/com/ibcon/factage_web/repositories/RoleRepository.java b/src/main/java/com/ibcon/factage_web/repositories/RoleRepository.java new file mode 100644 index 0000000..6b0dd66 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/repositories/RoleRepository.java @@ -0,0 +1,7 @@ +package com.ibcon.factage_web.repositories; + +import com.ibcon.factage_web.domain.Role; +import org.springframework.data.repository.CrudRepository; + +public interface RoleRepository extends CrudRepository { +} diff --git a/src/main/java/com/ibcon/factage_web/repositories/UserRepository.java b/src/main/java/com/ibcon/factage_web/repositories/UserRepository.java new file mode 100644 index 0000000..576444f --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/repositories/UserRepository.java @@ -0,0 +1,8 @@ +package com.ibcon.factage_web.repositories; + +import com.ibcon.factage_web.domain.User; +import org.springframework.data.repository.CrudRepository; + +public interface UserRepository extends CrudRepository { + User findByName(String name); +} diff --git a/src/main/java/com/ibcon/factage_web/services/UserService1.java b/src/main/java/com/ibcon/factage_web/services/UserService1.java new file mode 100644 index 0000000..fb639f8 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/UserService1.java @@ -0,0 +1,13 @@ +package com.ibcon.factage_web.services; + +import com.ibcon.factage_web.domain.User; + +public interface UserService1 { + Iterable listAllUsers(); + + User getUserById(Integer id); + + User save(User user); + + void delete(Integer id); +} diff --git a/src/main/java/com/ibcon/factage_web/services/UserServiceImpl.java b/src/main/java/com/ibcon/factage_web/services/UserServiceImpl.java new file mode 100644 index 0000000..d9f8cf6 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/UserServiceImpl.java @@ -0,0 +1,37 @@ +package com.ibcon.factage_web.services; + + +import com.ibcon.factage_web.domain.User; +import com.ibcon.factage_web.repositories.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class UserServiceImpl implements UserService1 { + private UserRepository userRepository; + + @Autowired + public void setUserRepository(UserRepository userRepository) { + this.userRepository = userRepository; + } + + @Override + public Iterable listAllUsers() { + return userRepository.findAll(); + } + + @Override + public User getUserById(Integer id) { + return userRepository.findOne(id); + } + + @Override + public User save(User user) { + return userRepository.save(user); + } + + @Override + public void delete(Integer id) { + userRepository.delete(id); + } +} diff --git a/src/main/java/com/ibcon/factage_web/services/crud/CrudService.java b/src/main/java/com/ibcon/factage_web/services/crud/CrudService.java new file mode 100644 index 0000000..53d7b10 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/crud/CrudService.java @@ -0,0 +1,13 @@ +package com.ibcon.factage_web.services.crud; + +import java.util.List; + +public interface CrudService { + List listAll(); + + T getById(Integer id); + + T saveOrUpdate(T domainObject); + + void delete(Integer id); +} diff --git a/src/main/java/com/ibcon/factage_web/services/crud/project/ProjectService.java b/src/main/java/com/ibcon/factage_web/services/crud/project/ProjectService.java new file mode 100644 index 0000000..e2826ca --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/crud/project/ProjectService.java @@ -0,0 +1,8 @@ +package com.ibcon.factage_web.services.crud.project; + +import com.ibcon.factage_web.domain.Project; +import com.ibcon.factage_web.services.crud.CrudService; + +public interface ProjectService extends CrudService { + Project findByProjectObjectId(Integer projectObjectId); +} diff --git a/src/main/java/com/ibcon/factage_web/services/crud/project/ProjectServiceImpl.java b/src/main/java/com/ibcon/factage_web/services/crud/project/ProjectServiceImpl.java new file mode 100644 index 0000000..b3e4edf --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/crud/project/ProjectServiceImpl.java @@ -0,0 +1,46 @@ +package com.ibcon.factage_web.services.crud.project; + +import com.ibcon.factage_web.domain.Project; +import com.ibcon.factage_web.repositories.ProjectRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class ProjectServiceImpl implements ProjectService { + private ProjectRepository projectRepository; + + @Autowired + public void setProjectRepository(ProjectRepository projectRepository) { + this.projectRepository = projectRepository; + } + + @Override + public List listAll() { + List projects = new ArrayList<>(); + projectRepository.findAll().forEach(projects::add); + return projects; + } + + @Override + public Project getById(Integer id) { + return projectRepository.findOne(id); + } + + @Override + public Project saveOrUpdate(Project project) { + return projectRepository.save(project); + } + + @Override + public void delete(Integer id) { + projectRepository.delete(id); + } + + @Override + public Project findByProjectObjectId(Integer projectObjectId) { + return projectRepository.findByProjectObjectId(projectObjectId); + } +} diff --git a/src/main/java/com/ibcon/factage_web/services/crud/role/RoleService.java b/src/main/java/com/ibcon/factage_web/services/crud/role/RoleService.java new file mode 100644 index 0000000..da51513 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/crud/role/RoleService.java @@ -0,0 +1,7 @@ +package com.ibcon.factage_web.services.crud.role; + +import com.ibcon.factage_web.domain.Role; +import com.ibcon.factage_web.services.crud.CrudService; + +public interface RoleService extends CrudService { +} diff --git a/src/main/java/com/ibcon/factage_web/services/crud/role/RoleServiceImpl.java b/src/main/java/com/ibcon/factage_web/services/crud/role/RoleServiceImpl.java new file mode 100644 index 0000000..0aae809 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/crud/role/RoleServiceImpl.java @@ -0,0 +1,44 @@ +package com.ibcon.factage_web.services.crud.role; + +import com.ibcon.factage_web.domain.Role; +import com.ibcon.factage_web.repositories.RoleRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +@Profile("springdatajpa") +public class RoleServiceImpl implements RoleService { + + private RoleRepository roleRepository; + + @Autowired + public void setRoleRepository(RoleRepository roleRepository) { + this.roleRepository = roleRepository; + } + + @Override + public List listAll() { + List roles = new ArrayList<>(); + roleRepository.findAll().forEach(roles::add); + return roles; + } + + @Override + public Role getById(Integer id) { + return roleRepository.findOne(id); + } + + @Override + public Role saveOrUpdate(Role domainObject) { + return roleRepository.save(domainObject); + } + + @Override + public void delete(Integer id) { + roleRepository.delete(id); + } +} \ No newline at end of file diff --git a/src/main/java/com/ibcon/factage_web/services/crud/user/UserDetailsImpl.java b/src/main/java/com/ibcon/factage_web/services/crud/user/UserDetailsImpl.java new file mode 100644 index 0000000..5f8a8a2 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/crud/user/UserDetailsImpl.java @@ -0,0 +1,66 @@ +package com.ibcon.factage_web.services.crud.user; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.util.Collection; + +public class UserDetailsImpl implements UserDetails { + + private Collection authorities; + private String name; + private String password; + private Boolean active = true; + + public void setAuthorities(Collection authorities) { + this.authorities = authorities; + } + + public void setUsername(String username) { + this.name = username; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setActive(Boolean active) { + this.active = active; + } + + @Override + public Collection getAuthorities() { + return authorities; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public String getUsername() { + return name; + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return active; + } +} diff --git a/src/main/java/com/ibcon/factage_web/services/crud/user/UserDetailsServiceImpl.java b/src/main/java/com/ibcon/factage_web/services/crud/user/UserDetailsServiceImpl.java new file mode 100644 index 0000000..c20c229 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/crud/user/UserDetailsServiceImpl.java @@ -0,0 +1,33 @@ +package com.ibcon.factage_web.services.crud.user; + +import com.ibcon.factage_web.domain.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.core.convert.converter.Converter; +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; + +@Service("userDetailsService") +public class UserDetailsServiceImpl implements UserDetailsService { + + private UserServiceCrud userService; + private Converter userUserDetailsConverter; + + @Autowired + public void setUserService(UserServiceCrud userService) { + this.userService = userService; + } + + @Autowired + @Qualifier(value = "userToUserDetails") + public void setUserUserDetailsConverter(Converter userUserDetailsConverter) { + this.userUserDetailsConverter = userUserDetailsConverter; + } + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + return userUserDetailsConverter.convert(userService.findByUserName(username)); + } +} diff --git a/src/main/java/com/ibcon/factage_web/services/crud/user/UserServiceCrud.java b/src/main/java/com/ibcon/factage_web/services/crud/user/UserServiceCrud.java new file mode 100644 index 0000000..924c7b5 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/crud/user/UserServiceCrud.java @@ -0,0 +1,8 @@ +package com.ibcon.factage_web.services.crud.user; + +import com.ibcon.factage_web.domain.User; +import com.ibcon.factage_web.services.crud.CrudService; + +public interface UserServiceCrud extends CrudService { + User findByUserName(String username); +} diff --git a/src/main/java/com/ibcon/factage_web/services/crud/user/UserServiceCrudImp.java b/src/main/java/com/ibcon/factage_web/services/crud/user/UserServiceCrudImp.java new file mode 100644 index 0000000..478b6d0 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/crud/user/UserServiceCrudImp.java @@ -0,0 +1,61 @@ +package com.ibcon.factage_web.services.crud.user; + +import com.ibcon.factage_web.domain.User; +import com.ibcon.factage_web.repositories.UserRepository; +import com.ibcon.factage_web.services.encryption.EncryptionService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; +import java.util.ArrayList; +import java.util.List; + +@Service +@Profile("springdatajpa") +public class UserServiceCrudImp implements UserServiceCrud { + private UserRepository userRepository; + + @Autowired + public void setUserRepository(UserRepository userRepository) { + this.userRepository = userRepository; + } + + private EncryptionService encryptionService; + + @Autowired + public void setEncryptionService(EncryptionService encryptionService) { + this.encryptionService = encryptionService; + } + + + @Override + public List listAll() { + List users = new ArrayList<>(); + userRepository.findAll().forEach(users::add); + return users; + } + + @Override + public User getById(Integer id) { + return userRepository.findOne(id); + } + + @Override + public User saveOrUpdate(User domainObject) { + if(domainObject.getPassword() != null){ + domainObject.setEncryptedPassword(encryptionService.encryptString(domainObject.getPassword())); + } + return userRepository.save(domainObject); + } + @Override + @Transactional + public void delete(Integer id) { + userRepository.delete(id); + } + + @Override + public User findByUserName(String username) { + return userRepository.findByName(username); + } +} diff --git a/src/main/java/com/ibcon/factage_web/services/encryption/EncryptionService.java b/src/main/java/com/ibcon/factage_web/services/encryption/EncryptionService.java new file mode 100644 index 0000000..38fbb89 --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/encryption/EncryptionService.java @@ -0,0 +1,6 @@ +package com.ibcon.factage_web.services.encryption; + +public interface EncryptionService { + String encryptString(String input); + boolean checkPassword(String plainPassword, String encryptedPassword); +} diff --git a/src/main/java/com/ibcon/factage_web/services/encryption/EncryptionServiceImpl.java b/src/main/java/com/ibcon/factage_web/services/encryption/EncryptionServiceImpl.java new file mode 100644 index 0000000..4a9af8b --- /dev/null +++ b/src/main/java/com/ibcon/factage_web/services/encryption/EncryptionServiceImpl.java @@ -0,0 +1,24 @@ +package com.ibcon.factage_web.services.encryption; + +import org.jasypt.util.password.StrongPasswordEncryptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class EncryptionServiceImpl implements EncryptionService { + + private StrongPasswordEncryptor strongEncryptor; + + @Autowired + public void setStrongEncryptor(StrongPasswordEncryptor strongEncryptor) { + this.strongEncryptor = strongEncryptor; + } + + public String encryptString(String input){ + return strongEncryptor.encryptPassword(input); + } + + public boolean checkPassword(String plainPassword, String encryptedPassword){ + return strongEncryptor.checkPassword(plainPassword, encryptedPassword); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..abca851 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:sqlserver://sdevsqlphn1d.ibcon.office;database=3SWEB +spring.datasource.username=sa +spring.datasource.password=11111Q! +spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver +spring.jpa.show-sql=true +spring.jpa.hibernate.ddl-auto = validate + +#spring.thymeleaf.prefix=${project.base-dir}/src/main/resources/templates/ +spring.thymeleaf.cache=false \ No newline at end of file diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/static/images/user_header.gif b/src/main/resources/static/images/user_header.gif new file mode 100644 index 0000000000000000000000000000000000000000..25f52eb9af446e6acb0bc1e283d40e57089e9b4e GIT binary patch literal 2067 zcmW+!X;4;27QLWGMje8<1TZMbqVh1Kwoz~!P?23^J{wU$0>PHmB_OWIQxF$KNBID| zSlr-49}qWCBxMW;7@T(GLm%S?!z8F78Al^UP$|9hw10Hn+qbIEx#t{j-z9GDQEOo> z*a6tT8EgVt;R@RM@V56u0R(^nZ~y^-AOT1OBnA=(Nq~ev0Vn~=fO4P$D1reQ)@ay-03*N&2yI3rAQB-G zBN8W)AQBP^gc3p-p`1`bC=wZnOo+^g%!w?Bj6?yV5TY=maH0sJAW?y+gs6rLOl3^vOchK;hQN?8WDGe&!BCSxQ=D*M95@G|DZ(Y- z65$f#66ccO5^@Th5>6SXoKwLmav8WxxXifBxh%MhTmh~St}w1}t_ZFmSAna9tBk9h ztAeY@5jYZ#j3ehLIBM!^W)lHS02d%MGlT>}B0^$9;zANaLP0@LA}AA-3n~OfA%l>K zkeQIVkcE&@C?FIf6ebid6d@E8DhQPbl?jy#RR|RYfQE{%?(Wwjh8mm zq96fE1SN(NM@gWBNC7E9%8+uT0x6;lC=-+!${b~ZGNJ;g5L6f{92J2Iq6(-IR2ixq zRe|aUFfC}B+nVIs-XFm~rvBq)hS2|~&wb9HsLwF#_jFj|sxxFY>Ya*wE}Ux0w)&JU zbYPY?Gsk=G9G&5u+jwxYPN_bVXxZXB&8s=nH`nn(o?Eg(Z{7BDz>#_GCHH)*fANU^ zOUC=6o>8SirG<2V_sUn4MV>qGz%TWuKmgY#~gY%?cYrok4Gj(%zyLr#t*yV@n-FnKQ{DqUE4iA(s(7#P+wK8$OPlo@t_QX+PeZ4{|3_&#Sy<MDy9*6(MY zI@{+q>}X|ePg#X$-1o!U4(8fc7`Nsf>Z$Y$nvvap?w^-uI-Q6LENqQ6v3z~%3Y4tu zF6*B2hF*+!dK>OsY?G%?7;&h;Hz&9zW@7p;S?z!GUe~wy#l_84hNQDG9bw&jdan-T z2StD7ulLU~_&KfaKj1ih>Ci}OpFgo@%=+N8I{k*Ao!gpTuCni|7!@+Ey!3n%zvxx4 zdb)0OLBQ)@ONAJ8eM@2O(ydS09NiNdbFEsf%BEJw8&;|J=DP9zPNle+xEp^CjY|tY7?o8Ua%an0bKW)9 zcWu(&OS7K0f35qj$XNK+b8bsm;ggtkM-5KS&pm?*^=+|F@^TW_O}G(nYux8Nc&1Ix z{lLzIx=8(IL+6mV`L#m|J09I@_^kM1cT9R%lx}3uXxEq=x5(D=FEjezS3c1VFYhYr z=}a}%*A4CX#NN%tvLP{VeES;5Q4bc`4%lQ_yehjD)%!3XhFaw>8|k|y&pJ3|L1^CV zl`S(D+Xv{y-MKmQ{nx*^t%tMgk7mIs<99WlnLLp3aKlTNl-ZW4pQQiQ zI6l}fzxL%xZ<*+gRa>I~=31Csw? zJ}K7rj%(|th({-ayO!|9ozo{r$96Axy4U`$J9DuvI;gW5((rOe>5 + + + + + +
+
+ +
+ Welcome +
+ + + +
+
+
+
+
+

Панель управления

+ +

Управление пользователями

+
+
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/fragments/headerinc.html b/src/main/resources/templates/fragments/headerinc.html new file mode 100644 index 0000000..1637aaf --- /dev/null +++ b/src/main/resources/templates/fragments/headerinc.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..4ebb811 --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,12 @@ + + + + Главная + + + +
+ +
+ + \ 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..46c7e94 --- /dev/null +++ b/src/main/resources/templates/login.html @@ -0,0 +1,36 @@ + + + + Login Form + + + +
+ +
+ +
+
+ +
+ +
+ + + + + + + + + + + +
+ +
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/projects.html b/src/main/resources/templates/projects.html new file mode 100644 index 0000000..7f65da2 --- /dev/null +++ b/src/main/resources/templates/projects.html @@ -0,0 +1,36 @@ + + + + Список проектов + + + +
+ +
+
+

Проекты

+
+ + + + + + + + + + + + + + + + + +
IdNameUser ruleViewEditDelete
Project NameProject DB NameView Edit Delete
+ +
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/userform.html b/src/main/resources/templates/userform.html new file mode 100644 index 0000000..ee53ab3 --- /dev/null +++ b/src/main/resources/templates/userform.html @@ -0,0 +1,61 @@ + + + + Форма пользователя + + + +
+ + +

User Details

+
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+
+
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/users.html b/src/main/resources/templates/users.html new file mode 100644 index 0000000..b95aae7 --- /dev/null +++ b/src/main/resources/templates/users.html @@ -0,0 +1,37 @@ + + + + Список пользователей + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + +
IdNameUser ruleExpiration dateActiveViewEditDelete
IdName

Expiration DateActiveView Edit Delete
+ +
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/usershow.html b/src/main/resources/templates/usershow.html new file mode 100644 index 0000000..c3226d6 --- /dev/null +++ b/src/main/resources/templates/usershow.html @@ -0,0 +1,46 @@ + + + + Пользователь + + + +
+ +

User Details

+
+
+
+ +
+

User Id

+
+
+ +
+

User Name

+
+
+
+ +
+

User Group

+
+
+
+ +
+

Expiration Date

+
+
+
+ +
+

Active

+
+
+
+
+
+ + \ No newline at end of file diff --git a/src/test/java/com/ibcon/factage_web/FactageWebApplicationTests.java b/src/test/java/com/ibcon/factage_web/FactageWebApplicationTests.java new file mode 100644 index 0000000..7dc80e9 --- /dev/null +++ b/src/test/java/com/ibcon/factage_web/FactageWebApplicationTests.java @@ -0,0 +1,16 @@ +package com.ibcon.factage_web; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class FactageWebApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/src/test/java/com/ibcon/factage_web/repositories/UserRepositoryTest.java b/src/test/java/com/ibcon/factage_web/repositories/UserRepositoryTest.java new file mode 100644 index 0000000..ae4821c --- /dev/null +++ b/src/test/java/com/ibcon/factage_web/repositories/UserRepositoryTest.java @@ -0,0 +1,77 @@ +package com.ibcon.factage_web.repositories; + +import com.ibcon.factage_web.domain.User; +import com.ibcon.factage_web.services.crud.role.RoleService; +import com.ibcon.factage_web.services.crud.user.UserServiceCrud; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Date; +import java.time.LocalDate; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class UserRepositoryTest { + @Autowired + private UserRepository userRepository; + + @Autowired + RoleService roleService; + + @Autowired + UserServiceCrud userServiceCrud; + + @Before + public void setUp() throws Exception { +// User user1 = new User("Vasya", 1, 1, new Date(31052018L), true); +// User user2 = new User("Anya", 1, 2, new Date(31052015L), false); +// +// assertNull(user1.getId()); +// assertNull(user2.getId()); +// +// this.userRepository.save(user1); +// this.userRepository.save(user2); +// +// assertNotNull(user1.getId()); +// assertNotNull(user2.getId()); + } + + @Test + public void fetchDataTest() { +// User userA = userRepository.findByName("Anya"); +// +// assertNotNull(userA); +// assertEquals((Integer) 2, userA.getGroupRule()); +// +// Iterable users = userRepository.findAll(); +// int count = 0; +// for (User user : users) { +// count++; +// } +// assertEquals(count, 2); + } + + @Test + public void addRoleTest() { + User user = new User("testTEST", new Date(), true); + user.setPassword("1"); + user.addRole(roleService.getById(1)); + user.addRole(roleService.getById(2)); + user.addRole(roleService.getById(3)); + userServiceCrud.saveOrUpdate(user); + } + + @Test + public void deleteDataTest() { + } + + @After + public void tearDown() throws Exception { + } + +} \ No newline at end of file From bec0249b6dd6cac73fcd169d378d99efd2b414c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BB=D1=8C=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=D1=8C?= Date: Thu, 22 Jun 2017 18:19:28 +0300 Subject: [PATCH 2/2] project's views added --- .../controllers/ProjectController.java | 2 +- src/main/resources/templates/projectform.html | 71 +++++++++++++++++++ src/main/resources/templates/projects.html | 4 +- src/main/resources/templates/projectshow.html | 62 ++++++++++++++++ 4 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/templates/projectform.html create mode 100644 src/main/resources/templates/projectshow.html diff --git a/src/main/java/com/ibcon/factage_web/controllers/ProjectController.java b/src/main/java/com/ibcon/factage_web/controllers/ProjectController.java index c278941..b0dda95 100644 --- a/src/main/java/com/ibcon/factage_web/controllers/ProjectController.java +++ b/src/main/java/com/ibcon/factage_web/controllers/ProjectController.java @@ -43,7 +43,7 @@ public String showUser(@PathVariable Integer id, Model model) { @RequestMapping("project/edit/{id}") public String edit(@PathVariable Integer id, Model model) { - model.addAttribute("user", projectService.getById(id)); + model.addAttribute("project", projectService.getById(id)); return "projectform"; } diff --git a/src/main/resources/templates/projectform.html b/src/main/resources/templates/projectform.html new file mode 100644 index 0000000..c70ac00 --- /dev/null +++ b/src/main/resources/templates/projectform.html @@ -0,0 +1,71 @@ + + + + Форма проекта + + + +
+ + +

Project Details

+
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/projects.html b/src/main/resources/templates/projects.html index 7f65da2..de492a8 100644 --- a/src/main/resources/templates/projects.html +++ b/src/main/resources/templates/projects.html @@ -25,8 +25,8 @@ Project DB Name View - Edit - Delete + Edit + Delete diff --git a/src/main/resources/templates/projectshow.html b/src/main/resources/templates/projectshow.html new file mode 100644 index 0000000..7efe9ae --- /dev/null +++ b/src/main/resources/templates/projectshow.html @@ -0,0 +1,62 @@ + + + + Проект + + + +
+ +

Project Details

+
+
+
+ +
+

User Id

+
+
+ +
+

User Id

+
+
+ +
+

User Id

+
+
+ +
+

User Id

+
+
+ +
+

User Id

+
+
+ +
+

User Id

+
+
+ +
+

User Id

+
+
+ +
+

User Id

+
+
+ +
+

User Id

+
+
+
+
+ + \ No newline at end of file