boot + gardle사용하여 Springsecurity 실습해보기
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
boot_gradle_security/bin/main/application.yml
|
||||
|
||||
/boot_gradle_security/bin/main/application.yml
|
||||
/boot_gradle_security/src/main/resources/application.yml
|
||||
application.yml
|
||||
|
||||
25
boot_gradle_security/.classpath
Normal file
25
boot_gradle_security/.classpath
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/test" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="test"/>
|
||||
<attribute name="gradle_used_by_scope" value="test"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
||||
BIN
boot_gradle_security/.gradle/6.0.1/fileChanges/last-build.bin
Normal file
BIN
boot_gradle_security/.gradle/6.0.1/fileChanges/last-build.bin
Normal file
Binary file not shown.
BIN
boot_gradle_security/.gradle/6.0.1/fileHashes/fileHashes.lock
Normal file
BIN
boot_gradle_security/.gradle/6.0.1/fileHashes/fileHashes.lock
Normal file
Binary file not shown.
0
boot_gradle_security/.gradle/6.0.1/gc.properties
Normal file
0
boot_gradle_security/.gradle/6.0.1/gc.properties
Normal file
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
#Thu Jan 30 11:05:07 KST 2020
|
||||
gradle.version=6.0.1
|
||||
0
boot_gradle_security/.gradle/vcs-1/gc.properties
Normal file
0
boot_gradle_security/.gradle/vcs-1/gc.properties
Normal file
28
boot_gradle_security/.project
Normal file
28
boot_gradle_security/.project
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>boot_gradle_security</name>
|
||||
<comment>Project boot_test created by Buildship.</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,2 @@
|
||||
connection.project.dir=
|
||||
eclipse.preferences.version=1
|
||||
@@ -0,0 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
@@ -0,0 +1,2 @@
|
||||
boot.validation.initialized=true
|
||||
eclipse.preferences.version=1
|
||||
21
boot_gradle_security/HELP.md
Normal file
21
boot_gradle_security/HELP.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# Getting Started
|
||||
|
||||
### Reference Documentation
|
||||
For further reference, please consider the following sections:
|
||||
|
||||
* [Official Gradle documentation](https://docs.gradle.org)
|
||||
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/gradle-plugin/reference/html/)
|
||||
* [Spring Web](https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/reference/htmlsingle/#boot-features-developing-web-applications)
|
||||
|
||||
### Guides
|
||||
The following guides illustrate how to use some features concretely:
|
||||
|
||||
* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
|
||||
* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
|
||||
* [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/)
|
||||
|
||||
### Additional Links
|
||||
These additional references should also help you:
|
||||
|
||||
* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle)
|
||||
|
||||
20
boot_gradle_security/bin/main/application_temp.yml
Normal file
20
boot_gradle_security/bin/main/application_temp.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
spring:
|
||||
mvc:
|
||||
view:
|
||||
prefix: /WEB-INF/jsp/
|
||||
suffix: .jsp
|
||||
|
||||
datasource:
|
||||
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
url: jdbc:sqlserver://192.168.0.31:1433;instanceName=BSHOP_DATA
|
||||
username: id
|
||||
password: pw
|
||||
|
||||
# jsp파일 reload할때마다 재부팅해야되서 해당설정 추가해주었음.
|
||||
server:
|
||||
servlet:
|
||||
jsp:
|
||||
init-parameters:
|
||||
development: true
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,30 @@
|
||||
<?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.boot.test1.mapper.AccountMapper">
|
||||
|
||||
<select id="readAccount" parameterType="String" resultType="com.boot.test1.vo.Account">
|
||||
SELECT * FROM [BSHOP_DATA].dbo.USER_INFO
|
||||
WHERE ID= #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertUser" parameterType="com.boot.test1.vo.Account">
|
||||
INSERT [BSHOP_DATA].dbo.USER_INFO
|
||||
VALUES (
|
||||
#{id},
|
||||
#{password},
|
||||
#{isAccountNonExpired},
|
||||
#{isAccountNonLocked},
|
||||
#{isCredentialsNonExpired},
|
||||
#{isEnabled}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<insert id="insertUserAuthority" parameterType="com.boot.test1.vo.Authority">
|
||||
INSERT INTO [BSHOP_DATA].dbo.AUTHORITY
|
||||
VALUES (
|
||||
#{userName},
|
||||
#{authorityName}
|
||||
)
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
<?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.boot.test1.mapper.TestMapper">
|
||||
|
||||
<select id="getCurrentTime" resultType="String">
|
||||
SELECT SYSDATETIME()
|
||||
</select>
|
||||
</mapper>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
boot_gradle_security/bin/main/com/boot/test1/vo/Account.class
Normal file
BIN
boot_gradle_security/bin/main/com/boot/test1/vo/Account.class
Normal file
Binary file not shown.
BIN
boot_gradle_security/bin/main/com/boot/test1/vo/Authority.class
Normal file
BIN
boot_gradle_security/bin/main/com/boot/test1/vo/Authority.class
Normal file
Binary file not shown.
Binary file not shown.
42
boot_gradle_security/build.gradle
Normal file
42
boot_gradle_security/build.gradle
Normal file
@@ -0,0 +1,42 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.2.4.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'boot.practice'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
testImplementation('org.springframework.boot:spring-boot-starter-test') {
|
||||
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
|
||||
}
|
||||
//for Db Connect -- 1
|
||||
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
|
||||
|
||||
// for Jsp
|
||||
compile('org.apache.tomcat.embed:tomcat-embed-jasper')
|
||||
compile('javax.servlet:jstl:1.2')
|
||||
|
||||
//for Db Connect -- 2
|
||||
compile 'com.microsoft.sqlserver:mssql-jdbc'
|
||||
|
||||
// MyBatis
|
||||
compile("org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2")
|
||||
compile("org.mybatis:mybatis:3.4.5")
|
||||
|
||||
// for Spring Security
|
||||
compile("org.springframework.boot:spring-boot-starter-security")
|
||||
|
||||
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
BIN
boot_gradle_security/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
boot_gradle_security/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
boot_gradle_security/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
boot_gradle_security/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
172
boot_gradle_security/gradlew
vendored
Normal file
172
boot_gradle_security/gradlew
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
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
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
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
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
84
boot_gradle_security/gradlew.bat
vendored
Normal file
84
boot_gradle_security/gradlew.bat
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
1
boot_gradle_security/settings.gradle
Normal file
1
boot_gradle_security/settings.gradle
Normal file
@@ -0,0 +1 @@
|
||||
rootProject.name = 'boot_gradle_security'
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.boot.test1;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class BootTestApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BootTestApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.boot.test1.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter{
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception{
|
||||
http
|
||||
.authorizeRequests() // 해당 메소드 아래는 각 경로에 따른 권한을 지정할 수 있다.
|
||||
.antMatchers("/" , "/login" , "/service" , "/resources/**" , "/create").permitAll() // 로그인 권한은 누구나, resources파일도 모든권한
|
||||
.antMatchers("/admin").hasRole("ADMIN") // 괄호의 권한을 가진 유저만 접근가능, ROLE_가 붙어서 적용 됨. 즉, 테이블에 ROLE_권한명 으로 저장해야 함.
|
||||
.anyRequest().authenticated() // 로그인된 사용자가 요청을 수행할 떄 필요하다. 만약 사용자가 인증되지 않았다면, 스프링 시큐리티 필터는 요청을 잡아내고 사용자를 로그인 페이지로 리다이렉션 해준다.
|
||||
.and()
|
||||
.formLogin() // 하위에 내가 직접 구현한 로그인 폼, 로그인 성공시 이동 경로 설정 가능. , 로그인 폼의 아이디,패스워드는 username, password로 맞춰야 함
|
||||
.permitAll()
|
||||
.and()
|
||||
.logout()
|
||||
.permitAll();
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PasswordEncoder passwordEncoder() {
|
||||
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.boot.test1.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.boot.test1.mapper.AccountMapper;
|
||||
import com.boot.test1.service.AccountService;
|
||||
import com.boot.test1.vo.Account;
|
||||
import com.boot.test1.vo.Authority;
|
||||
|
||||
@RestController
|
||||
public class AccountController {
|
||||
|
||||
@Autowired
|
||||
AccountService accountService;
|
||||
|
||||
@Autowired
|
||||
AccountMapper accountMapper;
|
||||
|
||||
// ADMIN 계정 부여
|
||||
@RequestMapping("/create")
|
||||
public Account create() {
|
||||
|
||||
String adminId = "admin";
|
||||
|
||||
Account account = new Account();
|
||||
account.setId(adminId);
|
||||
account.setPassword("1234");
|
||||
|
||||
Authority authority = new Authority();
|
||||
|
||||
authority.setUserName(adminId);
|
||||
authority.setAuthorityName("ROLE_ADMIN");
|
||||
|
||||
accountService.save(account, authority);
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.boot.test1.controller;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.boot.test1.mapper.AccountMapper;
|
||||
import com.boot.test1.mapper.TestMapper;
|
||||
import com.boot.test1.vo.Account;
|
||||
|
||||
@MapperScan("com.boot.test1.mapper")
|
||||
@Controller
|
||||
public class WebController {
|
||||
|
||||
@Autowired
|
||||
TestMapper testMapper;
|
||||
|
||||
@Autowired
|
||||
AccountMapper accountMapper;
|
||||
|
||||
@RequestMapping("/")
|
||||
public String startPoint() {
|
||||
System.out.println(" / 타는지 ");
|
||||
System.out.println(" DB에서 가지고온 현재시간 : " + testMapper.getCurrentTime() );
|
||||
|
||||
return "index";
|
||||
}
|
||||
|
||||
@RequestMapping("/jsp")
|
||||
public String jspCheck(Model model) {
|
||||
System.out.println(" /jsp 타는지 ");
|
||||
|
||||
model.addAttribute("name", "name 입니다.");
|
||||
return "index";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.boot.test1.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import com.boot.test1.vo.Account;
|
||||
import com.boot.test1.vo.Authority;
|
||||
|
||||
@Mapper
|
||||
public interface AccountMapper {
|
||||
|
||||
Account readAccount(String id);
|
||||
|
||||
List<String> readAuthorites(String id);
|
||||
|
||||
void insertUser(Account account);
|
||||
|
||||
void insertUserAuthority(Authority authority);
|
||||
|
||||
List<Account> readAllUsers();
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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.boot.test1.mapper.AccountMapper">
|
||||
|
||||
<select id="readAccount" parameterType="String" resultType="com.boot.test1.vo.Account">
|
||||
SELECT * FROM [BSHOP_DATA].dbo.USER_INFO
|
||||
WHERE ID= #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertUser" parameterType="com.boot.test1.vo.Account">
|
||||
INSERT [BSHOP_DATA].dbo.USER_INFO
|
||||
VALUES (
|
||||
#{id},
|
||||
#{password},
|
||||
#{isAccountNonExpired},
|
||||
#{isAccountNonLocked},
|
||||
#{isCredentialsNonExpired},
|
||||
#{isEnabled}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<insert id="insertUserAuthority" parameterType="com.boot.test1.vo.Authority">
|
||||
INSERT INTO [BSHOP_DATA].dbo.AUTHORITY
|
||||
VALUES (
|
||||
#{userName},
|
||||
#{authorityName}
|
||||
)
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.boot.test1.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface TestMapper {
|
||||
String getCurrentTime();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?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.boot.test1.mapper.TestMapper">
|
||||
|
||||
<select id="getCurrentTime" resultType="String">
|
||||
SELECT SYSDATETIME()
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.boot.test1.repo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.boot.test1.mapper.AccountMapper;
|
||||
import com.boot.test1.vo.Account;
|
||||
import com.boot.test1.vo.Authority;
|
||||
|
||||
@Repository
|
||||
public class AccountRepository {
|
||||
|
||||
@Autowired
|
||||
AccountMapper accountMapper;
|
||||
|
||||
public Account save(Account account, Authority authority ) {
|
||||
accountMapper.insertUser(account);
|
||||
accountMapper.insertUserAuthority(authority);
|
||||
return account;
|
||||
}
|
||||
|
||||
public Account findById(String username) {
|
||||
return accountMapper.readAccount(username);
|
||||
}
|
||||
|
||||
public List<String>findauthoritiesbyid(String username){
|
||||
return (List<String>)accountMapper.readAuthorites(username);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.boot.test1.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.boot.test1.repo.AccountRepository;
|
||||
import com.boot.test1.vo.Account;
|
||||
import com.boot.test1.vo.Authority;
|
||||
|
||||
@Service
|
||||
public class AccountService implements UserDetailsService{
|
||||
|
||||
@Autowired
|
||||
AccountRepository accounts;
|
||||
|
||||
@Autowired
|
||||
PasswordEncoder passwordEncoder;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
|
||||
Account account = accounts.findById(username);
|
||||
account.setAuthorities(getAuthorities(username));
|
||||
|
||||
UserDetails userDetails = new UserDetails() {
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
};
|
||||
return account;
|
||||
}
|
||||
|
||||
public Account save(Account account, Authority authority) {
|
||||
|
||||
account.setPassword(passwordEncoder.encode(account.getPassword()));
|
||||
account.setAccountNonExpired(true);
|
||||
account.setAccountNonLocked(true);
|
||||
account.setCredentialsNonExpired(true);
|
||||
account.setEnabled(true);
|
||||
|
||||
return accounts.save(account, authority);
|
||||
}
|
||||
|
||||
private Collection<? extends GrantedAuthority> getAuthorities(String username) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.boot.test1.vo;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
public class Account implements UserDetails{
|
||||
|
||||
private String id;
|
||||
private String password;
|
||||
private boolean isAccountNonExpired;
|
||||
private boolean isAccountNonLocked;
|
||||
private boolean isCredentialsNonExpired;
|
||||
private boolean isEnabled;
|
||||
|
||||
private Collection <? extends GrantedAuthority> authorities;
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
// TODO Auto-generated method stub
|
||||
return this.authorities;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setAccountNonExpired(boolean isAccountNonExpired) {
|
||||
this.isAccountNonExpired = isAccountNonExpired;
|
||||
}
|
||||
|
||||
public void setAccountNonLocked(boolean isAccountNonLocked) {
|
||||
this.isAccountNonLocked = isAccountNonLocked;
|
||||
}
|
||||
|
||||
public void setCredentialsNonExpired(boolean isCredentialsNonExpired) {
|
||||
this.isCredentialsNonExpired = isCredentialsNonExpired;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean isEnabled) {
|
||||
this.isEnabled = isEnabled;
|
||||
}
|
||||
|
||||
public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
|
||||
this.authorities = authorities;
|
||||
}
|
||||
|
||||
|
||||
// UserDetails의 필수 메서드들
|
||||
@Override
|
||||
public String getPassword() {
|
||||
// TODO Auto-generated method stub
|
||||
return this.password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
// TODO Auto-generated method stub
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
// TODO Auto-generated method stub
|
||||
return this.isAccountNonExpired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
// TODO Auto-generated method stub
|
||||
return this.isAccountNonLocked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
// TODO Auto-generated method stub
|
||||
return this.isCredentialsNonExpired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
// TODO Auto-generated method stub
|
||||
return this.isEnabled;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.boot.test1.vo;
|
||||
|
||||
public class Authority {
|
||||
|
||||
private String userName;
|
||||
private String authorityName;
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
public String getAuthorityName() {
|
||||
return authorityName;
|
||||
}
|
||||
public void setAuthorityName(String authorityName) {
|
||||
this.authorityName = authorityName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Authority [userName=" + userName + ", authorityName=" + authorityName + "]";
|
||||
}
|
||||
|
||||
}
|
||||
20
boot_gradle_security/src/main/resources/application_temp.yml
Normal file
20
boot_gradle_security/src/main/resources/application_temp.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
spring:
|
||||
mvc:
|
||||
view:
|
||||
prefix: /WEB-INF/jsp/
|
||||
suffix: .jsp
|
||||
|
||||
datasource:
|
||||
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
url: jdbc:sqlserver://192.168.0.31:1433;instanceName=BSHOP_DATA
|
||||
username: id
|
||||
password: pw
|
||||
|
||||
# jsp파일 reload할때마다 재부팅해야되서 해당설정 추가해주었음.
|
||||
server:
|
||||
servlet:
|
||||
jsp:
|
||||
init-parameters:
|
||||
development: true
|
||||
|
||||
|
||||
66
boot_gradle_security/src/main/webapp/WEB-INF/jsp/index.jsp
Normal file
66
boot_gradle_security/src/main/webapp/WEB-INF/jsp/index.jsp
Normal file
@@ -0,0 +1,66 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Insert title here</title>
|
||||
|
||||
<script type="text/javascript">
|
||||
function login() {
|
||||
if (!$("#mainForm").valid()) {
|
||||
CommonUtil.alertValidationMessage($("#mainForm"));
|
||||
return false;
|
||||
}
|
||||
|
||||
$("#mainForm").submit(function() {
|
||||
if (!$("#mainForm").valid()) {
|
||||
CommonUtil.alertValidationMessage($("#mainForm"));
|
||||
return false;
|
||||
} else {
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1> 로그인 </h1>
|
||||
<form method="POST" id="mainForm" action="/authenticate">
|
||||
<div class="loginForm">
|
||||
<ul>
|
||||
|
||||
<li>id : <input data-val-required="아이디 필드가 필요합니다." data-name="아이디"
|
||||
id="ID" maxlength="15" name="ID" placeholder="아이디를 입력해주세요"
|
||||
type="text" value="" required />
|
||||
</li>
|
||||
|
||||
<li>pw : <input data-val-required="비밀번호 필드가 필요합니다." data-name="비밀번호"
|
||||
id="Password" maxlength="16" name="Password"
|
||||
autocomplete="new-password" placeholder="패스워드를 입력해주세요"
|
||||
type="password" required />
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
<label> <input class="id_save" id="remember-me"
|
||||
name="remember-me" title="Remember Me" type="checkbox" /> Remember Me
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<input type="button" src="/img/login/loginBtn.png" alt="로그인" class="btn" id="btnLogin" onclick="login();" value="전송" />
|
||||
</div>
|
||||
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}">
|
||||
|
||||
</form>
|
||||
|
||||
<br>
|
||||
name : ${name}
|
||||
</body>
|
||||
</html>
|
||||
13
boot_gradle_security/src/main/webapp/WEB-INF/jsp/main.jsp
Normal file
13
boot_gradle_security/src/main/webapp/WEB-INF/jsp/main.jsp
Normal file
@@ -0,0 +1,13 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Insert title here</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1> Main Page 입니다. </h1>
|
||||
</body>
|
||||
</html>
|
||||
13
boot_gradle_security/src/main/webapp/WEB-INF/jsp/success.jsp
Normal file
13
boot_gradle_security/src/main/webapp/WEB-INF/jsp/success.jsp
Normal file
@@ -0,0 +1,13 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Insert title here</title>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>Success</h1>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.boot.test1;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class BootTestApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
4
forCommit.sh
Normal file
4
forCommit.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#! /bin/bash
|
||||
|
||||
echo "workspace -> git remote directory 파일 복사하기"
|
||||
|
||||
Reference in New Issue
Block a user