feat : 사용하지 않는 모듈 제거
This commit is contained in:
32
authorization-server2/.gitignore
vendored
32
authorization-server2/.gitignore
vendored
@@ -1,32 +0,0 @@
|
|||||||
HELP.md
|
|
||||||
.gradle
|
|
||||||
build/
|
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
|
||||||
!**/src/main/**
|
|
||||||
!**/src/test/**
|
|
||||||
|
|
||||||
### STS ###
|
|
||||||
.apt_generated
|
|
||||||
.classpath
|
|
||||||
.factorypath
|
|
||||||
.project
|
|
||||||
.settings
|
|
||||||
.springBeans
|
|
||||||
.sts4-cache
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
|
||||||
.idea
|
|
||||||
*.iws
|
|
||||||
*.iml
|
|
||||||
*.ipr
|
|
||||||
out/
|
|
||||||
|
|
||||||
### NetBeans ###
|
|
||||||
/nbproject/private/
|
|
||||||
/nbbuild/
|
|
||||||
/dist/
|
|
||||||
/nbdist/
|
|
||||||
/.nb-gradle/
|
|
||||||
|
|
||||||
### VS Code ###
|
|
||||||
.vscode/
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'org.springframework.boot' version '2.1.5.RELEASE'
|
|
||||||
id 'java'
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'io.spring.dependency-management'
|
|
||||||
|
|
||||||
group = 'io.bluemoon'
|
|
||||||
version = '0.0.1-SNAPSHOT'
|
|
||||||
sourceCompatibility = '1.8'
|
|
||||||
|
|
||||||
configurations {
|
|
||||||
compileOnly {
|
|
||||||
extendsFrom annotationProcessor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
ext {
|
|
||||||
set('springCloudVersion', 'Greenwich.SR1')
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
|
||||||
implementation 'org.springframework.cloud:spring-cloud-starter-oauth2'
|
|
||||||
// implementation 'org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:2.1.5.RELEASE'
|
|
||||||
implementation 'org.springframework.cloud:spring-cloud-starter-security'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
|
||||||
implementation 'com.squareup.okhttp3:okhttp:3.9.1'
|
|
||||||
implementation 'com.google.code.gson:gson'
|
|
||||||
compileOnly 'org.projectlombok:lombok'
|
|
||||||
runtimeOnly 'mysql:mysql-connector-java'
|
|
||||||
// runtimeOnly 'org.postgresql:postgresql'
|
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencyManagement {
|
|
||||||
imports {
|
|
||||||
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
@@ -1,6 +0,0 @@
|
|||||||
#Fri Jul 05 17:06:35 KST 2019
|
|
||||||
distributionBase=GRADLE_USER_HOME
|
|
||||||
distributionPath=wrapper/dists
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
|
||||||
172
authorization-server2/gradlew
vendored
172
authorization-server2/gradlew
vendored
@@ -1,172 +0,0 @@
|
|||||||
#!/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='"-Xmx64m"'
|
|
||||||
|
|
||||||
# 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
authorization-server2/gradlew.bat
vendored
84
authorization-server2/gradlew.bat
vendored
@@ -1,84 +0,0 @@
|
|||||||
@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="-Xmx64m"
|
|
||||||
|
|
||||||
@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,6 +0,0 @@
|
|||||||
pluginManagement {
|
|
||||||
repositories {
|
|
||||||
gradlePluginPortal()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rootProject.name = 'authorization-server2'
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
|
|
||||||
|
|
||||||
//@EnableResourceServer
|
|
||||||
@SpringBootApplication
|
|
||||||
public class AuthorizationServer2Application {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(AuthorizationServer2Application.class, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.config;
|
|
||||||
|
|
||||||
import io.bluemoon.authorizationserver2.service.user.CustomUserDetailsServiceImpl;
|
|
||||||
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.context.annotation.Primary;
|
|
||||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
|
||||||
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
|
|
||||||
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
|
|
||||||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
|
|
||||||
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
|
|
||||||
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
|
|
||||||
import org.springframework.security.oauth2.provider.ClientDetailsService;
|
|
||||||
import org.springframework.security.oauth2.provider.approval.ApprovalStore;
|
|
||||||
import org.springframework.security.oauth2.provider.approval.JdbcApprovalStore;
|
|
||||||
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
|
|
||||||
import org.springframework.security.oauth2.provider.code.AuthorizationCodeServices;
|
|
||||||
import org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices;
|
|
||||||
import org.springframework.security.oauth2.provider.token.TokenStore;
|
|
||||||
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableAuthorizationServer
|
|
||||||
public class AuthorizationServer2Config extends AuthorizationServerConfigurerAdapter {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ApprovalStore approvalStore;
|
|
||||||
|
|
||||||
private ClientDetailsService clientDetailsService;
|
|
||||||
private AuthenticationManager authenticationManager;
|
|
||||||
|
|
||||||
private DataSource dataSource;
|
|
||||||
private CustomUserDetailsServiceImpl customUserDetailsService;
|
|
||||||
|
|
||||||
public AuthorizationServer2Config(
|
|
||||||
ClientDetailsService clientDetailsService,
|
|
||||||
AuthenticationManager authenticationManager,
|
|
||||||
DataSource dataSource,
|
|
||||||
CustomUserDetailsServiceImpl customUserDetailsService
|
|
||||||
) {
|
|
||||||
this.clientDetailsService = clientDetailsService;
|
|
||||||
this.authenticationManager = authenticationManager;
|
|
||||||
this.dataSource = dataSource;
|
|
||||||
this.customUserDetailsService = customUserDetailsService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
|
|
||||||
security.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
|
|
||||||
endpoints
|
|
||||||
// authentication
|
|
||||||
// 비밀 번호 부여는 AuthenticationManager를 주입해야 켜짐
|
|
||||||
.authenticationManager(authenticationManager)
|
|
||||||
// jdbc token processing
|
|
||||||
.tokenStore(jdbcTokenStore(dataSource))
|
|
||||||
|
|
||||||
// 사용자 세부 정보가 필요할 때
|
|
||||||
.userDetailsService(customUserDetailsService)
|
|
||||||
// approval store
|
|
||||||
.approvalStore(approvalStore)
|
|
||||||
// refresh token
|
|
||||||
.reuseRefreshTokens(true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
|
|
||||||
clients.withClientDetails(clientDetailsService);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public TokenStore jdbcTokenStore(DataSource dataSource) {
|
|
||||||
return new JdbcTokenStore(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Primary
|
|
||||||
public JdbcClientDetailsService jdbcClientDetailsService(DataSource dataSource) {
|
|
||||||
return new JdbcClientDetailsService(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Bean
|
|
||||||
// public AuthorizationCodeServices jdbcAuthorizationCodeServies(DataSource dataSource) {
|
|
||||||
// return new JdbcAuthorizationCodeServices(dataSource);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ApprovalStore jdbcApprovalStore(DataSource dataSource) {
|
|
||||||
return new JdbcApprovalStore(dataSource);
|
|
||||||
}
|
|
||||||
// jwt
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.config;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.core.annotation.Order;
|
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
||||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
|
||||||
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
|
|
||||||
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
|
|
||||||
|
|
||||||
//@Order(SecurityProperties.BASIC_AUTH_ORDER)
|
|
||||||
//@Configuration
|
|
||||||
//@EnableResourceServer
|
|
||||||
// not use
|
|
||||||
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void configure(HttpSecurity http) throws Exception {
|
|
||||||
http
|
|
||||||
.authorizeRequests()
|
|
||||||
.antMatchers("/signIn").permitAll()
|
|
||||||
.antMatchers("/signUp").permitAll()
|
|
||||||
.antMatchers("/signInMiddleWare").permitAll()
|
|
||||||
.antMatchers("/signUpMiddleWare").permitAll()
|
|
||||||
.antMatchers("/projectCreateMiddleWare").permitAll()
|
|
||||||
.anyRequest()
|
|
||||||
.authenticated();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
|
|
||||||
@EnableWebSecurity
|
|
||||||
@Configuration
|
|
||||||
public class WebMvcConfig2 implements WebMvcConfigurer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addViewControllers(ViewControllerRegistry registry) {
|
|
||||||
registry.addViewController("/signIn").setViewName("signIn");
|
|
||||||
registry.addViewController("/signUp").setViewName("signUp");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
||||||
registry.addResourceHandler("/**")
|
|
||||||
.addResourceLocations("/resources -> next depth");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.config;
|
|
||||||
import io.bluemoon.authorizationserver2.service.user.CustomUserDetailsServiceImpl;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.core.annotation.Order;
|
|
||||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
|
||||||
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.EnableWebSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
||||||
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
//@EnableWebSecurity
|
|
||||||
@Order(-1)
|
|
||||||
public class WebSecurity2Config extends WebSecurityConfigurerAdapter {
|
|
||||||
private CustomUserDetailsServiceImpl customUserDetailsService;
|
|
||||||
|
|
||||||
public WebSecurity2Config(
|
|
||||||
CustomUserDetailsServiceImpl customUserDetailsService
|
|
||||||
) {
|
|
||||||
this.customUserDetailsService = customUserDetailsService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Override
|
|
||||||
public AuthenticationManager authenticationManagerBean() throws Exception {
|
|
||||||
return super.authenticationManagerBean();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
|
||||||
auth.authenticationProvider(daoAuthenticationProvider());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
|
||||||
http
|
|
||||||
.csrf().disable().cors().disable()
|
|
||||||
.requestMatchers()
|
|
||||||
.antMatchers("/css/**", "/script/**", "image/**", "/fonts/**", "lib/**")
|
|
||||||
|
|
||||||
.and()
|
|
||||||
.headers().frameOptions().disable()
|
|
||||||
.and()
|
|
||||||
.authorizeRequests()
|
|
||||||
.antMatchers("/css/**", "/script/**", "image/**", "/fonts/**", "lib/**").permitAll()
|
|
||||||
.anyRequest()
|
|
||||||
.authenticated();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public DaoAuthenticationProvider daoAuthenticationProvider() {
|
|
||||||
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
|
|
||||||
daoAuthenticationProvider.setUserDetailsService(customUserDetailsService);
|
|
||||||
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder());
|
|
||||||
return daoAuthenticationProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 패스워드 인코딩 수정
|
|
||||||
// @Bean
|
|
||||||
// @SuppressWarnings("deprecation")
|
|
||||||
// public static NoOpPasswordEncoder passwordEncoder() {
|
|
||||||
// return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public static PasswordEncoder passwordEncoder() {
|
|
||||||
return new BCryptPasswordEncoder();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.controller;
|
|
||||||
|
|
||||||
import io.bluemoon.authorizationserver2.domain.client.OAuthClientDetails;
|
|
||||||
import io.bluemoon.authorizationserver2.domain.oauth.OAuthUser;
|
|
||||||
import io.bluemoon.authorizationserver2.service.user.OAuthUserService;
|
|
||||||
import io.bluemoon.authorizationserver2.utils.APIRequest;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.Principal;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class AuthController {
|
|
||||||
|
|
||||||
private OAuthUserService oAuthUserService;
|
|
||||||
|
|
||||||
public AuthController(
|
|
||||||
OAuthUserService oAuthUserService
|
|
||||||
) {
|
|
||||||
this.oAuthUserService = oAuthUserService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = "/user")
|
|
||||||
public Principal getUser(Principal user) {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/signInMiddleWare")
|
|
||||||
public String signInMiddleWare(HttpServletRequest request) throws IOException {
|
|
||||||
OAuthUser user = requestToUser(request);
|
|
||||||
|
|
||||||
return oAuthUserService.readUser(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/signUpMiddleWare")
|
|
||||||
public OAuthUser signUpMiddleWare(HttpServletRequest request) {
|
|
||||||
|
|
||||||
OAuthUser user = requestToUser(request);
|
|
||||||
|
|
||||||
return oAuthUserService.createUser(user);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/projectCreateMiddleWare")
|
|
||||||
public OAuthClientDetails proejctCreateMiddleWare(HttpServletRequest request) {
|
|
||||||
OAuthClientDetails authClientDetails = new OAuthClientDetails();
|
|
||||||
authClientDetails.setClientId(request.getParameter("client_id"));
|
|
||||||
authClientDetails.setClientSecret(request.getParameter("client_secret"));
|
|
||||||
return oAuthUserService.createProject(authClientDetails);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private OAuthUser requestToUser(HttpServletRequest request) {
|
|
||||||
OAuthUser user = new OAuthUser();
|
|
||||||
user.setUsername(request.getParameter("username"));
|
|
||||||
user.setPassword(request.getParameter("password"));
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.domain.client;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Entity
|
|
||||||
@Table(name = "oauth_client_details")
|
|
||||||
public class OAuthClientDetails {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@Column
|
|
||||||
private String clientId;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String resourceIds;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String clientSecret;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String scope;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String authorizedGrantTypes;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String webServerRedirectUri;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String authorities;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private Integer accessTokenValidity;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private Integer refreshTokenValidity;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String additionalInformation;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String autoApprove;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.domain.client;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface OAuthClientDetailsRepository extends JpaRepository<OAuthClientDetails, String> {
|
|
||||||
|
|
||||||
Optional<OAuthClientDetails> findByClientId(String clientId);
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.domain.oauth;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Entity
|
|
||||||
@Table(name = "oauth_user")
|
|
||||||
public class OAuthUser {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private int id;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String status;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String reSellerId;
|
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "oAuthUser", fetch = FetchType.EAGER)
|
|
||||||
private Collection<OAuthUserRole> userRole;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private LocalDateTime createdAt;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private LocalDateTime updatedAt;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.domain.oauth;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface OAuthUserRepository extends JpaRepository<OAuthUser, Integer> {
|
|
||||||
|
|
||||||
Optional<OAuthUser> findByUsername(String username);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.domain.oauth;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Entity
|
|
||||||
@ToString(exclude = "oAuthUser")
|
|
||||||
@Table(name = "oauth_user_role")
|
|
||||||
public class OAuthUserRole {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private int id;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String role;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private String resourceIds;
|
|
||||||
|
|
||||||
@ManyToOne(optional = false)
|
|
||||||
@JoinColumn(name = "userId")
|
|
||||||
private OAuthUser oAuthUser;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private LocalDateTime createdAt;
|
|
||||||
|
|
||||||
@Column
|
|
||||||
private LocalDateTime updatedAt;
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.domain.oauth;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface OAuthUserRoleRepository extends JpaRepository<OAuthUserRole, Integer> {
|
|
||||||
List<OAuthUserRole> findByOAuthUser(OAuthUser user);
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.domain.user;
|
|
||||||
|
|
||||||
import io.bluemoon.authorizationserver2.domain.oauth.OAuthUser;
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class CustomUserDetails implements UserDetails {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 6396079419309274853L;
|
|
||||||
private Integer id;
|
|
||||||
private String username;
|
|
||||||
private String password;
|
|
||||||
private List<String> userRole;
|
|
||||||
|
|
||||||
public CustomUserDetails(OAuthUser user, List<String> userRoles) {
|
|
||||||
this.id = user.getId();
|
|
||||||
this.username = user.getUsername();
|
|
||||||
this.password = user.getPassword();
|
|
||||||
this.userRole = userRoles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
|
||||||
List<GrantedAuthority> authorities = new ArrayList<>();
|
|
||||||
for (String role: userRole) {
|
|
||||||
authorities.add(new SimpleGrantedAuthority(role));
|
|
||||||
}
|
|
||||||
return authorities;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAccountNonExpired() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAccountNonLocked() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCredentialsNonExpired() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.service.user;
|
|
||||||
|
|
||||||
import io.bluemoon.authorizationserver2.domain.oauth.OAuthUser;
|
|
||||||
import io.bluemoon.authorizationserver2.domain.oauth.OAuthUserRepository;
|
|
||||||
import io.bluemoon.authorizationserver2.domain.oauth.OAuthUserRole;
|
|
||||||
import io.bluemoon.authorizationserver2.domain.oauth.OAuthUserRoleRepository;
|
|
||||||
import io.bluemoon.authorizationserver2.domain.user.*;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CustomUserDetailsServiceImpl implements UserDetailsService {
|
|
||||||
|
|
||||||
// User Info
|
|
||||||
private OAuthUserRepository oAuthUserRepository;
|
|
||||||
private OAuthUserRoleRepository oAuthUserRoleRepository;
|
|
||||||
|
|
||||||
public CustomUserDetailsServiceImpl(
|
|
||||||
OAuthUserRepository oAuthUserRepository,
|
|
||||||
OAuthUserRoleRepository oAuthUserRoleRepository
|
|
||||||
) {
|
|
||||||
this.oAuthUserRepository = oAuthUserRepository;
|
|
||||||
this.oAuthUserRoleRepository = oAuthUserRoleRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
|
||||||
System.out.println("why?????????????"+username);
|
|
||||||
Optional<OAuthUser> user = oAuthUserRepository.findByUsername(username);
|
|
||||||
if (user.isPresent()) {
|
|
||||||
System.out.println(user);
|
|
||||||
List<OAuthUserRole> userRoles = oAuthUserRoleRepository.findByOAuthUser(user.get());
|
|
||||||
System.out.println(userRoles);
|
|
||||||
System.out.println("---------------------------");
|
|
||||||
List<String> urs = new ArrayList<>();
|
|
||||||
for (OAuthUserRole ur : userRoles) {
|
|
||||||
urs.add(ur.getRole());
|
|
||||||
}
|
|
||||||
|
|
||||||
CustomUserDetails userDetail = new CustomUserDetails(user.get(), urs);
|
|
||||||
return userDetail;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
throw new UsernameNotFoundException("UsernameNotFound[" + username + "]");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User role check
|
|
||||||
* @param user
|
|
||||||
* @param userRole
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
// private CustomUserDetails createUser(User user, List<UserRole> userRole) {
|
|
||||||
// CustomUserDetails userDetail =
|
|
||||||
//
|
|
||||||
//// if (userDetail.getSocial_type().getVaule().equals("FACEBOOK")) {
|
|
||||||
//// userDetail.setRoles(Arrays.asList("ROLE_FACEBOOK"));
|
|
||||||
//// } else {
|
|
||||||
//// userDetail.setRoles(Arrays.asList("ROLE_USER"));
|
|
||||||
//// }
|
|
||||||
// return userDetail;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.service.user;
|
|
||||||
|
|
||||||
import io.bluemoon.authorizationserver2.domain.client.OAuthClientDetails;
|
|
||||||
import io.bluemoon.authorizationserver2.domain.oauth.OAuthUser;
|
|
||||||
import io.bluemoon.authorizationserver2.utils.APIRequest;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public interface OAuthUserService {
|
|
||||||
OAuthUser createUser(OAuthUser user);
|
|
||||||
|
|
||||||
String readUser(OAuthUser user) throws IOException;
|
|
||||||
|
|
||||||
OAuthClientDetails createProject(OAuthClientDetails clientDetails);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.service.user;
|
|
||||||
|
|
||||||
import io.bluemoon.authorizationserver2.domain.client.OAuthClientDetails;
|
|
||||||
import io.bluemoon.authorizationserver2.domain.client.OAuthClientDetailsRepository;
|
|
||||||
import io.bluemoon.authorizationserver2.domain.oauth.OAuthUser;
|
|
||||||
import io.bluemoon.authorizationserver2.domain.oauth.OAuthUserRepository;
|
|
||||||
import io.bluemoon.authorizationserver2.domain.oauth.OAuthUserRoleRepository;
|
|
||||||
import io.bluemoon.authorizationserver2.utils.APIRequest;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class OAuthUserServiceImpl implements OAuthUserService {
|
|
||||||
|
|
||||||
private OAuthUserRepository userRepository;
|
|
||||||
private OAuthUserRoleRepository userRoleRepository;
|
|
||||||
private PasswordEncoder passwordEncoder;
|
|
||||||
private OAuthClientDetailsRepository oAuthClientDetailsRepository;
|
|
||||||
|
|
||||||
public OAuthUserServiceImpl(
|
|
||||||
OAuthUserRepository userRepository,
|
|
||||||
OAuthUserRoleRepository userRoleRepository,
|
|
||||||
PasswordEncoder passwordEncoder,
|
|
||||||
OAuthClientDetailsRepository oAuthClientDetailsRepository
|
|
||||||
) {
|
|
||||||
this.userRepository = userRepository;
|
|
||||||
this.userRoleRepository = userRoleRepository;
|
|
||||||
this.passwordEncoder = passwordEncoder;
|
|
||||||
this.oAuthClientDetailsRepository = oAuthClientDetailsRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OAuthUser createUser(OAuthUser user) {
|
|
||||||
// 중복 체크
|
|
||||||
user.setPassword(passwordEncoder.encode(user.getPassword()));
|
|
||||||
return userRepository.saveAndFlush(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String readUser(OAuthUser user) throws IOException {
|
|
||||||
Optional<OAuthUser> optionalOAuthUser =
|
|
||||||
userRepository.findByUsername(user.getUsername());
|
|
||||||
|
|
||||||
if (optionalOAuthUser.isPresent()) {
|
|
||||||
|
|
||||||
if (passwordEncoder.matches(user.getPassword(), optionalOAuthUser.get().getPassword())) {
|
|
||||||
// client id
|
|
||||||
Optional<OAuthClientDetails> optionalOAuthClientDetails = oAuthClientDetailsRepository.findByClientId(user.getUsername());
|
|
||||||
|
|
||||||
if (optionalOAuthClientDetails.isPresent()) {
|
|
||||||
// token 발급
|
|
||||||
Map<String, Object> userInfo = new HashMap<>();
|
|
||||||
userInfo.put("grant_type", "password");
|
|
||||||
userInfo.put("username", user.getUsername());
|
|
||||||
userInfo.put("password", user.getPassword());
|
|
||||||
|
|
||||||
Map<String, Object> authInfo = new HashMap<>();
|
|
||||||
authInfo.put("client_id", optionalOAuthClientDetails.get().getClientId());
|
|
||||||
authInfo.put("client_secret", "1234");
|
|
||||||
|
|
||||||
APIRequest.ResponseWrapper responseWrapper = APIRequest.getIRequestExecutor().createOAuthToken(userInfo, authInfo);
|
|
||||||
|
|
||||||
return responseWrapper.getBody();
|
|
||||||
|
|
||||||
// return optionalOAuthClientDetails.get();
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
// if (optionalOAuthClientDetails.isPresent()) {
|
|
||||||
// System.out.println(optionalOAuthClientDetails.get());
|
|
||||||
// } else {
|
|
||||||
// System.out.println(user.getUsername());
|
|
||||||
// System.out.println(user.getPassword());
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public OAuthClientDetails createProject(OAuthClientDetails clientDetails) {
|
|
||||||
clientDetails.setClientSecret(passwordEncoder.encode(clientDetails.getClientSecret()));
|
|
||||||
return oAuthClientDetailsRepository.save(clientDetails);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2.utils;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import lombok.Getter;
|
|
||||||
import okhttp3.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class APIRequest {
|
|
||||||
|
|
||||||
private static IRequestExecutor iRequestExecutor = new DefaultRequestExecutor();
|
|
||||||
|
|
||||||
public static IRequestExecutor getIRequestExecutor() {
|
|
||||||
return iRequestExecutor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IRequestExecutor {
|
|
||||||
ResponseWrapper createOAuthToken(Map userInfo, Map authInfo) throws IOException;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class DefaultRequestExecutor implements IRequestExecutor {
|
|
||||||
static okhttp3.OkHttpClient client = null;
|
|
||||||
static void init() {
|
|
||||||
client = new okhttp3.OkHttpClient();
|
|
||||||
}
|
|
||||||
static {
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResponseWrapper createOAuthToken(Map userInfo, Map authInfo) throws IOException {
|
|
||||||
String url = "http://localhost:8081/auth/oauth/token";
|
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
||||||
RequestBody formBody = new FormBody.Builder()
|
|
||||||
.add("grant_type", userInfo.get("grant_type").toString())
|
|
||||||
.add("username", userInfo.get("username").toString())
|
|
||||||
.add("password", userInfo.get("password").toString())
|
|
||||||
.build();
|
|
||||||
// String jsonString = gson.toJson(userInfo);
|
|
||||||
// RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), jsonString);
|
|
||||||
Request request = new Request.Builder()
|
|
||||||
.url(url)
|
|
||||||
.addHeader("Authorization", Credentials.basic(authInfo.get("client_id").toString(),authInfo.get("client_secret").toString()))
|
|
||||||
.post(formBody)
|
|
||||||
// .header("Content-type", "application/json")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Call call = client.newCall(request);
|
|
||||||
Response response = call.execute();
|
|
||||||
ResponseWrapper result = new ResponseWrapper(response.body().string(), convertToString(response.headers()));
|
|
||||||
System.out.println("----------===================------------");
|
|
||||||
System.out.println(result.getBody());
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String convertToString(Object input) {
|
|
||||||
if (input == null) {
|
|
||||||
return "null";
|
|
||||||
} else if (input instanceof Map) {
|
|
||||||
Gson gson = new GsonBuilder()
|
|
||||||
.excludeFieldsWithModifiers(Modifier.STATIC)
|
|
||||||
.excludeFieldsWithModifiers(Modifier.PROTECTED)
|
|
||||||
.disableHtmlEscaping()
|
|
||||||
.create();
|
|
||||||
return gson.toJson((Map)input);
|
|
||||||
} else if (input instanceof List) {
|
|
||||||
Gson gson = new GsonBuilder()
|
|
||||||
.excludeFieldsWithModifiers(Modifier.STATIC)
|
|
||||||
.excludeFieldsWithModifiers(Modifier.PROTECTED)
|
|
||||||
.disableHtmlEscaping()
|
|
||||||
.create();
|
|
||||||
return gson.toJson((List)input);
|
|
||||||
} else {
|
|
||||||
return input.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public static class ResponseWrapper {
|
|
||||||
private String body;
|
|
||||||
private String header;
|
|
||||||
|
|
||||||
public ResponseWrapper(String body, String header) {
|
|
||||||
this.body = body;
|
|
||||||
this.header = header;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
server.port=8081
|
|
||||||
server.servlet.context-path=/uaa
|
|
||||||
|
|
||||||
security.oauth2.authorization.check-token-access=isAuthenticated()
|
|
||||||
|
|
||||||
spring.main.allow-bean-definition-overriding=true
|
|
||||||
spring.datasource.url=jdbc:mysql://127.0.0.1/oauth2?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&serverTimezone=UTC
|
|
||||||
spring.datasource.username=root
|
|
||||||
spring.datasource.password=bluemoon
|
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
|
||||||
spring.datasource.platform=schema
|
|
||||||
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDB53Dialect
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
spring.jpa.database = MYSQL
|
|
||||||
spring.jpa.hibernate.ddl-auto=update
|
|
||||||
spring.jpa.generate-ddl=true
|
|
||||||
spring.jpa.show-sql=true
|
|
||||||
#spring.jpa.generate-ddl=false
|
|
||||||
#spring.jpa.hibernate.ddl-auto=none
|
|
||||||
|
|
||||||
# jwt
|
|
||||||
#security.oauth2.resource.prefer-token-info=false
|
|
||||||
|
|
||||||
logging.level.web=debug
|
|
||||||
spring.http.log-request-details=true
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
use oauth2;
|
|
||||||
-- used in tests that use HSQL
|
|
||||||
create table oauth_client_details (
|
|
||||||
client_id VARCHAR(255) primary key,
|
|
||||||
resource_ids VARCHAR(255),
|
|
||||||
client_secret VARCHAR(255),
|
|
||||||
scope VARCHAR(255),
|
|
||||||
authorized_grant_types VARCHAR(255),
|
|
||||||
web_server_redirect_uri VARCHAR(255),
|
|
||||||
authorities VARCHAR(255),
|
|
||||||
access_token_validity INTEGER,
|
|
||||||
refresh_token_validity INTEGER,
|
|
||||||
additional_information VARCHAR(4096),
|
|
||||||
autoapprove VARCHAR(255)
|
|
||||||
) DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
create table oauth_client_token (
|
|
||||||
token_id VARCHAR(255),
|
|
||||||
token BLOB,
|
|
||||||
authentication_id VARCHAR(255) PRIMARY KEY,
|
|
||||||
user_name VARCHAR(255),
|
|
||||||
client_id VARCHAR(255)
|
|
||||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
create table oauth_access_token (
|
|
||||||
token_id VARCHAR(255),
|
|
||||||
token BLOB,
|
|
||||||
authentication_id VARCHAR(255) PRIMARY KEY,
|
|
||||||
user_name VARCHAR(255),
|
|
||||||
client_id VARCHAR(255),
|
|
||||||
authentication BLOB,
|
|
||||||
refresh_token VARCHAR(255)
|
|
||||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8;;
|
|
||||||
|
|
||||||
create table oauth_refresh_token (
|
|
||||||
token_id VARCHAR(255),
|
|
||||||
token BLOB,
|
|
||||||
authentication BLOB
|
|
||||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
create table oauth_code (
|
|
||||||
code VARCHAR(255), authentication BLOB
|
|
||||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
create table oauth_approvals (
|
|
||||||
userId VARCHAR(255),
|
|
||||||
clientId VARCHAR(255),
|
|
||||||
scope VARCHAR(255),
|
|
||||||
status VARCHAR(10),
|
|
||||||
expiresAt TIMESTAMP,
|
|
||||||
lastModifiedAt TIMESTAMP
|
|
||||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
|
|
||||||
-- customized oauth_client_details table
|
|
||||||
create table ClientDetails (
|
|
||||||
appId VARCHAR(255) PRIMARY KEY,
|
|
||||||
resourceIds VARCHAR(255),
|
|
||||||
appSecret VARCHAR(255),
|
|
||||||
scope VARCHAR(255),
|
|
||||||
grantTypes VARCHAR(255),
|
|
||||||
redirectUrl VARCHAR(255),
|
|
||||||
authorities VARCHAR(255),
|
|
||||||
access_token_validity INTEGER,
|
|
||||||
refresh_token_validity INTEGER,
|
|
||||||
additionalInformation VARCHAR(4096),
|
|
||||||
autoApproveScopes VARCHAR(255)
|
|
||||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
CREATE TABLE `user` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`user_name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
|
|
||||||
`password` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
|
||||||
`user_type` char(1) COLLATE utf8_unicode_ci NOT NULL,
|
|
||||||
`reg_date` datetime NOT NULL,
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `user_name` (`user_name`)
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
|
|
||||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<form role="form" th:action="@{/signInMiddleWare}" method="post">
|
|
||||||
<div class="form-group row">
|
|
||||||
<label for="username" class="col-sm-2 col-form-label">ID</label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<input type="text" class="form-control" id="username" placeholder="id" name="username">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="form-group row">
|
|
||||||
<label for="password" class="col-sm-2 col-form-label">Password</label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<input type="password" class="form-control" id="password" placeholder="password" name="password">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<input type="hidden" id="csrf_token" name="${_csrf.parameterName}" value="${_csrf.token}"/>
|
|
||||||
<button type="submit" class="btn btn-primary">Sign in</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
|
||||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
|
||||||
</html>
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
|
|
||||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<form role="form" th:action="@{/signUpMiddleWare}" method="post">
|
|
||||||
<div class="form-group row">
|
|
||||||
<label for="username" class="col-sm-2 col-form-label">ID</label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<input type="text" class="form-control" id="username" placeholder="id" name="username">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="form-group row">
|
|
||||||
<label for="password" class="col-sm-2 col-form-label">Password</label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<input type="password" class="form-control" id="password" placeholder="password" name="password">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<input type="hidden" id="csrf_token" name="${_csrf.parameterName}" value="${_csrf.token}"/>
|
|
||||||
<button type="submit" class="btn btn-primary">Sign in</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
|
||||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
|
||||||
</html>
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package io.bluemoon.authorizationserver2;
|
|
||||||
|
|
||||||
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 AuthorizationServer2ApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
## 설명 *() 괄호 안의 내용은 프로젝트 이름*
|
## 설명 *() 괄호 안의 내용은 프로젝트 이름*
|
||||||
- 스프링 클라우드를 사용해서 만든 OAuth2 SSO 시스템 개발. *(gateway-zuul, Authorization-server)*
|
- 스프링 클라우드를 사용해서 만든 OAuth2 SSO 시스템 개발. *(gateway-zuul, Authorization-server)*
|
||||||
- 스프링 클라우들 사용해서 만들 OAuth 2.0 시스템 *(zuul-oauth2, Authorization-server2)*
|
|
||||||
|
|
||||||
## 환경
|
## 환경
|
||||||
- java 8
|
- java 8
|
||||||
|
|||||||
@@ -66,20 +66,7 @@ public class TestServiceApplication {
|
|||||||
public String helloMk2Secret(Principal principal) {
|
public String helloMk2Secret(Principal principal) {
|
||||||
return principal == null ? "hello anonymous" : "heelo" + principal.getName();
|
return principal == null ? "hello anonymous" : "heelo" + principal.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "test")
|
|
||||||
@ResponseBody
|
|
||||||
public String test() {
|
|
||||||
return "test";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@RestController("/tests")
|
|
||||||
public static class TestController2 {
|
|
||||||
@RequestMapping(method = RequestMethod.DELETE)
|
|
||||||
public void test(@RequestParam String test) {
|
|
||||||
System.out.println(test);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@@ -14,3 +15,7 @@ public class TestServiceApplicationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
32
zuul-oauth2/.gitignore
vendored
32
zuul-oauth2/.gitignore
vendored
@@ -1,32 +0,0 @@
|
|||||||
HELP.md
|
|
||||||
.gradle
|
|
||||||
build/
|
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
|
||||||
!**/src/main/**
|
|
||||||
!**/src/test/**
|
|
||||||
|
|
||||||
### STS ###
|
|
||||||
.apt_generated
|
|
||||||
.classpath
|
|
||||||
.factorypath
|
|
||||||
.project
|
|
||||||
.settings
|
|
||||||
.springBeans
|
|
||||||
.sts4-cache
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
|
||||||
.idea
|
|
||||||
*.iws
|
|
||||||
*.iml
|
|
||||||
*.ipr
|
|
||||||
out/
|
|
||||||
|
|
||||||
### NetBeans ###
|
|
||||||
/nbproject/private/
|
|
||||||
/nbbuild/
|
|
||||||
/dist/
|
|
||||||
/nbdist/
|
|
||||||
/.nb-gradle/
|
|
||||||
|
|
||||||
### VS Code ###
|
|
||||||
.vscode/
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'org.springframework.boot' version '2.1.5.RELEASE'
|
|
||||||
id 'java'
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'io.spring.dependency-management'
|
|
||||||
|
|
||||||
group = 'io.bluemoon'
|
|
||||||
version = '0.0.1-SNAPSHOT'
|
|
||||||
sourceCompatibility = '1.8'
|
|
||||||
|
|
||||||
configurations {
|
|
||||||
compileOnly {
|
|
||||||
extendsFrom annotationProcessor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
ext {
|
|
||||||
set('springCloudVersion', 'Greenwich.SR1')
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
|
||||||
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-zuul'
|
|
||||||
compileOnly 'org.projectlombok:lombok'
|
|
||||||
annotationProcessor 'org.projectlombok:lombok'
|
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencyManagement {
|
|
||||||
imports {
|
|
||||||
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BIN
zuul-oauth2/gradle/wrapper/gradle-wrapper.jar
vendored
BIN
zuul-oauth2/gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
@@ -1,6 +0,0 @@
|
|||||||
#Tue Jul 02 16:45:08 KST 2019
|
|
||||||
distributionBase=GRADLE_USER_HOME
|
|
||||||
distributionPath=wrapper/dists
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
|
|
||||||
172
zuul-oauth2/gradlew
vendored
172
zuul-oauth2/gradlew
vendored
@@ -1,172 +0,0 @@
|
|||||||
#!/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='"-Xmx64m"'
|
|
||||||
|
|
||||||
# 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
zuul-oauth2/gradlew.bat
vendored
84
zuul-oauth2/gradlew.bat
vendored
@@ -1,84 +0,0 @@
|
|||||||
@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="-Xmx64m"
|
|
||||||
|
|
||||||
@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,6 +0,0 @@
|
|||||||
pluginManagement {
|
|
||||||
repositories {
|
|
||||||
gradlePluginPortal()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rootProject.name = 'zuul-oauth2'
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package io.bluemoon.zuuloauth2;
|
|
||||||
|
|
||||||
import io.bluemoon.zuuloauth2.utils.UserContextInterceptor;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
|
||||||
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
import java.security.Principal;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
@EnableZuulProxy
|
|
||||||
public class ZuulOauth2Application {
|
|
||||||
|
|
||||||
@LoadBalanced
|
|
||||||
@Bean
|
|
||||||
public RestTemplate getRestTemplate() {
|
|
||||||
// RestTemplate template = new RestTemplate();
|
|
||||||
// List interceptors = template.getInterceptors();
|
|
||||||
// if (interceptors == null) {
|
|
||||||
// template.setInterceptors(Collections.singletonList(new UserContextInterceptor()));
|
|
||||||
// } else {
|
|
||||||
// interceptors.add(new UserContextInterceptor());
|
|
||||||
// template.setInterceptors(interceptors);
|
|
||||||
// }
|
|
||||||
// return template;
|
|
||||||
return new RestTemplate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
@RequestMapping("/")
|
|
||||||
public static class TestController {
|
|
||||||
@RequestMapping(method = RequestMethod.GET)
|
|
||||||
public String test(Principal principal) {
|
|
||||||
System.out.println(principal.getName());
|
|
||||||
System.out.println(principal.toString());
|
|
||||||
return "aa";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(ZuulOauth2Application.class, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package io.bluemoon.zuuloauth2.filter;
|
|
||||||
|
|
||||||
import com.netflix.zuul.ZuulFilter;
|
|
||||||
import com.netflix.zuul.context.RequestContext;
|
|
||||||
import com.netflix.zuul.exception.ZuulException;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class AuthenticationFilter extends ZuulFilter {
|
|
||||||
private static final int FILTER_ORDER = 2;
|
|
||||||
private static final boolean SHOULD_FILTER = false;
|
|
||||||
|
|
||||||
private FilterUtils filterUtils;
|
|
||||||
private RestTemplate restTemplate;
|
|
||||||
|
|
||||||
public AuthenticationFilter(
|
|
||||||
FilterUtils filterUtils,
|
|
||||||
RestTemplate restTemplate
|
|
||||||
) {
|
|
||||||
this.filterUtils = filterUtils;
|
|
||||||
this.restTemplate = restTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String filterType() {
|
|
||||||
return FilterUtils.PRE_FILTER_TYPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int filterOrder() {
|
|
||||||
return FILTER_ORDER;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldFilter() {
|
|
||||||
return SHOULD_FILTER;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isAuthTokenPresent() {
|
|
||||||
if (filterUtils.getAuthToken() != null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object run() throws ZuulException {
|
|
||||||
RequestContext ctx = RequestContext.getCurrentContext();
|
|
||||||
log.debug("what???{}", ctx);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
package io.bluemoon.zuuloauth2.filter;
|
|
||||||
|
|
||||||
import com.netflix.zuul.context.RequestContext;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class FilterUtils {
|
|
||||||
public static final String CORRELATION_ID = "tmx-correlation-id";
|
|
||||||
public static final String AUTH_TOKEN = "Authorization";
|
|
||||||
public static final String USER_ID = "tmx-user-id";
|
|
||||||
public static final String ORG_ID = "tmx-org-id";
|
|
||||||
public static final String PRE_FILTER_TYPE = "pre";
|
|
||||||
public static final String POST_FILTER_TYPE = "post";
|
|
||||||
public static final String ROUTE_FILTER_TYPE = "route";
|
|
||||||
|
|
||||||
public String getCorrelationId() {
|
|
||||||
RequestContext ctx = RequestContext.getCurrentContext();
|
|
||||||
|
|
||||||
if (ctx.getRequest().getHeader(CORRELATION_ID) != null) {
|
|
||||||
return ctx.getRequest().getHeader(CORRELATION_ID);
|
|
||||||
} else {
|
|
||||||
return ctx.getZuulRequestHeaders().get(CORRELATION_ID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCorrelationId(String correlationId) {
|
|
||||||
RequestContext ctx = RequestContext.getCurrentContext();
|
|
||||||
ctx.addZuulRequestHeader(CORRELATION_ID, correlationId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final String getOrgId() {
|
|
||||||
RequestContext ctx = RequestContext.getCurrentContext();
|
|
||||||
if (ctx.getRequest().getHeader(ORG_ID) != null) {
|
|
||||||
return ctx.getRequest().getHeader(ORG_ID);
|
|
||||||
} else {
|
|
||||||
return ctx.getZuulRequestHeaders().get(ORG_ID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrgId(String orgId) {
|
|
||||||
RequestContext ctx = RequestContext.getCurrentContext();
|
|
||||||
ctx.addZuulRequestHeader(ORG_ID, orgId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final String getUserId() {
|
|
||||||
RequestContext ctx = RequestContext.getCurrentContext();
|
|
||||||
if (ctx.getRequest().getHeader(USER_ID) != null) {
|
|
||||||
return ctx.getRequest().getHeader(USER_ID);
|
|
||||||
} else {
|
|
||||||
return ctx.getZuulRequestHeaders().get(USER_ID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserId(String userId) {
|
|
||||||
RequestContext ctx = RequestContext.getCurrentContext();
|
|
||||||
ctx.addZuulRequestHeader(USER_ID, userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAuthToken() {
|
|
||||||
RequestContext ctx = RequestContext.getCurrentContext();
|
|
||||||
return ctx.getRequest().getHeader(AUTH_TOKEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getServiceId() {
|
|
||||||
RequestContext ctx = RequestContext.getCurrentContext();
|
|
||||||
|
|
||||||
if (ctx.get("serviceId")==null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return ctx.get("serviceId").toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package io.bluemoon.zuuloauth2.utils;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class UserContext {
|
|
||||||
public static final String CORREATION_ID = "tmx-correlation-id";
|
|
||||||
public static final String AUTH_TOKEN = "Authorization";
|
|
||||||
public static final String USER_ID = "tmx-user-id";
|
|
||||||
public static final String ORG_ID = "tmx-org-id";
|
|
||||||
|
|
||||||
private String correlationId;
|
|
||||||
private String authToken;
|
|
||||||
private String userId;
|
|
||||||
private String orgId;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package io.bluemoon.zuuloauth2.utils;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.servlet.*;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class UserContextFilter implements Filter {
|
|
||||||
@Override
|
|
||||||
public void init(FilterConfig filterConfig) throws ServletException {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
|
||||||
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
|
||||||
log.debug("I am entering the licensing service id with auth token : ", httpServletRequest.getHeader("Authorization"));
|
|
||||||
|
|
||||||
UserContextHolder.getContext().setCorrelationId(httpServletRequest.getHeader(UserContext.CORREATION_ID));
|
|
||||||
UserContextHolder.getContext().setUserId(httpServletRequest.getHeader(UserContext.USER_ID));
|
|
||||||
UserContextHolder.getContext().setAuthToken(httpServletRequest.getHeader(UserContext.AUTH_TOKEN));
|
|
||||||
UserContextHolder.getContext().setOrgId(httpServletRequest.getHeader(UserContext.ORG_ID));
|
|
||||||
|
|
||||||
chain.doFilter(httpServletRequest, response);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package io.bluemoon.zuuloauth2.utils;
|
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
public class UserContextHolder {
|
|
||||||
private static final ThreadLocal<UserContext> userContext = new ThreadLocal<UserContext>();
|
|
||||||
|
|
||||||
public static final UserContext getContext() {
|
|
||||||
UserContext context = userContext.get();
|
|
||||||
|
|
||||||
if (context == null) {
|
|
||||||
context = createEmptyContext();
|
|
||||||
userContext.set(context);
|
|
||||||
}
|
|
||||||
return userContext.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final void setContext(UserContext context) {
|
|
||||||
Assert.notNull(context, "Only non-null UserContext instances are permitted");
|
|
||||||
userContext.set(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final UserContext createEmptyContext() {
|
|
||||||
return new UserContext();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package io.bluemoon.zuuloauth2.utils;
|
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.HttpRequest;
|
|
||||||
import org.springframework.http.client.ClientHttpRequestExecution;
|
|
||||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
|
||||||
import org.springframework.http.client.ClientHttpResponse;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class UserContextInterceptor implements ClientHttpRequestInterceptor {
|
|
||||||
@Override
|
|
||||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
|
|
||||||
|
|
||||||
HttpHeaders headers = request.getHeaders();
|
|
||||||
headers.add(UserContext.CORREATION_ID, UserContextHolder.getContext().getCorrelationId());
|
|
||||||
headers.add(UserContext.AUTH_TOKEN, UserContextHolder.getContext().getAuthToken());
|
|
||||||
|
|
||||||
return execution.execute(request, body);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
server.port=8765
|
|
||||||
|
|
||||||
zuul.sensitive-headers=
|
|
||||||
|
|
||||||
zuul.routes.mk2-service.path=/api/**
|
|
||||||
zuul.routes.mk2-service.url=http://127.0.0.1:8082/api
|
|
||||||
zuul.routes.mk2-service.sensitive-headers=
|
|
||||||
#zuul.routes.mk2-service.sensitive-headers=Cookie,Set-Cookie,Authorization
|
|
||||||
|
|
||||||
zuul.routes.mk2-oauth.path=/auth/**
|
|
||||||
#zuul.routes.mk2-oauth.url=https://59a7bc58.ngrok.io
|
|
||||||
zuul.routes.mk2-oauth.url=http://localhost:8081/auth
|
|
||||||
zuul.routes.mk2-oauth.sensitive-headers=
|
|
||||||
#zuul.routes.mk2-oauth.sensitive-headers=Cookie,Set-Cookie,Authorization
|
|
||||||
#zuul.routes.mk2-oauth.path=/mk2auth/**
|
|
||||||
|
|
||||||
|
|
||||||
logging.level.web=debug
|
|
||||||
spring.http.log-request-details=true
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package io.bluemoon.zuuloauth2;
|
|
||||||
|
|
||||||
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 ZuulOauth2ApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user