From 9b3f2eaf1353898ed3299ae97334ba139cc8602f Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期五, 23 九月 2022 09:20:03 +0800 Subject: [PATCH] 初始化 --- mvnw | 316 ++++++++++++ .gitignore | 37 + src/main/resources/templates/index.html | 29 + src/main/java/com/terra/land/entity/MyRealm.java | 71 ++ src/main/java/com/terra/land/service/UserService.java | 41 + mvnw.cmd | 188 +++++++ src/main/resources/log4j.properties | 18 src/main/java/com/terra/land/config/ShiroConfig.java | 200 +++++++ 说明.txt | 5 pom.xml | 165 ++++++ src/main/java/com/terra/land/LandApplication.java | 15 src/main/resources/mapper/UserMapper.xml | 9 src/main/java/com/terra/land/entity/LoginInfo.java | 93 +++ src/main/java/com/terra/land/controller/ApiController.java | 169 ++++++ src/main/java/com/terra/land/entity/User.java | 65 ++ src/main/java/com/terra/land/entity/Result.java | 60 ++ src/main/java/com/terra/land/mapper/UserMapper.java | 21 src/main/resources/application.yml | 47 + 18 files changed, 1,544 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 088836b..549e00a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,33 @@ +HELP.md target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -pom.xml.next -release.properties +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..8a8fb22 --- /dev/null +++ b/mvnw @@ -0,0 +1,316 @@ +#!/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 +# +# https://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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven 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 /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + 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 Mingw, 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)`" +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="`\\unset -f command; \\command -v 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 + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +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 + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_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..1d8ab01 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,188 @@ +@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 https://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 Maven 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 keystroke 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 set title of command window +title %0 +@REM enable echoing by 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 "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\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 + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%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 "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\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% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a1ab451 --- /dev/null +++ b/pom.xml @@ -0,0 +1,165 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <!-- https://start.springboot.io/ --> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-parent</artifactId> + <version>2.7.3</version> + <relativePath/> + </parent> + + <groupId>com.terra</groupId> + <artifactId>sso</artifactId> + <version>1.0.0</version> + <name>sso</name> + <description>SSO鍗曠偣鐧诲綍</description> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <java.version>1.8</java.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jdbc</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-thymeleaf</artifactId> + <version>2.2.2.RELEASE</version> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-redis</artifactId> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-pool2</artifactId> + </dependency> + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-aop</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-devtools</artifactId> + <optional>true</optional> + </dependency> + <dependency> + <groupId>com.alibaba</groupId> + <artifactId>fastjson</artifactId> + <version>1.2.47</version> + </dependency> + + <dependency> + <groupId>org.apache.shiro</groupId> + <artifactId>shiro-spring</artifactId> + <version>1.9.1</version> + </dependency> + <dependency> + <groupId>org.apache.shiro</groupId> + <artifactId>shiro-web</artifactId> + <version>1.9.1</version> + </dependency> + <dependency> + <groupId>org.apache.shiro</groupId> + <artifactId>shiro-core</artifactId> + <version>1.9.1</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.mybatis.spring.boot</groupId> + <artifactId>mybatis-spring-boot-starter</artifactId> + <version>2.2.0</version> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.17</version> + </dependency> + <!--鏁村悎druid鏁版嵁婧�--> + <dependency> + <groupId>com.alibaba</groupId> + <artifactId>druid</artifactId> + <version>1.2.8</version> + </dependency> + <!--log4j--> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.17</version> + </dependency> + <!-- thymeleaf涓巗hiro鏁村悎 --> + <dependency> + <groupId>com.github.theborakompanioni</groupId> + <artifactId>thymeleaf-extras-shiro</artifactId> + <version>2.1.0</version> + </dependency> + <!--瀵煎叆hutool鐨勪緷璧�--> + <dependency> + <groupId>cn.hutool</groupId> + <artifactId>hutool-all</artifactId> + <version>4.5.7</version> + </dependency> + <!--shiro缂撳瓨锛屾坊鍔爀hcache--> + <dependency> + <groupId>org.apache.shiro</groupId> + <artifactId>shiro-ehcache</artifactId> + <version>1.4.0</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + <!--<dependency> + <groupId>org.thymeleaf.extras</groupId> + <artifactId>thymeleaf-extras-springsecurity5</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-oauth2-resource-server</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-oauth2-client</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.security</groupId> + <artifactId>spring-security-test</artifactId> + <scope>test</scope> + </dependency>--> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/src/main/java/com/terra/land/LandApplication.java b/src/main/java/com/terra/land/LandApplication.java new file mode 100644 index 0000000..037cf29 --- /dev/null +++ b/src/main/java/com/terra/land/LandApplication.java @@ -0,0 +1,15 @@ +package com.terra.land; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * LandApplication + * @author + */ +@SpringBootApplication +public class LandApplication { + public static void main(String[] args) { + SpringApplication.run(LandApplication.class, args); + } +} diff --git a/src/main/java/com/terra/land/config/ShiroConfig.java b/src/main/java/com/terra/land/config/ShiroConfig.java new file mode 100644 index 0000000..f376f43 --- /dev/null +++ b/src/main/java/com/terra/land/config/ShiroConfig.java @@ -0,0 +1,200 @@ +package com.terra.land.config; + +import com.alibaba.druid.pool.DruidDataSource; +import com.terra.land.entity.MyRealm; +import org.apache.shiro.authc.credential.HashedCredentialsMatcher; +import org.apache.shiro.codec.Base64; +import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor; +import org.apache.shiro.spring.web.ShiroFilterFactoryBean; +import org.apache.shiro.web.mgt.CookieRememberMeManager; +import org.apache.shiro.web.mgt.DefaultWebSecurityManager; +import org.apache.shiro.web.servlet.SimpleCookie; +import org.apache.shiro.web.session.mgt.DefaultWebSessionManager; +import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.HashMap; +import java.util.Map; + +/** + * ShiroConfig + * @author + */ +@SuppressWarnings("ALL") +@Configuration +public class ShiroConfig { + @ConfigurationProperties(prefix = "spring.datasource") + @Bean + public DruidDataSource druidDataSource() { + return new DruidDataSource(); + } + + /*@Bean(name = "securityManager") + public DefaultWebSecurityManager securityManager(@Qualifier("myRealm") MyRealm myRealm){ + DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); + securityManager.setRealm(myRealm); + + return securityManager; + }*/ + + @Bean(name = "securityManager") + public DefaultWebSecurityManager securityManager(@Qualifier("myRealm") MyRealm myRealm, + @Qualifier("rememberMeManager") CookieRememberMeManager rememberMeManager, + @Qualifier("mySessionManager") DefaultWebSessionManager webSessionManager) { + DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); + securityManager.setRealm(myRealm); + securityManager.setRememberMeManager(rememberMeManager); + securityManager.setSessionManager(webSessionManager); + + return securityManager; + } + + @Bean + public MyRealm myRealm() { + MyRealm myShiroRealm = new MyRealm(); + + return myShiroRealm; + } + + @Bean(name = "rememberMeManager") + public CookieRememberMeManager rememberMeManager() { + // cookie绠$悊鍣� + CookieRememberMeManager cookieRememberMeManager = new CookieRememberMeManager(); + + // cookie鐨勫悕瀛� + SimpleCookie simpleCookie = new SimpleCookie("rememberMe"); + + // 璁剧疆鏈夋晥鏈熸椂闂�30澶╋紝绉� + simpleCookie.setMaxAge(259200); + + cookieRememberMeManager.setCookie(simpleCookie); + + // rememberMe cookie鍔犲瘑鐨勫瘑閽� 寤鸿姣忎釜椤圭洰閮戒笉涓�鏍� 榛樿AES绠楁硶 瀵嗛挜闀垮害(128 256 512 浣�) + cookieRememberMeManager.setCipherKey(Base64.decode("6ZmI6I2j5Y+R5aSn5ZOlAA==")); + + return cookieRememberMeManager; + } + + /** + * 鍒涘缓DefaultWebSessionManager绫� + * + * @return + */ + @Bean(name = "mySessionManager") + public DefaultWebSessionManager mySessionManager() { + DefaultWebSessionManager defaultSessionManager = new DefaultWebSessionManager(); + + // 灏唖essionIdUrlRewritingEnabled灞炴�ц缃垚false + defaultSessionManager.setSessionIdUrlRewritingEnabled(false); + + defaultSessionManager.setGlobalSessionTimeout(8 * 60 * 60 * 1000); + defaultSessionManager.setSessionValidationSchedulerEnabled(true); + defaultSessionManager.setSessionIdCookieEnabled(true); + + return defaultSessionManager; + } + + @Bean + public ShiroFilterFactoryBean bean(@Qualifier("securityManager") DefaultWebSecurityManager securityManager) { + ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean(); + bean.setSecurityManager(securityManager); + + /** + * 娣诲姞shiro鐨勫唴缃繃婊ゅ櫒 + * anon: 鏃犻渶璁よ瘉鍗冲彲璁块棶 + * authc: 蹇呴』璁よ瘉鎵嶈兘鐢� + * user: 蹇呴』鎷ユ湁 鈥滆浣忔垜鈥� 鍔熻兘鎵嶈兘鐢� + * perms: 鎷ユ湁瀵规煇涓祫婧愮殑鏉冮檺鎵嶈兘鐢� + * role: 鎷ユ湁鏌愪釜瑙掕壊鏉冮檺鎵嶈兘璁块棶 + */ + Map<String, String> filterMap = new HashMap<>(5); + + // 鐧婚檰鍚庢巿鏉冿紝姝e父鎯呭喌涓嬫病鏈夋巿鏉冧細璺宠浆鍒版湭鎺堟潈椤甸潰 + //filterMap.put("/toAdd", "perms[user:add]"); + //filterMap.put("/toUpdate", "perms[user:update]"); + + // 鐧诲嚭锛岃缃敞閿�杩囨护鍣� + //filterMap.put("/logout", "logout"); + + /** + * /** 鍖归厤鎵�鏈夌殑璺緞 + * 閫氳繃Map闆嗗悎缁勬垚浜嗕竴涓嫤鎴櫒閾� 锛岃嚜椤跺悜涓嬭繃婊わ紝涓�鏃﹀尮閰嶏紝鍒欎笉鍐嶆墽琛屼笅闈㈢殑杩囨护 + * 濡傛灉涓嬮潰鐨勫畾涔変笌涓婇潰鍐茬獊锛岄偅鎸夌収浜嗚皝鍏堝畾涔夎皝璇翠簡绠� + * 鎵�浠�/** 涓�瀹氳閰嶇疆鍦ㄦ渶鍚� + * 杩欓噷鏄惁瑕佸鎵�鏈夎矾寰勮繘琛岃璇佽鎯呭喌鑰屽畾锛屽洜涓轰竴浜涜矾鐢辫烦杞彲鑳藉湪娌$櫥闄嗗嚭鐜板鑷村嚭閿欙紝鎵�浠ヨ繖閲岃�冭檻娓呮 + **/ + //filterMap.put("/**", "authc"); + + // 灏嗘嫤鎴櫒閾捐缃埌shiro涓� + bean.setFilterChainDefinitionMap(filterMap); + + // 璁剧疆鐧诲綍椤甸潰 + bean.setLoginUrl("/toLogin"); + + // 鐧诲綍鎴愬姛鍚庤璺宠浆鐨勯摼鎺� + //bean.setSuccessUrl("/toIndex"); + + // 璁剧疆鏈巿鏉冮〉闈� + bean.setUnauthorizedUrl("/noauth"); + + return bean; + } + + /** + * 瀵嗙爜鍖归厤鍑瘉绠$悊鍣� + * + * 瀵嗙爜鏍¢獙瑙勫垯HashedCredentialsMatcher + * 杩欎釜绫绘槸涓轰簡瀵瑰瘑鐮佽繘琛岀紪鐮佺殑 , + * 闃叉瀵嗙爜鍦ㄦ暟鎹簱閲屾槑鐮佷繚瀛� , 褰撶劧鍦ㄧ櫥闄嗚璇佺殑鏃跺�� , + * 杩欎釜绫讳篃璐熻矗瀵筬orm閲岃緭鍏ョ殑瀵嗙爜杩涜缂栫爜 + * 澶勭悊璁よ瘉鍖归厤澶勭悊鍣細濡傛灉鑷畾涔夐渶瑕佸疄鐜扮户鎵縃ashedCredentialsMatcher + */ + @Bean(name = "hashedCredentialsMatcher") + public HashedCredentialsMatcher hashedCredentialsMatcher() { + HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher(); + + // 鏁e垪绠楁硶:杩欓噷浣跨敤MD5绠楁硶; + hashedCredentialsMatcher.setHashAlgorithmName("MD5"); + + // 鏁e垪鐨勬鏁帮紝姣斿鏁e垪涓ゆ锛岀浉褰撲簬md5(md5("")); + hashedCredentialsMatcher.setHashIterations(1024); + hashedCredentialsMatcher.setStoredCredentialsHexEncoded(true); + + return hashedCredentialsMatcher; + } + + /** + * 寮�鍚痵hiro aop娉ㄨВ鏀寔 + * 浣跨敤浠g悊鏂瑰紡;鎵�浠ラ渶瑕佸紑鍚唬鐮佹敮鎸� + * @param securityManager + */ + @Bean + public DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator(){ + DefaultAdvisorAutoProxyCreator advisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator(); + advisorAutoProxyCreator.setProxyTargetClass(true); + + return advisorAutoProxyCreator; + } + + @Bean + public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(DefaultWebSecurityManager securityManager){ + AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor(); + authorizationAttributeSourceAdvisor.setSecurityManager(securityManager); + + return authorizationAttributeSourceAdvisor; + } + + /** + * 寮�鍚痗glib浠g悊 + */ + @Bean + public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() { + DefaultAdvisorAutoProxyCreator creator = new DefaultAdvisorAutoProxyCreator(); + creator.setProxyTargetClass(true); + + return creator; + } +} diff --git a/src/main/java/com/terra/land/controller/ApiController.java b/src/main/java/com/terra/land/controller/ApiController.java new file mode 100644 index 0000000..03e6fcd --- /dev/null +++ b/src/main/java/com/terra/land/controller/ApiController.java @@ -0,0 +1,169 @@ +package com.terra.land.controller; + +import com.terra.land.entity.LoginInfo; +import com.terra.land.entity.Result; +import com.terra.land.entity.User; +import com.terra.land.service.UserService; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.*; +import org.apache.shiro.subject.Subject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + +/** + * LoginController + * @author + */ +@RestController +@RequestMapping("/") +public class ApiController { + @Autowired + UserService userService; + + @RequestMapping("/getName") + public User getName(String loginName) { + return userService.queryUserByName(loginName); + } + + /** + * 璺冲埌棣栭〉 + * + * @return String + */ + @RequestMapping({"/", "/toIndex"}) + public ModelAndView toIndex(ModelAndView mv) { + mv.setViewName("index"); + + User user = (User) SecurityUtils.getSubject().getPrincipal(); + if (user != null) { + mv.addObject("msg", "Hello " + user.getLoginName() + " !"); + } + + return mv; + } + + /** + * 璺冲埌鐧诲綍椤� + * + * @return String + */ + @RequestMapping("/toLogin") + public ModelAndView toLogin(ModelAndView mv) { + mv.setViewName("login"); + + return mv; + } + + /** + * 璺冲埌鏈巿鏉冮〉闈� + * + * @return String + */ + @RequestMapping("/noauth") + public ModelAndView toNoAuth(ModelAndView mv) { + mv.setViewName("noauth"); + + return mv; + } + + /** + * 鐢ㄤ簬娴嬭瘯璁颁綇鎴戝拰璁よ瘉鐨勫尯鍒� + * + * @return String + */ + @RequestMapping("/buy") + public String buy() { + Subject subject = SecurityUtils.getSubject(); + + // 鍙湁璁よ瘉鍚庢墠鑳借闂紝濡傛灉鍙槸璁颁綇鎴戝垯闇�瑕佸厛鐧诲綍 + if (!subject.isAuthenticated()) { + return "redirect:/toLogin"; + } + + return "add"; + } + + /** + * 鐧诲綍璁よ瘉 + * + * @return String + */ + @RequestMapping("/login") + public ModelAndView login(String username, String password, String service, Integer rememberMe) { + ModelAndView mv = new ModelAndView(); + try { + Subject subject = SecurityUtils.getSubject(); + + // 鑾峰彇浠ょ墝 + UsernamePasswordToken token = new UsernamePasswordToken(username, password); + if (rememberMe != null && rememberMe == 1) { + token.setRememberMe(true); + } + + // 鐧诲綍璁よ瘉 + subject.login(token); + + mv.setViewName("index"); + if (service != null && service.length() > 0) { + mv.addObject("url", service); + } else { + mv.addObject("msg", username); + } + } catch (UnknownAccountException e) { // 杩斿洖null灏变細杩涘叆杩欓噷 + mv.setViewName("login"); + mv.addObject("msg", "鐢ㄦ埛鍚嶄笉瀛樺湪锛�"); + } catch (IncorrectCredentialsException e) { // 瀵嗙爜閿欒灏变細杩涘叆杩欓噷 + mv.setViewName("login"); + mv.addObject("msg", "瀵嗙爜閿欒锛�"); + } + + return mv; + } + + /** + * 娉ㄩ攢 + * + * @return String + */ + @RequestMapping("/logout") + public ModelAndView logout() { + Subject subject = SecurityUtils.getSubject(); + subject.logout(); + + ModelAndView mv = new ModelAndView(); + mv.setViewName("login"); + + return mv; + } + + /** + * Ajax鐧诲綍 + * + * @param userInfo + * @return + */ + @ResponseBody + @RequestMapping(value = "/ajaxLogin", method = RequestMethod.POST, produces = "application/json; charset=UTF-8") + public Result ajaxLogin(@RequestBody User userInfo) { + try { + Subject subject = SecurityUtils.getSubject(); + + UsernamePasswordToken token = new UsernamePasswordToken(userInfo.getLoginName(), userInfo.getPassword()); + subject.login(token); + + LoginInfo loginInfo = userService.getLoginInfo(userInfo.getLoginName()); + + return new Result(200, loginInfo != null ? "鐧诲綍鎴愬姛" : "鐧诲綍澶辫触", loginInfo); + } catch (IncorrectCredentialsException e) { + return new Result(500, "瀵嗙爜閿欒"); + } catch (LockedAccountException e) { + return new Result(500, "鐧诲綍澶辫触锛岃鐢ㄦ埛宸茶鍐荤粨"); + } catch (AuthenticationException e) { + return new Result(500, "璇ョ敤鎴蜂笉瀛樺湪"); + } catch (Exception e) { + e.printStackTrace(); + return new Result(500, e.getMessage()); + } + } +} diff --git a/src/main/java/com/terra/land/entity/LoginInfo.java b/src/main/java/com/terra/land/entity/LoginInfo.java new file mode 100644 index 0000000..82ceb5c --- /dev/null +++ b/src/main/java/com/terra/land/entity/LoginInfo.java @@ -0,0 +1,93 @@ +package com.terra.land.entity; + +import java.io.Serializable; +import java.util.Set; + +/** + * LoginInfo + * @author + */ +public class LoginInfo implements Serializable { + private Integer uuid; + + private String name; + + private String townId; + + private Set<String> roleList; + + private Set<String> permissionList; + + private String token; + + public LoginInfo() { + } + + public LoginInfo(Set<String> roleList, Set<String> permissionList) { + this.roleList = roleList; + this.permissionList = permissionList; + } + + public LoginInfo(Integer userId, String userName, Set<String> roleList, Set<String> permissionList) { + this.uuid = userId; + this.name = userName; + this.roleList = roleList; + this.permissionList = permissionList; + } + + public String getTownId() { + return townId; + } + + public void setTownId(String townId) { + this.townId = townId; + } + + public Integer getUuid() { + return uuid; + } + + public void setUuid(Integer uuid) { + this.uuid = uuid; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public Integer getUserId() { + return uuid; + } + + public void setUserId(Integer userId) { + this.uuid = userId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set<String> getRoleList() { + return roleList; + } + + public void setRoleList(Set<String> roleList) { + this.roleList = roleList; + } + + public Set<String> getPermissionList() { + return permissionList; + } + + public void setPermissionList(Set<String> permissionList) { + this.permissionList = permissionList; + } +} diff --git a/src/main/java/com/terra/land/entity/MyRealm.java b/src/main/java/com/terra/land/entity/MyRealm.java new file mode 100644 index 0000000..9730676 --- /dev/null +++ b/src/main/java/com/terra/land/entity/MyRealm.java @@ -0,0 +1,71 @@ +package com.terra.land.entity; + +import com.terra.land.service.UserService; +import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.*; +import org.apache.shiro.authz.AuthorizationInfo; +import org.apache.shiro.authz.SimpleAuthorizationInfo; +import org.apache.shiro.realm.AuthorizingRealm; +import org.apache.shiro.subject.PrincipalCollection; +import org.apache.shiro.subject.Subject; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * MyRealm + * @author + */ +public class MyRealm extends AuthorizingRealm { + @Autowired + UserService userService; + + /** + * 鎵ц鎺堟潈 + * + * @param principalCollection + * @return + */ + @Override + protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { + // 璁よ瘉涔嬪悗锛屽鏋滃墠绔痵hiro鏍囩涓湁鍑虹幇闇�瑕佹潈闄愮殑鏍囩锛屾垨鑰呰繃婊ゅ櫒涓煇涓摼鎺ラ渶瑕佹潈闄愶紝灏变細杩涜璁よ瘉 + System.out.println("鎵ц浜嗘巿鏉�"); + SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); + + // 鑾峰緱褰撳墠subject + Subject subject = SecurityUtils.getSubject(); + + // 鑾峰緱褰撳墠鐨刾rincipal,涔熷氨鏄璇佸畬鍚庢垜浠斁鍏ョ殑淇℃伅 + User currentUser = (User) subject.getPrincipal(); + + // 娣诲姞鏉冮檺 + info.addStringPermission(currentUser.getPerms()); + + // 娣诲姞瑙掕壊 + info.addRole(currentUser.getRole()); + + return info; + } + + /** + * 鎵ц璁よ瘉 + * + * @param token + * @return + * @throws AuthenticationException + */ + @Override + protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { + System.out.println("鎵ц浜嗚璇�"); + UsernamePasswordToken userToken = (UsernamePasswordToken) token; + + // 浠庢暟鎹簱涓煡璇㈣鐢ㄦ埛 + User user = userService.queryUserByName(userToken.getUsername()); + + // 濡傛灉涓嶅瓨鍦ㄨ鐢ㄦ埛锛岃繑鍥炰竴涓┖閿欒锛屽墠绔篃鍙互鐩稿簲鏄剧ず鎻愮ず + if (user == null) { + return null; + } + + // 绗竴涓弬鏁颁负principal;绗簩涓弬鏁颁负浠庢暟鎹簱涓煡鍑虹殑鐢ㄤ簬楠岃瘉鐨勫瘑鐮侊紝shiro涓瘑鐮侀獙璇佷笉闇�瑕佹垜浠嚜宸卞幓鍋氾紱绗笁涓弬鏁颁负realmName + return new SimpleAuthenticationInfo(user, user.getPassword(), getName()); + } +} diff --git a/src/main/java/com/terra/land/entity/Result.java b/src/main/java/com/terra/land/entity/Result.java new file mode 100644 index 0000000..9db31ca --- /dev/null +++ b/src/main/java/com/terra/land/entity/Result.java @@ -0,0 +1,60 @@ +package com.terra.land.entity; + +/** + * Result + * @author + */ +public class Result { + public Result() { + } + + public Result(int code, String message) { + this.code = code; + this.message = message; + } + + public Result(int code, String message, LoginInfo loginInfo) { + this.code = code; + this.message = message; + this.loginInfo = loginInfo; + } + + /** + * 鍝嶅簲鐘舵�佺爜 + */ + private int code; + + /** + * 鍝嶅簲鎻愮ず淇℃伅 + */ + private String message; + + /** + * 鍝嶅簲缁撴灉瀵硅薄 + */ + private LoginInfo loginInfo; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public LoginInfo getData() { + return loginInfo; + } + + public void setData(LoginInfo loginInfo) { + this.loginInfo = loginInfo; + } +} diff --git a/src/main/java/com/terra/land/entity/User.java b/src/main/java/com/terra/land/entity/User.java new file mode 100644 index 0000000..e6b1abf --- /dev/null +++ b/src/main/java/com/terra/land/entity/User.java @@ -0,0 +1,65 @@ +package com.terra.land.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import java.io.Serializable; + +/** + * User + * @author + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class User implements Serializable { + public int getUserId() { + return userId; + } + + public void setUserId(int userId) { + this.userId = userId; + } + + public String getLoginName() { + return loginName; + } + + public void setLoginName(String loginName) { + this.loginName = loginName; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getPerms() { + return perms; + } + + public void setPerms(String perms) { + this.perms = perms; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + private int userId; + + private String loginName; + + private String password; + + private String perms; + + private String role; +} diff --git a/src/main/java/com/terra/land/mapper/UserMapper.java b/src/main/java/com/terra/land/mapper/UserMapper.java new file mode 100644 index 0000000..e448a9a --- /dev/null +++ b/src/main/java/com/terra/land/mapper/UserMapper.java @@ -0,0 +1,21 @@ +package com.terra.land.mapper; + +import com.terra.land.entity.User; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; + +/** + * UserMapper + * @author + */ +@Mapper +@Repository +public interface UserMapper { + /** + * 鏍规嵁鍚嶇О鏌ヨ鐢ㄦ埛 + * @param loginName + * @return + */ + public User queryUserByName(String loginName); +} + diff --git a/src/main/java/com/terra/land/service/UserService.java b/src/main/java/com/terra/land/service/UserService.java new file mode 100644 index 0000000..38c7821 --- /dev/null +++ b/src/main/java/com/terra/land/service/UserService.java @@ -0,0 +1,41 @@ +package com.terra.land.service; + +import com.terra.land.entity.LoginInfo; +import com.terra.land.entity.User; +import com.terra.land.mapper.UserMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * UserService + * @author + */ +@Service +public class UserService implements UserMapper { + @Autowired + UserMapper userMapper; + + @Override + public User queryUserByName(String loginName) { + return userMapper.queryUserByName(loginName); + } + + public LoginInfo getLoginInfo(String loginName) { + User user = queryUserByName(loginName); + if (null == user) { + return null; + } + + Set<String> roleList = new HashSet<>(); + Set<String> permissionList = new HashSet<>(); + + LoginInfo loginInfo = new LoginInfo(user.getUserId(), user.getLoginName(), roleList, permissionList); + loginInfo.setToken(UUID.randomUUID().toString()); + + return loginInfo; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..0670431 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,47 @@ +server: + tomcat: + uri-encoding: UTF-8 + max-threads: 1000 + min-spare-threads: 5 + port: 9002 + context-path: /land + +spring: + datasource: + username : postgres + password: postgres + url : jdbc:postgresql://127.0.0.1:5432/langfang + driver-class-name: org.postgresql.Driver + type: com.alibaba.druid.pool.DruidDataSource # 鑷畾涔夋暟鎹簮 + + #Spring Boot 榛樿鏄笉娉ㄥ叆杩欎簺灞炴�у�肩殑锛岄渶瑕佽嚜宸辩粦瀹� + #druid 鏁版嵁婧愪笓鏈夐厤缃� + initialSize: 5 + minIdle: 5 + maxActive: 20 + maxWait: 60000 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: SELECT 1 FROM now() + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + + #閰嶇疆鐩戞帶缁熻鎷︽埅鐨刦ilters锛宻tat:鐩戞帶缁熻銆乴og4j锛氭棩蹇楄褰曘�亀all锛氶槻寰ql娉ㄥ叆 + #濡傛灉鍏佽鏃舵姤閿� java.lang.ClassNotFoundException: org.apache.log4j.Priority + #鍒欏鍏� log4j 渚濊禆鍗冲彲锛孧aven 鍦板潃锛歨ttps://mvnrepository.com/artifact/log4j/log4j + filters: stat,wall,log4j + maxPoolPreparedStatementPerConnectionSize: 20 + useGlobalDataSourceStat: true + connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 + +#ojdbc: +# jdbcUrl: jdbc:postgresql://192.168.20.106:5432/langfang +# driverclass: org.postgresql.Driver +# username: postgres +# password: postgres + +mybatis: + type-aliases-package: com.terra.land.mapper + mapper-locations: classpath:mapper/*.xml diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties new file mode 100644 index 0000000..41827c3 --- /dev/null +++ b/src/main/resources/log4j.properties @@ -0,0 +1,18 @@ +log4j.rootLogger=INFO, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m %n + +# General Apache libraries +log4j.logger.org.apache=WARN + +# Spring +log4j.logger.org.springframework=WARN + +# Default Shiro logging +log4j.logger.org.apache.shiro=INFO + +# Disable verbose logging +log4j.logger.org.apache.shiro.util.ThreadContext=WARN +log4j.logger.org.apache.shiro.cache.ehcache.EhCache=WARN diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml new file mode 100644 index 0000000..31dea40 --- /dev/null +++ b/src/main/resources/mapper/UserMapper.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.terra.land.mapper.UserMapper"> + <select id="queryUserByName" resultType="com.terra.land.entity.User"> + select userid,loginname,password from magbg.org_user where loginname=#{loginName} + </select> +</mapper> \ 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..903aa0c --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,29 @@ +<!DOCTYPE html> +<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"> +<head> + <meta charset="UTF-8"> + <title>Land绯荤粺-棣栭〉</title> + <script> + window.onload=function () { + var url = document.getElementById("url").value; + if (url){ + window.location.href = url; + } + } + </script> +</head> +<body> +<h1>棣栭〉</h1> +<h2 th:text="${msg}"></h2> +<input id="url" type="hidden" th:value="${url}"> + +<div shiro:guest=""> + <a th:href="@{/toLogin}">鐧诲綍</a> +</div> +<br /> +<div shiro:user> + <a th:href="@{/logout}">娉ㄩ攢</a> +</div> + +</body> +</html> diff --git "a/\350\257\264\346\230\216.txt" "b/\350\257\264\346\230\216.txt" new file mode 100644 index 0000000..2203fb8 --- /dev/null +++ "b/\350\257\264\346\230\216.txt" @@ -0,0 +1,5 @@ +http://localhost:9001/ +http://localhost:9001/toIndex +http://localhost:9001/toLogin +http://localhost:9001/getName?loginName=admin +http://localhost:9001/login?username=admin&password=admin&rememberMe=0&service=http://www.baidu.com -- Gitblit v1.9.3